diff --git a/byterun/include/module_manager.h b/byterun/include/module_manager.h index 00452b9e9..91ad07c61 100644 --- a/byterun/include/module_manager.h +++ b/byterun/include/module_manager.h @@ -3,6 +3,7 @@ #include #include +#include "parser.h" #include "utils.h" Bytefile *run_with_imports(Bytefile *root, int argc, char **argv, @@ -50,8 +51,16 @@ enum BUILTIN : uint { BUILTIN_LgetEnv, // 36 BUILTIN_Lrandom, // 37 BUILTIN_Ltime, // 38 - BUILTIN_Barray, // 39 // can't be run with run_stdlib_func - BUILTIN_NONE, // 40 + // + BUILTIN_LkindOf, // 39 + BUILTIN_LcompareTags, // 40 +// +#define BUILTIN_NAME(name) BUILTIN_##name, + FORALL_BINOP_FUNC(BUILTIN_NAME) +#undef BUILTIN_NAME + // + BUILTIN_Barray, // 41+14 // can't be run with run_stdlib_func + BUILTIN_NONE, // 42+14 }; enum BUILTIN id_by_builtin(const char *name); diff --git a/byterun/include/parser.h b/byterun/include/parser.h index 23ec0a768..1a275f29e 100644 --- a/byterun/include/parser.h +++ b/byterun/include/parser.h @@ -19,6 +19,23 @@ DEF(CMD_BINOP_AND, &&) \ DEF(CMD_BINOP_OR, ||) +// NOTE: includes additional ':' operator +#define FORALL_BINOP_FUNC(DEF) \ + DEF(Ls__Infix_58) \ + DEF(Ls__Infix_3333) \ + DEF(Ls__Infix_3838) \ + DEF(Ls__Infix_6161) \ + DEF(Ls__Infix_3361) \ + DEF(Ls__Infix_6061) \ + DEF(Ls__Infix_60) \ + DEF(Ls__Infix_6261) \ + DEF(Ls__Infix_62) \ + DEF(Ls__Infix_43) \ + DEF(Ls__Infix_45) \ + DEF(Ls__Infix_42) \ + DEF(Ls__Infix_47) \ + DEF(Ls__Infix_37) + const char *read_cmd(char *ip, const Bytefile *bf); // Bytefile *read_file(const char *fname); diff --git a/byterun/src/interpreter.c b/byterun/src/interpreter.c index 79ca676f4..14de0320c 100644 --- a/byterun/src/interpreter.c +++ b/byterun/src/interpreter.c @@ -454,7 +454,7 @@ void run_main(Bytefile* bf, int argc, char **argv) { case CMD_CTRL_FAIL: { // FAIL %d %d int line = ip_read_int(&s.ip); int col = ip_read_int(&s.ip); - print_stack(&s); + print_stack(&s); // NOTE: debug info Bmatch_failure(s_pop(), argv[0], BOX(line), BOX(col)); break; } diff --git a/byterun/src/module_manager.cpp b/byterun/src/module_manager.cpp index c3ca2b1e8..e8fbc3d3b 100644 --- a/byterun/src/module_manager.cpp +++ b/byterun/src/module_manager.cpp @@ -492,7 +492,6 @@ struct StdFunc { bool is_vararg = false; }; -// TODO: FIXME: add kind, binops BUILTIN id_by_builtin(const char *name) { static const std::unordered_map std_func = { {"Luppercase", BUILTIN_Luppercase}, @@ -534,6 +533,14 @@ BUILTIN id_by_builtin(const char *name) { {"LgetEnv", BUILTIN_LgetEnv}, {"Lrandom", BUILTIN_Lrandom}, {"Ltime", BUILTIN_Ltime}, + // + {"LkindOf", BUILTIN_LkindOf}, + {"LcompareTags", BUILTIN_LcompareTags}, + // +#define BUILTIN_ELEM(name) {#name, BUILTIN_##name}, + FORALL_BINOP_FUNC(BUILTIN_ELEM) +#undef BUILTIN_ELEM + // {".array", BUILTIN_Barray}, }; @@ -558,8 +565,10 @@ void run_stdlib_func(BUILTIN id, size_t args_count) { s_push(ret); break; case BUILTIN_Lassert: - // .args_count = 2, .is_vararg = true - call_anyarg_func<20>((void (*)()) & Lassert, args_count); + s_popn(args_count); + std::cout << "!!> assert is not properly checked yet, skipping\n"; + // NOTE: basic params: .args_count = 2, .is_vararg = true + // call_anyarg_func<20>((void (*)()) & Lassert, args_count); break; case BUILTIN_Lstring: ret = Lstring(s_nth_i(0)); // .is_args = true @@ -608,8 +617,10 @@ void run_stdlib_func(BUILTIN id, size_t args_count) { s_push(ret); break; case BUILTIN_Lsprintf: - // .args_count = 1, .is_vararg = true - call_anyarg_func<20>((void (*)()) & Lsprintf, args_count); + s_popn(args_count); + std::cout << "!!> printf is not properly checked yet, skipping\n"; + // NOTE: basic params: .args_count = 1, .is_vararg = true + // call_anyarg_func<20>((void (*)()) & Lsprintf, args_count); break; case BUILTIN_Lsubstring: ret = (void *)Lsubstring(s_nth_i(0)); // .is_args = true; @@ -671,8 +682,10 @@ void run_stdlib_func(BUILTIN id, size_t args_count) { s_push(ret); break; case BUILTIN_Lprintf: - // .args_count = 1, .is_vararg = true - call_anyarg_func<20>((void (*)()) & Lprintf, args_count); + s_popn(args_count); + std::cout << "!!> printf is not properly checked yet, skipping\n"; + // NOTE: basic params: .args_count = 1, .is_vararg = true + // call_anyarg_func<20>((void (*)()) & Lprintf, args_count); break; case BUILTIN_Lfopen: ret = (void *)Lfopen((char *)*s_nth(1), (char *)*s_nth(0)); @@ -700,8 +713,10 @@ void run_stdlib_func(BUILTIN id, size_t args_count) { s_push(ret); break; case BUILTIN_Lfprintf: - // .args_count = 2, .is_vararg = true - call_anyarg_func<20>((void (*)()) & Lfprintf, args_count); + s_popn(args_count); + std::cout << "!!> printf is not properly checked yet, skipping\n"; + // NOTE: basic params: .args_count = 2, .is_vararg = true + // call_anyarg_func<20>((void (*)()) & Lfprintf, args_count); break; case BUILTIN_Lregexp: ret = (void *)Lregexp((char *)*s_nth(0)); @@ -715,8 +730,9 @@ void run_stdlib_func(BUILTIN id, size_t args_count) { s_push(ret); break; case BUILTIN_Lfailure: - // .args_count = 1, .is_vararg = true - call_anyarg_func<20>((void (*)()) & Lfailure, args_count); + std::cout << "!!> failure is not properly checked yet, skipping\n"; + // NOTE: basic params: .args_count = 1, .is_vararg = true + // call_anyarg_func<20>((void (*)()) & Lfailure, args_count); break; case BUILTIN_Lsystem: ret = (void *)Lsystem((char *)*s_nth(0)); @@ -737,6 +753,24 @@ void run_stdlib_func(BUILTIN id, size_t args_count) { ret = (void *)Ltime(); s_push(ret); break; + case BUILTIN_LkindOf: + ret = (void *)LkindOf(*s_nth(0)); + s_popn(1); + s_push(ret); + break; + case BUILTIN_LcompareTags: + ret = (void *)LcompareTags((char *)*s_nth(1), (char *)*s_nth(0)); + s_popn(2); + s_push(ret); + break; +#define BUILTIN_CASE(name) \ + case BUILTIN_##name: \ + ret = (void *)name((char *)*s_nth(1), (char *)*s_nth(0)); \ + s_popn(2); \ + s_push(ret); \ + break; + FORALL_BINOP_FUNC(BUILTIN_CASE) +#undef BUILTIN_CASE default: failure("RUNTIME ERROR: stdlib function <%u> not found\n", id); break; diff --git a/byterun/stdlib_regression_check.sh b/byterun/stdlib_regression_check.sh index 18eaf47b5..6ff55eac7 100755 --- a/byterun/stdlib_regression_check.sh +++ b/byterun/stdlib_regression_check.sh @@ -17,7 +17,7 @@ for mod in ../stdlib/*.lama; do done echo "Run tests:" -for test in ../stdlib/regression/*01.lama; do +for test in ../stdlib/regression/*.lama; do echo $test $compiler -b $test -I ../stdlib/ > /dev/null test_file="${test%.*}" @@ -25,7 +25,7 @@ for test in ../stdlib/regression/*01.lama; do # cat $test_file.input | ./byterun.exe -p test*.bc > test.bc.code # cat $test_file.input | ./byterun.exe -p test*.bc echo "" | ./byterun.exe -vi test*.bc - echo "" | ./byterun.exe -vi test*.bc > test.log + # echo "" | ./byterun.exe -vi test*.bc > test.log # sed '1d;s/^..//' $test_file.t > test_orig.log # diff test.log test_orig.log