diff --git a/byterun/dep_check.sh b/byterun/dep_check.sh index 76fad74d1..bccbeab48 100755 --- a/byterun/dep_check.sh +++ b/byterun/dep_check.sh @@ -10,17 +10,22 @@ compiler=../_build/default/src/Driver.exe echo "Used compiler path:" echo $compiler -$compiler -b regression/Dep.lama > /dev/null +$compiler -b regression/Dep.lama +$compiler -b -I regression/ regression/Dep2.lama + +$compiler -b ../stdlib/List.lama +$compiler -b ../stdlib/Ref.lama +$compiler -b ../stdlib/Fun.lama for test in regression/dep_test*.lama; do echo $test - $compiler -b $test -I regression/ > /dev/null + $compiler -b $test -I regression/ test_file="${test%.*}" echo $test_file - cat $test_file.input | ./byterun.exe -vi dep_test*.bc > /dev/null + cat $test_file.input | ./byterun.exe -vi dep_test*.bc rm dep_test*.bc echo "done" done -rm Dep.bc +rm *.bc rm *.o diff --git a/byterun/regression/Dep2.i b/byterun/regression/Dep2.i new file mode 100644 index 000000000..445dc0b22 --- /dev/null +++ b/byterun/regression/Dep2.i @@ -0,0 +1,3 @@ +I,Std; +F,f; +F,g; diff --git a/byterun/regression/Dep2.lama b/byterun/regression/Dep2.lama new file mode 100644 index 000000000..7c678f2d7 --- /dev/null +++ b/byterun/regression/Dep2.lama @@ -0,0 +1,3 @@ +import Dep; + +public fun g(a, b) { a * b } diff --git a/byterun/regression/dep_test002.input b/byterun/regression/dep_test002.input new file mode 100644 index 000000000..e69de29bb diff --git a/byterun/regression/dep_test002.lama b/byterun/regression/dep_test002.lama new file mode 100644 index 000000000..32734d6de --- /dev/null +++ b/byterun/regression/dep_test002.lama @@ -0,0 +1,3 @@ +import Dep2; + +f(1, 2) diff --git a/byterun/regression/dep_test003.input b/byterun/regression/dep_test003.input new file mode 100644 index 000000000..e69de29bb diff --git a/byterun/regression/dep_test003.lama b/byterun/regression/dep_test003.lama new file mode 100644 index 000000000..35e9e6ae1 --- /dev/null +++ b/byterun/regression/dep_test003.lama @@ -0,0 +1,4 @@ +import Fun; +import List; + +write(fix (fun (f) {fun (n) {if n == 1 then 1 else n * f (n-1) fi}})(5)) diff --git a/byterun/src/interpreter.c b/byterun/src/interpreter.c index 27bae6d11..e860e3ca4 100644 --- a/byterun/src/interpreter.c +++ b/byterun/src/interpreter.c @@ -82,13 +82,23 @@ void run_prepare_exec(int argc, char **argv) { void run_mod_rec(uint mod_id, int argc, char **argv, bool do_verification) { Bytefile* mod = mod_get(mod_id); +#ifdef DEBUG_VERSION + printf("- run mod rec, %i imports\n", mod->imports_number); +#endif for (size_t i = 0; i < mod->imports_number; ++i) { - if (find_mod_loaded(get_import_safe(mod, i)) < 0 && strcmp(get_import_safe(mod, i), "Std") != 0) { // not loaded - int32_t import_mod = mod_load(get_import_safe(mod, i), do_verification); + const char* import_str = get_import_safe(mod, i); + if (find_mod_loaded(import_str) < 0 && strcmp(import_str, "Std") != 0) { // not loaded +#ifdef DEBUG_VERSION + printf("- mod load <%s>\n", import_str); +#endif + int32_t import_mod = mod_load(import_str, do_verification); if (import_mod < 0) { - failure("module %s not found\n", get_import_safe(mod, i)); + failure("module <%s> not found\n", import_str); } - run_mod_rec(mod_id, argc, argv, do_verification); +#ifdef DEBUG_VERSION + printf("- mod run <%s>\n", import_str); +#endif + run_mod_rec(import_mod, argc, argv, do_verification); } } @@ -390,7 +400,7 @@ void run_mod(uint mod_id, int argc, char **argv) { s.is_closure_call, args_sz, locals_sz); #ifdef WITH_CHECK if ((void **)__gc_stack_top + (aint)max_additional_stack_sz - 1 <= s.stack) { - s_failure(&s, "stack owerflow"); + s_failure(&s, "stack overflow"); } #endif break; @@ -498,7 +508,7 @@ void run_mod(uint mod_id, int argc, char **argv) { struct ModSearchResult func = mod_search_pub_symbol(call_func_name); if (func.mod_file == NULL) { - failure("RUNTIME:ERROR: external function <%s> with <%zu> args not found\n", call_func_name, args_count); + failure("RUNTIME ERROR: external function <%s> with <%zu> args not found\n", call_func_name, args_count); } call_happened = true; diff --git a/byterun/src/module_manager.cpp b/byterun/src/module_manager.cpp index 0d2189885..1a9f66382 100644 --- a/byterun/src/module_manager.cpp +++ b/byterun/src/module_manager.cpp @@ -45,6 +45,9 @@ uint32_t mod_add_impl(Bytefile *bf, bool do_verification, manager.modules.push_back({.name = name ? *name : "", .bf = bf}); for (size_t i = 0; i < bf->public_symbols_number; ++i) { const char *public_name = get_public_name_safe(bf, i); +#ifdef DEBUG_VERSION + std::cerr << "- load public " << public_name << "\n"; +#endif size_t public_offset = get_public_offset_safe(bf, i); if (strcmp(public_name, "main") == 0) { bf->main_offset = public_offset; diff --git a/byterun/src/parser.cpp b/byterun/src/parser.cpp index b8c77b3d0..e50827351 100644 --- a/byterun/src/parser.cpp +++ b/byterun/src/parser.cpp @@ -44,11 +44,11 @@ Bytefile *read_file(const char *fname) { Bytefile *file; if (f == 0) { - failure("%s\n", strerror(errno)); + failure("read file %s: %s\n", fname, strerror(errno)); } if (fseek(f, 0, SEEK_END) == -1) { - failure("%s\n", strerror(errno)); + failure("read file %s: %s\n", fname, strerror(errno)); } long size = ftell(f);