tests (except exceptions and ostap additional logs print) are passed

This commit is contained in:
ProgramSnail 2025-04-12 21:00:20 +03:00
parent 4d7afdeae0
commit d8eb21c066
4 changed files with 27 additions and 20 deletions

View file

@ -328,7 +328,7 @@ static inline void **var_by_category(enum VarCategory category, size_t id) {
s_failure(&s,
"can't read arguments: too big id"); //, %i >= %ul", id, count);
}
return ((void **)d->contents) + count - id; // order is not important
return ((void **)d->contents) + id + 1; // order is not important
}
return var;

View file

@ -395,6 +395,7 @@ void run_main(Bytefile* bf, int argc, char **argv) {
s_failure(&s, "closure");
}
#endif
s_rotate_n(args_count);
// NOTE: call_offset < 0 => deal with closure of builtin function
s_push_i(BOX(call_offset));

View file

@ -12,32 +12,33 @@ extern "C" {
#include <filesystem>
#include <map>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
template <size_t N, typename... Args>
template <size_t N, bool return_value, typename... Args>
requires(N == 0)
void call_func(void (*f)(), size_t n, Args... args) {
// std::cout << std::endl << "args_count=" << n << " "; // TODO FIXME TMP
std::cout << std::endl; // TODO: TMP, to work with problematic \n display
asm volatile("movq %0, %%r11"
: /* no outputs */
: "m"(n));
/*s_push(*/ ((void (*)(Args...))f)(args...); //);
s_push(0);
if constexpr (return_value) {
s_push(((void *(*)(Args...))f)(args...));
} else {
((void (*)(Args...))f)(args...);
s_push(0);
}
}
template <size_t N, typename... Args>
template <size_t N, bool return_value, typename... Args>
requires(N != 0)
void call_func(void (*f)(), size_t n, Args... args) {
void *arg = s_pop();
call_func<N - 1, Args..., void *>(f, n, arg, args...);
call_func<N - 1, return_value, Args..., void *>(f, n, arg, args...);
// TODO: check that arg is added on the right position
}
template <size_t N, bool do_check = true>
template <size_t N, bool return_value, bool do_check = true>
void call_anyarg_func(void (*f)(), size_t n) {
if constexpr (do_check) {
if (n > N) {
@ -45,9 +46,9 @@ void call_anyarg_func(void (*f)(), size_t n) {
}
}
if (n == N) {
call_func<N>(f, n);
call_func<N, return_value>(f, n);
} else if constexpr (N > 0) {
call_anyarg_func<N - 1, false>(f, n);
call_anyarg_func<N - 1, return_value, false>(f, n);
}
}
@ -591,7 +592,7 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
break;
case BUILTIN_Lassert:
// NOTE: basic params: .args_count = 2, .is_vararg = true
call_anyarg_func<20>((void (*)()) & Lassert, args_count);
call_anyarg_func<20, false>((void (*)()) & Lassert, args_count);
break;
case BUILTIN_Lstring:
ret = Lstring(s_nth_i(0)); // .is_args = true
@ -641,7 +642,7 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
break;
case BUILTIN_Lsprintf:
// NOTE: basic params: .args_count = 1, .is_vararg = true
call_anyarg_func<20>((void (*)()) & Lsprintf, args_count);
call_anyarg_func<20, true>((void (*)()) & Lsprintf, args_count);
break;
case BUILTIN_Lsubstring:
// std::cout << "substr\n";
@ -707,7 +708,7 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
break;
case BUILTIN_Lprintf:
// NOTE: basic params: .args_count = 1, .is_vararg = true
call_anyarg_func<20>((void (*)()) & Lprintf, args_count);
call_anyarg_func<20, false>((void (*)()) & Lprintf, args_count);
break;
case BUILTIN_Lfopen:
ret = (void *)Lfopen((char *)*s_nth(1), (char *)*s_nth(0));
@ -736,7 +737,7 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
break;
case BUILTIN_Lfprintf:
// NOTE: basic params: .args_count = 2, .is_vararg = true
call_anyarg_func<20>((void (*)()) & Lfprintf, args_count);
call_anyarg_func<20, false>((void (*)()) & Lfprintf, args_count);
break;
case BUILTIN_Lregexp:
ret = (void *)Lregexp((char *)*s_nth(0));
@ -751,7 +752,7 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
break;
case BUILTIN_Lfailure:
// NOTE: basic params: .args_count = 1, .is_vararg = true
call_anyarg_func<20>((void (*)()) & Lfailure, args_count);
call_anyarg_func<20, false>((void (*)()) & Lfailure, args_count);
break;
case BUILTIN_Lsystem:
ret = (void *)Lsystem((char *)*s_nth(0));

View file

@ -31,11 +31,16 @@ for test in ../stdlib/regression/*.lama; do
# echo "" | ./byterun.exe -p $test_file.bc
# echo "" | ./byterun.exe -vi $test_file.bc
echo "" | ./byterun.exe -vi $test_file.bc > test.log
# sed '1d;s/^..//' $test_file.t > test_orig.log
# diff test.log test_orig.log
sed '1d;2d;3d;s/^..//' $test_path.t > test_orig.log
# echo "Result:"
# cat test.log
# echo "Original:"
# cat test_orig.log
echo "Diff:"
diff test.log test_orig.log
rm $test_file.bc
# rm test.log test_orig.log
rm test.log test_orig.log
echo "done"
done