+added an mb_gc function; +added a gc statement to the shell.

This commit is contained in:
paladin-t 2016-01-26 16:51:06 +08:00
parent ec897a3281
commit 7d970d666a
6 changed files with 39 additions and 0 deletions

View File

@ -1,4 +1,5 @@
Jan. 26 2016
Added an mb_gc function
Added a SET_IMPORTING_DIRS statement to the shell
Added friendly error promption when memory overflow
Added source file information to stepped handler

Binary file not shown.

View File

@ -11281,6 +11281,25 @@ int mb_set_inputer(struct mb_interpreter_t* s, mb_input_func_t p) {
return result;
}
int mb_gc(struct mb_interpreter_t* s, int_t* collected) {
/* Trigger GC */
#ifdef MB_ENABLE_GC
int_t diff = _mb_allocated;
_gc_collect_garbage(s, 1);
diff = _mb_allocated - diff;
if(collected)
*collected = diff;
#else /* MB_ENABLE_GC */
mb_unrefvar(s);
mb_unrefvar(collected);
#endif /* MB_ENABLE_GC */
return MB_FUNC_OK;
}
int mb_get_userdata(struct mb_interpreter_t* s, void** d) {
/* Get the userdata of a MY-BASIC environment */
int result = MB_FUNC_OK;

View File

@ -514,6 +514,7 @@ MBAPI int mb_set_error_handler(struct mb_interpreter_t* s, mb_error_handler_t h)
MBAPI int mb_set_printer(struct mb_interpreter_t* s, mb_print_func_t p);
MBAPI int mb_set_inputer(struct mb_interpreter_t* s, mb_input_func_t p);
MBAPI int mb_gc(struct mb_interpreter_t* s, int_t* collected);
MBAPI int mb_get_userdata(struct mb_interpreter_t* s, void** d);
MBAPI int mb_set_userdata(struct mb_interpreter_t* s, void* d);
MBAPI int mb_set_import_handler(struct mb_interpreter_t* s, mb_import_handler_t h);

Binary file not shown.

View File

@ -1140,6 +1140,23 @@ static int set_importing_dirs(struct mb_interpreter_t* s, void** l) {
return result;
}
static int gc(struct mb_interpreter_t* s, void** l) {
int result = MB_FUNC_OK;
int_t collected = 0;
mb_assert(s && l);
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_attempt_close_bracket(s, l));
mb_check(mb_gc(s, &collected));
mb_check(mb_push_int(s, l, collected));
return result;
}
static int beep(struct mb_interpreter_t* s, void** l) {
int result = MB_FUNC_OK;
@ -1224,6 +1241,7 @@ static void _on_startup(void) {
#endif /* _HAS_TICKS */
mb_reg_fun(bas, now);
mb_reg_fun(bas, set_importing_dirs);
mb_reg_fun(bas, gc);
mb_reg_fun(bas, beep);
}