diff --git a/HISTORY b/HISTORY index cd9a9cd..5846a22 100755 --- a/HISTORY +++ b/HISTORY @@ -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 diff --git a/MY-BASIC Quick Reference.pdf b/MY-BASIC Quick Reference.pdf index 30a8d53..51dafa8 100644 Binary files a/MY-BASIC Quick Reference.pdf and b/MY-BASIC Quick Reference.pdf differ diff --git a/core/my_basic.c b/core/my_basic.c index 50233b2..0a10645 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -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; diff --git a/core/my_basic.h b/core/my_basic.h index 5dfa93b..e4ec8cd 100755 --- a/core/my_basic.h +++ b/core/my_basic.h @@ -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); diff --git a/output/my_basic.exe b/output/my_basic.exe index 2bf58d2..6756c68 100755 Binary files a/output/my_basic.exe and b/output/my_basic.exe differ diff --git a/shell/main.c b/shell/main.c index 02d9d74..a2dac22 100755 --- a/shell/main.c +++ b/shell/main.c @@ -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); }