diff --git a/apps/interpreter/source/main.cpp b/apps/interpreter/source/main.cpp index 84332d7..4932c36 100644 --- a/apps/interpreter/source/main.cpp +++ b/apps/interpreter/source/main.cpp @@ -172,8 +172,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 = (float(*)())(module.code.memory.data.get() + offset); - auto x = fptr(); + auto fptr = (float(*)(float))(module.code.memory.data.get() + offset); + auto x = fptr(6.f); std::cout << "Result: " << std::boolalpha << x << std::endl; } } diff --git a/examples/jit_test.psl b/examples/jit_test.psl index 79df4e7..6d87861 100644 --- a/examples/jit_test.psl +++ b/examples/jit_test.psl @@ -1,4 +1,2 @@ -func test() -> f32: - if 0.0 >= 1.0: - return 3.1415 - return 2.71828 +func test(x : f32) -> f32: + return x * 1.5 diff --git a/libs/jit/source/arch/aarch64/compiler.cpp b/libs/jit/source/arch/aarch64/compiler.cpp index 4e0ac14..5c9188d 100644 --- a/libs/jit/source/arch/aarch64/compiler.cpp +++ b/libs/jit/source/arch/aarch64/compiler.cpp @@ -634,18 +634,33 @@ namespace pslang::jit::aarch64 { // TODO: floating-point / struct arguments scopes.emplace_back(); - for (std::size_t i = 0; i < node.arguments.size(); ++i) + + std::uint8_t reg = 0; + std::uint8_t fp_reg = 0; + + for (auto const & argument : node.arguments) { - auto type = ast::get_type(*node.arguments[i].type); + auto type = ast::get_type(*argument.type); if (types::is_bool_type(*type)) { - builder.tst(i, i); - builder.csetm(i, 0b0001); + builder.tst(reg, reg); + builder.csetm(reg, 0b0001); + push(reg); + ++reg; } else if (types::is_integer_type(*type)) - extend(i, type); - push(i); - scopes.back().variables[node.arguments[i].name] = {.frame_offset = stack_offset}; + { + extend(reg, type); + push(reg); + ++reg; + } + else if (types::is_floating_point_type(*type)) + { + auto mode = fp_mode_for(*type); + push_fp(fp_reg, mode); + ++fp_reg; + } + scopes.back().variables[argument.name] = {.frame_offset = stack_offset}; } apply(*node.statements); scopes.pop_back();