Open mingodad opened 1 month ago
The problem was that I was building everything statically linked but the call to set_compile_target
that calls vm_init
doesn't propagate the error when the "libkcsbltin.so"
is not found.
With the changes shown bellow and a few others it's working with builtins
statically linked using the vm
:
--------------------------- src/backend/vm/vminstr.c ---------------------------
index 4b4978f..f8110b4 100644
@@ -583,8 +583,8 @@ static void vm_load_var(const struct var var)
default: assert(0);
case T_POINTER:
if (var.symbol) {
- emit_vm_push_string(var.symbol->value.string);
assert(var.symbol->symtype == SYM_STRING_VALUE);
+ emit_vm_push_string(var.symbol->value.string);
if (var.offset) {
emit_vm_push_imm(VMOP_INT32, (union vm_imm){ .dword = var.offset });
emit_vm_op(VM_ADD, VMOP_UINT64);
@@ -1240,20 +1240,30 @@ INTERNAL void add_ref_module(const char *name)
emit_vm_code(((struct vm_code){ .opcode = VM_REFLIB, .d.name = str_init(name) }));
}
-INTERNAL void vm_init(FILE *stream, const char *file)
+#ifdef STATIC_BUILTINS
+extern vm_builtin_t vm_get_builtin_by_index(int index);
+extern const char *vm_get_builtin_name_by_index(int index);
+#endif
+
+INTERNAL int vm_init(FILE *stream, const char *file)
{
int is_save = (file != NULL);
vm_ctx.stream = stream;
vm_ctx.file = file;
assert(!vm_prog.global);
+#ifdef STATIC_BUILTINS
+ builtin_get_func = vm_get_builtin_by_index;
+ vm_builtin_get_name_t builtin_get_name = vm_get_builtin_name_by_index;
+#else
vm_builtin_library = load_library("kcsbltin", 0);
- if (!vm_builtin_library) return;
+ if (!vm_builtin_library) return 0;
builtin_get_func = (vm_builtin_get_func_t)get_function(vm_builtin_library, "vm_get_builtin_by_index");
- if (!builtin_get_func) return;
+ if (!builtin_get_func) return 0;
vm_builtin_get_name_t builtin_get_name =
(vm_builtin_get_name_t)get_function(vm_builtin_library, "vm_get_builtin_name_by_index");
- if (!builtin_get_name) return;
+ if (!builtin_get_name) return 0;
+#endif
for (int i = 1; ; ++i) {
const char *name = builtin_get_name(i);
if (!name) break;
@@ -1271,6 +1281,7 @@ INTERNAL void vm_init(FILE *stream, const char *file)
assert(array_len(&vm_glbl.code) == 1);
emit_vm_enter(0); /* update it by actual global variable size later. */
is_global_mode = 0;
+ return 1;
}
INTERNAL void vm_gen_lir(struct definition *def)
If I understood correctly the https://github.com/Kray-G/kcs#architecture it's possible to build this project without
JIT
and I've got it to build withoutJITX86
but then I'm getting a segfault.If possible I'll try to build it with
emscriptem
and load it in a playground similar to https://mingodad.github.io/parsertl-playground/playground/ .Here is the output of the build:
Here is the output of
valgrind
:test.c:
Here is the changes made to
Makefile
to be able to execute the tests (because in Ubuntu 18.04 the defaultsh
isn'tbash
and the actual built binary iskcs
instead ofkcc
):