+added an mb_schedule_suspend interface
This commit is contained in:
parent
3487cf13b6
commit
edb1e8da56
3
HISTORY
3
HISTORY
@ -1,3 +1,6 @@
|
|||||||
|
Jun. 19 2015
|
||||||
|
Added an mb_schedule_suspend interface to schedule to suspend the execution
|
||||||
|
|
||||||
Jun. 15 2015
|
Jun. 15 2015
|
||||||
Fixed a wrong token position marking issue with interactive mode, thanks to Daniel Haensse for pointing it out
|
Fixed a wrong token position marking issue with interactive mode, thanks to Daniel Haensse for pointing it out
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ extern "C" {
|
|||||||
/** Macros */
|
/** Macros */
|
||||||
#define _VER_MAJOR 1
|
#define _VER_MAJOR 1
|
||||||
#define _VER_MINOR 1
|
#define _VER_MINOR 1
|
||||||
#define _VER_REVISION 55
|
#define _VER_REVISION 56
|
||||||
#define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION))
|
#define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION))
|
||||||
|
|
||||||
/* Uncomment this line to treat warnings as error */
|
/* Uncomment this line to treat warnings as error */
|
||||||
@ -278,7 +278,7 @@ typedef struct _object_t {
|
|||||||
unsigned short source_row;
|
unsigned short source_row;
|
||||||
unsigned short source_col;
|
unsigned short source_col;
|
||||||
#else /* MB_ENABLE_SOURCE_TRACE */
|
#else /* MB_ENABLE_SOURCE_TRACE */
|
||||||
char source_pos;
|
char source_pos;
|
||||||
#endif /* MB_ENABLE_SOURCE_TRACE */
|
#endif /* MB_ENABLE_SOURCE_TRACE */
|
||||||
} _object_t;
|
} _object_t;
|
||||||
|
|
||||||
@ -316,6 +316,7 @@ typedef struct _parsing_context_t {
|
|||||||
typedef struct _running_context_t {
|
typedef struct _running_context_t {
|
||||||
_ls_node_t* temp_values;
|
_ls_node_t* temp_values;
|
||||||
_ls_node_t* suspent_point;
|
_ls_node_t* suspent_point;
|
||||||
|
int schedule_suspend_tag;
|
||||||
_ls_node_t* sub_stack;
|
_ls_node_t* sub_stack;
|
||||||
_var_t* next_loop_var;
|
_var_t* next_loop_var;
|
||||||
mb_value_t intermediate_value;
|
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
|
#ifdef MB_ENABLE_SOURCE_TRACE
|
||||||
_set_error_pos(s, optr->source_pos, optr->source_row, optr->source_col);
|
_set_error_pos(s, optr->source_pos, optr->source_row, optr->source_col);
|
||||||
#else /* MB_ENABLE_SOURCE_TRACE */
|
#else /* MB_ENABLE_SOURCE_TRACE */
|
||||||
_set_error_pos(s, 0, 0, 0);
|
_set_error_pos(s, 0, 0, 0);
|
||||||
#endif /* MB_ENABLE_SOURCE_TRACE */
|
#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 */
|
#else /* MB_ENABLE_SOURCE_TRACE */
|
||||||
mb_unrefvar(row);
|
mb_unrefvar(row);
|
||||||
mb_unrefvar(col);
|
mb_unrefvar(col);
|
||||||
obj->source_pos = (char)pos;
|
obj->source_pos = (char)pos;
|
||||||
#endif /* MB_ENABLE_SOURCE_TRACE */
|
#endif /* MB_ENABLE_SOURCE_TRACE */
|
||||||
|
|
||||||
node = _ls_pushback(ast, obj);
|
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));
|
tmp.func = (_func_t*)mb_malloc(sizeof(_func_t));
|
||||||
memset(tmp.func, 0, sizeof(_func_t));
|
memset(tmp.func, 0, sizeof(_func_t));
|
||||||
tmp.func->name = sym;
|
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;
|
(*obj)->data.func = tmp.func;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -2713,7 +2714,7 @@ int _dispose_object(_object_t* obj) {
|
|||||||
obj->source_row = 0;
|
obj->source_row = 0;
|
||||||
obj->source_col = 0;
|
obj->source_col = 0;
|
||||||
#else /* MB_ENABLE_SOURCE_TRACE */
|
#else /* MB_ENABLE_SOURCE_TRACE */
|
||||||
obj->source_pos = 0;
|
obj->source_pos = 0;
|
||||||
#endif /* MB_ENABLE_SOURCE_TRACE */
|
#endif /* MB_ENABLE_SOURCE_TRACE */
|
||||||
++result;
|
++result;
|
||||||
|
|
||||||
@ -2942,8 +2943,16 @@ int _execute_statement(mb_interpreter_t* s, _ls_node_t** l) {
|
|||||||
default:
|
default:
|
||||||
break;
|
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)
|
if(result != MB_FUNC_OK && result != MB_FUNC_SUSPEND && result != MB_SUB_RETURN)
|
||||||
goto _exit;
|
goto _exit;
|
||||||
|
|
||||||
if(ast) {
|
if(ast) {
|
||||||
obj = (_object_t*)(ast->data);
|
obj = (_object_t*)(ast->data);
|
||||||
if(_IS_EOS(obj)) {
|
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);
|
_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)) {
|
if(skip_to_eoi && running->skip_to_eoi && running->skip_to_eoi == _ls_back(running->sub_stack)) {
|
||||||
running->skip_to_eoi = 0;
|
running->skip_to_eoi = 0;
|
||||||
obj = (_object_t*)(ast->data);
|
obj = (_object_t*)(ast->data);
|
||||||
@ -3540,21 +3550,21 @@ _exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int mb_has_arg(struct mb_interpreter_t* s, void** l) {
|
int mb_has_arg(struct mb_interpreter_t* s, void** l) {
|
||||||
/* Detect whether there is any more argument */
|
/* Detect whether there is any more argument */
|
||||||
int result = 0;
|
int result = 0;
|
||||||
_ls_node_t* ast = 0;
|
_ls_node_t* ast = 0;
|
||||||
_object_t* obj = 0;
|
_object_t* obj = 0;
|
||||||
|
|
||||||
mb_assert(s && l);
|
mb_assert(s && l);
|
||||||
|
|
||||||
ast = (_ls_node_t*)(*l);
|
ast = (_ls_node_t*)(*l);
|
||||||
if(ast) {
|
if(ast) {
|
||||||
obj = (_object_t*)(ast->data);
|
obj = (_object_t*)(ast->data);
|
||||||
if(!_IS_FUNC(obj, _core_close_bracket) && obj->type != _DT_EOS)
|
if(!_IS_FUNC(obj, _core_close_bracket) && obj->type != _DT_EOS)
|
||||||
result = obj->data.integer;
|
result = obj->data.integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mb_pop_int(struct mb_interpreter_t* s, void** l, int_t* val) {
|
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) {
|
int mb_suspend(struct mb_interpreter_t* s, void** l) {
|
||||||
/* Suspend current execution and save the context */
|
/* Suspend current execution and save the context */
|
||||||
int result = MB_FUNC_OK;
|
int result = MB_FUNC_OK;
|
||||||
_ls_node_t* ast;
|
_ls_node_t* ast = 0;
|
||||||
|
|
||||||
mb_assert(s && l && *l);
|
mb_assert(s && l && *l);
|
||||||
|
|
||||||
@ -3965,6 +3975,17 @@ int mb_suspend(struct mb_interpreter_t* s, void** l) {
|
|||||||
return result;
|
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) {
|
int mb_debug_get(struct mb_interpreter_t* s, const char* n, mb_value_t* val) {
|
||||||
/* Get the value of an identifier */
|
/* Get the value of an identifier */
|
||||||
int result = MB_FUNC_OK;
|
int result = MB_FUNC_OK;
|
||||||
|
@ -47,7 +47,7 @@ extern "C" {
|
|||||||
#endif /* MB_ENABLE_ALLOC_STAT */
|
#endif /* MB_ENABLE_ALLOC_STAT */
|
||||||
|
|
||||||
#ifndef MB_ENABLE_SOURCE_TRACE
|
#ifndef MB_ENABLE_SOURCE_TRACE
|
||||||
# define MB_ENABLE_SOURCE_TRACE
|
# define MB_ENABLE_SOURCE_TRACE
|
||||||
#endif /* MB_ENABLE_SOURCE_TRACE */
|
#endif /* MB_ENABLE_SOURCE_TRACE */
|
||||||
|
|
||||||
#ifndef MB_COMPACT_MODE
|
#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_load_file(struct mb_interpreter_t* s, const char* f);
|
||||||
MBAPI int mb_run(struct mb_interpreter_t* s);
|
MBAPI int mb_run(struct mb_interpreter_t* s);
|
||||||
MBAPI int mb_suspend(struct mb_interpreter_t* s, void** l);
|
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_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);
|
MBAPI int mb_debug_set(struct mb_interpreter_t* s, const char* n, mb_value_t val);
|
||||||
|
Binary file not shown.
@ -36,8 +36,8 @@
|
|||||||
IDI_ICON_MAIN ICON "icon.ico"
|
IDI_ICON_MAIN ICON "icon.ico"
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 1,1,55,0
|
FILEVERSION 1,1,56,0
|
||||||
PRODUCTVERSION 1,1,55,0
|
PRODUCTVERSION 1,1,56,0
|
||||||
FILEFLAGSMASK 0x17L
|
FILEFLAGSMASK 0x17L
|
||||||
# ifdef _DEBUG
|
# ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
@ -55,13 +55,13 @@
|
|||||||
VALUE "Comments", "MY-BASIC"
|
VALUE "Comments", "MY-BASIC"
|
||||||
VALUE "CompanyName", "W. Renxin"
|
VALUE "CompanyName", "W. Renxin"
|
||||||
VALUE "FileDescription", "MY-BASIC interpreter"
|
VALUE "FileDescription", "MY-BASIC interpreter"
|
||||||
VALUE "FileVersion", "1, 1, 55, 0"
|
VALUE "FileVersion", "1, 1, 56, 0"
|
||||||
VALUE "InternalName", "my_basic"
|
VALUE "InternalName", "my_basic"
|
||||||
VALUE "LegalCopyright", "Copyright (C) 2011 - 2015 W. Renxin"
|
VALUE "LegalCopyright", "Copyright (C) 2011 - 2015 W. Renxin"
|
||||||
VALUE "LegalTrademarks", "MY-BASIC"
|
VALUE "LegalTrademarks", "MY-BASIC"
|
||||||
VALUE "OriginalFilename", "my_basic.exe"
|
VALUE "OriginalFilename", "my_basic.exe"
|
||||||
VALUE "ProductName", "MY-BASIC"
|
VALUE "ProductName", "MY-BASIC"
|
||||||
VALUE "ProductVersion", "1, 1, 55, 0"
|
VALUE "ProductVersion", "1, 1, 56, 0"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
@ -110,7 +110,7 @@ static void _append_line(_code_line_t* code, char* txt) {
|
|||||||
code->size += _LINE_INC_STEP;
|
code->size += _LINE_INC_STEP;
|
||||||
code->lines = (char**)realloc(code->lines, sizeof(char*) * code->size);
|
code->lines = (char**)realloc(code->lines, sizeof(char*) * code->size);
|
||||||
}
|
}
|
||||||
l = strlen(txt);
|
l = (int)strlen(txt);
|
||||||
buf = (char*)malloc(l + 2);
|
buf = (char*)malloc(l + 2);
|
||||||
memcpy(buf, txt, l);
|
memcpy(buf, txt, l);
|
||||||
buf[l] = '\n';
|
buf[l] = '\n';
|
||||||
@ -267,7 +267,7 @@ static void _list_program(const char* sn, const char* cn) {
|
|||||||
if(lsn == 0 && lcn == 0) {
|
if(lsn == 0 && lcn == 0) {
|
||||||
long i = 0;
|
long i = 0;
|
||||||
for(i = 0; i < c->count; ++i) {
|
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 {
|
} else {
|
||||||
long i = 0;
|
long i = 0;
|
||||||
@ -288,7 +288,7 @@ static void _list_program(const char* sn, const char* cn) {
|
|||||||
if(i >= c->count)
|
if(i >= c->count)
|
||||||
break;
|
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) {
|
static void _alter_program(const char* no) {
|
||||||
long lno = 0;
|
long lno = 0;
|
||||||
int i = 0;
|
long i = 0;
|
||||||
mb_assert(no);
|
mb_assert(no);
|
||||||
lno = atoi(no);
|
lno = atoi(no);
|
||||||
if(lno < 1 || lno > c->count) {
|
if(lno < 1 || lno > c->count) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user