mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-05 22:38:44 +00:00
interpreter: recursive module fix, more tests
This commit is contained in:
parent
58f0bfc0b9
commit
b6b843fb44
10 changed files with 43 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
3
byterun/regression/Dep2.i
Normal file
3
byterun/regression/Dep2.i
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
I,Std;
|
||||
F,f;
|
||||
F,g;
|
||||
3
byterun/regression/Dep2.lama
Normal file
3
byterun/regression/Dep2.lama
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import Dep;
|
||||
|
||||
public fun g(a, b) { a * b }
|
||||
0
byterun/regression/dep_test002.input
Normal file
0
byterun/regression/dep_test002.input
Normal file
3
byterun/regression/dep_test002.lama
Normal file
3
byterun/regression/dep_test002.lama
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import Dep2;
|
||||
|
||||
f(1, 2)
|
||||
0
byterun/regression/dep_test003.input
Normal file
0
byterun/regression/dep_test003.input
Normal file
4
byterun/regression/dep_test003.lama
Normal file
4
byterun/regression/dep_test003.lama
Normal file
|
|
@ -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))
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue