88 #include "controller.h"
107 virtual void valuate(
r_code::Code *destination, uint16 write_index, uint16 &extent_index)
const = 0;
108 virtual bool match(
const r_code::Code *
object, uint16 index) = 0;
109 virtual Atom *get_code() = 0;
111 virtual uint16 get_code_size() = 0;
113 virtual bool intersect(
const Value* )
const {
return false; }
114 virtual bool _intersect(
const AtomValue* )
const {
return false; }
115 virtual bool _intersect(
const StructureValue* )
const {
return false; }
116 virtual bool _intersect(
const ObjectValue* )
const {
return false; }
118 virtual bool contains(
const Atom )
const {
return false; }
119 virtual bool contains(
const Atom* )
const {
return false; }
120 virtual bool contains(
const r_code::Code* )
const {
return false; }
128 uint16 extent_index = 1;
129 valuate(code, 0, extent_index);
130 return code->trace_string();
150 void valuate(
r_code::Code *destination, uint16 write_index, uint16 &extent_index)
const override;
151 bool match(
const r_code::Code *
object, uint16 index)
override;
152 Atom *get_code()
override;
154 uint16 get_code_size()
override;
165 void valuate(
r_code::Code *destination, uint16 write_index, uint16 &extent_index)
const override;
166 bool match(
const r_code::Code *
object, uint16 index)
override;
167 Atom *get_code()
override;
169 uint16 get_code_size()
override;
171 bool intersect(
const Value *v)
const override;
172 bool _intersect(
const AtomValue *v)
const override;
174 bool contains(
const Atom a)
const override;
191 void valuate(
r_code::Code* destination, uint16 write_index, uint16& extent_index)
const override {
192 destination->code(write_index) = Atom::IPointer(extent_index);
193 copy_structure(destination, extent_index, &structure_->code(0), 0);
204 static void copy_structure(
205 r_code::Code* destination, uint16& extent_index,
const Atom* source, uint16 source_index);
207 bool match(
const r_code::Code *
object, uint16 index)
override;
208 Atom *get_code()
override;
210 uint16 get_code_size()
override;
212 bool intersect(
const Value *v)
const override;
215 bool contains(
const Atom *s)
const override;
226 void valuate(
r_code::Code *destination, uint16 write_index, uint16 &extent_index)
const override;
227 bool match(
const r_code::Code *
object, uint16 index)
override;
228 Atom *get_code()
override;
230 uint16 get_code_size()
override;
232 bool intersect(
const Value *v)
const override;
233 bool _intersect(
const ObjectValue *v)
const override;
239 MATCH_SUCCESS_POSITIVE = 0,
240 MATCH_SUCCESS_NEGATIVE = 1,
251 std::vector<P<Value> > map_;
253 uint32 unbound_values_;
255 void add_unbound_value(uint8
id);
258 int16 fwd_after_index_;
259 int16 fwd_before_index_;
261 bool match_fwd_timings(
const _Fact *f_object);
262 bool match(
const r_code::Code *
object, uint16 o_base_index, uint16 o_index,
const r_code::Code *pattern, uint16 p_index, uint16 o_arity);
264 void abstract_member(
const r_code::Code *
object, uint16 index,
r_code::Code *abstracted_object, uint16 write_index, uint16 &extent_index,
int first_search_index = 0);
277 Atom get_structure_variable(
const r_code::Code *
object, uint16 index,
int first_search_index = 0);
288 virtual void clear();
292 static _Fact *abstract_f_ihlp(
const _Fact *fact);
301 _Fact *abstract_fact(
_Fact *fact,
const _Fact *original,
bool force_sync,
int timing_vars_first_search_index = 0);
304 void reset_fwd_timings(
_Fact *reference_fact);
317 return match_timings(after, before, fwd_after_index_, fwd_before_index_);
320 MatchResult match_fwd_lenient(
const _Fact *f_object,
const _Fact *f_pattern);
321 bool match_fwd_strict(
const _Fact *f_object,
const _Fact *f_pattern);
328 return i >= 0 && i < map_.size() && map_[i]->get_code() != NULL &&
329 map_[i]->get_code()[0].getDescriptor() == Atom::TIMESTAMP;
331 bool has_fwd_after()
const {
return is_timestamp(fwd_after_index_); }
332 bool has_fwd_before()
const {
return is_timestamp(fwd_before_index_); }
333 Timestamp get_fwd_after()
const;
334 Timestamp get_fwd_before()
const;
337 bool match_structure(
const r_code::Code *
object, uint16 o_base_index, uint16 o_index,
const r_code::Code *pattern, uint16 p_index);
338 bool match_atom(Atom o_atom, Atom p_atom);
340 void bind_variable(BoundValue *value, uint8
id);
341 void bind_variable(Atom *code, uint8
id, uint16 value_index, Atom *intermediate_results);
343 Atom *get_value_code(uint16
id)
const;
344 uint16 get_value_code_size(uint16
id)
const;
345 uint16 get_first_index()
const {
return first_index_; }
352 bool intersect(
const BindingMap *bm)
const;
354 bool is_fully_specified()
const;
356 Atom *get_code(uint16 i)
const {
return map_[i]->get_code(); }
357 r_code::Code *get_object(uint16 i)
const {
return map_[i]->get_object(); }
358 int16 get_fwd_after_index()
const {
return fwd_after_index_; }
359 int16 get_fwd_before_index()
const {
return fwd_before_index_; }
360 bool scan_variable(uint16
id)
const;
374 bool match_timings(Timestamp after, Timestamp before, uint32 after_index, uint32 before_index);
383 static uint16 get_abstracted_ihlp_exposed_args_index(
const r_code::Code* ihlp);
389 std::string
trace_string(uint16 i)
const {
return map_[i]->trace_string(); }
395 int16 bwd_after_index_;
396 int16 bwd_before_index_;
398 bool match_bwd_timings(
const _Fact *f_object,
const _Fact *f_pattern);
406 void init_timing_indexes(
const r_code::Code* source, int16& after_index, int16& before_index) {
407 if (source->code_size() <= FACT_BEFORE)
410 if (source->code(FACT_AFTER).getDescriptor() == Atom::VL_PTR)
411 after_index = source->code(FACT_AFTER).asIndex();
412 if (source->code(FACT_BEFORE).getDescriptor() == Atom::VL_PTR)
413 before_index = source->code(FACT_BEFORE).asIndex();
421 void add_unbound_values(
const r_code::Code* hlp, uint16 structure_index);
431 void build_ihlp_structure(
442 void init_from_ihlp_args(
452 void clear()
override;
455 void init_from_f_ihlp(
const _Fact *f_ihlp);
456 Fact *build_f_ihlp(
r_code::Code *hlp, uint16 opcode,
bool wr_enabled)
const;
466 int16 get_ihlp_exposed_args_position(int16 index)
const;
468 void reset_bwd_timings(
_Fact *reference_fact);
470 MatchResult match_bwd_lenient(
const _Fact *f_object,
const _Fact *f_pattern);
471 bool match_bwd_strict(
const _Fact *f_object,
const _Fact *f_pattern);
473 bool has_bwd_after()
const {
return is_timestamp(bwd_after_index_); }
474 bool has_bwd_before()
const {
return is_timestamp(bwd_before_index_); }
475 Timestamp get_bwd_after()
const;
476 Timestamp get_bwd_before()
const;