diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/builtins.c | 9 | ||||
| -rw-r--r-- | src/builtins.h | 1 | ||||
| -rw-r--r-- | src/interp.c | 3 | ||||
| -rw-r--r-- | src/interp.h | 1 |
4 files changed, 13 insertions, 1 deletions
diff --git a/src/builtins.c b/src/builtins.c index 98252f8..fe14b8f 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -6,6 +6,14 @@ #include <float.h> #include <math.h> +SExpRef builtin_alwaysgc(Interp *interp, SExpRef args) { + if (LENGTH(args) != 1) return new_error(interp, "_alwaysgc: arg num error.\n"); + SExpRef arg = CAR(args); + if (VALTYPE(arg) != kBooleanSExp) return new_error(interp, "alwaysgc: type error.\n"); + interp->alwaysgc = REF(arg)->boolean; + return NIL; +} + SExpRef builtin_symbol2string(Interp *interp, SExpRef args) { if (LENGTH(args) != 1) return new_error(interp, "symbol->string: arg num error.\n"); SExpRef arg = CAR(args); @@ -601,6 +609,7 @@ SExpRef builtin_num_equal(Interp *interp, SExpRef args) { } } + SExpRef builtin_num_neq(Interp *interp, SExpRef args) { int args_len = LENGTH(args); if (args_len != 2) return new_error(interp, "/=: wrong argument number.\n"); diff --git a/src/builtins.h b/src/builtins.h index 5b6b763..eb95f2d 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -53,5 +53,6 @@ SExpRef builtin_ge(Interp *interp, SExpRef args); SExpRef builtin_le(Interp *interp, SExpRef args); SExpRef builtin_princ(Interp *interp, SExpRef args); SExpRef builtin_gcstat(Interp *interp, SExpRef args); +SExpRef builtin_alwaysgc(Interp *interp, SExpRef args); #endif diff --git a/src/interp.c b/src/interp.c index 983ba8e..5a23d0b 100644 --- a/src/interp.c +++ b/src/interp.c @@ -140,6 +140,7 @@ void Interp_init(Interp *self) { Interp_add_userfunc(self, "_gcstat", builtin_gcstat); + Interp_add_userfunc(self, "_alwaysgc", builtin_alwaysgc); SExpRef ret = Interp_eval_string(self, bamboo_lisp_prelude); Interp *interp = self; @@ -249,7 +250,7 @@ void Interp_add_primitive(Interp *self, const char *name, LispPrimitive fn) { void Interp_gc(Interp *interp, SExpRef tmproot) { int freesize = IntVector_len(&interp->empty_space); int heapsize = SExpVector_len(&interp->objs); - if (freesize > heapsize >> 4) { + if (freesize > (heapsize >> 4) && !interp->alwaysgc) { return; } SExpRefVector gcstack; diff --git a/src/interp.h b/src/interp.h index 1989ab3..4b9caba 100644 --- a/src/interp.h +++ b/src/interp.h @@ -35,6 +35,7 @@ struct interp { char *errmsg_buf; Parser *parser; int gensym_cnt; + bool alwaysgc; }; void Interp_init(Interp *self); |
