replicode
hlp_context.h
Go to the documentation of this file.
1 // hlp_context.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_context_h
32 #define hlp_context_h
33 
34 #include "../r_code/object.h"
35 
36 #include "_context.h"
37 #include "hlp_overlay.h"
38 
39 
40 namespace r_exec {
41 
43  public _Context {
44 public:
45  HLPContext();
46  HLPContext(Atom *code, uint16_t index, HLPOverlay *const overlay, Data data = STEM);
47 
48  HLPContext operator *() const;
49 
50  HLPContext &operator =(const HLPContext &c) {
51 
52  code = c.code;
53  index = c.index;
54  return *this;
55  }
56 
57  Atom &operator [](uint16_t i) const {
58  return code[index + i];
59  }
60 
61  bool operator ==(const HLPContext &c) const;
62  bool operator !=(const HLPContext &c) const;
63 
64  HLPContext getChild(uint16_t index) const {
65 
66  return HLPContext(code, this->index + index, (HLPOverlay *)overlay);
67  }
68 
69  bool evaluate(uint16_t &result_index) const; // index is set to the index of the result, undefined in case of failure.
70  bool evaluate_no_dereference(uint16_t &result_index) const;
71 
72 // __Context implementation.
73  _Context *assign(const _Context *c) {
74 
75  HLPContext *_c = new HLPContext(*(HLPContext *)c);
76  return _c;
77  }
78 
79  bool equal(const _Context *c) const {
80  return *this == *(HLPContext *)c;
81  }
82 
83  Atom &get_atom(uint16_t i) const {
84  return this->operator [](i);
85  }
86 
87  uint16_t get_object_code_size() const;
88 
89  uint16_t getChildrenCount() const {
90 
91  return code[index].getAtomCount();
92  }
93  _Context *_getChild(uint16_t index) const {
94 
95  HLPContext *_c = new HLPContext(getChild(index));
96  return _c;
97  }
98 
99  _Context *dereference() const {
100 
101  HLPContext *_c = new HLPContext(**this);
102  return _c;
103  }
104 };
105 }
106 
107 
108 #endif
Definition: hlp_overlay.h:43
Definition: _context.h:45
#define dll_export
Definition: dll.h:44
Definition: _context.cpp:34
_Context * dereference() const
Definition: hlp_context.h:99
uint8_t getAtomCount() const
Definition: atom.cpp:399
Atom * code
Definition: _context.h:48
Definition: hlp_context.h:42
Atom & get_atom(uint16_t i) const
Definition: hlp_context.h:83
bool equal(const _Context *c) const
Definition: hlp_context.h:79
Data
Definition: _context.h:51
Definition: atom.h:45
uint16_t index
Definition: _context.h:49
_Context * _getChild(uint16_t index) const
Definition: hlp_context.h:93
HLPContext getChild(uint16_t index) const
Definition: hlp_context.h:64
_Context * assign(const _Context *c)
Definition: hlp_context.h:73
uint16_t getChildrenCount() const
Definition: hlp_context.h:89