xo-expression: + explicit_symbol_def feature in PrimitiveInterface
This commit is contained in:
parent
5c4b062cf8
commit
37b2bc85a4
3 changed files with 39 additions and 7 deletions
|
|
@ -35,10 +35,11 @@ namespace xo {
|
|||
|
||||
public:
|
||||
static ref::rp<Primitive> make(const std::string & name,
|
||||
FunctionPointer fnptr) {
|
||||
FunctionPointer fnptr,
|
||||
bool explicit_symbol_def) {
|
||||
TypeDescr fn_type = Reflect::require<FunctionPointer>();
|
||||
|
||||
return new Primitive(fn_type, name, fnptr);
|
||||
return new Primitive(fn_type, name, fnptr, explicit_symbol_def);
|
||||
}
|
||||
|
||||
FunctionPointer value() const { return value_; }
|
||||
|
|
@ -54,6 +55,9 @@ namespace xo {
|
|||
|
||||
// ----- PrimitiveInterface -----
|
||||
|
||||
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_); }
|
||||
|
||||
// ----- FunctionInterface -----
|
||||
|
||||
virtual std::string const & name() const override { return name_; }
|
||||
|
|
@ -74,11 +78,13 @@ namespace xo {
|
|||
private:
|
||||
Primitive(TypeDescr fn_type,
|
||||
const std::string & name,
|
||||
FunctionPointer fnptr)
|
||||
FunctionPointer fnptr,
|
||||
bool explicit_symbol_def)
|
||||
: PrimitiveInterface(fn_type),
|
||||
name_{name},
|
||||
value_td_{Reflect::require_function<FunctionPointer>()},
|
||||
value_{fnptr}
|
||||
value_{fnptr},
|
||||
explicit_symbol_def_{explicit_symbol_def}
|
||||
{
|
||||
if (!value_td_->is_function())
|
||||
throw std::runtime_error("Primitive: expected function pointer");
|
||||
|
|
@ -97,13 +103,21 @@ namespace xo {
|
|||
TypeDescr value_td_;
|
||||
/** address of executable function **/
|
||||
FunctionPointer value_;
|
||||
/** if true, use Jit.intern_symbol() to provide explicit binding.
|
||||
* Currently mystified as to what's distinguishes functions like ::sin(), ::sqrt()
|
||||
* (which work do not require this) from symbols like ::mul_i32(), which do)
|
||||
**/
|
||||
bool explicit_symbol_def_ = false;
|
||||
}; /*Primitive*/
|
||||
|
||||
/** adopt function @p x as a callable primitive function named @p name **/
|
||||
template <typename FunctionPointer>
|
||||
ref::rp<Primitive<FunctionPointer>>
|
||||
make_primitive(const std::string & name, FunctionPointer x) {
|
||||
return Primitive<FunctionPointer>::make(name, x);
|
||||
make_primitive(const std::string & name,
|
||||
FunctionPointer x,
|
||||
bool explicit_symbol_def)
|
||||
{
|
||||
return Primitive<FunctionPointer>::make(name, x, explicit_symbol_def);
|
||||
}
|
||||
} /*namespace ast*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@
|
|||
namespace xo {
|
||||
namespace ast {
|
||||
class PrimitiveInterface : public FunctionInterface {
|
||||
public:
|
||||
using void_function_type = void (*)();
|
||||
|
||||
public:
|
||||
PrimitiveInterface(TypeDescr fn_type)
|
||||
: FunctionInterface(exprtype::primitive, fn_type) {}
|
||||
|
|
@ -22,6 +25,19 @@ namespace xo {
|
|||
return ref::brw<PrimitiveInterface>::from(x);
|
||||
}
|
||||
|
||||
/** 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.
|
||||
* Do know it's not needed for ::sin(), ::sqrt().
|
||||
* Do know that my extern "C" functions like ::mul_i32(), ::mul_f64()
|
||||
* need something else.
|
||||
**/
|
||||
virtual bool explicit_symbol_def() const = 0;
|
||||
|
||||
/** function address for this primitive
|
||||
**/
|
||||
virtual void_function_type function_address() const = 0;
|
||||
|
||||
// virtual const std::string & name() const;
|
||||
// virtual int n_arg() const;
|
||||
// virtual TypeDescr fn_retval() const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue