From 7ed008543c6b31a788a1425bfa471cfe90a04e16 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sun, 4 Jan 2026 12:27:46 +0300 Subject: [PATCH] Aarch64 compiler wip: support function arguments (integers only) --- apps/interpreter/source/main.cpp | 4 ++-- examples/jit_test.psl | 7 ++----- libs/jit/source/arch/aarch64/compiler.cpp | 12 +++++++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/interpreter/source/main.cpp b/apps/interpreter/source/main.cpp index 48b888d..d78d17e 100644 --- a/apps/interpreter/source/main.cpp +++ b/apps/interpreter/source/main.cpp @@ -170,8 +170,8 @@ int main(int argc, char ** argv) { // TODO: remove, testing-only code; should execute entry point instead auto offset = module.code.symbol_table.at("test"); - auto fptr = (int(*)())(module.code.memory.data.get() + offset); - auto x = fptr(); + auto fptr = (int(*)(int))(module.code.memory.data.get() + offset); + auto x = fptr(42); std::cout << "Result: " << std::boolalpha << x << std::endl; } } diff --git a/examples/jit_test.psl b/examples/jit_test.psl index 380ff49..06492d1 100644 --- a/examples/jit_test.psl +++ b/examples/jit_test.psl @@ -1,5 +1,2 @@ -func test() -> i32: - let x = 42 + 69 - mut y = (x * 2) / 3 - y = y + 13 - return x - y +func test(x : i32) -> i32: + return x * x diff --git a/libs/jit/source/arch/aarch64/compiler.cpp b/libs/jit/source/arch/aarch64/compiler.cpp index c484a54..635eb70 100644 --- a/libs/jit/source/arch/aarch64/compiler.cpp +++ b/libs/jit/source/arch/aarch64/compiler.cpp @@ -345,17 +345,23 @@ namespace pslang::jit::aarch64 void apply(ast::statement_list const & node) { - scopes.emplace_back(); for (auto const & statement : node.statements) apply(*statement); builder.add_imm(31, 31, scopes.back().stack_offset); - scopes.pop_back(); } void do_apply(ast::function_definition const & node) { - // TODO: arguments + // TODO: floating-point / struct arguments + scopes.emplace_back(); + for (std::size_t i = 0; i < node.arguments.size(); ++i) + { + extend(i, ast::get_type(*node.arguments[i].type)); + push(i); + scopes.back().variables[node.arguments[i].name] = {.frame_offset = stack_offset}; + } apply(*node.statements); + scopes.pop_back(); } private: