diff --git a/byterun/include/stack.h b/byterun/include/stack.h index e04ecdb46..246c855de 100644 --- a/byterun/include/stack.h +++ b/byterun/include/stack.h @@ -173,7 +173,9 @@ static inline void s_enter_f(char *rp, bool is_closure_call, auint args_sz, s_failure(&s, "not enough parameters in function stack"); } - void *closure = is_closure_call ? s_nth(args_sz) : NULL; + void *closure = is_closure_call ? *s_nth(args_sz) : NULL; + // printf("is_closure_call: %i, closure: %li\n", is_closure_call, + // (aint)closure); // s_push_nil(s); // sp contains value, frame starts with next value s_pushn_nil(frame_sz()); @@ -289,15 +291,15 @@ static inline void **var_by_category(enum VarCategory category, size_t id) { s_failure(&s, "not boxed value expected in closure index"); } data *d = TO_DATA(s.fp->closure); - size_t count = get_len(d) - 1; + int count = get_len(d) - 1; #ifdef DEBUG_VERSION printf("id is %i, count is %i\n", id, count); #endif - if (count <= id) { + if ((int64_t)id >= count) { s_failure(&s, "can't read arguments: too big id"); //, %i >= %ul", id, count); } - return (void **)d->contents + id; // order is not important + return ((void **)d->contents) + count - id; // order is not important } return var; diff --git a/byterun/regression_check.sh b/byterun/regression_check.sh index 92dec825a..a7dd02d4c 100755 --- a/byterun/regression_check.sh +++ b/byterun/regression_check.sh @@ -8,11 +8,12 @@ suffix=".lama" for test in ../regression/*.lama; do echo $test lamac -b $test > /dev/null - ./byterun.exe -v test*.bc > /dev/null + test_file="${test%.*}" + echo $test_file + cat $test_file.input | ./byterun.exe -vi test*.bc > /dev/null rm test*.bc echo "done" done -rm test.bc rm *.o diff --git a/byterun/src/analyzer.cpp b/byterun/src/analyzer.cpp index 2f86801e3..a437f62aa 100644 --- a/byterun/src/analyzer.cpp +++ b/byterun/src/analyzer.cpp @@ -128,11 +128,11 @@ void analyze(Bytefile *bf) { current_ip = ip; saved_current_ip = current_ip; - // #ifdef DEBUG_VERSION +#ifdef DEBUG_VERSION const auto [cmd, l] = parse_command(&ip, bf, std::cout); - // #else - // const auto [cmd, l] = parse_command(&ip, bf); - // #endif +#else + const auto [cmd, l] = parse_command(&ip, bf); +#endif if (current_begin_counter == nullptr && cmd != Cmd::BEGIN && cmd != Cmd::CBEGIN) { @@ -144,9 +144,9 @@ void analyze(Bytefile *bf) { } current_stack_depth = visited[current_ip - bf->code_ptr]; - // #ifdef DEBUG_VERSION +#ifdef DEBUG_VERSION std::cout << " -- [" << current_stack_depth << ']' << '\n'; - // #endif +#endif ++current_ip; // skip command byte diff --git a/byterun/src/interpreter.c b/byterun/src/interpreter.c index 3dc5475d6..8008fb3b2 100644 --- a/byterun/src/interpreter.c +++ b/byterun/src/interpreter.c @@ -14,7 +14,7 @@ void *__stop_custom_data; #define ASSERT_UNBOXED(memo, x) \ do \ if (!UNBOXED(x)) \ - failure("unboxed value expected in %s\n", memo); \ + failure("%s: unboxed value expected in %s\n", __LINE__, memo); \ while (0) struct State s; @@ -94,9 +94,9 @@ void run(Bytefile *bf, int argc, char **argv) { s.instr_ip = s.ip; uint8_t x = ip_read_byte(&s.ip), h = (x & 0xF0) >> 4, l = x & 0x0F; -#ifdef DEBUG_VERSION - printf("0x%.8x\n", s.ip - bf->code_ptr - 1); -#endif +// #ifdef DEBUG_VERSION + printf("0x%.8x: %s\n", s.ip - bf->code_ptr - 1, read_cmd(s.ip - 1, s.bf)); +// #endif switch (h) { case CMD_EXIT: @@ -106,10 +106,13 @@ void run(Bytefile *bf, int argc, char **argv) { case CMD_BINOP: { // BINOP ops[l-1] void *snd = s_pop(); void *fst = s_pop(); - if (l == CMD_BINOP_SUB) { + int op = l - 1; + if (op == CMD_BINOP_SUB) { s_push_i(Ls__Infix_45(fst, snd)); + } else if (op == CMD_BINOP_EQ) { + s_push_i(Ls__Infix_6161(fst, snd)); } else { - switch (l - 1) { + switch (op) { #define BINOP_OPR(val, op) \ case val: \ ASSERT_UNBOXED("captured op:1", fst); \ @@ -357,7 +360,8 @@ void run(Bytefile *bf, int argc, char **argv) { #endif s_push(bf->code_ptr + call_offset); - void *closure = Bclosure((aint *)__gc_stack_top, args_count); + void *closure = Bclosure((aint *)__gc_stack_top, BOX(args_count)); + // printf("args is %li, count is %li\n", args_count, get_len(TO_DATA(closure))); s_popn(args_count + 1); s_push(closure); @@ -397,8 +401,8 @@ void run(Bytefile *bf, int argc, char **argv) { aint args_count = ip_read_int(&s.ip); #ifdef DEBUG_VERSION - printf("tag hash is %i, n is %i, peek is %i\n", - UNBOX(LtagHash((char *)name)), args_count, s_peek(&s)); + printf("tag hash is %i, n is %i, peek is %i, unboxed: %li\n", + UNBOX(LtagHash((char *)name)), args_count, s_peek(&s), UNBOXED(s_peek(&s))); #endif s_push_i(Btag(s_pop(), LtagHash((char *)name), BOX(args_count))); diff --git a/byterun/src/parser.cpp b/byterun/src/parser.cpp index a2795a606..918747759 100644 --- a/byterun/src/parser.cpp +++ b/byterun/src/parser.cpp @@ -596,7 +596,7 @@ void print_file(const Bytefile &bf, std::ostream &out) { while (true) { out << std::setfill('0') << std::setw(8) << std::hex << ip - bf.code_ptr - << ": "; + << ": " << std::dec; const auto [cmd, l] = parse_command(&ip, &bf, out); out << '\n';