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 
14 template<typename T=void, typename... args>
15 struct Primitive {
16 
17  Op op;
18  void* f;
19 
20  Primitive(const Primitive<T,args...>& other) = delete; // probably not the best idea to copy these
21  Primitive(const Primitive<T,args...>&& other) = delete; // probably not the best idea to copy these
22 
28  template<typename VirtualMachineState_t>
29  Primitive(Op o, typename VirtualMachineState_t::FT* _f) : f((void*)_f), op(o) {
30  assert(f != nullptr);
31  }
32 
37  template<typename VirtualMachineState_t>
38  Primitive(Op o, void(*_f)(VirtualMachineState_t*,int)) : op(o) {
39  f = (void*)(new typename VirtualMachineState_t::FT(_f)); // make a copy
40  assert(f != nullptr);
41  }
42 
43  // this is helpful for other Builtins to call even though it is not used in VMS running
44  template<typename VirtualMachineState_t>
45  void call(VirtualMachineState_t* vms, int arg) {
46  auto myf = reinterpret_cast<typename VirtualMachineState_t::FT*>(f);
47  (*myf)(vms, arg);
48  }
49 
51  return Instruction(f,arg);
52  }
53 };
Definition: Primitive.h:15
void * f
Definition: Primitive.h:18
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:38
Instruction makeInstruction(int arg=0)
Definition: Primitive.h:50
Primitive(const Primitive< T, args... > &other)=delete
void call(VirtualMachineState_t *vms, int arg)
Definition: Primitive.h:45
Op op
Definition: Primitive.h:17
Primitive(Op o, typename VirtualMachineState_t::FT *_f)
Constructor here assumes the std::function type.
Definition: Primitive.h:29