replicode
hlp_overlay.h
Go to the documentation of this file.
1 // hlp_overlay.h
2 //
3 // Author: Eric Nivel
4 //
5 // BSD license:
6 // Copyright (c) 2010, Eric Nivel
7 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are met:
10 //
11 // - Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // - Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 // - Neither the name of Eric Nivel nor the
17 // names of their contributors may be used to endorse or promote products
18 // derived from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
24 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef hlp_overlay_h
32 #define hlp_overlay_h
33 
34 #include "overlay.h"
35 #include "binding_map.h"
36 
37 
38 namespace r_exec {
39 
40 class HLPContext;
41 
42 // HLP: high-level patterns.
43 class HLPOverlay:
44  public Overlay {
45  friend class HLPContext;
46 protected:
48 
50 
51  bool evaluate_guards(uint16_t guard_set_iptr_index);
52  bool evaluate_fwd_guards();
53  bool evaluate(uint16_t index);
54 
55  bool check_fwd_timings();
56 
57  bool scan_bwd_guards();
58  bool scan_location(uint16_t index);
59  bool scan_variable(uint16_t index);
60 
61  void store_evidence(_Fact *evidence, bool prediction, bool simulation); // stores both actual and non-simulated predicted evidences.
62 
63  HLPOverlay(Controller *c, HLPBindingMap *bindings);
64 public:
65  static bool EvaluateBWDGuards(Controller *c, HLPBindingMap *bindings); // updates the bindings.
66  static bool CheckFWDTimings(Controller *c, HLPBindingMap *bindings); // updates the bindings.
67  static bool ScanBWDGuards(Controller *c, HLPBindingMap *bindings); // does not update the bindings.
68 
69  HLPOverlay(Controller *c, const HLPBindingMap *bindings, bool load_code);
70  virtual ~HLPOverlay();
71 
73  return bindings;
74  }
75 
76  Atom *get_value_code(uint16_t id) const;
77  uint16_t get_value_code_size(uint16_t id) const;
78 
79  Code *get_unpacked_object() const;
80 
81  bool evaluate_bwd_guards();
82 };
83 }
84 
85 
86 #endif
P< HLPBindingMap > bindings
Definition: hlp_overlay.h:47
HLPOverlay(Controller *c, HLPBindingMap *bindings)
Definition: hlp_overlay.cpp:57
Atom * get_value_code(uint16_t id) const
Definition: hlp_overlay.cpp:68
Definition: factory.h:98
Code * get_unpacked_object() const
Definition: hlp_overlay.cpp:209
HLPBindingMap * get_bindings() const
Definition: hlp_overlay.h:72
static bool EvaluateBWDGuards(Controller *c, HLPBindingMap *bindings)
Definition: hlp_overlay.cpp:39
void load_code()
Definition: overlay.cpp:63
Definition: hlp_overlay.h:43
bool evaluate_guards(uint16_t guard_set_iptr_index)
Definition: hlp_overlay.cpp:78
static bool ScanBWDGuards(Controller *c, HLPBindingMap *bindings)
Definition: hlp_overlay.cpp:51
Definition: overlay.h:116
Definition: _context.cpp:34
r_code::list< P< _Fact > > patterns
Definition: hlp_overlay.h:49
bool scan_bwd_guards()
Definition: hlp_overlay.cpp:141
Definition: base.h:47
uint16_t get_value_code_size(uint16_t id) const
Definition: hlp_overlay.cpp:73
Definition: binding_map.h:252
bool evaluate_bwd_guards()
Definition: hlp_overlay.cpp:95
bool scan_variable(uint16_t index)
Definition: hlp_overlay.cpp:190
Definition: hlp_context.h:42
virtual ~HLPOverlay()
Definition: hlp_overlay.cpp:65
Definition: atom.h:45
bool check_fwd_timings()
Definition: hlp_overlay.cpp:107
void store_evidence(_Fact *evidence, bool prediction, bool simulation)
Definition: hlp_overlay.cpp:214
bool evaluate(uint16_t index)
Definition: hlp_overlay.cpp:100
bool scan_location(uint16_t index)
Definition: hlp_overlay.cpp:163
Definition: list.h:42
Definition: object.h:172
Definition: overlay.h:50
bool evaluate_fwd_guards()
Definition: hlp_overlay.cpp:90
static bool CheckFWDTimings(Controller *c, HLPBindingMap *bindings)
Definition: hlp_overlay.cpp:45