xo-jit: + primitive wrapper (accept+ignore envptr as 1st argument)

This commit is contained in:
Roland Conybeare 2024-07-07 16:57:05 -04:00
commit 4c8289336d
4 changed files with 138 additions and 20 deletions

View file

@ -111,6 +111,16 @@ namespace xo {
llvm::Type * codegen_type(TypeDescr td);
llvm::Value * codegen_constant(ref::brw<xo::ast::ConstantInterface> expr);
llvm::Function * codegen_primitive(ref::brw<xo::ast::PrimitiveInterface> expr);
/** like @ref codegen_primitive , but create wrapper function that accepts (and discards)
* environment pointer as first argument.
*
* Implementation consists of tail call to natural primitive, that skips the unused
* environment pointer
**/
llvm::Function * codegen_primitive_wrapper(ref::brw<xo::ast::PrimitiveInterface> expr,
llvm::IRBuilder<> & ir_builder);
llvm::Value * codegen_apply(ref::brw<xo::ast::Apply> expr, llvm::IRBuilder<> & ir_builder);
/* NOTE: codegen_lambda() needs to be reentrant too.
* for example can have a lambda in apply position.

View file

@ -29,9 +29,17 @@ namespace xo {
/** establish llvm representation for a function type
* described by @p fn_td
*
* @param wrapper_flag If true, create function type for a wrapper
* to be associated with a closure.
* The wrapper accepts (and ignores) an envapi pointer as first argument.
* Necessary to (for example) support function pointers that may refer
* to either {primitive functions, functions-requiring-closures},
* with choice deferred until runtime
**/
static llvm::FunctionType * function_td_to_llvm_type(xo::ref::brw<LlvmContext> llvm_cx,
TypeDescr fn_td);
TypeDescr fn_td,
bool wrapper_flag = false);
/** establish llvm concrete representation for a particular lambda's
* runtime local environment: