diff --git a/byterun/Sort.bc b/byterun/Sort.bc deleted file mode 100644 index 29990be1a..000000000 Binary files a/byterun/Sort.bc and /dev/null differ diff --git a/byterun/include/stack.h b/byterun/include/stack.h index df60e8a61..e6b9f0c6f 100644 --- a/byterun/include/stack.h +++ b/byterun/include/stack.h @@ -66,8 +66,12 @@ static inline void s_push_i(aint val) { s_push((void *)val); } static inline void s_push_nil() { s_push(NULL); } static inline void s_pushn_nil(size_t n) { + if ((void **)__gc_stack_top + (aint)n - 1 <= s.stack) { + s_failure(&s, "stack overflow"); + } for (size_t i = 0; i < n; ++i) { - s_push(NULL); + __gc_stack_top -= sizeof(void *); + *(void **)__gc_stack_top = NULL; } } @@ -82,7 +86,6 @@ static inline void *s_pop() { printf("--> pop\n"); #endif void *value = *(void **)__gc_stack_top; - // *(void **)__gc_stack_top = NULL; __gc_stack_top += sizeof(void *); return value; } @@ -90,9 +93,10 @@ static inline void *s_pop() { static inline aint s_pop_i() { return (aint)s_pop(); } static inline void s_popn(size_t n) { - for (size_t i = 0; i < n; ++i) { - s_pop(); + if ((void **)__gc_stack_top + (aint)n - 1 >= s_top()) { + s_failure(&s, "empty stack"); } + __gc_stack_top += n * sizeof(void *); } // ------ functions ------ diff --git a/byterun/src/cli.c b/byterun/src/cli.c index c0d0a2dc3..b580ffb2c 100644 --- a/byterun/src/cli.c +++ b/byterun/src/cli.c @@ -8,7 +8,6 @@ int main(int argc, char** argv) { failure("no file name provided"); } - // printf("size of aint is %i\n", sizeof(aint)); bytefile *f = read_file(argv[1]); // #ifdef DEBUG_VERSION // dump_file (stdout, f); diff --git a/byterun/src/interpreter.c b/byterun/src/interpreter.c index b215a50c1..9ed9df2b5 100644 --- a/byterun/src/interpreter.c +++ b/byterun/src/interpreter.c @@ -40,27 +40,6 @@ void run(bytefile *bf, int argc, char **argv) { printf("--- interpreter run ---\n"); #endif - // const char *ops[] = { - // "+", "-", "*", "/", "%", "<", "<=", ">", ">=", "==", "!=", "&&", "!!"}; - // aint (*ops_func[])(void *, void *) = { - // &Ls__Infix_43, // + - // &Ls__Infix_45, // - - // &Ls__Infix_42, // * - // &Ls__Infix_47, // / - // &Ls__Infix_37, // % - // &Ls__Infix_60, // < - // &Ls__Infix_6061, // <= - // &Ls__Infix_62, // > - // &Ls__Infix_6261, // >= - // &Ls__Infix_6161, // == - // &Ls__Infix_3361, // != - // &Ls__Infix_3838, // && - // &Ls__Infix_3333, // !! - // }; - - // const char *pats[] = {"=str", "#string", "#array", "#sexp", - // "#ref", "#val", "#fun"}; - // argc, argv { s_push_i(BOX(argc)); @@ -78,7 +57,6 @@ void run(bytefile *bf, int argc, char **argv) { #endif do { - // char *before_op_ip = s.ip; // save to set s.prev_ip bool call_happened = false; if (s.ip >= bf->code_ptr + bf->code_size) { @@ -104,7 +82,7 @@ void run(bytefile *bf, int argc, char **argv) { case CMD_BINOP: { // BINOP ops[l-1] void *left = s_pop(); void *right = s_pop(); - switch ((int)l) { + switch (l) { case CMD_BINOP_ADD: // + s_push_i(Ls__Infix_43(right, left)); break;