commit 3827f29c7034c5f50b02d0cd2835ac37b9de1ea7
parent 110645e2491b7a531c0bea47f74e0c66e77a307e
Author: citbl <citbl@citbl.org>
Date: Sun, 9 Nov 2025 14:33:56 +1000
wip
Diffstat:
5 files changed, 56 insertions(+), 11 deletions(-)
diff --git a/.zed/debug.json b/.zed/debug.json
@@ -11,7 +11,7 @@
"cwd": "$ZED_WORKTREE_ROOT"
},
"program": "$ZED_WORKTREE_ROOT/oxc",
- "args": ["$ZED_WORKTREE_ROOT/ex-call-simple1.ox"],
+ "args": ["$ZED_WORKTREE_ROOT/ex-for-advanced2.ox"],
"request": "launch",
"adapter": "CodeLLDB"
}
diff --git a/NOTES.md b/NOTES.md
@@ -103,3 +103,13 @@ you lower print to a runtime call printf
- lowering: emit literal value to IR once folded
- C++: consteval, Zig: comptime, Rust: constfn
- gate with fuel(?), depth restriction and memory limits
+
+
+add_to_scope is used during semc
+add_symbol is used during genc, feels wrong
+
+
+when we semc we need to build the scope and symbols list for each
+but then in gen we need to fetch the symbols and pad them with pointers
+
+separate the gccjit impl to a separate tree than the symbols table of semantic analysis
diff --git a/ex-call-args.ox b/ex-call-args.ox
@@ -0,0 +1,8 @@
+void callee_test(string message) {
+ print(message);
+}
+
+void main() {
+ callee_test("hello, there");
+}
+
diff --git a/src/gen/gen.c b/src/gen/gen.c
@@ -144,7 +144,7 @@ find_symbol(Gen* gen, Span name)
const char* sym_name = span_str(gen->src, sym->name, (char[IDENTSZ]) { 0 });
// printf("symbol %s\n", sym_name);
// printf("ident %s\n", ident_name);
- if (strncmp(sym_name, ident_name, strlen(sym_name)) == 0) {
+ if (strcmp(sym_name, ident_name) == 0) {
printf("found symbol %s\n", sym_name);
return sym;
}
@@ -524,17 +524,37 @@ handle_func_call(Gen* gen, Node* node)
{
Node* fcallee = node->data.call_expr.callee;
const char* func_name = span_str(gen->src, fcallee->data.ident.name, (char[IDENTSZ]) { 0 });
- if (strcmp(func_name, "print") == 0) return lower_builtin_print(gen, node);
- // TODO handle args
- // gcc_jit_rvalue* args[16]; // @future fixed at 16 parameters in call
- // for (int i = 0; i < argc; i++) {
- // args[i] = handle_expr(gen, node->data.call_expr.args[i]);
- // }
- // return gcc_jit_context_new_call(gen->ctx, NULL, callee, argc, args);
+ // short circuit to print
+ if (strcmp(func_name, "print") == 0) return lower_builtin_print(gen, node);
gcc_jit_function* callee = lookup_function(gen, func_name);
- return gcc_jit_context_new_call(gen->ctx, NULL, callee, 0, NULL);
+ gcc_jit_location* loc = loc_from_node(gen, node);
+
+ // args handling
+ gcc_jit_rvalue* args[16];
+ size_t argc = node->data.call_expr.len;
+
+ if (argc > 16) { softpanic("we don't currently handle more than 16 arguments in a function call"); }
+
+ for (size_t i = 0; i < argc; i++) {
+ args[i] = handle_expr(gen, node->data.call_expr.args[i]);
+ }
+ return gcc_jit_context_new_call(gen->ctx, loc, callee, argc, args);
+
+ // TODO consider
+ /*
+ // calling bob() directly
+ void emit_direct_call(gcc_jit_context *ctxt, SymbolId bob, gcc_jit_function *caller) {
+ GccObj *cal = ensure_func(ctxt, bob);
+ gcc_jit_block *b = gcc_jit_function_new_block(caller, "call_bob");
+ gcc_jit_rvalue *args[] = {};
+ gcc_jit_block_add_eval(b, NULL, gcc_jit_context_new_call(ctxt, cal->func, 0, args));
+ gcc_jit_block_end_with_void_return(b, NULL);
+ }
+ */
+
+ // return gcc_jit_context_new_call(gen->ctx, NULL, callee, 0, NULL);
// TODO handle return values
// almost unrelated could be useful to deal with return values:
@@ -610,6 +630,8 @@ add_symbol(Gen* gen, Symbol* sym)
}
gen->scope->symbols[gen->scope->len++] = sym;
+
+ printf("we now have %zu symbols.\n", gen->scope->len);
}
static bool build_block(Gen*, Node*);
@@ -955,6 +977,11 @@ build_func_decl(Gen* gen, Node* node)
gcc_jit_type* ret_type = ox_type_to_c_type(gen, return_type);
gcc_jit_location* loc = loc_from_node(gen, node);
+ size_t argc = node->data.function_decl.p_len;
+ for (size_t i = 0; i < argc; i++) {
+ // make a bunch of gcc params stored in the symbols table of the func scope
+ }
+
gcc_jit_function* func = gcc_jit_context_new_function(gen->ctx,
loc,
GCC_JIT_FUNCTION_EXPORTED, // declared
diff --git a/src/sem.c b/src/sem.c
@@ -112,7 +112,7 @@ scope_var(Scope* scope, Ast* ast, Node* node)
sym->name = node->data.var_decl.name;
sym->decl = node->data.var_decl.init;
sym->type = type;
-
+ printf("scope_var: adding to scope %s (%s)\n", var_name, type_name);
add_to_scope(scope, sym);
}