-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpz_generic_run.h
192 lines (179 loc) · 3.52 KB
/
pz_generic_run.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
* Plasma bytecode generic interpreter definitions
* vim: ts=4 sw=4 et
*
* Copyright (C) Plasma Team
* Distributed under the terms of the MIT license, see ../LICENSE.code
*/
#ifndef PZ_GENERIC_RUN_H
#define PZ_GENERIC_RUN_H
#include "pz.h"
#include "pz_closure.h"
#include "pz_gc.h"
#include "pz_generic_closure.h"
#include "pz_memory.h"
namespace pz {
/*
* Tokens for the token-oriented execution.
*/
enum InstructionToken {
PZT_NOP,
PZT_LOAD_IMMEDIATE_8,
PZT_LOAD_IMMEDIATE_16,
PZT_LOAD_IMMEDIATE_32,
PZT_LOAD_IMMEDIATE_64,
PZT_ZE_8_16,
PZT_ZE_8_32,
PZT_ZE_8_64,
PZT_ZE_16_32,
PZT_ZE_16_64,
PZT_ZE_32_64,
PZT_SE_8_16,
PZT_SE_8_32,
PZT_SE_8_64,
PZT_SE_16_32,
PZT_SE_16_64,
PZT_SE_32_64,
PZT_TRUNC_64_32,
PZT_TRUNC_64_16,
PZT_TRUNC_64_8,
PZT_TRUNC_32_16,
PZT_TRUNC_32_8,
PZT_TRUNC_16_8,
PZT_ADD_8,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_STORE_32,
PZT_STORE_64,
PZT_GET_ENV,
PZT_END, // Not part of PZ format.
PZT_CCALL, // Not part of PZ format.
PZT_CCALL_ALLOC, // Not part of PZ format.
PZT_CCALL_SPECIAL, // Not part of PZ format.
PZT_LAST_TOKEN = PZT_CCALL_ALLOC,
#ifdef PZ_DEV
PZT_INVALID_TOKEN = 0xF0,
#endif
};
union StackValue {
uint8_t u8;
int8_t s8;
uint16_t u16;
int16_t s16;
uint32_t u32;
int32_t s32;
uint64_t u64;
int64_t s64;
uintptr_t uptr;
intptr_t sptr;
void * ptr;
};
#define RETURN_STACK_SIZE 2048*4
#define EXPR_STACK_SIZE 4096*4
struct Context final : public AbstractGCTracer {
uint8_t * ip;
void * env;
Memory<uint8_t*[RETURN_STACK_SIZE]> return_stack;
unsigned rsp;
Memory<StackValue[EXPR_STACK_SIZE]> expr_stack;
unsigned esp;
Context(GCCapability & gc);
~Context();
bool allocate();
bool release(bool fast);
void do_trace(HeapMarkState * state) const override;
};
int
generic_main_loop(Context &context,
Heap *heap,
Closure *closure,
PZ &pz);
} // namespace pz
#endif // ! PZ_GENERIC_RUN_H