diff --git a/apps/interpreter/source/main.cpp b/apps/interpreter/source/main.cpp index 2a6b68c..fab9ed3 100644 --- a/apps/interpreter/source/main.cpp +++ b/apps/interpreter/source/main.cpp @@ -182,7 +182,7 @@ int main(int argc, char ** argv) { // TODO: remove, testing-only code; should execute entry point instead auto offset = pcontext.symbols.at("test"); - auto fptr = (std::uint32_t(*)(std::uint32_t))(executable.data.get() + offset); + auto fptr = (int(*)(int))(executable.data.get() + offset); auto x = fptr(0); std::cout << "Result: " << std::boolalpha << x << std::endl; } diff --git a/examples/jit_test.psl b/examples/jit_test.psl index 26ef3aa..59f768c 100644 --- a/examples/jit_test.psl +++ b/examples/jit_test.psl @@ -10,5 +10,5 @@ func add_or_sub(add : bool) -> (u32 -> u32): else: return sub1 -func test(x: u32) -> u32: - return (!0us) as u32 +func test(x: i32) -> i32: + return 10 / 0 diff --git a/libs/jit/source/arch/aarch64/compiler.cpp b/libs/jit/source/arch/aarch64/compiler.cpp index dcfa948..16d8802 100644 --- a/libs/jit/source/arch/aarch64/compiler.cpp +++ b/libs/jit/source/arch/aarch64/compiler.cpp @@ -477,8 +477,19 @@ namespace pslang::jit::aarch64 } break; case ast::binary_operation_type::remainder: - // TODO: implement via div & mul & sub - throw std::runtime_error("remainder operator is not implemented"); + if (types::is_signed_integer_type(*node.inferred_type)) + { + builder.sdiv_reg(1, 0, 2); + builder.mul_reg(0, 2, 0); + builder.sub_reg(1, 0, 0); + } + else if (types::is_unsigned_integer_type(*node.inferred_type)) + { + builder.udiv_reg(1, 0, 2); + builder.mul_reg(0, 2, 0); + builder.sub_reg(1, 0, 0); + } + break; case ast::binary_operation_type::binary_and: builder.and_reg(1, 0, 0); break; diff --git a/spec.txt b/spec.txt index 87227d8..8aded3e 100644 --- a/spec.txt +++ b/spec.txt @@ -111,8 +111,8 @@ Arithmetic (only same integer/floating-point type): -x x + y x * y - x / y // in case of integers, rounds down when y>0 when x<0, consistently with % - x % y // integer only; mathematical, i.e. always in [0, y-1] when y>0 even when x<0; TODO: what if y<0? + x / y + x % y Pointer arithmetic (any pointer type + any integer type): p + x