commit e23a867178b73c4060a19364dc528f1588f09964
parent a219ed2c46b9e6b44e8c2bd59bac5211f5b716f1
Author: citbl <citbl@citbl.org>
Date: Sun, 9 Nov 2025 13:27:50 +1000
func call (ignore arguments and return value for now)
Diffstat:
4 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/.zed/debug.json b/.zed/debug.json
@@ -6,8 +6,8 @@
{
"label": "Debug native binary",
"build": {
- "command": "make check",
- "args": ["debug"],
+ "command": "make",
+ "args": ["check"],
"cwd": "$ZED_WORKTREE_ROOT"
},
"program": "$ZED_WORKTREE_ROOT/oxc",
diff --git a/src/gen/gen.c b/src/gen/gen.c
@@ -103,6 +103,7 @@ gen_init(Scope* scope, const char* src, Node* node, bool quiet)
type_void = gcc_jit_context_get_type(ctx, GCC_JIT_TYPE_VOID);
type_cstr = gcc_jit_context_get_type(ctx, GCC_JIT_TYPE_CONST_CHAR_PTR);
type_voidp = gcc_jit_context_get_type(ctx, GCC_JIT_TYPE_VOID_PTR);
+ /* gcc_jit_type_dyncast_function_ptr_type; */
gcc_jit_location* loc = gcc_jit_context_new_location(ctx, node->filename, 0, 0);
@@ -507,6 +508,20 @@ lookup_function(Gen* gen, const char* func_name)
{
// callee node which contains an ident
// args list which contains args with len and cap
+
+ // TODO impl @next lookup function after maybe reworking the symbols table
+ // gen->scope..symbols
+ for (size_t i = 0; i < gen->scope->len; i++) {
+ Symbol* sym = gen->scope->symbols[i];
+
+ if (sym->ctype == type_voidp) {
+ const char* name = span_str(gen->src, sym->name, (char[IDENTSZ]) { 0 });
+ if (strcmp(name, func_name) == 0) {
+ return sym->d.funcvalue; //
+ }
+ }
+ }
+ return NULL;
}
static gcc_jit_rvalue*
@@ -516,20 +531,19 @@ handle_func_call(Gen* gen, Node* node)
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);
- softpanic("unhandled func call named: %s", func_name);
+ // softpanic("unhandled func call named: %s", func_name);
// almost unrelated could be useful to deal with return values:
// gcc_jit_rvalue* rv = handle_func_call(gen, node);
// if (rv) { gcc_jit_block_add_eval(gen->curr_block, loc_from_node(gen, node), rv); }
// return false;
- return NULL;
-
//
// TODO handle any function other than print...
//
// int argc = node->data.call_expr.len;
gcc_jit_function* callee = lookup_function(gen, func_name);
+ return gcc_jit_context_new_call(gen->ctx, NULL, callee, 0, NULL);
// 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]);
@@ -965,6 +979,13 @@ build_func_decl(Gen* gen, Node* node)
gen->curr_block = block;
gen->curr_func = func;
+ Symbol* sym = (Symbol*)calloc(1, sizeof(Symbol));
+ sym->name = node->data.function_decl.name;
+ sym->decl = node;
+ sym->ctype = type_voidp;
+ sym->d.funcvalue = func;
+ add_symbol(gen, sym);
+
build_block(gen, node->data.function_decl.body);
if (gen->curr_block && ret_type == type_int) { // TODO handle more return types in function declarations
diff --git a/src/sem.c b/src/sem.c
@@ -21,7 +21,7 @@ scope_init(Node* node)
.len = 0,
.ch_cap = CALLOC_SZ,
.ch_len = 0,
- .depth = BASE_DEPTH,
+ .depth = BASE_DEPTH,
.owner = node,
.id = next_id++ };
diff --git a/src/types.h b/src/types.h
@@ -277,6 +277,7 @@ typedef struct Symbol {
gcc_jit_type* ctype;
union {
+ gcc_jit_function* funcvalue;
gcc_jit_lvalue* lvalue;
gcc_jit_param* param;
gcc_jit_rvalue* const_rvalue;
@@ -285,7 +286,6 @@ typedef struct Symbol {
// @later NOTE: our symbols are a list, there is an argument to be made to change to a linked list;
// as a linked list will outperform an allocated list up to 12-16 elements, or so.
-
// @later NOTE: also consider their relation between each other and the rest of the compiler is a bit of a circulas mess;
// which is fine as long as we're boostrapping and getting it off the ground.
typedef struct Scope {