From c7e0232b15460137f1babf40e878af0a09fdbc21 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 19 Jan 2026 15:14:13 +0300 Subject: [PATCH] Aarch64 JIT: check function pointer support --- apps/interpreter/source/main.cpp | 7 ++++--- examples/jit_test.psl | 16 ++++++++++------ libs/types/include/pslang/types/type_fwd.hpp | 1 + libs/types/source/type.cpp | 7 +++++++ plans.txt | 4 +++- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/apps/interpreter/source/main.cpp b/apps/interpreter/source/main.cpp index 5177b97..4c8bec5 100644 --- a/apps/interpreter/source/main.cpp +++ b/apps/interpreter/source/main.cpp @@ -173,9 +173,10 @@ int main(int argc, char ** argv) { // TODO: remove, testing-only code; should execute entry point instead - auto offset = pcontext.symbols.at("foo"); - auto fptr = (uint32_t(*)(uint32_t))(executable.data.get() + offset); - auto x = fptr(10u); + auto offset = pcontext.symbols.at("add_or_sub"); + using type = std::uint32_t(*)(std::uint32_t); + auto fptr = (type(*)(bool))(executable.data.get() + offset); + auto x = fptr(false)(10u); std::cout << "Result: " << std::boolalpha << x << std::endl; } } diff --git a/examples/jit_test.psl b/examples/jit_test.psl index 2f9f62d..4aa5c04 100644 --- a/examples/jit_test.psl +++ b/examples/jit_test.psl @@ -1,7 +1,11 @@ -func foo(x : u32) -> u32: - if x == 0u: - return 42u - return 1u + bar(x - 1u) +func add1(x : u32) -> u32: + return x + 1u -func bar(x : u32) -> u32: - return foo(x) +func sub1(x : u32) -> u32: + return x - 1u + +func add_or_sub(add : bool) -> (u32 -> u32): + if add: + return add1 + else: + return sub1 diff --git a/libs/types/include/pslang/types/type_fwd.hpp b/libs/types/include/pslang/types/type_fwd.hpp index 284e368..5d81453 100644 --- a/libs/types/include/pslang/types/type_fwd.hpp +++ b/libs/types/include/pslang/types/type_fwd.hpp @@ -22,6 +22,7 @@ namespace pslang::types bool is_floating_point_type(type const & type); bool is_numeric_type(type const & type); bool is_builtin_type(type const & type); + bool is_function_type(type const & type); std::size_t builtin_type_size(type const & type); diff --git a/libs/types/source/type.cpp b/libs/types/source/type.cpp index eedc91e..2c52a09 100644 --- a/libs/types/source/type.cpp +++ b/libs/types/source/type.cpp @@ -123,6 +123,13 @@ namespace pslang::types return false; } + bool is_function_type(type const & type) + { + if (std::get_if(&type)) + return true; + return false; + } + std::size_t builtin_type_size(type const & type) { if (std::get_if(&type)) diff --git a/plans.txt b/plans.txt index 7dff4cd..d0ef036 100644 --- a/plans.txt +++ b/plans.txt @@ -11,8 +11,10 @@ Future plans: * Extension functions: operator overloading, destructors, iterators & for loop, move assignment (replaces built-in copy) * Metaprogramming: assigning types to variables (of type `type`), functions can take `type` as regular arguments and return `type`, all type computations are compile-time only +Aarch64 compiler: +* Struct values + Backlog: -* Mutually recursive functions * Mutually recursive structs (relevant only with pointers) * Empty array expression * Calling functions as methods