diff --git a/byterun/include/runtime_externs.h b/byterun/include/runtime_externs.h index 7585f14ba..c9ef96b75 100644 --- a/byterun/include/runtime_externs.h +++ b/byterun/include/runtime_externs.h @@ -84,7 +84,7 @@ struct re_pattern_buffer *Lregexp(char *regexp); int LregexpMatch(struct re_pattern_buffer *b, char *s, int pos); -void *Bstring(void *); +void *Bstring(void *p); void *Lclone(void *p); diff --git a/byterun/include/stack.h b/byterun/include/stack.h index 1679345e1..a3fde5a27 100644 --- a/byterun/include/stack.h +++ b/byterun/include/stack.h @@ -31,3 +31,7 @@ void s_enter_f(struct State *s, char *func_ip, size_t params_sz, void s_exit_f(struct State *s); void **var_by_category(struct State *s, enum VarCategory category, int id); + +// --- changed runtime operations --- + +void *s_Bsexp(struct State *state, int bn, int tag); diff --git a/byterun/src/interpreter.c b/byterun/src/interpreter.c index 03b93f39c..4caa5cd90 100644 --- a/byterun/src/interpreter.c +++ b/byterun/src/interpreter.c @@ -67,17 +67,19 @@ void run(bytefile *bf) { if (l < 1) { failure("BINOP: l < 1"); } - f_binop(&s, ops[l-1]); + void* left = s_pop(&s); + void* right = s_pop(&s); + s_push(&s, (void*)ops_func[l-1](left, right)); break; case 1: switch (l) { case 0: // CONST %d - s_put_i(&s, ip_read_int(&s.ip)); + s_push(&s, (void*)BOX(ip_read_int(&s.ip))); break; case 1: // STRING %s - s_put_const_str(&s, ip_read_string(&s.ip, bf)); + s_push(&s, Bstring((void*)ip_read_string(&s.ip, bf))); break; case 2: // SEXP %s %d // create sexpr with tag=%s and %d elements from stack diff --git a/byterun/src/stack.c b/byterun/src/stack.c index 07033b38b..834cb454a 100644 --- a/byterun/src/stack.c +++ b/byterun/src/stack.c @@ -4,6 +4,19 @@ extern size_t STACK_SIZE; +extern size_t __gc_stack_top, __gc_stack_bottom; + +#define PRE_GC() \ + bool flag = false; \ + flag = __gc_stack_top == 0; \ + if (flag) { __gc_stack_top = (size_t)__builtin_frame_address(0); } \ + assert(__gc_stack_top != 0); \ + assert(__builtin_frame_address(0) <= (void *)__gc_stack_top); + +#define POST_GC() \ + assert(__builtin_frame_address(0) <= (void *)__gc_stack_top); \ + if (flag) { __gc_stack_top = 0; } + // ------ basic stack oprs ------ void s_push(struct State *s, void *val) { @@ -134,3 +147,5 @@ void **var_by_category(struct State *s, enum VarCategory category, return var; } + +// --- changed runtime operations --- diff --git a/byterun/src/types.c b/byterun/src/types.c index 8307b7724..5d2f3d06a 100644 --- a/byterun/src/types.c +++ b/byterun/src/types.c @@ -20,7 +20,7 @@ void **f_prev_fp(struct Frame *fp) { uint64_t f_locals_sz(struct Frame *fp) { return UNBOX(fp->locals_sz_box); } uint64_t f_args_sz(struct Frame *fp) { return UNBOX(fp->args_sz_box); } void **f_locals(struct Frame *fp) { return (void **)fp - f_locals_sz(fp) - frame_sz(); } -void **f_args(struct Frame *fp) { return (void **)fp + f_args_sz(fp); } +void **f_args(struct Frame *fp) { return (void **)fp + 1; } // --- State ---