86 #include "binding_map.h"
87 #include "../r_code/replicode_defs.h"
90 #include "cpp_programs.h"
91 #include "../r_code/utils.h"
97 template<
class O,
class S> MemExec<O, S>::MemExec() : S() {
100 template<
class O,
class S> MemExec<O, S>::~MemExec() {
102 if (state_ == RUNNING)
112 Atom head = source->code_[0];
113 switch (head.getDescriptor()) {
115 return new Group(source);
117 uint16 opcode = head.asOpcode();
118 if (opcode == Opcodes::Fact)
119 return new Fact(source);
120 else if (opcode == Opcodes::AntiFact)
121 return new AntiFact(source);
122 else if (opcode == Opcodes::Goal)
123 return new Goal(source);
124 else if (opcode == Opcodes::Pred)
125 return new Pred(source);
126 else if (opcode == Opcodes::ICst)
127 return new ICST(source);
128 else if (opcode == Opcodes::MkRdx)
129 return new MkRdx(source);
130 else if (opcode == Opcodes::MkActChg ||
131 opcode == Opcodes::MkHighAct ||
132 opcode == Opcodes::MkHighSln ||
133 opcode == Opcodes::MkLowAct ||
134 opcode == Opcodes::MkLowRes ||
135 opcode == Opcodes::MkLowSln ||
136 opcode == Opcodes::MkNew ||
137 opcode == Opcodes::MkSlnChg ||
138 opcode == Opcodes::Success ||
139 opcode == Opcodes::Perf)
142 return new O(source);
147 template<
class O,
class S>
r_code::Code *MemExec<O, S>::_build_object(Atom head)
const {
150 object->code(0) = head;
154 template<
class O,
class S>
r_code::Code *MemExec<O, S>::build_object(Atom head)
const {
157 switch (head.getDescriptor()) {
159 object =
new Group();
162 uint16 opcode = head.asOpcode();
163 if (opcode == Opcodes::Fact)
165 else if (opcode == Opcodes::AntiFact)
166 object =
new AntiFact();
167 else if (opcode == Opcodes::Pred)
169 else if (opcode == Opcodes::Goal)
171 else if (opcode == Opcodes::ICst)
173 else if (opcode == Opcodes::MkRdx)
174 object =
new MkRdx();
175 else if (opcode == Opcodes::MkActChg ||
176 opcode == Opcodes::MkHighAct ||
177 opcode == Opcodes::MkHighSln ||
178 opcode == Opcodes::MkLowAct ||
179 opcode == Opcodes::MkLowRes ||
180 opcode == Opcodes::MkLowSln ||
181 opcode == Opcodes::MkNew ||
182 opcode == Opcodes::MkSlnChg ||
183 opcode == Opcodes::Success ||
184 opcode == Opcodes::Perf)
186 else if (O::RequiresPacking())
194 object->code(0) = head;
202 if (object->code(0).getDescriptor() == Atom::GROUP)
206 if (O::RequiresPacking())
207 _object = O::Pack(
object,
this);
209 _object = (O *)
object;
214 template<
class O,
class S>
void MemExec<O, S>::inject(O *
object, View *view) {
216 view->set_object(
object);
217 S::inject_new_object(view);