commit a219ed2c46b9e6b44e8c2bd59bac5211f5b716f1
parent 6b7f77c9f144585e6d8e226ebfe547bb2002f03f
Author: citbl <citbl@citbl.org>
Date: Sat, 8 Nov 2025 21:09:13 +1000
minor wips
Diffstat:
8 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/.clangd b/.clangd
@@ -11,7 +11,7 @@ CompileFlags:
-Wmissing-prototypes,
# -Wconversion,
-xc,
- -std=c99,
+ -std=c17,
-g,
-I/opt/homebrew/opt/libgccjit/include,
-L/opt/homebrew/opt/libgccjit/lib/gcc/current,
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-binop-simple1.ox"],
+ "args": ["$ZED_WORKTREE_ROOT/ex-call-simple1.ox"],
"request": "launch",
"adapter": "CodeLLDB"
}
diff --git a/ex-call-simple1.ox b/ex-call-simple1.ox
@@ -0,0 +1,8 @@
+void callee_test() {
+ print("hello");
+}
+
+void main() {
+ callee_test();
+}
+
diff --git a/src/gen/gen.c b/src/gen/gen.c
@@ -502,11 +502,12 @@ lower_builtin_print(Gen* gen, Node* node)
return NULL;
}
-// static gcc_jit_function*
-// lookup_function(Gen* gen, const char* func_name)
-// {
-// // TODO see todo below about linked list parameters...
-// }
+static gcc_jit_function*
+lookup_function(Gen* gen, const char* func_name)
+{
+ // callee node which contains an ident
+ // args list which contains args with len and cap
+}
static gcc_jit_rvalue*
handle_func_call(Gen* gen, Node* node)
@@ -516,19 +517,25 @@ handle_func_call(Gen* gen, Node* node)
if (strcmp(func_name, "print") == 0) return lower_builtin_print(gen, node);
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);
+ gcc_jit_function* callee = lookup_function(gen, func_name);
// 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);
- // return NULL;
+ return NULL;
}
static gcc_jit_rvalue*
@@ -607,14 +614,6 @@ static gcc_jit_rvalue* build_bool_value(Gen*, Node*);
static int block_counter = 0, loop_counter = 0;
static bool
-build_call_expression(Gen* gen, Node* node)
-{
- 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;
-}
-
-static bool
build_for_statement(Gen* gen, Node* node)
{
gcc_jit_location* loc = loc_from_node(gen, node);
@@ -882,8 +881,6 @@ build_statement(Gen* gen, Node* node)
return build_if_statement(gen, node);
case NODE_FOR:
return build_for_statement(gen, node);
- case NODE_CALL_EXPR:
- return build_call_expression(gen, node);
default:
printf("build_statement unhandled, %s\n", node_type_str(node->type));
break;
@@ -970,7 +967,7 @@ build_func_decl(Gen* gen, Node* node)
build_block(gen, node->data.function_decl.body);
- if (gen->curr_block && ret_type == type_int) { // TODO handle more return types
+ if (gen->curr_block && ret_type == type_int) { // TODO handle more return types in function declarations
gcc_jit_rvalue* ret_value = gcc_jit_context_new_rvalue_from_int(gen->ctx, type_int, 0);
gcc_jit_block_end_with_return(gen->curr_block, loc, ret_value);
} else if (gen->curr_block && ret_type == type_void) {
diff --git a/src/main.c b/src/main.c
@@ -61,7 +61,7 @@ main(int argc, char* argv[])
printf("--- sem --- \n");
Scope program_scope = scope_init(ast.node);
- scope_build(&program_scope, &ast);
+ scope_program(&program_scope, &ast);
scope_print(&program_scope, &ast);
printf("--- gen --- \n");
diff --git a/src/parser/expr.c b/src/parser/expr.c
@@ -33,7 +33,8 @@ parse_func_call(Parser* par)
if (call->data.call_expr.len == call->data.call_expr.cap) {
call->data.call_expr.cap *= 2;
- call->data.call_expr.args = (Node**)realloc(call->data.call_expr.args, call->data.call_expr.cap * sizeof(Node*));
+ call->data.call_expr.args
+ = (Node**)realloc(call->data.call_expr.args, call->data.call_expr.cap * sizeof(Node*));
}
call->data.call_expr.args[call->data.call_expr.len++] = arg;
@@ -190,7 +191,12 @@ parse_primary(Parser* par)
}
const char* name = span_str(par->src, (Span) { .start = tok.start, .end = tok.end }, (char[IDENTSZ]) { 0 });
- panic("Expected Primary Expr, but found '%s' (%s at %s:%zu:%zu", name, token_type_str(tok.type), par->filename, tok.line, tok.col);
+ panic("Expected Primary Expr, but found '%s' (%s at %s:%zu:%zu",
+ name,
+ token_type_str(tok.type),
+ par->filename,
+ tok.line,
+ tok.col);
return NULL;
}
diff --git a/src/sem.c b/src/sem.c
@@ -113,8 +113,6 @@ scope_var(Scope* scope, Ast* ast, Node* node)
sym->decl = node->data.var_decl.init;
sym->type = type;
- assert(var_name != NULL);
-
add_to_scope(scope, sym);
}
@@ -139,7 +137,7 @@ scope_func(Scope* parent_scope, Ast* ast, Node* node)
}
void
-scope_build(Scope* scope, Ast* ast)
+scope_program(Scope* scope, Ast* ast)
{
for (size_t i = 0; i < ast->node->data.program.len; i++) {
Node* node = ast->node->data.program.decl[i];
diff --git a/src/sem.h b/src/sem.h
@@ -18,5 +18,5 @@ Symbol* scope_find_symbol(Scope* scope, const char* name);
// Type checking functions
int types_equal(TypeInfo* a, TypeInfo* b);
-void scope_build(Scope*, Ast*);
+void scope_program(Scope*, Ast*);
void scope_print(Scope*, Ast*);