Aarch64 compiler wip: support function arguments (integers only)

This commit is contained in:
Nikita Lisitsa 2026-01-04 12:27:46 +03:00
parent 43f2d4531a
commit 7ed008543c
3 changed files with 13 additions and 10 deletions

View file

@ -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;
}
}

View file

@ -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

View file

@ -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: