xo-interpreter: apply expressions + llvm builtins working!
This commit is contained in:
parent
7ca1366bec
commit
1d1e72adf3
31 changed files with 531 additions and 50 deletions
|
|
@ -80,6 +80,9 @@ namespace xo {
|
|||
const rp<Expression> & fn() const { return fn_; }
|
||||
const std::vector<rp<Expression>> & argv() const { return argv_; }
|
||||
|
||||
std::size_t n_arg() const { return argv_.size(); }
|
||||
const rp<Expression> & lookup_arg(size_t i) const { return argv_.at(i); }
|
||||
|
||||
virtual std::set<std::string> get_free_variables() const override {
|
||||
std::set<std::string> retval = fn_->get_free_variables();
|
||||
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@ namespace xo {
|
|||
|
||||
public:
|
||||
static rp<PrimitiveExpr> 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<FunctionPointer>();
|
||||
|
||||
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<void*>(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<void_function_type>(value_); }
|
||||
|
|
|
|||
|
|
@ -7,12 +7,14 @@
|
|||
|
||||
#include "ProcedureExprInterface.hpp"
|
||||
#include "llvmintrinsic.hpp"
|
||||
#include "xo/reflect/TaggedPtr.hpp"
|
||||
#include <type_traits>
|
||||
|
||||
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<PrimitiveExprInterface>::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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue