-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnjvm.h
121 lines (96 loc) · 2.6 KB
/
njvm.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*--- njvm.h ---*/
/* begin instructions */
#define HALT 0
#define PUSHC 1 /*pushc <n>*/
#define ADD 2
#define SUB 3
#define MUL 4
#define DIV 5
#define MOD 6
#define RDINT 7
#define WRINT 8
#define ASF 9 /*asf <n>*/
#define RSF 10
#define PUSHL 11 /*pushl <n>, wert von frame in stack*/
#define POPL 12 /*popl <n>, wert von stack in frame*/
#define EQ 13 /* == */
#define NE 14 /* != */
#define LT 15 /* < */
#define LE 16 /* <= */
#define GT 17 /* > */
#define GE 18 /* >= */
#define JMP 19 /* jmp <target> */
#define BRF 20 /* brf <target> */
#define BRT 21 /* brt <target> */
#define CALL 22 /* call <target> */
#define RET 23
#define DROP 24 /* drop <n> */
#define PUSHR 25
#define POPR 26
#define DUP 27
#define NEW 28 /* new <n> */
#define GETF 29 /* getf <n> */
#define PUTF 30 /* putf <n> */
#define NEWA 31
#define GETLA 32
#define GETFA 33
#define PUTFA 34
#define PUSHN 35
#define REFEQ 36
#define REFNE 37
#define VMCALL 38 /* vmcall <n>,<m> */
/* end instructions */
/* begin makros */
#define IMMEDIATE(x) ((x) & 0x00FFFFFF)
#define NUMBER_OF_ARGS(y) (((y) & 0x00FF0000) >> 16)
#define INDEX(z) ((z) & 0x0000FFFF)
#define SIGN_EXTEND(i) ((i) & 0x00800000 ? (i) | 0xFF000000 : (i))
#define MSB (1<<(8*sizeof(unsigned int)-1))
#define COUNT_IS_BYTES(size) (((size)&MSB)!=0)
#define COUNT_IS_OBJREFS(size) (((size)&MSB)==0)
#define COUNT_FROM_SIZE(size) ((size)& ~MSB)
#define OBJ_HAS_BYTES(objref) COUNT_IS_BYTES((objref)->size)
#define OBJ_HAS_OBJREF(objref) COUNT_IS_OBJREFS((objref)->size)
#define COUNT_FROM_OBJREF(objref) COUNT_FROM_SIZE((objref)->size)
/* end makros */
/* size of the Stack */
#define stackSize 1024
/* Objekt declaration */
typedef union{
struct object *field[1];
unsigned char byte[1];
}Data;
typedef struct object{
unsigned int vmt;
unsigned int size;
Data data;
}Object;
typedef Object *ObjRef;
typedef struct{
bool isNumber;
union{
ObjRef objRef;
int number;
}u;
}StackItem;
/* funktionen */
void printHelp(void);
void program(unsigned int *code);
void printProgram(unsigned int *code);
void push(int num, bool isNumber);
int pop(void);
Object *popObject(void);
void pushFrame(Object *object, int point);
Object *popFrame(int point);
int compare(int n1, int n2, int instruction);
void openFile(int i, int argc, char *argv[]);
void closeFile(void);
void debug(void);
Object *newStackVal(bool isObject, int size);
int getStackVal(int i);
char *getTypeOfVariable(int j);
void *getHeapAddress(int i);
Object *getf(int index);
void putf(int index, Object *objValue, Object *objRef);
void nullStackFrame(int frameP, int stackP);
void error(char *errMsg);