diff --git a/HISTORY b/HISTORY index 9ff9415..ac0e723 100755 --- a/HISTORY +++ b/HISTORY @@ -1,190 +1,193 @@ -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 -Polished data precision related macros - -Apr. 27 2015 -Added code line inserting/removing to interpreter shell -Changed mb_dispose_value as public - -Apr. 23 2015 Version 1.1 -Added debug APIs -Added (nestable) multi line IF statement support - -Apr. 15 2015 -Added mb_pop_usertype, mb_push_usertype to support user defined type -Polished code -Polished document - -Apr. 13 2015 -Added mixed integer/float array support -Added warning prompt when passing strings to maths functions -Fixed a memory leak when storing strings in an array -Polished the interpreter commands - -Apr. 11 2015 -Moved struct mb_interpreter_t from my_basic.h to my_basic.c -Added an mb_has_arg interface to tell whether there is any more argument -Added an MB_ENABLE_SOURCE_TRACE macro to enable or disable source tracing -Disposed parsing context at runtime to reduce memory occupation - -Apr. 10 2015 -Improved compatibility with PellesC -Fixed a double precision float parsing bug on all 32bit systems, thanks to Pito for pointing it out -Fixed an exponential number parsing bug, thanks to Pito for pointing it out -Fixed a crash bug when a script begins with a meaningless negtive number - -Mar. 25 2015 -Changed _strupr macro to mb_strupr function -Added an mb_memdup function -Fixed an intermediate value disposing more than once bug - -Dec. 17 2014 -Fixed a calculation crash bug -Fixed a memory leak with intermediate value - -Dec. 16 2014 -Fixed a negative calculation bug in a function argument - -Dec. 9 2014 -Improved compatibility with BCB - -May. 25 2014 -Added an mb_set_inputer function which allows the user to specify an INPUT reader, thanks to Michael P. Welch for suggestion -Added an mb_remove_reserved_func function which allows the user to disable/remove a reserved statement - -May. 22 2014 -Fixed a crash bug when missing colon in a combined line, thanks to Michael P. Welch for pointing it out -Fixed a missing lexical cursor stepping bug in INPUT function - -Mar. 17 2014 -Added an XCode project -Added a safe stdin reader function mb_gets -Fixed a crash bug in INPUT function - -Feb. 17 2014 -Added mod by zero processing - -Feb. 16 2014 -Fixed a crash bug in _core_for, thanks to mummylauncher for pointing it out - -Jul. 19 2013 -Fixed a crash bug in _execute_statement, thanks to Jon Mayo for pointing it out - -Feb. 25 2013 -Fixed a cross routine multi-statement execution bug, thanks to Bruce Kendall for pointing it out -Fixed a memory corruption bug when loading a script file - -Jan. 9 2013 -Fixed a crash bug when using EDIT command - -Dec. 14 2012 -Added an invalid expression error handling -Added an out of memory error handling - -Dec. 5 2012 -Fixed a minus calculation bug, thanks to Bill Walker for pointing it out - -Nov. 14 2012 -Fixed a cross routine RETURN bug, thanks to Bruce Kendall for pointing it out - -Sep. 12 2012 -Fixed a bug in ASC -Fixed a label parsing, jumping bug, thanks to Ahmad Hawwash for pointing above two issues out -Fixed a crash bug in IF statement -Added divide by zero processing -Added calculation error raising - -Sep. 1 2012 -Fixed a redisposing bug when retrieving a string argument, thanks to Ahmad Hawwash for pointing it out -Fixed a memory leak after retrieving a composited string argument - -Aug. 29 2012 -Modified an odd string comparison behavior, thanks to Matthias Nott for testing it out -Added a warning system, disabled warning as default -Improved compatibility with GCC - -Aug. 3 2012 -Implemented memory occupation statistics -Improved compatibility on 64bit systems -Fixed some warnings under a stricter mode - -Jul. 21 2012 -Added a compatibility macro for PRINT a newline -Added an mb_attempt_func_end C API -Fixed a unary minus symbol parsing bug - -Jul. 19 2012 -Fixed a crash bug caused by a mistake in calculation priority table, thanks to Bruce Kendall for pointing it out - -Jul. 10 2012 -Implemented KILL command -Fixed a negative calculation bug -Added an invalid identifier usage error handling -Avoided some warnings on gcc - -Jul. 5 2012 -Implemented LIST, EDIT, LOAD, SAVE commands - -Jul. 4 2012 -Fixed some crash bugs -Fixed some memory leaks - -Jul. 3 2012 -Modified/added math functions: FLOOR, CEIL, FIX -Fixed an INPUT type issue -Changed float number formatting from using "%f" to "%g" in PRINT, thanks to Bruce Kendall for pointing above three issues out -Refactored the way to load a script file -Done several small improvements - -Jun. 29 2012 -Fixed a newline mistake in PRINT - -Jun. 29 2012 -Implemented customizable print functor -Improved PRINT statement -Fixed an infinity loop bug in RND function -Fixed some crash bugs - -Jun. 28 2012 -Fixed a cross routine RETURN bug, thanks to Bruce Kendall for pointing it out -Fixed some memory leaks -Refactored error position informing - -Jun. 18 2012 -Implemented user extended abort, thanks to Bruce Kendall for giving suggestion - -Apr. 30 2012 -Compress number to integer if necessary - -Apr. 27 2012 -Fixed a string connecting crash bug, thanks to Ahmad Hawwash for pointing it out -Improved portability on gcc - -Aug. 3 2011 -Fixed hashtable removing bug - -Jun. 18 2011 -Fixed some mistakes -Allowed underline character appear in an identifier - -Apr. 15 2011 -Fixed garbage collection and _label_t disposing bugs - -Apr. 14 2011 -Fixed some list / comparison operator bugs - -Feb. 15 2011 -Improved portability on Cocoa -Improved portability on VC++ 6.0 -Fixed a suspend / resume bug - -Feb. 9 2011 -Fixed struct mb_interpreter_t declaration warnings on gcc - -Feb. 1 2011 Version 1.0 -First release. +Jun. 15 2015 +Fixed a wrong token position marking issue with interactive mode, thanks to Daniel Haensse for pointing it out + +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 +Polished data precision related macros + +Apr. 27 2015 +Added code line inserting/removing to interpreter shell +Changed mb_dispose_value as public + +Apr. 23 2015 Version 1.1 +Added debug APIs +Added (nestable) multi line IF statement support + +Apr. 15 2015 +Added mb_pop_usertype, mb_push_usertype to support user defined type +Polished code +Polished document + +Apr. 13 2015 +Added mixed integer/float array support +Added warning prompt when passing strings to maths functions +Fixed a memory leak when storing strings in an array +Polished the interpreter commands + +Apr. 11 2015 +Moved struct mb_interpreter_t from my_basic.h to my_basic.c +Added an mb_has_arg interface to tell whether there is any more argument +Added an MB_ENABLE_SOURCE_TRACE macro to enable or disable source tracing +Disposed parsing context at runtime to reduce memory occupation + +Apr. 10 2015 +Improved compatibility with PellesC +Fixed a double precision float parsing bug on all 32bit systems, thanks to Pito for pointing it out +Fixed an exponential number parsing bug, thanks to Pito for pointing it out +Fixed a crash bug when a script begins with a meaningless negtive number + +Mar. 25 2015 +Changed _strupr macro to mb_strupr function +Added an mb_memdup function +Fixed an intermediate value disposing more than once bug + +Dec. 17 2014 +Fixed a calculation crash bug +Fixed a memory leak with intermediate value + +Dec. 16 2014 +Fixed a negative calculation bug in a function argument + +Dec. 9 2014 +Improved compatibility with BCB + +May. 25 2014 +Added an mb_set_inputer function which allows the user to specify an INPUT reader, thanks to Michael P. Welch for suggestion +Added an mb_remove_reserved_func function which allows the user to disable/remove a reserved statement + +May. 22 2014 +Fixed a crash bug when missing colon in a combined line, thanks to Michael P. Welch for pointing it out +Fixed a missing lexical cursor stepping bug in INPUT function + +Mar. 17 2014 +Added an XCode project +Added a safe stdin reader function mb_gets +Fixed a crash bug in INPUT function + +Feb. 17 2014 +Added mod by zero processing + +Feb. 16 2014 +Fixed a crash bug in _core_for, thanks to mummylauncher for pointing it out + +Jul. 19 2013 +Fixed a crash bug in _execute_statement, thanks to Jon Mayo for pointing it out + +Feb. 25 2013 +Fixed a cross routine multi-statement execution bug, thanks to Bruce Kendall for pointing it out +Fixed a memory corruption bug when loading a script file + +Jan. 9 2013 +Fixed a crash bug when using EDIT command + +Dec. 14 2012 +Added an invalid expression error handling +Added an out of memory error handling + +Dec. 5 2012 +Fixed a minus calculation bug, thanks to Bill Walker for pointing it out + +Nov. 14 2012 +Fixed a cross routine RETURN bug, thanks to Bruce Kendall for pointing it out + +Sep. 12 2012 +Fixed a bug in ASC +Fixed a label parsing, jumping bug, thanks to Ahmad Hawwash for pointing above two issues out +Fixed a crash bug in IF statement +Added divide by zero processing +Added calculation error raising + +Sep. 1 2012 +Fixed a redisposing bug when retrieving a string argument, thanks to Ahmad Hawwash for pointing it out +Fixed a memory leak after retrieving a composited string argument + +Aug. 29 2012 +Modified an odd string comparison behavior, thanks to Matthias Nott for testing it out +Added a warning system, disabled warning as default +Improved compatibility with GCC + +Aug. 3 2012 +Implemented memory occupation statistics +Improved compatibility on 64bit systems +Fixed some warnings under a stricter mode + +Jul. 21 2012 +Added a compatibility macro for PRINT a newline +Added an mb_attempt_func_end C API +Fixed a unary minus symbol parsing bug + +Jul. 19 2012 +Fixed a crash bug caused by a mistake in calculation priority table, thanks to Bruce Kendall for pointing it out + +Jul. 10 2012 +Implemented KILL command +Fixed a negative calculation bug +Added an invalid identifier usage error handling +Avoided some warnings on gcc + +Jul. 5 2012 +Implemented LIST, EDIT, LOAD, SAVE commands + +Jul. 4 2012 +Fixed some crash bugs +Fixed some memory leaks + +Jul. 3 2012 +Modified/added math functions: FLOOR, CEIL, FIX +Fixed an INPUT type issue +Changed float number formatting from using "%f" to "%g" in PRINT, thanks to Bruce Kendall for pointing above three issues out +Refactored the way to load a script file +Done several small improvements + +Jun. 29 2012 +Fixed a newline mistake in PRINT + +Jun. 29 2012 +Implemented customizable print functor +Improved PRINT statement +Fixed an infinity loop bug in RND function +Fixed some crash bugs + +Jun. 28 2012 +Fixed a cross routine RETURN bug, thanks to Bruce Kendall for pointing it out +Fixed some memory leaks +Refactored error position informing + +Jun. 18 2012 +Implemented user extended abort, thanks to Bruce Kendall for giving suggestion + +Apr. 30 2012 +Compress number to integer if necessary + +Apr. 27 2012 +Fixed a string connecting crash bug, thanks to Ahmad Hawwash for pointing it out +Improved portability on gcc + +Aug. 3 2011 +Fixed hashtable removing bug + +Jun. 18 2011 +Fixed some mistakes +Allowed underline character appear in an identifier + +Apr. 15 2011 +Fixed garbage collection and _label_t disposing bugs + +Apr. 14 2011 +Fixed some list / comparison operator bugs + +Feb. 15 2011 +Improved portability on Cocoa +Improved portability on VC++ 6.0 +Fixed a suspend / resume bug + +Feb. 9 2011 +Fixed struct mb_interpreter_t declaration warnings on gcc + +Feb. 1 2011 Version 1.0 +First release. diff --git a/core/my_basic.c b/core/my_basic.c index 1c92653..bae9dd3 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 54 +#define _VER_REVISION 55 #define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION)) /* Uncomment this line to treat warnings as error */ @@ -307,6 +307,9 @@ typedef struct _parsing_context_t { _object_t* last_symbol; _parsing_state_e parsing_state; _symbol_state_e symbol_state; + int parsing_pos; + unsigned short parsing_row; + unsigned short parsing_col; } _parsing_context_t; /* Running context */ @@ -3314,6 +3317,7 @@ int mb_open(struct mb_interpreter_t** s) { context = (_parsing_context_t*)mb_malloc(sizeof(_parsing_context_t)); memset(context, 0, sizeof(_parsing_context_t)); + context->parsing_row = 1; (*s)->parsing_context = context; running = (_running_context_t*)mb_malloc(sizeof(_running_context_t)); @@ -3413,6 +3417,7 @@ int mb_reset(struct mb_interpreter_t** s, bool_t clrf/* = false*/) { (*s)->parsing_context = context; } memset(context, 0, sizeof(_parsing_context_t)); + context->parsing_row = 1; ast = (*s)->ast; _ls_foreach(ast, _destroy_object); @@ -3799,8 +3804,6 @@ int mb_load_string(struct mb_interpreter_t* s, const char* l) { char ch = 0; int status = 0; int i = 0; - unsigned short row = 1; - unsigned short col = 0; unsigned short _row = 0; unsigned short _col = 0; char wrapped = '\0'; @@ -3814,16 +3817,16 @@ int mb_load_string(struct mb_interpreter_t* s, const char* l) { ch = l[i]; if((ch == '\n' || ch == '\r') && (!wrapped || wrapped == ch)) { wrapped = ch; - ++row; - col = 0; + ++context->parsing_row; + context->parsing_col = 0; } else { wrapped = '\0'; - ++col; + ++context->parsing_col; } - status = _parse_char(s, ch, i, _row, _col); + status = _parse_char(s, ch, context->parsing_pos, _row, _col); result = status; if(status) { - _set_error_pos(s, i, _row, _col); + _set_error_pos(s, context->parsing_pos, _row, _col); if(s->error_handler) { (s->error_handler)(s, s->last_error, (char*)mb_get_error_desc(s->last_error), s->last_error_pos, @@ -3834,11 +3837,12 @@ int mb_load_string(struct mb_interpreter_t* s, const char* l) { goto _exit; } - _row = row; - _col = col; + _row = context->parsing_row; + _col = context->parsing_col; ++i; + ++context->parsing_pos; }; - status = _parse_char(s, MB_EOS, i, row, col); + status = _parse_char(s, MB_EOS, context->parsing_pos, context->parsing_row, context->parsing_col); _exit: context->parsing_state = _PS_NORMAL; diff --git a/output/my_basic.exe b/output/my_basic.exe index f78645e..120e022 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 48f7a5f..61fec14 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 ae81208..591692b 100755 --- a/resource/my_basic.rc +++ b/resource/my_basic.rc @@ -1,77 +1,77 @@ -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS - -#include "windows.h" - -#undef APSTUDIO_READONLY_SYMBOLS - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) -# ifdef _WIN32 - LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED -# pragma code_page(936) -# endif //_WIN32 - -# ifdef APSTUDIO_INVOKED - - 1 TEXTINCLUDE - BEGIN - "resource.h\0" - END - - 2 TEXTINCLUDE - BEGIN - "#include ""windows.h""\r\n" - "\0" - END - - 3 TEXTINCLUDE - BEGIN - "\r\n" - "\0" - END - -# endif - - IDI_ICON_MAIN ICON "icon.ico" - - VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,1,54,0 - PRODUCTVERSION 1,1,54,0 - FILEFLAGSMASK 0x17L -# ifdef _DEBUG - FILEFLAGS 0x1L -# else - FILEFLAGS 0x0L -# endif - FILEOS 0x4L - FILETYPE 0x1L - FILESUBTYPE 0x0L - BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "080404b0" - BEGIN - VALUE "Comments", "MY-BASIC" - VALUE "CompanyName", "W. Renxin" - VALUE "FileDescription", "MY-BASIC interpreter" - 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, 54, 0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x804, 1200 - END - END - -#endif - -#ifndef APSTUDIO_INVOKED - -#endif +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + +#include "windows.h" + +#undef APSTUDIO_READONLY_SYMBOLS + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) +# ifdef _WIN32 + LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED +# pragma code_page(936) +# endif //_WIN32 + +# ifdef APSTUDIO_INVOKED + + 1 TEXTINCLUDE + BEGIN + "resource.h\0" + END + + 2 TEXTINCLUDE + BEGIN + "#include ""windows.h""\r\n" + "\0" + END + + 3 TEXTINCLUDE + BEGIN + "\r\n" + "\0" + END + +# endif + + IDI_ICON_MAIN ICON "icon.ico" + + VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,1,55,0 + PRODUCTVERSION 1,1,55,0 + FILEFLAGSMASK 0x17L +# ifdef _DEBUG + FILEFLAGS 0x1L +# else + FILEFLAGS 0x0L +# endif + FILEOS 0x4L + FILETYPE 0x1L + FILESUBTYPE 0x0L + BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "080404b0" + BEGIN + VALUE "Comments", "MY-BASIC" + VALUE "CompanyName", "W. Renxin" + VALUE "FileDescription", "MY-BASIC interpreter" + VALUE "FileVersion", "1, 1, 55, 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, 55, 0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x804, 1200 + END + END + +#endif + +#ifndef APSTUDIO_INVOKED + +#endif diff --git a/shell/main.c b/shell/main.c index a990d26..78e5da8 100755 --- a/shell/main.c +++ b/shell/main.c @@ -103,12 +103,19 @@ static void _clear_code(_code_line_t* code) { } static void _append_line(_code_line_t* code, char* txt) { + int l = 0; + char* buf = 0; mb_assert(code && txt); if(code->count + 1 == code->size) { code->size += _LINE_INC_STEP; code->lines = (char**)realloc(code->lines, sizeof(char*) * code->size); } - code->lines[code->count++] = strdup(txt); + l = strlen(txt); + buf = (char*)malloc(l + 2); + memcpy(buf, txt, l); + buf[l] = '\n'; + buf[l + 1] = '\0'; + code->lines[code->count++] = buf; } static char* _get_code(_code_line_t* code) { @@ -435,11 +442,11 @@ static int _do_line(void) { } else if(_str_eq(line, "NEW")) { result = _new_program(); } else if(_str_eq(line, "RUN")) { - int i = 0; - mb_assert(c); - result = mb_reset(&bas, false); - for(i = 0; i < c->count; ++i) - mb_load_string(bas, c->lines[i]); + int i = 0; + mb_assert(c); + result = mb_reset(&bas, false); + for(i = 0; i < c->count; ++i) + mb_load_string(bas, c->lines[i]); result = mb_run(bas); printf("\n"); } else if(_str_eq(line, "BYE")) {