diff --git a/HISTORY b/HISTORY index ac0e723..85fbc55 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,6 @@ +Jun. 19 2015 +Added an mb_schedule_suspend interface to schedule to suspend the execution + Jun. 15 2015 Fixed a wrong token position marking issue with interactive mode, thanks to Daniel Haensse for pointing it out diff --git a/core/my_basic.c b/core/my_basic.c index 2282663..47c4c5b 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 55 +#define _VER_REVISION 56 #define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION)) /* Uncomment this line to treat warnings as error */ @@ -278,7 +278,7 @@ typedef struct _object_t { unsigned short source_row; unsigned short source_col; #else /* MB_ENABLE_SOURCE_TRACE */ - char source_pos; + char source_pos; #endif /* MB_ENABLE_SOURCE_TRACE */ } _object_t; @@ -316,6 +316,7 @@ typedef struct _parsing_context_t { typedef struct _running_context_t { _ls_node_t* temp_values; _ls_node_t* suspent_point; + int schedule_suspend_tag; _ls_node_t* sub_stack; _var_t* next_loop_var; mb_value_t intermediate_value; @@ -1463,7 +1464,7 @@ _object_t* _operate_operand(mb_interpreter_t* s, _object_t* optr, _object_t* opn #ifdef MB_ENABLE_SOURCE_TRACE _set_error_pos(s, optr->source_pos, optr->source_row, optr->source_col); #else /* MB_ENABLE_SOURCE_TRACE */ - _set_error_pos(s, 0, 0, 0); + _set_error_pos(s, 0, 0, 0); #endif /* MB_ENABLE_SOURCE_TRACE */ } @@ -1901,7 +1902,7 @@ int _append_symbol(mb_interpreter_t* s, char* sym, bool_t* delsym, int pos, unsi #else /* MB_ENABLE_SOURCE_TRACE */ mb_unrefvar(row); mb_unrefvar(col); - obj->source_pos = (char)pos; + obj->source_pos = (char)pos; #endif /* MB_ENABLE_SOURCE_TRACE */ node = _ls_pushback(ast, obj); @@ -1975,7 +1976,7 @@ int _create_symbol(mb_interpreter_t* s, _ls_node_t* l, char* sym, _object_t** ob tmp.func = (_func_t*)mb_malloc(sizeof(_func_t)); memset(tmp.func, 0, sizeof(_func_t)); tmp.func->name = sym; - memcpy(&tmp.func->pointer, value, sizeof(tmp.func->pointer)); + memcpy(&tmp.func->pointer, value, sizeof(tmp.func->pointer)); (*obj)->data.func = tmp.func; break; @@ -2713,7 +2714,7 @@ int _dispose_object(_object_t* obj) { obj->source_row = 0; obj->source_col = 0; #else /* MB_ENABLE_SOURCE_TRACE */ - obj->source_pos = 0; + obj->source_pos = 0; #endif /* MB_ENABLE_SOURCE_TRACE */ ++result; @@ -2942,8 +2943,16 @@ int _execute_statement(mb_interpreter_t* s, _ls_node_t** l) { default: break; } + + if(running->schedule_suspend_tag) { + mb_suspend(s, (void**)(&ast)); + result = MB_FUNC_SUSPEND; + running->schedule_suspend_tag = 0; + } + if(result != MB_FUNC_OK && result != MB_FUNC_SUSPEND && result != MB_SUB_RETURN) goto _exit; + if(ast) { obj = (_object_t*)(ast->data); if(_IS_EOS(obj)) { @@ -2959,6 +2968,7 @@ int _execute_statement(mb_interpreter_t* s, _ls_node_t** l) { _handle_error_on_obj(s, SE_RN_COLON_EXPECTED, DON(ast), MB_FUNC_ERR, _exit, result); } } + if(skip_to_eoi && running->skip_to_eoi && running->skip_to_eoi == _ls_back(running->sub_stack)) { running->skip_to_eoi = 0; obj = (_object_t*)(ast->data); @@ -3540,21 +3550,21 @@ _exit: } int mb_has_arg(struct mb_interpreter_t* s, void** l) { - /* Detect whether there is any more argument */ - int result = 0; - _ls_node_t* ast = 0; - _object_t* obj = 0; + /* Detect whether there is any more argument */ + int result = 0; + _ls_node_t* ast = 0; + _object_t* obj = 0; - mb_assert(s && l); + mb_assert(s && l); - ast = (_ls_node_t*)(*l); - if(ast) { - obj = (_object_t*)(ast->data); - if(!_IS_FUNC(obj, _core_close_bracket) && obj->type != _DT_EOS) - result = obj->data.integer; - } + ast = (_ls_node_t*)(*l); + if(ast) { + obj = (_object_t*)(ast->data); + if(!_IS_FUNC(obj, _core_close_bracket) && obj->type != _DT_EOS) + result = obj->data.integer; + } - return result; + return result; } int mb_pop_int(struct mb_interpreter_t* s, void** l, int_t* val) { @@ -3955,7 +3965,7 @@ _exit: int mb_suspend(struct mb_interpreter_t* s, void** l) { /* Suspend current execution and save the context */ int result = MB_FUNC_OK; - _ls_node_t* ast; + _ls_node_t* ast = 0; mb_assert(s && l && *l); @@ -3965,6 +3975,17 @@ int mb_suspend(struct mb_interpreter_t* s, void** l) { return result; } +int mb_schedule_suspend(struct mb_interpreter_t* s) { + /* Schedule to suspend current execution and will save the context */ + int result = MB_FUNC_OK; + + mb_assert(s); + + s->running_context->schedule_suspend_tag = 1; + + return result; +} + int mb_debug_get(struct mb_interpreter_t* s, const char* n, mb_value_t* val) { /* Get the value of an identifier */ int result = MB_FUNC_OK; diff --git a/core/my_basic.h b/core/my_basic.h index 31277e1..ef80adc 100755 --- a/core/my_basic.h +++ b/core/my_basic.h @@ -47,7 +47,7 @@ extern "C" { #endif /* MB_ENABLE_ALLOC_STAT */ #ifndef MB_ENABLE_SOURCE_TRACE -# define MB_ENABLE_SOURCE_TRACE +# define MB_ENABLE_SOURCE_TRACE #endif /* MB_ENABLE_SOURCE_TRACE */ #ifndef MB_COMPACT_MODE @@ -278,6 +278,7 @@ MBAPI int mb_load_string(struct mb_interpreter_t* s, const char* l); MBAPI int mb_load_file(struct mb_interpreter_t* s, const char* f); MBAPI int mb_run(struct mb_interpreter_t* s); MBAPI int mb_suspend(struct mb_interpreter_t* s, void** l); +MBAPI int mb_schedule_suspend(struct mb_interpreter_t* s); MBAPI int mb_debug_get(struct mb_interpreter_t* s, const char* n, mb_value_t* val); MBAPI int mb_debug_set(struct mb_interpreter_t* s, const char* n, mb_value_t val); diff --git a/output/my_basic_mac b/output/my_basic_mac index 61fec14..8eee60b 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 591692b..2cda7fb 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,55,0 - PRODUCTVERSION 1,1,55,0 + FILEVERSION 1,1,56,0 + PRODUCTVERSION 1,1,56,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, 55, 0" + VALUE "FileVersion", "1, 1, 56, 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" + VALUE "ProductVersion", "1, 1, 56, 0" END END BLOCK "VarFileInfo" diff --git a/shell/main.c b/shell/main.c index 78e5da8..0e36f38 100755 --- a/shell/main.c +++ b/shell/main.c @@ -110,7 +110,7 @@ static void _append_line(_code_line_t* code, char* txt) { code->size += _LINE_INC_STEP; code->lines = (char**)realloc(code->lines, sizeof(char*) * code->size); } - l = strlen(txt); + l = (int)strlen(txt); buf = (char*)malloc(l + 2); memcpy(buf, txt, l); buf[l] = '\n'; @@ -267,7 +267,7 @@ static void _list_program(const char* sn, const char* cn) { if(lsn == 0 && lcn == 0) { long i = 0; for(i = 0; i < c->count; ++i) { - printf("%d]%s\n", i + 1, c->lines[i]); + printf("%ld]%s\n", i + 1, c->lines[i]); } } else { long i = 0; @@ -288,7 +288,7 @@ static void _list_program(const char* sn, const char* cn) { if(i >= c->count) break; - printf("%d]%s\n", i + 1, c->lines[i]); + printf("%ld]%s\n", i + 1, c->lines[i]); } } } @@ -339,7 +339,7 @@ static void _insert_program(const char* no) { static void _alter_program(const char* no) { long lno = 0; - int i = 0; + long i = 0; mb_assert(no); lno = atoi(no); if(lno < 1 || lno > c->count) {