diff --git a/HISTORY b/HISTORY index cd18e41..9ff9415 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,7 @@ +May. 6 2015 +Removed redundant EOS tokens +Polished data precision related macros + May. 5 2015 Added string type support for non-simple array Fixed a memory leak when storing strings to a non-string array diff --git a/core/my_basic.c b/core/my_basic.c index feb265a..1c92653 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -78,7 +78,7 @@ extern "C" { /** Macros */ #define _VER_MAJOR 1 #define _VER_MINOR 1 -#define _VER_REVISION 53 +#define _VER_REVISION 54 #define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION)) /* Uncomment this line to treat warnings as error */ @@ -1939,6 +1939,12 @@ int _create_symbol(mb_interpreter_t* s, _ls_node_t* l, char* sym, _object_t** ob type = _get_symbol_type(s, sym, &value); (*obj)->type = type; switch(type) { + case _DT_NIL: + safe_free(*obj); + *obj = 0; + safe_free(sym); + + break; case _DT_INT: memcpy(tmp.any, value, sizeof(_raw_t)); (*obj)->data.integer = tmp.integer; @@ -2083,7 +2089,7 @@ _data_e _get_symbol_type(mb_interpreter_t* s, char* sym, _raw_t* value) { context = s->parsing_context; /* int_t */ - tmp.integer = (int_t)strtol(sym, &conv_suc, 0); + tmp.integer = (int_t)mb_strtol(sym, &conv_suc, 0); if(*conv_suc == '\0') { memcpy(*value, tmp.any, sizeof(_raw_t)); @@ -2092,7 +2098,7 @@ _data_e _get_symbol_type(mb_interpreter_t* s, char* sym, _raw_t* value) { goto _exit; } /* real_t */ - tmp.float_point = (real_t)strtod(sym, &conv_suc); + tmp.float_point = (real_t)mb_strtod(sym, &conv_suc); if(*conv_suc == '\0') { memcpy(*value, tmp.any, sizeof(_raw_t)); @@ -2155,7 +2161,10 @@ _data_e _get_symbol_type(mb_interpreter_t* s, char* sym, _raw_t* value) { } /* MB_EOS */ if(_sl == 1 && sym[0] == MB_EOS) { - result = _DT_EOS; + if(_IS_EOS(context->last_symbol)) + result = _DT_NIL; + else + result = _DT_EOS; goto _exit; } @@ -3779,7 +3788,7 @@ int mb_dispose_value(struct mb_interpreter_t* s, mb_value_t val) { mb_assert(s); if(val.type == MB_DT_STRING) - mb_free(val.value.string); + safe_free(val.value.string); return result; } @@ -3863,7 +3872,7 @@ int mb_load_file(struct mb_interpreter_t* s, const char* f) { buf[l] = '\0'; result = mb_load_string(s, buf); - mb_free(buf); + safe_free(buf); if(result) goto _exit; @@ -5977,14 +5986,14 @@ int _std_val(mb_interpreter_t* s, void** l) { mb_check(mb_attempt_close_bracket(s, l)); - val.value.integer = (int_t)strtol(arg, &conv_suc, 0); + val.value.integer = (int_t)mb_strtol(arg, &conv_suc, 0); if(*conv_suc == '\0') { val.type = MB_DT_INT; mb_check(mb_push_value(s, l, val)); goto _exit; } - val.value.float_point = (real_t)strtod(arg, &conv_suc); + val.value.float_point = (real_t)mb_strtod(arg, &conv_suc); if(*conv_suc == '\0') { val.type = MB_DT_REAL; mb_check(mb_push_value(s, l, val)); @@ -6107,10 +6116,10 @@ int _std_input(mb_interpreter_t* s, void** l) { if(obj->data.variable->data->type == _DT_INT || obj->data.variable->data->type == _DT_REAL) { _get_inputer(s)(line, sizeof(line)); obj->data.variable->data->type = _DT_INT; - obj->data.variable->data->data.integer = (int_t)strtol(line, &conv_suc, 0); + obj->data.variable->data->data.integer = (int_t)mb_strtol(line, &conv_suc, 0); if(*conv_suc != '\0') { obj->data.variable->data->type = _DT_REAL; - obj->data.variable->data->data.float_point = (real_t)strtod(line, &conv_suc); + obj->data.variable->data->data.float_point = (real_t)mb_strtod(line, &conv_suc); if(*conv_suc != '\0') { result = MB_FUNC_ERR; diff --git a/core/my_basic.h b/core/my_basic.h index fc9f5d2..31277e1 100755 --- a/core/my_basic.h +++ b/core/my_basic.h @@ -75,6 +75,13 @@ extern "C" { # define real_t float #endif +#ifndef mb_strtol +# define mb_strtol(__s, __e, __r) strtol((__s), (__e), (__r)) +#endif +#ifndef mb_strtod +# define mb_strtod(__s, __e) strtod((__s), (__e)) +#endif + #ifndef MB_INT_FMT # define MB_INT_FMT "%d" #endif diff --git a/output/my_basic.exe b/output/my_basic.exe index 4868a73..f78645e 100755 Binary files a/output/my_basic.exe and b/output/my_basic.exe differ diff --git a/output/my_basic_mac b/output/my_basic_mac index aee967f..48f7a5f 100755 Binary files a/output/my_basic_mac and b/output/my_basic_mac differ diff --git a/resource/my_basic.rc b/resource/my_basic.rc index 41149be..ae81208 100755 --- a/resource/my_basic.rc +++ b/resource/my_basic.rc @@ -36,8 +36,8 @@ IDI_ICON_MAIN ICON "icon.ico" VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,1,53,0 - PRODUCTVERSION 1,1,53,0 + FILEVERSION 1,1,54,0 + PRODUCTVERSION 1,1,54,0 FILEFLAGSMASK 0x17L # ifdef _DEBUG FILEFLAGS 0x1L @@ -55,13 +55,13 @@ VALUE "Comments", "MY-BASIC" VALUE "CompanyName", "W. Renxin" VALUE "FileDescription", "MY-BASIC interpreter" - VALUE "FileVersion", "1, 1, 53, 0" + VALUE "FileVersion", "1, 1, 54, 0" VALUE "InternalName", "my_basic" VALUE "LegalCopyright", "Copyright (C) 2011 - 2015 W. Renxin" VALUE "LegalTrademarks", "MY-BASIC" VALUE "OriginalFilename", "my_basic.exe" VALUE "ProductName", "MY-BASIC" - VALUE "ProductVersion", "1, 1, 53, 0" + VALUE "ProductVersion", "1, 1, 54, 0" END END BLOCK "VarFileInfo"