TorqueScript  0.2
executionscope.hpp
1 
15 #pragma once
16 
17 #include <vector>
18 #include <memory>
19 #include <unordered_map>
20 
21 #include <torquescript/storedvalue.hpp>
22 #include <torquescript/stringhelpers.hpp>
23 #include <torquescript/function.hpp>
24 #include <torquescript/stringtable.hpp>
25 #include <torquescript/codeblock.hpp>
26 #include <torquescript/stringtable.hpp>
27 #include <torquescript/interpreterconfiguration.hpp>
28 #include <torquescript/storedvaluestack.hpp>
29 #include <torquescript/consoleobject.hpp>
30 
31 namespace TorqueScript
32 {
34  {
35  LoopDescriptor(const AddressType pointer, const std::size_t size) : mInstructionPointer(pointer), mLoopSize(size)
36  {
37 
38  }
39 
40  AddressType mInstructionPointer;
41  std::size_t mLoopSize;
42  };
43 
48  {
54  ObjectInstantiationDescriptor(const std::string typeName, const std::string& name) : mName(name), mTypeName(typeName)
55  {
56 
57  }
58 
60  std::string mName;
61 
63  std::string mTypeName;
64 
66  std::vector<ObjectInstantiationDescriptor> mChildren;
67 
69  std::map<std::string, StoredValue> mFieldAssignments;
70  };
71 
73  {
74  ExecutionScopeData(Function* function) : mCurrentFunction(function)
75  {
76 
77  }
78 
79  Function* mCurrentFunction;
80 
83 
85  std::vector<ObjectInstantiationDescriptor> mObjectInstantiations;
86 
87  std::vector<LoopDescriptor> mLoopDescriptors;
88  std::map<std::size_t, StoredValue> mLocalVariables;
89  };
90 
96  {
97  public:
99 
100  void pushFrame(Function* function);
101  void popFrame();
102 
103  void pushLoop(const AddressType pointer, const std::size_t depth);
104  LoopDescriptor popLoop();
105  LoopDescriptor currentLoopDescriptor();
106 
107  bool isAwaitingParentInstantiation();
108  void pushObjectInstantiation(const std::string& typeName, const std::string& name);
109  ObjectInstantiationDescriptor popObjectInstantiation();
110  ObjectInstantiationDescriptor& currentObjectInstantiation();
111 
112  bool isLoopStackEmpty();
113  std::size_t getFrameDepth();
114 
115  Function* getCurrentFunction();
116  StoredValueStack& getStack();
117  StoredValueStack& getReturnStack();
118 
119  StoredValue* getVariable(const std::string& name);
120  StoredValue* getVariable(const std::size_t name);
121  void setVariable(const std::string& name, StoredValue variable);
122  void setVariable(const std::size_t name, StoredValue variable);
123 
126 
127  private:
128  StringTable* mStringTable;
129 
131  std::vector<ExecutionScopeData> mExecutionScopeData;
132  };
133 }
A specific scope of execution - this is used to delineate local variables primarily.
Definition: executionscope.hpp:96
const InterpreterConfiguration mConfig
The InterpreterConfiguration associated with this ExecutionScope.+.
Definition: executionscope.hpp:125
A function is callable subroutine from anywhere in the language, defined by a script....
Definition: function.hpp:40
Storage class used to keep variable values in-memory of arbitrary data types. This is the base class ...
Definition: storedvaluestack.hpp:32
Storage class used to keep variable values in-memory of arbitrary data types. The data types supporte...
Definition: storedvalue.hpp:80
A string table maintains a mapping of numeric identifiers to their raw string values....
Definition: stringtable.hpp:32
Definition: ast.hpp:28
long long int AddressType
Typedef for the signed integer type to be used when calculating addresses.
Definition: instructionsequence.hpp:28
Definition: executionscope.hpp:73
std::vector< ObjectInstantiationDescriptor > mObjectInstantiations
Awaiting root-level object instantiations.
Definition: executionscope.hpp:85
StoredValueStack mStack
The stack used for execution in this state.
Definition: executionscope.hpp:82
A structure representing overall interpreter runtime configuration. Some settings can be changed at r...
Definition: interpreterconfiguration.hpp:26
Definition: executionscope.hpp:34
Struct describing a tree of console object initializations.
Definition: executionscope.hpp:48
std::vector< ObjectInstantiationDescriptor > mChildren
All children of this object. These will not be initialized until the parent is initialized.
Definition: executionscope.hpp:66
ObjectInstantiationDescriptor(const std::string typeName, const std::string &name)
Constructs a new ObjectInstantiationDescriptor.
Definition: executionscope.hpp:54
std::map< std::string, StoredValue > mFieldAssignments
All resolved field names mapped to the values to set.
Definition: executionscope.hpp:69
std::string mName
The name to assign the new console object.
Definition: executionscope.hpp:60
std::string mTypeName
The typename to instantiate the console object as.
Definition: executionscope.hpp:63