mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-05 22:38:44 +00:00
tests (except exceptions and ostap additional logs print) are passed
This commit is contained in:
parent
4d7afdeae0
commit
d8eb21c066
4 changed files with 27 additions and 20 deletions
|
|
@ -328,7 +328,7 @@ static inline void **var_by_category(enum VarCategory category, size_t id) {
|
||||||
s_failure(&s,
|
s_failure(&s,
|
||||||
"can't read arguments: too big id"); //, %i >= %ul", id, count);
|
"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;
|
return var;
|
||||||
|
|
|
||||||
|
|
@ -395,6 +395,7 @@ void run_main(Bytefile* bf, int argc, char **argv) {
|
||||||
s_failure(&s, "closure");
|
s_failure(&s, "closure");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
s_rotate_n(args_count);
|
||||||
// NOTE: call_offset < 0 => deal with closure of builtin function
|
// NOTE: call_offset < 0 => deal with closure of builtin function
|
||||||
s_push_i(BOX(call_offset));
|
s_push_i(BOX(call_offset));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,32 +12,33 @@ extern "C" {
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
template <size_t N, typename... Args>
|
template <size_t N, bool return_value, typename... Args>
|
||||||
requires(N == 0)
|
requires(N == 0)
|
||||||
void call_func(void (*f)(), size_t n, Args... args) {
|
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"
|
asm volatile("movq %0, %%r11"
|
||||||
: /* no outputs */
|
: /* no outputs */
|
||||||
: "m"(n));
|
: "m"(n));
|
||||||
/*s_push(*/ ((void (*)(Args...))f)(args...); //);
|
if constexpr (return_value) {
|
||||||
s_push(0);
|
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)
|
requires(N != 0)
|
||||||
void call_func(void (*f)(), size_t n, Args... args) {
|
void call_func(void (*f)(), size_t n, Args... args) {
|
||||||
void *arg = s_pop();
|
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
|
// 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) {
|
void call_anyarg_func(void (*f)(), size_t n) {
|
||||||
if constexpr (do_check) {
|
if constexpr (do_check) {
|
||||||
if (n > N) {
|
if (n > N) {
|
||||||
|
|
@ -45,9 +46,9 @@ void call_anyarg_func(void (*f)(), size_t n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (n == N) {
|
if (n == N) {
|
||||||
call_func<N>(f, n);
|
call_func<N, return_value>(f, n);
|
||||||
} else if constexpr (N > 0) {
|
} 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;
|
break;
|
||||||
case BUILTIN_Lassert:
|
case BUILTIN_Lassert:
|
||||||
// NOTE: basic params: .args_count = 2, .is_vararg = true
|
// 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;
|
break;
|
||||||
case BUILTIN_Lstring:
|
case BUILTIN_Lstring:
|
||||||
ret = Lstring(s_nth_i(0)); // .is_args = true
|
ret = Lstring(s_nth_i(0)); // .is_args = true
|
||||||
|
|
@ -641,7 +642,7 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
|
||||||
break;
|
break;
|
||||||
case BUILTIN_Lsprintf:
|
case BUILTIN_Lsprintf:
|
||||||
// NOTE: basic params: .args_count = 1, .is_vararg = true
|
// 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;
|
break;
|
||||||
case BUILTIN_Lsubstring:
|
case BUILTIN_Lsubstring:
|
||||||
// std::cout << "substr\n";
|
// std::cout << "substr\n";
|
||||||
|
|
@ -707,7 +708,7 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
|
||||||
break;
|
break;
|
||||||
case BUILTIN_Lprintf:
|
case BUILTIN_Lprintf:
|
||||||
// NOTE: basic params: .args_count = 1, .is_vararg = true
|
// 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;
|
break;
|
||||||
case BUILTIN_Lfopen:
|
case BUILTIN_Lfopen:
|
||||||
ret = (void *)Lfopen((char *)*s_nth(1), (char *)*s_nth(0));
|
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;
|
break;
|
||||||
case BUILTIN_Lfprintf:
|
case BUILTIN_Lfprintf:
|
||||||
// NOTE: basic params: .args_count = 2, .is_vararg = true
|
// 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;
|
break;
|
||||||
case BUILTIN_Lregexp:
|
case BUILTIN_Lregexp:
|
||||||
ret = (void *)Lregexp((char *)*s_nth(0));
|
ret = (void *)Lregexp((char *)*s_nth(0));
|
||||||
|
|
@ -751,7 +752,7 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
|
||||||
break;
|
break;
|
||||||
case BUILTIN_Lfailure:
|
case BUILTIN_Lfailure:
|
||||||
// NOTE: basic params: .args_count = 1, .is_vararg = true
|
// 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;
|
break;
|
||||||
case BUILTIN_Lsystem:
|
case BUILTIN_Lsystem:
|
||||||
ret = (void *)Lsystem((char *)*s_nth(0));
|
ret = (void *)Lsystem((char *)*s_nth(0));
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,16 @@ for test in ../stdlib/regression/*.lama; do
|
||||||
# echo "" | ./byterun.exe -p $test_file.bc
|
# echo "" | ./byterun.exe -p $test_file.bc
|
||||||
# echo "" | ./byterun.exe -vi $test_file.bc
|
# echo "" | ./byterun.exe -vi $test_file.bc
|
||||||
echo "" | ./byterun.exe -vi $test_file.bc > test.log
|
echo "" | ./byterun.exe -vi $test_file.bc > test.log
|
||||||
# sed '1d;s/^..//' $test_file.t > test_orig.log
|
sed '1d;2d;3d;s/^..//' $test_path.t > test_orig.log
|
||||||
# diff test.log 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_file.bc
|
||||||
# rm test.log test_orig.log
|
rm test.log test_orig.log
|
||||||
echo "done"
|
echo "done"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue