mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-05 22:38:44 +00:00
fixes, more stdlib functions (& stdlib binops), printf and etc. temporally disabled
This commit is contained in:
parent
43088ec9f9
commit
3834897b78
5 changed files with 76 additions and 16 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "parser.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
Bytefile *run_with_imports(Bytefile *root, int argc, char **argv,
|
Bytefile *run_with_imports(Bytefile *root, int argc, char **argv,
|
||||||
|
|
@ -50,8 +51,16 @@ enum BUILTIN : uint {
|
||||||
BUILTIN_LgetEnv, // 36
|
BUILTIN_LgetEnv, // 36
|
||||||
BUILTIN_Lrandom, // 37
|
BUILTIN_Lrandom, // 37
|
||||||
BUILTIN_Ltime, // 38
|
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);
|
enum BUILTIN id_by_builtin(const char *name);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,23 @@
|
||||||
DEF(CMD_BINOP_AND, &&) \
|
DEF(CMD_BINOP_AND, &&) \
|
||||||
DEF(CMD_BINOP_OR, ||)
|
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);
|
const char *read_cmd(char *ip, const Bytefile *bf);
|
||||||
|
|
||||||
// Bytefile *read_file(const char *fname);
|
// Bytefile *read_file(const char *fname);
|
||||||
|
|
|
||||||
|
|
@ -454,7 +454,7 @@ void run_main(Bytefile* bf, int argc, char **argv) {
|
||||||
case CMD_CTRL_FAIL: { // FAIL %d %d
|
case CMD_CTRL_FAIL: { // FAIL %d %d
|
||||||
int line = ip_read_int(&s.ip);
|
int line = ip_read_int(&s.ip);
|
||||||
int col = 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));
|
Bmatch_failure(s_pop(), argv[0], BOX(line), BOX(col));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -492,7 +492,6 @@ struct StdFunc {
|
||||||
bool is_vararg = false;
|
bool is_vararg = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: FIXME: add kind, binops
|
|
||||||
BUILTIN id_by_builtin(const char *name) {
|
BUILTIN id_by_builtin(const char *name) {
|
||||||
static const std::unordered_map<std::string, BUILTIN> std_func = {
|
static const std::unordered_map<std::string, BUILTIN> std_func = {
|
||||||
{"Luppercase", BUILTIN_Luppercase},
|
{"Luppercase", BUILTIN_Luppercase},
|
||||||
|
|
@ -534,6 +533,14 @@ BUILTIN id_by_builtin(const char *name) {
|
||||||
{"LgetEnv", BUILTIN_LgetEnv},
|
{"LgetEnv", BUILTIN_LgetEnv},
|
||||||
{"Lrandom", BUILTIN_Lrandom},
|
{"Lrandom", BUILTIN_Lrandom},
|
||||||
{"Ltime", BUILTIN_Ltime},
|
{"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},
|
{".array", BUILTIN_Barray},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -558,8 +565,10 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
|
||||||
s_push(ret);
|
s_push(ret);
|
||||||
break;
|
break;
|
||||||
case BUILTIN_Lassert:
|
case BUILTIN_Lassert:
|
||||||
// .args_count = 2, .is_vararg = true
|
s_popn(args_count);
|
||||||
call_anyarg_func<20>((void (*)()) & Lassert, 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;
|
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
|
||||||
|
|
@ -608,8 +617,10 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
|
||||||
s_push(ret);
|
s_push(ret);
|
||||||
break;
|
break;
|
||||||
case BUILTIN_Lsprintf:
|
case BUILTIN_Lsprintf:
|
||||||
// .args_count = 1, .is_vararg = true
|
s_popn(args_count);
|
||||||
call_anyarg_func<20>((void (*)()) & Lsprintf, 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;
|
break;
|
||||||
case BUILTIN_Lsubstring:
|
case BUILTIN_Lsubstring:
|
||||||
ret = (void *)Lsubstring(s_nth_i(0)); // .is_args = true;
|
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);
|
s_push(ret);
|
||||||
break;
|
break;
|
||||||
case BUILTIN_Lprintf:
|
case BUILTIN_Lprintf:
|
||||||
// .args_count = 1, .is_vararg = true
|
s_popn(args_count);
|
||||||
call_anyarg_func<20>((void (*)()) & Lprintf, 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;
|
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));
|
||||||
|
|
@ -700,8 +713,10 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
|
||||||
s_push(ret);
|
s_push(ret);
|
||||||
break;
|
break;
|
||||||
case BUILTIN_Lfprintf:
|
case BUILTIN_Lfprintf:
|
||||||
// .args_count = 2, .is_vararg = true
|
s_popn(args_count);
|
||||||
call_anyarg_func<20>((void (*)()) & Lfprintf, 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;
|
break;
|
||||||
case BUILTIN_Lregexp:
|
case BUILTIN_Lregexp:
|
||||||
ret = (void *)Lregexp((char *)*s_nth(0));
|
ret = (void *)Lregexp((char *)*s_nth(0));
|
||||||
|
|
@ -715,8 +730,9 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
|
||||||
s_push(ret);
|
s_push(ret);
|
||||||
break;
|
break;
|
||||||
case BUILTIN_Lfailure:
|
case BUILTIN_Lfailure:
|
||||||
// .args_count = 1, .is_vararg = true
|
std::cout << "!!> failure is not properly checked yet, skipping\n";
|
||||||
call_anyarg_func<20>((void (*)()) & Lfailure, args_count);
|
// NOTE: basic params: .args_count = 1, .is_vararg = true
|
||||||
|
// call_anyarg_func<20>((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));
|
||||||
|
|
@ -737,6 +753,24 @@ void run_stdlib_func(BUILTIN id, size_t args_count) {
|
||||||
ret = (void *)Ltime();
|
ret = (void *)Ltime();
|
||||||
s_push(ret);
|
s_push(ret);
|
||||||
break;
|
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:
|
default:
|
||||||
failure("RUNTIME ERROR: stdlib function <%u> not found\n", id);
|
failure("RUNTIME ERROR: stdlib function <%u> not found\n", id);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ for mod in ../stdlib/*.lama; do
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Run tests:"
|
echo "Run tests:"
|
||||||
for test in ../stdlib/regression/*01.lama; do
|
for test in ../stdlib/regression/*.lama; do
|
||||||
echo $test
|
echo $test
|
||||||
$compiler -b $test -I ../stdlib/ > /dev/null
|
$compiler -b $test -I ../stdlib/ > /dev/null
|
||||||
test_file="${test%.*}"
|
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 > test.bc.code
|
||||||
# cat $test_file.input | ./byterun.exe -p test*.bc
|
# cat $test_file.input | ./byterun.exe -p test*.bc
|
||||||
echo "" | ./byterun.exe -vi 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
|
# sed '1d;s/^..//' $test_file.t > test_orig.log
|
||||||
# diff test.log test_orig.log
|
# diff test.log test_orig.log
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue