From 13f728b1b2b422d3ce653d039423f9905c3318a5 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 28 Nov 2025 19:32:56 -0500 Subject: [PATCH] xo-interpreter: apply expressions + llvm builtins working! --- include/xo/expression/Apply.hpp | 3 +++ include/xo/expression/PrimitiveExpr.hpp | 14 +++++++------- include/xo/expression/PrimitiveExprInterface.hpp | 7 +++++++ src/expression/PrimitiveExpr.cpp | 7 +++++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/xo/expression/Apply.hpp b/include/xo/expression/Apply.hpp index 003b49fa..7dd66a7e 100644 --- a/include/xo/expression/Apply.hpp +++ b/include/xo/expression/Apply.hpp @@ -80,6 +80,9 @@ namespace xo { const rp & fn() const { return fn_; } const std::vector> & argv() const { return argv_; } + std::size_t n_arg() const { return argv_.size(); } + const rp & lookup_arg(size_t i) const { return argv_.at(i); } + virtual std::set get_free_variables() const override { std::set retval = fn_->get_free_variables(); diff --git a/include/xo/expression/PrimitiveExpr.hpp b/include/xo/expression/PrimitiveExpr.hpp index 6050e8db..86ca5e03 100644 --- a/include/xo/expression/PrimitiveExpr.hpp +++ b/include/xo/expression/PrimitiveExpr.hpp @@ -47,9 +47,9 @@ namespace xo { public: static rp make(const std::string & name, - FunctionPointer fnptr, - bool explicit_symbol_def, - llvmintrinsic intrinsic) { + FunctionPointer fnptr, + bool explicit_symbol_def, + llvmintrinsic intrinsic) { TypeDescr fn_type = Reflect::require(); return new PrimitiveExpr(fn_type, name, fnptr, explicit_symbol_def, intrinsic); @@ -60,16 +60,16 @@ namespace xo { FunctionPointer value() const { return value_; } TypeDescr value_td() const { return value_td_; } - TaggedPtr value_tp() const { + + // ----- PrimitiveExprInterface ----- + + virtual TaggedPtr value_tp() const final override { /* note: idk why, but need to spell this out in two steps with gcc 13.2 */ const void * erased_cptr = &value_; void * erased_ptr = const_cast(erased_cptr); return TaggedPtr(value_td_, erased_ptr); } - - // ----- PrimitiveExprInterface ----- - virtual llvmintrinsic intrinsic() const override { return intrinsic_; } virtual bool explicit_symbol_def() const override { return explicit_symbol_def_; } virtual void_function_type function_address() const override { return reinterpret_cast(value_); } diff --git a/include/xo/expression/PrimitiveExprInterface.hpp b/include/xo/expression/PrimitiveExprInterface.hpp index 9db7be14..0fbd0ae3 100644 --- a/include/xo/expression/PrimitiveExprInterface.hpp +++ b/include/xo/expression/PrimitiveExprInterface.hpp @@ -7,12 +7,14 @@ #include "ProcedureExprInterface.hpp" #include "llvmintrinsic.hpp" +#include "xo/reflect/TaggedPtr.hpp" #include namespace xo { namespace scm { class PrimitiveExprInterface : public ProcedureExprInterface { public: + using TaggedPtr = xo::reflect::TaggedPtr; using void_function_type = void (*)(); public: @@ -24,6 +26,11 @@ namespace xo { return bp::from(x); } + /** @return executable function as tagged pointer. + * Load-bearing for xo-interpreter. + **/ + virtual TaggedPtr value_tp() const = 0; + /** if true, Jit will try to explicitly symbol for this primitive * (instead of looking it up in host process). * Don't know if this works. diff --git a/src/expression/PrimitiveExpr.cpp b/src/expression/PrimitiveExpr.cpp index 09246a62..4d73b14c 100644 --- a/src/expression/PrimitiveExpr.cpp +++ b/src/expression/PrimitiveExpr.cpp @@ -8,8 +8,11 @@ extern "C" { * 1. Fallback implementation under llvm. * In practice will use llvm intrinsic instead. * See xo-jit/src/jit/MachPipeline.cpp - * 2. Schematika interpreter (aspirational asof jul 2025) - * + * 2. Schematika interpreter (aspirational asof jul 2025, wip nov 2025) + * For schematika interpreter need to uplift + * these to obj::Primitive. + * See BuiltinPrimitives::install_interpreter_conversions() + * in xo-interpreter/src/BuiltinPrimitives.cpp **/ bool