| 28 | class CallingFrame; |
| 29 | |
| 30 | class HostFunctionBase { |
| 31 | public: |
| 32 | HostFunctionBase() = delete; |
| 33 | HostFunctionBase(const uint64_t FuncCost) |
| 34 | : DefType(AST::FunctionType()), Cost(FuncCost) {} |
| 35 | virtual ~HostFunctionBase() = default; |
| 36 | |
| 37 | /// Run host function body. |
| 38 | virtual Expect<void> run(const CallingFrame &CallFrame, |
| 39 | Span<const ValVariant> Args, |
| 40 | Span<ValVariant> Rets) = 0; |
| 41 | |
| 42 | /// Getter for function type. |
| 43 | const AST::FunctionType &getFuncType() const noexcept { |
| 44 | return DefType.getCompositeType().getFuncType(); |
| 45 | } |
| 46 | |
| 47 | /// Getter for host function cost. |
| 48 | uint64_t getCost() const { return Cost; } |
| 49 | |
| 50 | /// Getter for defined type. |
| 51 | const AST::SubType &getDefinedType() const noexcept { return DefType; } |
| 52 | |
| 53 | protected: |
| 54 | AST::SubType DefType; |
| 55 | const uint64_t Cost; |
| 56 | }; |
| 57 | |
| 58 | template <typename T> class HostFunction : public HostFunctionBase { |
| 59 | public: |