-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame.h
67 lines (55 loc) · 1.75 KB
/
frame.h
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
/*
* frame.h
*
* Defines the Frame class used in the interpreter which stores information
* about the current function, instruction location, local variables and
* reference variables, as well as the operand stack.
*/
#pragma once
#include "types.h"
#include "gc/gc.h"
#include <string>
#include <map>
#include <list>
using namespace std;
typedef map<string, ValWrapper*> VarMap;
class Frame : public Collectable {
// Class representing a stack frame in interpreter execution
// and local reference names to shared ValWrappers
void follow(CollectedHeap& heap) override;
size_t getSize() override;
public:
// vector of local variable names to values (stored in ValWrapper)
VarMap vars;
// function that the frame is for
Function* func;
// operand stack
list<tagptr_t> opStack;
// index of current instruction in func's instructions list
int instructionIndex = 0;
// garbage collector
CollectedHeap* collector;
// offset to keep track of stuff
int offset = 0;
Frame(Function* func): func(func) {};
virtual ~Frame() {}
// instruction helpers
int numInstructions();
BcInstruction& getCurrInstruction();
void checkLegalInstruction();
// function value helpers
tagptr_t getConstantByIndex(int index);
Function* getFunctionByIndex(int index);
string getLocalByIndex(int index);
string getNameByIndex(int index);
string getRefByIndex(int index);
// var map helpers
tagptr_t getLocalVar(string name);
ValWrapper* getRefVar(string name);
void setLocalVar(string name, tagptr_t val);
void setRefVar(string name, tagptr_t val);
// operand stack helpers
void opStackPush(tagptr_t val);
tagptr_t opStackPeek();
tagptr_t opStackPop();
};