-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmachine.h
More file actions
81 lines (64 loc) · 2.23 KB
/
Copy pathmachine.h
File metadata and controls
81 lines (64 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#include "DataStack.h"
#include "Code.h"
#include "Registers.h"
#include "Allocator.h"
#include <functional>
namespace vm
{
class UserFunction;
class Int;
class String;
class Variable;
class Machine
{
public:
Machine(void);
~Machine(void);
void Restart();
bool IsHalted();
void Clock();
DataStack stack;
Registers registers;
Code code;
std::stack<int> callstack;
// Call a script function
void Call(const std::string& fname, std::vector<Data >& args, std::vector<Data > ret);
// Register a library function
bool RegisterLibraryFunction(const std::string& name, std::function<void (Machine&)> &);
// Get a variable using scoping rules
bool GetVariable(const std::string& name, Data &);
// Store a variable using scoping rules
bool StoreVariable(const std::string& name, Data );
bool GetGlobalVariable(const std::string& name, Data &);
bool StoreGlobalVariable(const std::string& name, Data );
bool GlobalVariableExists(const std::string& name);
bool LocalVariableExists(const std::string& name);
bool GetLocalVariable(const std::string& name, Data &);
bool StoreLocalVariable(const std::string& name, Data );
public:
void DumpMachine(std::ostream&);
private:
void PushLocalScope();
void PopLocalScope();
typedef std::map<std::string, Data > variablemap_t;
typedef std::vector<variablemap_t> variablescope_t;
typedef std::map<std::string, int> scriptfuncs_t;
typedef std::map<std::string, std::function<void (Machine&)> > libfuncs_t;
// Global variables
variablemap_t global_variables;
// Local variables
variablescope_t local_variables;
// Script functions that C programs can call
scriptfuncs_t scriptfuncs;
// Library functions
libfuncs_t library;
Allocator<Int> intAllocator;
Allocator<String> stringAllocator;
Allocator<Variable> variableAllocator;
friend class Call;
friend class CallLibrary;
friend class Return;
friend class Assembler;
};
}