-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm.h
63 lines (56 loc) · 1.2 KB
/
vm.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
#pragma once
#include "b_lex.h"
#include "b_object.h"
#include "b_seq.h"
#include <stddef.h>
typedef enum OpCode {
Exit,
NoOp,
PushI,
PushF,
PushN,
PushS,
Pop,
Binary,
Unary,
BuildList,
BuildDict,
BuildFunc,
Index,
SetIndex,
Call,
Ret,
Jmp,
Jz,
Jnz,
JzNoPop,
JnzNoPop,
LoadV,
SetV,
} OpCode;
typedef struct ByteCode {
OpCode head;
union {
long long i;
double f;
String *s;
size_t l;
TokenType op;
struct {
unsigned int scope, pos;
} v;
};
} ByteCode;
ByteCode ByteCode_new(OpCode head);
#define ByteCode_init(head, attr, val) \
({ \
ByteCode code = ByteCode_new(head); \
code.attr = val; \
code; \
})
void ByteCode_free(ByteCode code);
void ByteCode_print(ByteCode code);
typedef struct Seq(ByteCode) ByteCodeList;
void ByteCodeList_free(ByteCodeList list);
typedef struct Seq(Object) VMStack;
void run(ByteCodeList bytecode, size_t reserve);