xo-expression: naming: {Primitive,Function}ExprInterface
This commit is contained in:
parent
7ee41a4b71
commit
22670cda3d
9 changed files with 38 additions and 41 deletions
|
|
@ -10,14 +10,14 @@
|
|||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
class FunctionInterface : public Expression {
|
||||
class FunctionExprInterface : public Expression {
|
||||
public:
|
||||
FunctionInterface(exprtype extype, TypeDescr fn_type)
|
||||
FunctionExprInterface(exprtype extype, TypeDescr fn_type)
|
||||
: Expression(extype, fn_type) {}
|
||||
|
||||
/** downcast from Expression **/
|
||||
static bp<FunctionInterface> from(bp<Expression> x) {
|
||||
return bp<FunctionInterface>::from(x);
|
||||
static bp<FunctionExprInterface> from(bp<Expression> x) {
|
||||
return bp<FunctionExprInterface>::from(x);
|
||||
}
|
||||
|
||||
virtual const std::string & name() const = 0;
|
||||
|
|
@ -6,13 +6,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "Expression.hpp"
|
||||
#include "FunctionInterface.hpp"
|
||||
#include "FunctionExprInterface.hpp"
|
||||
#include "Variable.hpp"
|
||||
#include "LocalSymtab.hpp"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
//#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
@ -20,7 +19,7 @@ namespace xo {
|
|||
* @brief abstract syntax tree for a function definition
|
||||
*
|
||||
**/
|
||||
class Lambda : public FunctionInterface {
|
||||
class Lambda : public FunctionExprInterface {
|
||||
public:
|
||||
/**
|
||||
* @p name. Name for this lambda -- must be unique
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "PrimitiveInterface.hpp"
|
||||
#include "PrimitiveExprInterface.hpp"
|
||||
#include "pretty_expression.hpp"
|
||||
#include "llvmintrinsic.hpp"
|
||||
#include "xo/reflect/Reflect.hpp"
|
||||
|
|
@ -38,7 +38,7 @@ namespace xo {
|
|||
* won't work here.
|
||||
**/
|
||||
template <typename FunctionPointer>
|
||||
class Primitive: public PrimitiveInterface {
|
||||
class Primitive: public PrimitiveExprInterface {
|
||||
public:
|
||||
using Reflect = xo::reflect::Reflect;
|
||||
using TaggedPtr = xo::reflect::TaggedPtr;
|
||||
|
|
@ -111,7 +111,7 @@ namespace xo {
|
|||
FunctionPointer fnptr,
|
||||
bool explicit_symbol_def,
|
||||
llvmintrinsic intrinsic)
|
||||
: PrimitiveInterface(fn_type),
|
||||
: PrimitiveExprInterface(fn_type),
|
||||
name_{name},
|
||||
value_td_{Reflect::require_function<FunctionPointer>()},
|
||||
value_{fnptr},
|
||||
|
|
|
|||
|
|
@ -1,29 +1,27 @@
|
|||
/** @file PrimitiveInterface.hpp
|
||||
/** @file PrimitiveExprInterface.hpp
|
||||
*
|
||||
* Author: Roland Conybeare
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "FunctionInterface.hpp"
|
||||
#include "FunctionExprInterface.hpp"
|
||||
#include "llvmintrinsic.hpp"
|
||||
|
||||
//#include <cstdint>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
class PrimitiveInterface : public FunctionInterface {
|
||||
class PrimitiveExprInterface : public FunctionExprInterface {
|
||||
public:
|
||||
using void_function_type = void (*)();
|
||||
|
||||
public:
|
||||
explicit PrimitiveInterface(TypeDescr fn_type)
|
||||
: FunctionInterface(exprtype::primitive, fn_type) {}
|
||||
explicit PrimitiveExprInterface(TypeDescr fn_type)
|
||||
: FunctionExprInterface(exprtype::primitive, fn_type) {}
|
||||
|
||||
/** downcast from Expression **/
|
||||
static bp<PrimitiveInterface> from(bp<Expression> x) {
|
||||
return bp<PrimitiveInterface>::from(x);
|
||||
static bp<PrimitiveExprInterface> from(bp<Expression> x) {
|
||||
return bp<PrimitiveExprInterface>::from(x);
|
||||
}
|
||||
|
||||
/** if true, Jit will try to explicitly symbol for this primitive
|
||||
|
|
@ -259,7 +259,7 @@ namespace xo {
|
|||
TypeDescr lambda_td,
|
||||
const rp<LocalSymtab> & local_env,
|
||||
const rp<Expression> & body)
|
||||
: FunctionInterface(exprtype::lambda, lambda_td),
|
||||
: FunctionExprInterface(exprtype::lambda, lambda_td),
|
||||
name_{name},
|
||||
body_{body},
|
||||
local_env_{local_env}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "xo/expression/Expression.hpp"
|
||||
#include "xo/expression/ConstantInterface.hpp"
|
||||
#include "xo/expression/PrimitiveInterface.hpp"
|
||||
#include "xo/expression/PrimitiveExprInterface.hpp"
|
||||
#include "xo/expression/Apply.hpp"
|
||||
#include "xo/expression/Lambda.hpp"
|
||||
#include "xo/expression/Variable.hpp"
|
||||
|
|
@ -110,7 +110,7 @@ namespace xo {
|
|||
**/
|
||||
llvm::Type * codegen_type(TypeDescr td);
|
||||
llvm::Value * codegen_constant(bp<xo::scm::ConstantInterface> expr);
|
||||
llvm::Function * codegen_primitive(bp<xo::scm::PrimitiveInterface> expr);
|
||||
llvm::Function * codegen_primitive(bp<xo::scm::PrimitiveExprInterface> expr);
|
||||
|
||||
/** like @ref codegen_primitive , but create wrapper function that accepts (and discards)
|
||||
* environment pointer as first argument.
|
||||
|
|
@ -118,7 +118,7 @@ namespace xo {
|
|||
* Implementation consists of tail call to natural primitive, that skips the unused
|
||||
* environment pointer
|
||||
**/
|
||||
llvm::Function * codegen_primitive_wrapper(bp<xo::scm::PrimitiveInterface> expr,
|
||||
llvm::Function * codegen_primitive_wrapper(bp<xo::scm::PrimitiveExprInterface> expr,
|
||||
llvm::IRBuilder<> & ir_builder);
|
||||
|
||||
/** Generate closure for invoking a primitive function.
|
||||
|
|
@ -126,7 +126,7 @@ namespace xo {
|
|||
* to support function-pointer-like behavior for a target function
|
||||
* that may resolve to primitive-or-lambda at runtime
|
||||
**/
|
||||
llvm::Value * codegen_primitive_closure(bp<xo::scm::PrimitiveInterface> expr,
|
||||
llvm::Value * codegen_primitive_closure(bp<xo::scm::PrimitiveExprInterface> expr,
|
||||
llvm::IRBuilder<> & ir_builder);
|
||||
|
||||
llvm::Value * codegen_apply(bp<xo::scm::Apply> expr,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace xo {
|
|||
**/
|
||||
struct type2llvm {
|
||||
public:
|
||||
using FunctionInterface = xo::scm::FunctionInterface;
|
||||
using FunctionInterface = xo::scm::FunctionExprInterface;
|
||||
using Lambda = xo::scm::Lambda;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace xo {
|
|||
using xo::scm::Expression;
|
||||
using xo::scm::ConstantInterface;
|
||||
//using xo::scm::FunctionInterface;
|
||||
using xo::scm::PrimitiveInterface;
|
||||
using xo::scm::PrimitiveExprInterface;
|
||||
using xo::scm::Lambda;
|
||||
using xo::scm::Variable;
|
||||
using xo::scm::Apply;
|
||||
|
|
@ -166,7 +166,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
llvm::Function *
|
||||
MachPipeline::codegen_primitive(bp<PrimitiveInterface> expr)
|
||||
MachPipeline::codegen_primitive(bp<PrimitiveExprInterface> expr)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
|
||||
|
|
@ -251,7 +251,7 @@ namespace xo {
|
|||
} /*codegen_primitive*/
|
||||
|
||||
llvm::Function *
|
||||
MachPipeline::codegen_primitive_wrapper(bp<PrimitiveInterface> expr,
|
||||
MachPipeline::codegen_primitive_wrapper(bp<PrimitiveExprInterface> expr,
|
||||
llvm::IRBuilder<> & /*ir_builder*/)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
|
|
@ -369,7 +369,7 @@ namespace xo {
|
|||
} /*codegen_primitive_wrapper*/
|
||||
|
||||
llvm::Value *
|
||||
MachPipeline::codegen_primitive_closure(bp<xo::scm::PrimitiveInterface> expr,
|
||||
MachPipeline::codegen_primitive_closure(bp<xo::scm::PrimitiveExprInterface> expr,
|
||||
llvm::IRBuilder<> & ir_builder)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
|
|
@ -422,7 +422,7 @@ namespace xo {
|
|||
* allows substituting LLVM intrinsic
|
||||
*/
|
||||
if (apply->fn()->extype() == exprtype::primitive) {
|
||||
auto pm = PrimitiveInterface::from(apply->fn());
|
||||
auto pm = PrimitiveExprInterface::from(apply->fn());
|
||||
|
||||
if (pm) {
|
||||
llvm_closure = this->codegen_primitive_closure(pm, ir_builder);
|
||||
|
|
@ -979,7 +979,7 @@ namespace xo {
|
|||
case exprtype::constant:
|
||||
return this->codegen_constant(ConstantInterface::from(expr));
|
||||
case exprtype::primitive:
|
||||
return this->codegen_primitive_closure(PrimitiveInterface::from(expr), ir_builder);
|
||||
return this->codegen_primitive_closure(PrimitiveExprInterface::from(expr), ir_builder);
|
||||
case exprtype::apply:
|
||||
return this->codegen_apply(Apply::from(expr), envptr, ir_builder);
|
||||
case exprtype::lambda:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include "xo/pyreflect/pyreflect.hpp"
|
||||
#include "xo/expression/Expression.hpp"
|
||||
#include "xo/expression/Apply.hpp"
|
||||
#include "xo/expression/PrimitiveInterface.hpp"
|
||||
#include "xo/expression/PrimitiveExprInterface.hpp"
|
||||
#include "xo/expression/Primitive.hpp"
|
||||
#include "xo/expression/ConstantInterface.hpp"
|
||||
#include "xo/expression/Constant.hpp"
|
||||
|
|
@ -21,7 +21,7 @@ namespace xo {
|
|||
using xo::scm::exprtype;
|
||||
using xo::scm::Expression;
|
||||
using xo::scm::make_apply;
|
||||
using xo::scm::PrimitiveInterface;
|
||||
using xo::scm::PrimitiveExprInterface;
|
||||
using xo::scm::Primitive;
|
||||
using xo::scm::make_primitive;
|
||||
using xo::scm::ConstantInterface;
|
||||
|
|
@ -95,24 +95,24 @@ namespace xo {
|
|||
|
||||
// ----- Primitives -----
|
||||
|
||||
py::class_<PrimitiveInterface,
|
||||
py::class_<PrimitiveExprInterface,
|
||||
Expression,
|
||||
rp<PrimitiveInterface>>(m, "PrimitiveInterface")
|
||||
.def("name", &PrimitiveInterface::name,
|
||||
rp<PrimitiveExprInterface>>(m, "PrimitiveInterface")
|
||||
.def("name", &PrimitiveExprInterface::name,
|
||||
py::doc("name of this primitive function; use this name to invoke the function"))
|
||||
.def("n_arg", &PrimitiveInterface::n_arg,
|
||||
.def("n_arg", &PrimitiveExprInterface::n_arg,
|
||||
py::doc("number of arguments to this function (not counting return value)"))
|
||||
;
|
||||
|
||||
using int32_t = std::int32_t;
|
||||
|
||||
py::class_<Primitive<int32_t (*)(int32_t, int32_t)>,
|
||||
PrimitiveInterface,
|
||||
PrimitiveExprInterface,
|
||||
rp<Primitive<int32_t (*)(int32_t, int32_t)>>>(m, "Primitive_i32_i32")
|
||||
;
|
||||
|
||||
py::class_<Primitive<double (*)(double)>,
|
||||
PrimitiveInterface,
|
||||
PrimitiveExprInterface,
|
||||
rp<Primitive<double (*)(double)>>>(m, "Primitive_double_double")
|
||||
;
|
||||
using Fn_dbl_dbl_type = double (*)(double);
|
||||
|
|
@ -136,7 +136,7 @@ namespace xo {
|
|||
py::doc("create primitive representing the ::cos() function"));
|
||||
|
||||
py::class_<Primitive<double (*)(double, double)>,
|
||||
PrimitiveInterface,
|
||||
PrimitiveExprInterface,
|
||||
rp<Primitive<double (*)(double, double)>>>(m, "Primitive_double_double_double")
|
||||
;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue