Fleet  0.0.9
Inference in the LOT
Primitive.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Instruction.h"
4 
12 template<typename T=void, typename... args>
13 struct Primitive {
14 
15  Op op;
16  void* f;
17 
18  Primitive(const Primitive<T,args...>& other) = delete; // probably not the best idea to copy these
19  Primitive(const Primitive<T,args...>&& other) = delete; // probably not the best idea to copy these
20 
26  template<typename VirtualMachineState_t>
27  Primitive(Op o, typename VirtualMachineState_t::FT* _f) : f((void*)_f), op(o) {
28  assert(f != nullptr);
29  }
30 
35  template<typename VirtualMachineState_t>
36  Primitive(Op o, void(*_f)(VirtualMachineState_t*,int)) : op(o) {
37  f = (void*)(new typename VirtualMachineState_t::FT(_f)); // make a copy
38  assert(f != nullptr);
39  }
40 
41  // this is helpful for other Builtins to call even though it is not used in VMS running
42  template<typename VirtualMachineState_t>
43  void call(VirtualMachineState_t* vms, int arg) {
44  auto myf = reinterpret_cast<typename VirtualMachineState_t::FT*>(f);
45  (*myf)(vms, arg);
46  }
47 
49  return Instruction(f,arg);
50  }
51 };
Definition: Primitive.h:13
void * f
Definition: Primitive.h:16
Definition: Instruction.h:20
f here is a point to a void(VirtualMachineState_t* vms, int arg), where arg is just a supplemental ar...
Op
Definition: Ops.h:3
Primitive(Op o, void(*_f)(VirtualMachineState_t *, int))
This constructor takes an ordinary function pointer and converts it.
Definition: Primitive.h:36
Instruction makeInstruction(int arg=0)
Definition: Primitive.h:48
Primitive(const Primitive< T, args... > &other)=delete
void call(VirtualMachineState_t *vms, int arg)
Definition: Primitive.h:43
Op op
Definition: Primitive.h:15
Primitive(Op o, typename VirtualMachineState_t::FT *_f)
Constructor here assumes the std::function type.
Definition: Primitive.h:27