mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
xmake initial build, uint -> uint32_t (stdlib test 03 fails with xmake, possible due to newer c and c++ versions)
This commit is contained in:
parent
c348af161c
commit
6c19722d9e
11 changed files with 64 additions and 46 deletions
|
|
@ -1,6 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
dune build > /dev/null
|
xmake build
|
||||||
|
cp "build/linux/x86_64/release/byterun" byterun.exe
|
||||||
|
|
||||||
|
# dune build > /dev/null
|
||||||
|
|
||||||
prefix="../regression/"
|
prefix="../regression/"
|
||||||
suffix=".lama"
|
suffix=".lama"
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ Bytefile *run_with_imports(Bytefile *root, int argc, char **argv,
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
enum BUILTIN : uint {
|
enum BUILTIN : uint32_t {
|
||||||
BUILTIN_Luppercase, // 0
|
BUILTIN_Luppercase, // 0
|
||||||
BUILTIN_Llowercase, // 1
|
BUILTIN_Llowercase, // 1
|
||||||
BUILTIN_Lassert, // 2
|
BUILTIN_Lassert, // 2
|
||||||
|
|
|
||||||
|
|
@ -239,4 +239,4 @@ struct SMInstr {
|
||||||
|
|
||||||
std::vector<SMInstr> parse_sm(std::istream &in);
|
std::vector<SMInstr> parse_sm(std::istream &in);
|
||||||
|
|
||||||
std::optional<SMInstr> parse_sm(std::string &line);
|
std::optional<SMInstr> parse_sm(const std::string &line);
|
||||||
|
|
|
||||||
|
|
@ -9,19 +9,19 @@
|
||||||
|
|
||||||
/* The unpacked representation of bytecode file */
|
/* The unpacked representation of bytecode file */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint main_offset; /* offset of the function 'main' */
|
uint32_t main_offset; /* offset of the function 'main' */
|
||||||
char *string_ptr; /* A pointer to the beginning of the string table */
|
char *string_ptr; /* A pointer to the beginning of the string table */
|
||||||
int *imports_ptr; /* A pointer to the beginning of imports table */
|
int32_t *imports_ptr; /* A pointer to the beginning of imports table */
|
||||||
int *public_ptr; /* A pointer to the beginning of publics table */
|
int32_t *public_ptr; /* A pointer to the beginning of publics table */
|
||||||
char *code_ptr; /* A pointer to the bytecode itself */
|
char *code_ptr; /* A pointer to the bytecode itself */
|
||||||
void **global_ptr; /* A pointer to the global area */
|
void **global_ptr; /* A pointer to the global area */
|
||||||
char *substs_ptr; /* A pointer to the substs area */
|
char *substs_ptr; /* A pointer to the substs area */
|
||||||
int code_size; /* The size (in bytes) of code */
|
int32_t code_size; /* The size (in bytes) of code */
|
||||||
uint stringtab_size; /* The size (in bytes) of the string table */
|
uint32_t stringtab_size; /* The size (in bytes) of the string table */
|
||||||
uint global_area_size; /* The size (in words) of global area */
|
uint32_t global_area_size; /* The size (in words) of global area */
|
||||||
uint substs_area_size; /* number of required address substitutions */
|
uint32_t substs_area_size; /* number of required address substitutions */
|
||||||
uint imports_number; /* The number of imports */
|
uint32_t imports_number; /* The number of imports */
|
||||||
uint public_symbols_number; /* The number of public symbols */
|
uint32_t public_symbols_number; /* The number of public symbols */
|
||||||
char buffer[0];
|
char buffer[0];
|
||||||
} Bytefile;
|
} Bytefile;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
dune build > /dev/null
|
xmake build
|
||||||
|
cp "build/linux/x86_64/release/byterun" byterun.exe
|
||||||
|
|
||||||
|
# dune build > /dev/null
|
||||||
|
|
||||||
prefix="../regression/"
|
prefix="../regression/"
|
||||||
suffix=".lama"
|
suffix=".lama"
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ void analyze(Bytefile *bf, std::vector<size_t> &&add_publics) {
|
||||||
uint16_t mock_builtin_begin_counter = 0;
|
uint16_t mock_builtin_begin_counter = 0;
|
||||||
|
|
||||||
int current_stack_depth = 0;
|
int current_stack_depth = 0;
|
||||||
const uint globals_count = bf->global_area_size;
|
const uint32_t globals_count = bf->global_area_size;
|
||||||
uint current_locals_count = 0;
|
uint32_t current_locals_count = 0;
|
||||||
uint current_args_count = 0;
|
uint32_t current_args_count = 0;
|
||||||
bool is_in_closure = false;
|
bool is_in_closure = false;
|
||||||
uint16_t *current_begin_counter = nullptr;
|
uint16_t *current_begin_counter = nullptr;
|
||||||
int func_end_found = 0;
|
int func_end_found = 0;
|
||||||
|
|
@ -55,7 +55,7 @@ void analyze(Bytefile *bf, std::vector<size_t> &&add_publics) {
|
||||||
|
|
||||||
auto const check_correct_var = [&saved_current_ip, bf, &globals_count,
|
auto const check_correct_var = [&saved_current_ip, bf, &globals_count,
|
||||||
¤t_locals_count, ¤t_args_count,
|
¤t_locals_count, ¤t_args_count,
|
||||||
&is_in_closure](uint8_t l, uint id) {
|
&is_in_closure](uint8_t l, uint32_t id) {
|
||||||
if (l > 3) {
|
if (l > 3) {
|
||||||
ip_failure(saved_current_ip, bf, "unexpected variable category");
|
ip_failure(saved_current_ip, bf, "unexpected variable category");
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +264,7 @@ void analyze(Bytefile *bf, std::vector<size_t> &&add_publics) {
|
||||||
is_in_closure = (cmd == Cmd::CBEGIN);
|
is_in_closure = (cmd == Cmd::CBEGIN);
|
||||||
break;
|
break;
|
||||||
case Cmd::CLOSURE: {
|
case Cmd::CLOSURE: {
|
||||||
/*uint closure_offset = */ ip_read_int_unsafe(
|
/*uint32_t closure_offset = */ ip_read_int_unsafe(
|
||||||
¤t_ip); // closure offset
|
¤t_ip); // closure offset
|
||||||
size_t args_count = ip_read_int_unsafe(¤t_ip); // args count
|
size_t args_count = ip_read_int_unsafe(¤t_ip); // args count
|
||||||
extra_stack_during_opr = args_count;
|
extra_stack_during_opr = args_count;
|
||||||
|
|
@ -286,7 +286,7 @@ void analyze(Bytefile *bf, std::vector<size_t> &&add_publics) {
|
||||||
// }
|
// }
|
||||||
} break;
|
} break;
|
||||||
case Cmd::CALLC: {
|
case Cmd::CALLC: {
|
||||||
uint args_count = ip_read_int_unsafe(¤t_ip);
|
uint32_t args_count = ip_read_int_unsafe(¤t_ip);
|
||||||
current_stack_depth -= args_count + 1; // + closure itself
|
current_stack_depth -= args_count + 1; // + closure itself
|
||||||
if (current_stack_depth < 0) {
|
if (current_stack_depth < 0) {
|
||||||
ip_failure(saved_current_ip, bf, "not enough elements in stack");
|
ip_failure(saved_current_ip, bf, "not enough elements in stack");
|
||||||
|
|
@ -295,8 +295,8 @@ void analyze(Bytefile *bf, std::vector<size_t> &&add_publics) {
|
||||||
// NOTE: can't check args == cbegin args
|
// NOTE: can't check args == cbegin args
|
||||||
} break;
|
} break;
|
||||||
case Cmd::CALL: {
|
case Cmd::CALL: {
|
||||||
uint call_offset = ip_read_int_unsafe(¤t_ip); // call offset
|
uint32_t call_offset = ip_read_int_unsafe(¤t_ip); // call offset
|
||||||
uint args_count = ip_read_int_unsafe(¤t_ip);
|
uint32_t args_count = ip_read_int_unsafe(¤t_ip);
|
||||||
current_stack_depth -= args_count;
|
current_stack_depth -= args_count;
|
||||||
if (current_stack_depth < 0) {
|
if (current_stack_depth < 0) {
|
||||||
ip_failure(saved_current_ip, bf, "not enough elements in stack");
|
ip_failure(saved_current_ip, bf, "not enough elements in stack");
|
||||||
|
|
@ -309,11 +309,11 @@ void analyze(Bytefile *bf, std::vector<size_t> &&add_publics) {
|
||||||
|
|
||||||
if (is_command_name(bf->code_ptr + call_offset, bf, Cmd::BUILTIN)) {
|
if (is_command_name(bf->code_ptr + call_offset, bf, Cmd::BUILTIN)) {
|
||||||
if (args_count !=
|
if (args_count !=
|
||||||
*(uint *)(bf->code_ptr + call_offset + 1 + sizeof(uint32_t))) {
|
*(uint32_t *)(bf->code_ptr + call_offset + 1 + sizeof(uint32_t))) {
|
||||||
ip_failure(saved_current_ip, bf, "wrong builtin call argument count");
|
ip_failure(saved_current_ip, bf, "wrong builtin call argument count");
|
||||||
}
|
}
|
||||||
} else if (is_command_name(bf->code_ptr + call_offset, bf, Cmd::BEGIN)) {
|
} else if (is_command_name(bf->code_ptr + call_offset, bf, Cmd::BEGIN)) {
|
||||||
if (args_count != *(uint *)(bf->code_ptr + call_offset + 1)) {
|
if (args_count != *(uint32_t *)(bf->code_ptr + call_offset + 1)) {
|
||||||
ip_failure(saved_current_ip, bf, "wrong call argument count");
|
ip_failure(saved_current_ip, bf, "wrong call argument count");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -352,7 +352,7 @@ void analyze(Bytefile *bf, std::vector<size_t> &&add_publics) {
|
||||||
// add end to behave like end
|
// add end to behave like end
|
||||||
++func_end_found;
|
++func_end_found;
|
||||||
|
|
||||||
/*uint args_count = */ ip_read_int_unsafe(¤t_ip);
|
/*uint32_t args_count = */ ip_read_int_unsafe(¤t_ip);
|
||||||
|
|
||||||
// NOTE: args checks done in corresponding CALL/CALLC
|
// NOTE: args checks done in corresponding CALL/CALLC
|
||||||
} break;
|
} break;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,11 @@ int main(int argc, char **argv) {
|
||||||
else if (strcmp(argv[1], "-p") == 0) {
|
else if (strcmp(argv[1], "-p") == 0) {
|
||||||
do_print = true;
|
do_print = true;
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef WITH_CHECK
|
||||||
|
failure("wrong execution option (acceptable options - '-i')");
|
||||||
|
#else
|
||||||
failure("wrong execution option (acceptable options - '-i', '-v', '-vi')");
|
failure("wrong execution option (acceptable options - '-i', '-v', '-vi')");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ static inline void call_Barray(size_t elem_count) {
|
||||||
s_push(array);
|
s_push(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void call_builtin(uint builtin_id, uint args_count) {
|
void call_builtin(uint32_t builtin_id, uint32_t args_count) {
|
||||||
#ifndef WITH_CHECK
|
#ifndef WITH_CHECK
|
||||||
if (builtin_id >= BUILTIN_NONE) {
|
if (builtin_id >= BUILTIN_NONE) {
|
||||||
s_failure(&s, "invalid builtin");
|
s_failure(&s, "invalid builtin");
|
||||||
|
|
@ -211,7 +211,7 @@ void run_main(Bytefile* bf, int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case CMD_BASIC_JMP: { // JMP 0x%.8x
|
case CMD_BASIC_JMP: { // JMP 0x%.8x
|
||||||
uint jmp_p = ip_read_int(&s.ip);
|
uint32_t jmp_p = ip_read_int(&s.ip);
|
||||||
|
|
||||||
#ifndef WITH_CHECK
|
#ifndef WITH_CHECK
|
||||||
if (jmp_p >= s.bf->code_size) {
|
if (jmp_p >= s.bf->code_size) {
|
||||||
|
|
@ -284,7 +284,7 @@ void run_main(Bytefile* bf, int argc, char **argv) {
|
||||||
case CMD_CTRL:
|
case CMD_CTRL:
|
||||||
switch (l) {
|
switch (l) {
|
||||||
case CMD_CTRL_CJMPz: { // CJMPz 0x%.8x
|
case CMD_CTRL_CJMPz: { // CJMPz 0x%.8x
|
||||||
uint jmp_p = ip_read_int(&s.ip);
|
uint32_t jmp_p = ip_read_int(&s.ip);
|
||||||
|
|
||||||
#ifndef WITH_CHECK
|
#ifndef WITH_CHECK
|
||||||
if (jmp_p >= s.bf->code_size) {
|
if (jmp_p >= s.bf->code_size) {
|
||||||
|
|
@ -298,7 +298,7 @@ void run_main(Bytefile* bf, int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case CMD_CTRL_CJMPnz: { // CJMPnz 0x%.8x
|
case CMD_CTRL_CJMPnz: { // CJMPnz 0x%.8x
|
||||||
uint jmp_p = ip_read_int(&s.ip);
|
uint32_t jmp_p = ip_read_int(&s.ip);
|
||||||
|
|
||||||
#ifndef WITH_CHECK
|
#ifndef WITH_CHECK
|
||||||
if (jmp_p >= s.bf->code_size) {
|
if (jmp_p >= s.bf->code_size) {
|
||||||
|
|
@ -312,12 +312,12 @@ void run_main(Bytefile* bf, int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case CMD_CTRL_BEGIN: { // BEGIN %d %d // function begin
|
case CMD_CTRL_BEGIN: { // BEGIN %d %d // function begin
|
||||||
uint args_sz = ip_read_int(&s.ip);
|
uint32_t args_sz = ip_read_int(&s.ip);
|
||||||
// #ifdef WITH_CHECK
|
// #ifdef WITH_CHECK
|
||||||
uint locals_sz = ip_read_half_int(&s.ip);
|
uint32_t locals_sz = ip_read_half_int(&s.ip);
|
||||||
uint max_additional_stack_sz = ip_read_half_int(&s.ip);
|
uint32_t max_additional_stack_sz = ip_read_half_int(&s.ip);
|
||||||
// #else
|
// #else
|
||||||
// uint locals_sz = ip_read_int(&s.ip);
|
// uint32_t locals_sz = ip_read_int(&s.ip);
|
||||||
// #endif
|
// #endif
|
||||||
#ifndef WITH_CHECK
|
#ifndef WITH_CHECK
|
||||||
if (s.fp != NULL && s.call_ip == NULL) {
|
if (s.fp != NULL && s.call_ip == NULL) {
|
||||||
|
|
@ -336,12 +336,12 @@ void run_main(Bytefile* bf, int argc, char **argv) {
|
||||||
|
|
||||||
case CMD_CTRL_CBEGIN: { // CBEGIN %d %d
|
case CMD_CTRL_CBEGIN: { // CBEGIN %d %d
|
||||||
// NOTE: example not found, no checks done
|
// NOTE: example not found, no checks done
|
||||||
uint args_sz = ip_read_int(&s.ip);
|
uint32_t args_sz = ip_read_int(&s.ip);
|
||||||
// #ifdef WITH_CHECK
|
// #ifdef WITH_CHECK
|
||||||
uint locals_sz = ip_read_half_int(&s.ip);
|
uint32_t locals_sz = ip_read_half_int(&s.ip);
|
||||||
uint max_additional_stack_sz = ip_read_half_int(&s.ip);
|
uint32_t max_additional_stack_sz = ip_read_half_int(&s.ip);
|
||||||
// #else
|
// #else
|
||||||
// uint locals_sz = ip_read_int(&s.ip);
|
// uint32_t locals_sz = ip_read_int(&s.ip);
|
||||||
// #endif
|
// #endif
|
||||||
#ifndef WITH_CHECK
|
#ifndef WITH_CHECK
|
||||||
if (s.fp != NULL && s.call_ip == NULL) {
|
if (s.fp != NULL && s.call_ip == NULL) {
|
||||||
|
|
@ -403,7 +403,7 @@ void run_main(Bytefile* bf, int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case CMD_CTRL_CALL: { // CALL 0x%.8x %d // call function
|
case CMD_CTRL_CALL: { // CALL 0x%.8x %d // call function
|
||||||
uint call_p = ip_read_int(&s.ip);
|
uint32_t call_p = ip_read_int(&s.ip);
|
||||||
ip_read_int(&s.ip); // args count
|
ip_read_int(&s.ip); // args count
|
||||||
|
|
||||||
call_happened = true;
|
call_happened = true;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
dune build
|
# TODO: FIXME: error on test 3, possible UB or standard change
|
||||||
|
xmake build
|
||||||
|
cp "build/linux/x86_64/release/byterun" byterun.exe
|
||||||
|
|
||||||
|
dune build > /dev/null
|
||||||
|
|
||||||
prefix="../stdlib/regression/"
|
prefix="../stdlib/regression/"
|
||||||
suffix=".lama"
|
suffix=".lama"
|
||||||
|
|
@ -21,7 +25,7 @@ for mod in ../stdlib/*.lama; do
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Run tests:"
|
echo "Run tests:"
|
||||||
for test in ../stdlib/regression/*.lama; do
|
for test in ../stdlib/regression/*03.lama; do
|
||||||
echo $test
|
echo $test
|
||||||
$compiler -b $test -I ../stdlib/ > /dev/null
|
$compiler -b $test -I ../stdlib/ > /dev/null
|
||||||
test_path="${test%.*}"
|
test_path="${test%.*}"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
dune build > /dev/null
|
xmake build
|
||||||
|
cp "build/linux/x86_64/release/byterun" byterun.exe
|
||||||
|
|
||||||
|
# dune build > /dev/null
|
||||||
|
|
||||||
prefix="../regression/"
|
prefix="../regression/"
|
||||||
suffix=".lama"
|
suffix=".lama"
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
-- add_rules("mode.debug", "mode.release")
|
-- add_rules("mode.debug", "mode.release")
|
||||||
-- add_rules("c++.unity_build")
|
-- add_rules("c++.unity_build")
|
||||||
|
|
||||||
set_languages("c++20", "c20")
|
set_languages("c++23", "c23")
|
||||||
|
|
||||||
target("byterun")
|
target("byterun")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_includedirs("include")
|
add_includedirs("include")
|
||||||
add_files("../runtime/runtime.a")
|
add_files("../runtime/**.c", "../runtime/**.S")
|
||||||
add_files("src/**.cpp", "src/**.c")
|
add_files("src/**.cpp", "src/**.c")
|
||||||
remove_files("src/compiler.cpp")
|
remove_files("src/compiler.cpp")
|
||||||
set_warnings("allextra")
|
set_warnings("allextra")
|
||||||
set_rundir("$(projectdir)")
|
set_rundir("$(projectdir)")
|
||||||
|
add_defines("WITH_CHECK")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue