26 #define LEXICON_MEMOIZATION_TYPES short,std::string,int 45 template<
typename _t_input,
typename _t_output,
typename... VM_TYPES>
56 using FT = std::function<void(this_t*,int)>;
74 template<
typename... args>
75 struct stack_t { std::tuple<VMSStack<args>...> value; };
76 stack_t<VM_TYPES...> _stack;
79 template<
typename... args>
80 struct mem_t { std::tuple<std::map<std::pair<args,input_t>,output_t>...> value; };
81 mem_t<LEXICON_MEMOIZATION_TYPES> _mem;
83 template<
typename... args>
84 struct memstack_t { std::tuple< VMSStack<std::pair<args, input_t>>...> value; };
85 memstack_t<LEXICON_MEMOIZATION_TYPES> _memstack;
100 err(e), lp(0.0), recursion_depth(0), status(
vmstatus_t::
GOOD), pool(po) {
105 std::map<std::pair<T,input_t>,output_t>&
mem() {
return std::get<std::map<std::pair<T,input_t>,output_t>>(_mem.value); }
126 static_assert(contains_type<T,VM_TYPES...>() &&
"*** Error type T missing from VM_TYPES");
127 return std::get<VMSStack<T>>(_stack.value);
136 static_assert(contains_type<T,VM_TYPES...>() &&
"*** Error type T missing from VM_TYPES");
137 return std::get<VMSStack<T>>(_stack.value);
146 static_assert(contains_type<T,VM_TYPES...>() &&
"*** Error type T missing from VM_TYPES");
150 if(stack<T>().size() == 0) {
151 std::type_index a(
typeid(T));
153 print(
"*** Cannot pop from an empty stack -- this should not happen! Something is likely wrong with your grammar's argument types, return type, or arities:", a.name());
157 T x = stack<T>().top();
166 template<
size_t n,
typename...args>
168 static_assert( n >= 0 and n <
sizeof...(args) &&
"*** Higher n than args.");
169 return getpop<
typename std::tuple_element<n, std::tuple<args...> >::type>();
178 static_assert(contains_type<T,VM_TYPES...>() &&
"*** Error type T missing from VM_TYPES");
179 assert(stack<T>().size() > 0 &&
"Cannot gettop from an empty stack -- this should not happen! Something is likely wrong with your grammar's argument types, return type, or arities.");
180 return stack<T>().top();
185 static_assert(contains_type<T,VM_TYPES...>() &&
"*** Error type T missing from VM_TYPES");
194 static_assert(contains_type<T,VM_TYPES...>() &&
"*** Error type T missing from VM_TYPES");
195 stack<T>().push(std::move(x));
206 template<
typename T,
typename... args>
208 return (... && ((std::is_same<T,args>::value and stack<T>().size()==1) or stack<args>().
empty()));
212 return this->_exactly_one<T, VM_TYPES...>();
224 assert(status ==
vmstatus_t::COMPLETE &&
"*** Probably should not be calling this unless we are complete");
226 #ifndef NO_CHECK_END_STACK_SIZE 227 assert( exactly_one<output_t>() and xstack.
size() == 1 and
"When we return, all of the stacks should be empty or else something is awry.");
230 return gettop<output_t>();
245 if(program.
size() + runtime_counter.
total > MAX_RUN_PROGRAM ) {
257 auto f =
reinterpret_cast<FT*
>(i.
f);
void push(T &&x)
Definition: VirtualMachineState.h:193
Definition: VMSRuntimeError.h:13
Definition: VirtualMachineControl.h:13
void push(const T &val)
Push val onto the stack.
Definition: Stack.h:49
void * f
Definition: Instruction.h:24
Definition: VirtualMachineState.h:46
Program< this_t > program
Definition: VirtualMachineState.h:62
VMSStack< std::pair< T, input_t > > & memstack()
Definition: VirtualMachineState.h:108
bool exactly_one() const
Definition: VirtualMachineState.h:211
int arg
Definition: Instruction.h:25
T total
Definition: RuntimeCounter.h:24
Definition: FleetStatistics.h:5
output_t run()
Run.
Definition: VirtualMachineState.h:237
VMSStack< input_t > xstack
Definition: VirtualMachineState.h:63
RuntimeCounter runtime_counter
Definition: VirtualMachineState.h:94
bool _exactly_one() const
There is one element in stack T and the rest are empty. Used to check in returning the output...
Definition: VirtualMachineState.h:207
void increment(Instruction &i, T count=1)
Add count number of items to this instruction's count.
Definition: RuntimeCounter.h:33
Definition: Instruction.h:20
VirtualMachineState(input_t x, const output_t &e, VirtualMachinePool< this_t > *po)
Definition: VirtualMachineState.h:99
void pop()
Remove top from the stack.
Definition: Stack.h:59
T getpop()
Retrieves and pops the element of type T from the stack.
Definition: VirtualMachineState.h:145
_t_output output_t
Definition: VirtualMachineState.h:50
Instruction top()
Definition: Stack.h:83
double lp
Definition: VirtualMachineState.h:65
void print(FIRST f, ARGS... args)
Lock output_lock and print to std:cout.
Definition: IO.h:53
vmstatus_t
Definition: VMStatus.h:4
std::atomic< uintmax_t > vm_ops(0)
void push(T &x)
Definition: VirtualMachineState.h:184
bool empty() const
Definition: Stack.h:121
VMSStack< T > & stack()
Returns a reference to the stack (of a given type)
Definition: VirtualMachineState.h:125
T gettop()
Retrieves the top of the stack as a copy and does not remove.
Definition: VirtualMachineState.h:177
std::function< void(this_t *, int)> FT
Definition: VirtualMachineState.h:56
size_t size() const
Definition: Stack.h:117
void push_x(input_t x)
Definition: VirtualMachineState.h:198
const auto empty
Definition: DSL.h:8
const output_t & err
Definition: VirtualMachineState.h:64
const VMSStack< T > & stack() const
Const reference to top of stack.
Definition: VirtualMachineState.h:135
_t_input input_t
Definition: VirtualMachineState.h:49
This class manages counting operations at runtime and interfaces operations to a grammar NOTE: Curren...
VirtualMachinePool< this_t > * pool
Definition: VirtualMachineState.h:97
Definition: RuntimeCounter.h:16
unsigned long recursion_depth
Definition: VirtualMachineState.h:67
output_t get_output()
Return the output and do some checks that the stacks are as they should be if you're reading the outp...
Definition: VirtualMachineState.h:219
A program here stores just a stack of instructions which can be executed by the VirtualMachineState_t...
std::map< std::pair< T, input_t >, output_t > & mem()
Definition: VirtualMachineState.h:105
auto getpop_nth()
Getpops the n'th element of args (useful for writing primitives)
Definition: VirtualMachineState.h:167
vmstatus_t status
Definition: VirtualMachineState.h:89
Definition: VirtualMachinePool.h:42
Many things in Fleet are stacks and this is designed to allow for rapid changse to the stack type in ...