From 1548c16eeb9b6b20d772b77f22dae55c19628404 Mon Sep 17 00:00:00 2001 From: ProgramSnail Date: Thu, 14 Nov 2024 00:59:36 +0300 Subject: [PATCH] fixes, some cleanup --- byterun/Sort.bc | Bin 839 -> 0 bytes byterun/include/stack.h | 12 ++++++++---- byterun/src/cli.c | 1 - byterun/src/interpreter.c | 24 +----------------------- 4 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 byterun/Sort.bc diff --git a/byterun/Sort.bc b/byterun/Sort.bc deleted file mode 100644 index 29990be1a288b6db181dcfd2173f2c63cdae66c8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 839 zcmZuw!A-+J5IhWo#0V(_&RWYL-424zk>@i&-OJ<|mSVp#PB<_2yP|nh%@g7ujc__z6%{_1iKP{n6O-^B z#T~_@s1Udiwpy~hB;5=ES+8~d`Wjd_>C!0iVq~WMyiNQve(5d0q?7H#((SUGX{(JZ ze*r7@6LD?4I30hraiD68iIn7gD 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;