Skip to content

Customizing macros

Wang Renxin edited this page Jul 9, 2022 · 4 revisions

Some mechanisms of MY-BASIC can be configured by macros; some features can be disabled by macros as well.

Public

MB_SIMPLE_ARRAY

Enabled by default. An entire array uses a unified type mark, which means there are only two kinds of array: string and real_t.

Disable this macro if you would like to store generic type values in an array including int_t, real_t, usertype, etc. Besides, array of string is still another type. Note non simple array requires extra memory to store type mark of each element.

MB_ENABLE_ARRAY_REF

Enabled by default. Compiles with referenced array if this macro defined, otherwise compiles as value type array.

MB_MAX_DIMENSION_COUNT

Defined as 4 by default. Change this to support arrays of bigger maximum dimensions. Note it cannot be greater than the maximum number which an unsigned char precision can hold.

MB_ENABLE_COLLECTION_LIB

Enabled by default. Compiles including LIST and DICT libraries if this macro is defined.

MB_ENABLE_USERTYPE_REF

Enabled by default. Compiles with referenced usertype support if this macro defined.

MB_ENABLE_ALIVE_CHECKING_ON_USERTYPE_REF

Enabled by default. Compiles with alive object checking functionality on referenced usertype if this macro defined.

MB_ENABLE_CLASS

Enabled by default. Compiles with class (prototype) support if this macro defined.

MB_ENABLE_LAMBDA

Enabled by default. Compiles with Lambda (anonymous function) support if this macro defined.

MB_ENABLE_MODULE

Enabled by default. Compiles with module (namespace) support if this macro defined. Use IMPORT "@xxx" to import a module, and all symbols in that module could be used without the module prefix.

MB_ENABLE_UNICODE

Enabled by default. Compiles with UTF8 manipulation ability if this macro is defined, to handle UTF8 string properly with functions such as LEN, LEFT, RIGHT, MID, etc.

MB_ENABLE_UNICODE_ID

Enabled by default. Compiles with UTF8 token support if this macro defined, this feature requires MB_ENABLE_UNICODE enabled.

MB_ENABLE_FORK

Enabled by default. Compiles with fork support if this macro defined.

MB_GC_GARBAGE_THRESHOLD

Defined as 16 by default. It will trigger a sweep-collect GC cycle when such number of deallocation occurred.

MB_ENABLE_ALLOC_STAT

Enabled by default. Use MEM to tell how much memory in bytes is allocated by MY-BASIC. Note statistics of each allocation takes sizeof(intptr_t) more bytes memory to store meta data.

MB_ENABLE_SOURCE_TRACE

Enabled by default. MY-BASIC can tell where it goes in source code when an error occurs with this macro enabled.

Disable this to reduce some memory occupation. Only do this on memory sensitive systems.

MB_ENABLE_STACK_TRACE

Enabled by default. MY-BASIC will record stack frames including sub routines and native functions if this macro defined.

MB_ENABLE_FULL_ERROR

Enabled by default. Prompts detailed error message. Otherwise all error types will prompts a uniformed "Error occurred" message. However, it's always possible to get specific error type by checking error code in the callback.

MB_CONVERT_TO_INT_LEVEL

Describes how to deal with Real numbers after an expression is evaluated. Just leave it a Real if it's defined as MB_CONVERT_TO_INT_LEVEL_NONE; otherwise try to convert it to an Integer if it doesn't contains decimal part if it's defined as MB_CONVERT_TO_INT_LEVEL_ALL. Also you could use the mb_convert_to_int_if_posible macro to deal with an mb_value_t in your own BASIC functions.

MB_PRINT_INPUT_PROMPT Enabled by default. Prefers to output the specified input prompt to the interpreter's output function.

MB_PRINT_INPUT_CONTENT Disabled by default. Prefers to output the inputted content to the interpreter's output function.

MB_PREFER_SPEED

Enabled by default. Prefers running speed over space occupation as possible. Disable this to reduce memory footprint.

MB_COMPACT_MODE

Enabled by default. C struct may use a compact memory layout.

This might cause some strange pointer accessing bugs with some compilers (for example Some MCU compilers). Try disable this if you met any strange behaviours.

Protected

_WARNING_AS_ERROR

Defined as 0 by default.

Define this macro as 1 in my_basic.c to treat warnings as error, or they will be ignored silently.

Something like divide by zero, wrong typed arguments passed will trigger warnings.

_HT_ARRAY_SIZE_DEFAULT

Defined as 193 by default. Change this in my_basic.c to resize the hash tables buckets. Smaller value will reduce some memory occupation, size of hash table will influence tokenization and parsing time during loading, won't influence running performance.

_SINGLE_SYMBOL_MAX_LENGTH

Defined as 128 by default. Max length of a lexical symbol.

Not pre-defined

MB_DOUBLE_FLOAT

Add this macro to redefine real_t with double or other precisions instead of float.

MB_MANUAL_REAL_FORMATTING

Add this macro to use an alternative implementation for formatting real number.

MB_DISABLE_LOAD_FILE

Add this macro to disable calling file functions. Some compilers may have not implemented with standard file library.

MB_LAMBDA_ALIAS

Add this macro to add an alias for the keyword LAMBDA.

Clone this wiki locally