ox

The Ox programming language, compiler and tools (WIP)
Log | Files | Refs | README | LICENSE

commit 5cb4fd6849f05d0ef70be767716fd0dc1d3a9094
parent a09284a2808201d2eb28a83e3a0fd8ab34c43ab2
Author: citbl <citbl@citbl.org>
Date:   Sat, 15 Nov 2025 21:23:01 +1000

wip

Diffstat:
M.zed/debug.json | 2+-
MTODO | 2+-
ATODO-2 | 5+++++
Aex-call-simple.ox | 8++++++++
Dex-call-simple1.ox | 8--------
Msrc/gen/gen.c | 29+++++++++++++++++++++++------
6 files changed, 38 insertions(+), 16 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-for-advanced2.ox"], + "args": ["$ZED_WORKTREE_ROOT/ex-call-args.ox"], "request": "launch", "adapter": "CodeLLDB" } diff --git a/TODO b/TODO @@ -3,7 +3,7 @@ [x] variables, string first, so that we can print its content; [x] conditionals (basic) [x] loops (basic) -[ ] handle for loop with `i = i + 1` and `i += 1` (see ex-for-simple2 and TODO NODE_BINARY_EXPR) +[x] handle for loop with `i = i + 1` and `i += 1` (see ex-for-simple2 and TODO NODE_BINARY_EXPR) [ ] printing `-5` crashes, I think parsing is wrong for `-`, sees as value 5 [ ] print allow format or more than 1 arg [ ] print anything else than a string diff --git a/TODO-2 b/TODO-2 @@ -0,0 +1,5 @@ + + +when we get into a block that is a function body, + we should reference the variables that were passed + as defined per signature. diff --git a/ex-call-simple.ox b/ex-call-simple.ox @@ -0,0 +1,8 @@ +void callee_simple() { + print("hello world"); +} + +void main() { + callee_simple(); +} + diff --git a/ex-call-simple1.ox b/ex-call-simple1.ox @@ -1,8 +0,0 @@ -void callee_test() { - print("hello"); -} - -void main() { - callee_test(); -} - diff --git a/src/gen/gen.c b/src/gen/gen.c @@ -540,17 +540,31 @@ handle_func_call(Gen* gen, Node* node) for (size_t i = 0; i < argc; i++) { args[i] = handle_expr(gen, node->data.call_expr.args[i]); } + + /* + When generating the identifier expression message in the AST: + Lookup env["message"] -> you get a gcc_jit_param* or gcc_jit_lvalue*. + Use gcc_jit_param_as_rvalue / gcc_jit_lvalue_as_rvalue. + + gcc_jit_rvalue *msg = gcc_jit_param_as_rvalue(callee_param); + + gcc_jit_rvalue *args[1] = { msg }; + gcc_jit_block_add_eval( + b, loc, + gcc_jit_context_new_call(ctx, loc, print_fn, 1, args)); + */ + 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); + 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); } */ @@ -982,12 +996,15 @@ build_func_decl(Gen* gen, Node* node) // make a bunch of gcc params stored in the symbols table of the func scope } + // TODO create the gcc_jit_param* for the function + // Put each parameter into a symbol table/scope. + gcc_jit_function* func = gcc_jit_context_new_function(gen->ctx, loc, GCC_JIT_FUNCTION_EXPORTED, // declared ret_type, // ret strdup(func_name), // name - 0, // num params + 0, // num params // TODO @next we need to pass the params here as per AST definition NULL, // params 0); // is variadic