replicode
_context.h
Go to the documentation of this file.
1 // _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 _context_h
32 #define _context_h
33 
34 #include "../r_code/atom.h"
35 #include "overlay.h"
36 
37 
38 using namespace r_code;
39 
40 namespace r_exec {
41 
42 // Base class for evaluation contexts.
43 // Subclasses: IPGMContext and HLPContext.
44 // _Context * wrapped in Context, the latter used by operators.
46 protected:
47  Overlay *const overlay; // the overlay where the evaluation is performed; NULL when the context is dereferenced outside the original pgm or outside the value array.
48  Atom *code; // the object's code, or the code in value array, or the view's code when the context is dereferenced from Atom::VIEW.
49  uint16_t index; // in the code;
50 
51  typedef enum { // indicates whether the context refers to:
52  STEM = 0, // - the pgm/hlp being reducing inputs;
53  REFERENCE = 1, // - a reference to another object;
54  VIEW = 2, // - a view;
55  MKS = 3, // - the mks or an object;
56  VWS = 4, // - the vws of an object;
57  VALUE_ARRAY = 5, // - code in the overlay's value array.
58  BINDING_MAP = 6, // - values of a imdl/icst.
59  UNDEFINED = 7
60  } Data;
62 
63  _Context(Atom *code, uint16_t index, Overlay *overlay, Data data): overlay(overlay), code(code), index(index), data(data) {}
64 public:
65  virtual ~_Context() {}
66  virtual _Context *assign(const _Context *c) = 0;
67 
68  virtual bool equal(const _Context *c) const = 0;
69 
70  virtual Atom &get_atom(uint16_t i) const = 0;
71 
72  virtual uint16_t get_object_code_size() const = 0;
73 
74  virtual uint16_t getChildrenCount() const = 0;
75  virtual _Context *_getChild(uint16_t index) const = 0;
76 
77  virtual _Context *dereference() const = 0;
78 
79  void commit() const {
80  overlay->commit();
81  }
82  void rollback() const {
83  overlay->rollback();
84  }
85  void patch_code(uint16_t location, Atom value) const {
86  overlay->patch_code(location, value);
87  }
88  void unpatch_code(uint16_t patch_index) const {
89  overlay->unpatch_code(patch_index);
90  }
91  uint16_t get_last_patch_index() const {
92  return overlay->get_last_patch_index();
93  }
94 
95  uint16_t setAtomicResult(Atom a) const;
96  uint16_t setTimestampResult(uint64_t t) const;
97  uint16_t setCompoundResultHead(Atom a) const;
98  uint16_t addCompoundResultPart(Atom a) const;
99 
100  void trace() const;
101 };
102 }
103 
104 
105 #endif
_Context(Atom *code, uint16_t index, Overlay *overlay, Data data)
Definition: _context.h:63
Definition: _context.h:45
Definition: overlay.h:116
#define dll_export
Definition: dll.h:44
Data data
Definition: _context.h:61
Definition: _context.cpp:34
void unpatch_code(uint16_t patch_index)
Definition: overlay.cpp:115
Definition: atom.cpp:36
Atom * code
Definition: _context.h:48
void rollback() const
Definition: _context.h:82
void commit() const
Definition: _context.h:79
void unpatch_code(uint16_t patch_index) const
Definition: _context.h:88
uint16_t get_last_patch_index() const
Definition: _context.h:91
void rollback()
Definition: overlay.cpp:80
Data
Definition: _context.h:51
Definition: atom.h:45
uint16_t index
Definition: _context.h:49
uint16_t get_last_patch_index()
Definition: overlay.cpp:110
virtual ~_Context()
Definition: _context.h:65
void commit()
Definition: overlay.cpp:98
void patch_code(uint16_t index, Atom value)
Definition: overlay.cpp:104
Overlay *const overlay
Definition: _context.h:47
void patch_code(uint16_t location, Atom value) const
Definition: _context.h:85