Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 442 lines (366 sloc) 11.663 kb
7274aff Porting VM to C++
Slava Pestov authored
1 #include "master.hpp"
2
7f48eb2 Use C++ namespaces
Slava Pestov authored
3 namespace factor
4 {
5
7274aff Porting VM to C++
Slava Pestov authored
6 /* Simple non-optimizing compiler.
7
8 This is one of the two compilers implementing Factor; the second one is written
363bdf8 vm: minor fixes after code review
Slava Pestov authored
9 in Factor and performs advanced optimizations. See basis/compiler/compiler.factor.
7274aff Porting VM to C++
Slava Pestov authored
10
11 The non-optimizing compiler compiles a quotation at a time by concatenating
12 machine code chunks; prolog, epilog, call word, jump to word, etc. These machine
363bdf8 vm: minor fixes after code review
Slava Pestov authored
13 code chunks are generated from Factor code in basis/cpu/.../bootstrap.factor.
7274aff Porting VM to C++
Slava Pestov authored
14
15 Calls to words and constant quotations (referenced by conditionals and dips)
16 are direct jumps to machine code blocks. Literals are also referenced directly
17 without going through the literal table.
18
19 It actually does do a little bit of very simple optimization:
20
21 1) Tail call optimization.
22
23 2) If a quotation is determined to not call any other words (except for a few
24 special words which are open-coded, see below), then no prolog/epilog is
25 generated.
26
27 3) When in tail position and immediately preceded by literal arguments, the
28 'if' is generated inline, instead of as a call to the 'if' word.
29
30 4) When preceded by a quotation, calls to 'dip', '2dip' and '3dip' are
31 open-coded as retain stack manipulation surrounding a subroutine call.
32
33 5) Sub-primitives are primitive words which are implemented in assembly and not
34 in the VM. They are open-coded and no subroutine call is generated. This
35 includes stack shufflers, some fixnum arithmetic words, and words such as tag,
36 slot and eq?. A primitive call is relatively expensive (two subroutine calls)
37 so this results in a big speedup for relatively little effort. */
38
19835ab vm: non-optimizing compiler now compiles word definition quotations with...
Slava Pestov authored
39 void quotation_jit::init_quotation(cell quot)
40 {
41 elements = untag<quotation>(quot)->array;
42 }
43
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
44 bool quotation_jit::primitive_call_p(cell i, cell length)
7274aff Porting VM to C++
Slava Pestov authored
45 {
8800443 vm: remove primitive table, non-optimizing compiler now looks up primiti...
Slava Pestov authored
46 return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->special_objects[JIT_PRIMITIVE_WORD];
7274aff Porting VM to C++
Slava Pestov authored
47 }
48
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
49 bool quotation_jit::fast_if_p(cell i, cell length)
7274aff Porting VM to C++
Slava Pestov authored
50 {
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
51 return (i + 3) == length
7c0a59f The great type renaming
Slava Pestov authored
52 && tagged<object>(array_nth(elements.untagged(),i + 1)).type_p(QUOTATION_TYPE)
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
53 && array_nth(elements.untagged(),i + 2) == parent->special_objects[JIT_IF_WORD];
7274aff Porting VM to C++
Slava Pestov authored
54 }
55
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
56 bool quotation_jit::fast_dip_p(cell i, cell length)
7274aff Porting VM to C++
Slava Pestov authored
57 {
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
58 return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->special_objects[JIT_DIP_WORD];
7274aff Porting VM to C++
Slava Pestov authored
59 }
60
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
61 bool quotation_jit::fast_2dip_p(cell i, cell length)
7274aff Porting VM to C++
Slava Pestov authored
62 {
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
63 return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->special_objects[JIT_2DIP_WORD];
7274aff Porting VM to C++
Slava Pestov authored
64 }
65
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
66 bool quotation_jit::fast_3dip_p(cell i, cell length)
7274aff Porting VM to C++
Slava Pestov authored
67 {
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
68 return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->special_objects[JIT_3DIP_WORD];
7274aff Porting VM to C++
Slava Pestov authored
69 }
70
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
71 bool quotation_jit::mega_lookup_p(cell i, cell length)
7274aff Porting VM to C++
Slava Pestov authored
72 {
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
73 return (i + 4) <= length
7c0a59f The great type renaming
Slava Pestov authored
74 && tagged<object>(array_nth(elements.untagged(),i + 1)).type_p(FIXNUM_TYPE)
75 && tagged<object>(array_nth(elements.untagged(),i + 2)).type_p(ARRAY_TYPE)
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
76 && array_nth(elements.untagged(),i + 3) == parent->special_objects[MEGA_LOOKUP_WORD];
7274aff Porting VM to C++
Slava Pestov authored
77 }
78
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
79 bool quotation_jit::declare_p(cell i, cell length)
80 {
81 return (i + 2) <= length
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
82 && array_nth(elements.untagged(),i + 1) == parent->special_objects[JIT_DECLARE_WORD];
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
83 }
84
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
85 bool quotation_jit::special_subprimitive_p(cell obj)
31a260b vm: big overhaul of non-optimizing compiler
Slava Pestov authored
86 {
9c7731e @jckarter vm: suppress signal-handler stack frame generation
jckarter authored
87 // Subprimitives should be flagged with whether they require a stack frame.
88 // See #295.
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
89 return obj == parent->special_objects[SIGNAL_HANDLER_WORD]
90 || obj == parent->special_objects[LEAF_SIGNAL_HANDLER_WORD]
91 || obj == parent->special_objects[FFI_SIGNAL_HANDLER_WORD]
92 || obj == parent->special_objects[FFI_LEAF_SIGNAL_HANDLER_WORD];
93 }
94
95 bool quotation_jit::word_stack_frame_p(cell obj)
96 {
97 return (to_boolean(untag<word>(obj)->subprimitive) && !special_subprimitive_p(obj))
31a260b vm: big overhaul of non-optimizing compiler
Slava Pestov authored
98 || obj == parent->special_objects[JIT_PRIMITIVE_WORD];
99 }
100
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
101 bool quotation_jit::word_safepoint_p(cell obj)
102 {
2c2791a @jckarter vm: clean up baroque jit safepoint logic
jckarter authored
103 return !special_subprimitive_p(obj);
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
104 }
105
106 bool quotation_jit::safepoint_p()
7274aff Porting VM to C++
Slava Pestov authored
107 {
7c0a59f The great type renaming
Slava Pestov authored
108 fixnum length = array_capacity(elements.untagged());
7274aff Porting VM to C++
Slava Pestov authored
109
31a260b vm: big overhaul of non-optimizing compiler
Slava Pestov authored
110 for(fixnum i = 0; i < length; i++)
7274aff Porting VM to C++
Slava Pestov authored
111 {
7c0a59f The great type renaming
Slava Pestov authored
112 cell obj = array_nth(elements.untagged(),i);
113 switch(tagged<object>(obj).type())
7274aff Porting VM to C++
Slava Pestov authored
114 {
1857f90 VM: use better abstractions for tagged pointers, eliminate get()/set() s...
Slava Pestov authored
115 case WORD_TYPE:
2c2791a @jckarter vm: clean up baroque jit safepoint logic
jckarter authored
116 if(!word_safepoint_p(obj))
117 return false;
1857f90 VM: use better abstractions for tagged pointers, eliminate get()/set() s...
Slava Pestov authored
118 break;
119 default:
120 break;
7274aff Porting VM to C++
Slava Pestov authored
121 }
122 }
123
2c2791a @jckarter vm: clean up baroque jit safepoint logic
jckarter authored
124 return true;
7274aff Porting VM to C++
Slava Pestov authored
125 }
126
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
127 bool quotation_jit::stack_frame_p()
128 {
129 fixnum length = array_capacity(elements.untagged());
130
131 for(fixnum i = 0; i < length; i++)
132 {
133 cell obj = array_nth(elements.untagged(),i);
134 if (tagged<object>(obj).type() == WORD_TYPE && !word_safepoint_p(obj))
135 return false;
136 }
137
138 return true;
139 }
140
2058b31 vm: minor tweaks which reduce image size by ~300kb
Slava Pestov authored
141 bool quotation_jit::trivial_quotation_p(array *elements)
142 {
143 return array_capacity(elements) == 1 && tagged<object>(array_nth(elements,0)).type_p(WORD_TYPE);
144 }
145
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
146 void quotation_jit::emit_prolog(bool safepoint, bool stack_frame)
147 {
148 if(safepoint) emit(parent->special_objects[JIT_SAFEPOINT]);
149 if(stack_frame) emit(parent->special_objects[JIT_PROLOG]);
150 }
151
152 void quotation_jit::emit_epilog(bool safepoint, bool stack_frame)
7ac94bd @jckarter vm: always generate safepoints in jit
jckarter authored
153 {
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
154 if(safepoint) emit(parent->special_objects[JIT_SAFEPOINT]);
7ac94bd @jckarter vm: always generate safepoints in jit
jckarter authored
155 if(stack_frame) emit(parent->special_objects[JIT_EPILOG]);
156 }
157
2058b31 vm: minor tweaks which reduce image size by ~300kb
Slava Pestov authored
158 void quotation_jit::emit_quot(cell quot_)
159 {
b341527 vm: rename gc_root to data_root, add code_root to fix a problem where co...
Slava Pestov authored
160 data_root<quotation> quot(quot_,parent);
2058b31 vm: minor tweaks which reduce image size by ~300kb
Slava Pestov authored
161
6ee56ca vm: use iostreams instead of printf for debug messages, clean up a few t...
Slava Pestov authored
162 array *elements = untag<array>(quot->array);
2058b31 vm: minor tweaks which reduce image size by ~300kb
Slava Pestov authored
163
164 /* If the quotation consists of a single word, compile a direct call
165 to the word. */
166 if(trivial_quotation_p(elements))
167 literal(array_nth(elements,0));
168 else
169 {
19835ab vm: non-optimizing compiler now compiles word definition quotations with...
Slava Pestov authored
170 if(compiling) parent->jit_compile_quot(quot.value(),relocate);
2058b31 vm: minor tweaks which reduce image size by ~300kb
Slava Pestov authored
171 literal(quot.value());
172 }
173 }
174
7274aff Porting VM to C++
Slava Pestov authored
175 /* Allocates memory */
d44957b Cleaning up VM code
Slava Pestov authored
176 void quotation_jit::iterate_quotation()
7274aff Porting VM to C++
Slava Pestov authored
177 {
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
178 bool safepoint = safepoint_p();
d44957b Cleaning up VM code
Slava Pestov authored
179 bool stack_frame = stack_frame_p();
7274aff Porting VM to C++
Slava Pestov authored
180
d44957b Cleaning up VM code
Slava Pestov authored
181 set_position(0);
7274aff Porting VM to C++
Slava Pestov authored
182
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
183 emit_prolog(safepoint, stack_frame);
7274aff Porting VM to C++
Slava Pestov authored
184
7c0a59f The great type renaming
Slava Pestov authored
185 cell i;
186 cell length = array_capacity(elements.untagged());
7274aff Porting VM to C++
Slava Pestov authored
187 bool tail_call = false;
188
189 for(i = 0; i < length; i++)
190 {
d44957b Cleaning up VM code
Slava Pestov authored
191 set_position(i);
7274aff Porting VM to C++
Slava Pestov authored
192
b341527 vm: rename gc_root to data_root, add code_root to fix a problem where co...
Slava Pestov authored
193 data_root<object> obj(array_nth(elements.untagged(),i),parent);
7274aff Porting VM to C++
Slava Pestov authored
194
d44957b Cleaning up VM code
Slava Pestov authored
195 switch(obj.type())
7274aff Porting VM to C++
Slava Pestov authored
196 {
197 case WORD_TYPE:
31a260b vm: big overhaul of non-optimizing compiler
Slava Pestov authored
198 /* Sub-primitives */
ca7bca6 Big cleanup of literal table and relocation-related code
Slava Pestov authored
199 if(to_boolean(obj.as<word>()->subprimitive))
7274aff Porting VM to C++
Slava Pestov authored
200 {
31a260b vm: big overhaul of non-optimizing compiler
Slava Pestov authored
201 tail_call = emit_subprimitive(obj.value(), /* word */
202 i == length - 1, /* tail_call_p */
203 stack_frame); /* stack_frame_p */
7274aff Porting VM to C++
Slava Pestov authored
204 }
205 /* Everything else */
31a260b vm: big overhaul of non-optimizing compiler
Slava Pestov authored
206 else if(i == length - 1)
7274aff Porting VM to C++
Slava Pestov authored
207 {
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
208 emit_epilog(safepoint, stack_frame);
31a260b vm: big overhaul of non-optimizing compiler
Slava Pestov authored
209 tail_call = true;
210 word_jump(obj.value());
7274aff Porting VM to C++
Slava Pestov authored
211 }
31a260b vm: big overhaul of non-optimizing compiler
Slava Pestov authored
212 else
213 word_call(obj.value());
7274aff Porting VM to C++
Slava Pestov authored
214 break;
215 case WRAPPER_TYPE:
7c0a59f The great type renaming
Slava Pestov authored
216 push(obj.as<wrapper>()->object);
7274aff Porting VM to C++
Slava Pestov authored
217 break;
8800443 vm: remove primitive table, non-optimizing compiler now looks up primiti...
Slava Pestov authored
218 case BYTE_ARRAY_TYPE:
7274aff Porting VM to C++
Slava Pestov authored
219 /* Primitive calls */
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
220 if(primitive_call_p(i,length))
7274aff Porting VM to C++
Slava Pestov authored
221 {
80e64b8 Store VM object in a register on x86-64
Slava Pestov authored
222 /* On x86-64 and PowerPC, the VM pointer is stored in
223 a register; on other platforms, the RT_VM relocation
224 is used and it needs an offset parameter */
225 #ifdef FACTOR_X86
912b126 Split literal table into literal and parameter tables, literal table is ...
Slava Pestov authored
226 parameter(tag_fixnum(0));
d0c1c6b PowerPC: fix set-callstack primitive and start updating optimizing compi...
Slava Pestov authored
227 #endif
912b126 Split literal table into literal and parameter tables, literal table is ...
Slava Pestov authored
228 parameter(obj.value());
8800443 vm: remove primitive table, non-optimizing compiler now looks up primiti...
Slava Pestov authored
229 parameter(false_object);
1ed2bc6 @erikcharlebois 32 and 64 bit Linux PPC support
erikcharlebois authored
230 #ifdef FACTOR_PPC_TOC
231 parameter(obj.value());
232 parameter(false_object);
233 #endif
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
234 emit(parent->special_objects[JIT_PRIMITIVE]);
7274aff Porting VM to C++
Slava Pestov authored
235
236 i++;
237 }
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
238 else
239 push(obj.value());
240 break;
7274aff Porting VM to C++
Slava Pestov authored
241 case QUOTATION_TYPE:
242 /* 'if' preceeded by two literal quotations (this is why if and ? are
243 mutually recursive in the library, but both still work) */
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
244 if(fast_if_p(i,length))
7274aff Porting VM to C++
Slava Pestov authored
245 {
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
246 emit_epilog(safepoint, stack_frame);
d44957b Cleaning up VM code
Slava Pestov authored
247 tail_call = true;
7274aff Porting VM to C++
Slava Pestov authored
248
2058b31 vm: minor tweaks which reduce image size by ~300kb
Slava Pestov authored
249 emit_quot(array_nth(elements.untagged(),i));
250 emit_quot(array_nth(elements.untagged(),i + 1));
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
251 emit(parent->special_objects[JIT_IF]);
7274aff Porting VM to C++
Slava Pestov authored
252
253 i += 2;
254 }
255 /* dip */
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
256 else if(fast_dip_p(i,length))
7274aff Porting VM to C++
Slava Pestov authored
257 {
2058b31 vm: minor tweaks which reduce image size by ~300kb
Slava Pestov authored
258 emit_quot(obj.value());
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
259 emit(parent->special_objects[JIT_DIP]);
7274aff Porting VM to C++
Slava Pestov authored
260 i++;
261 }
262 /* 2dip */
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
263 else if(fast_2dip_p(i,length))
7274aff Porting VM to C++
Slava Pestov authored
264 {
2058b31 vm: minor tweaks which reduce image size by ~300kb
Slava Pestov authored
265 emit_quot(obj.value());
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
266 emit(parent->special_objects[JIT_2DIP]);
7274aff Porting VM to C++
Slava Pestov authored
267 i++;
268 }
269 /* 3dip */
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
270 else if(fast_3dip_p(i,length))
7274aff Porting VM to C++
Slava Pestov authored
271 {
2058b31 vm: minor tweaks which reduce image size by ~300kb
Slava Pestov authored
272 emit_quot(obj.value());
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
273 emit(parent->special_objects[JIT_3DIP]);
7274aff Porting VM to C++
Slava Pestov authored
274 i++;
275 }
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
276 else
277 push(obj.value());
278 break;
7274aff Porting VM to C++
Slava Pestov authored
279 case ARRAY_TYPE:
280 /* Method dispatch */
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
281 if(mega_lookup_p(i,length))
7274aff Porting VM to C++
Slava Pestov authored
282 {
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
283 emit_epilog(safepoint, stack_frame);
31a260b vm: big overhaul of non-optimizing compiler
Slava Pestov authored
284 tail_call = true;
d44957b Cleaning up VM code
Slava Pestov authored
285 emit_mega_cache_lookup(
7c0a59f The great type renaming
Slava Pestov authored
286 array_nth(elements.untagged(),i),
287 untag_fixnum(array_nth(elements.untagged(),i + 1)),
288 array_nth(elements.untagged(),i + 2));
7274aff Porting VM to C++
Slava Pestov authored
289 i += 3;
290 }
0a60f18 vm: ignore 'declare' calls in non-optimizing compiler
Slava Pestov authored
291 /* Non-optimizing compiler ignores declarations */
292 else if(declare_p(i,length))
293 i++;
294 else
295 push(obj.value());
296 break;
7274aff Porting VM to C++
Slava Pestov authored
297 default:
d44957b Cleaning up VM code
Slava Pestov authored
298 push(obj.value());
7274aff Porting VM to C++
Slava Pestov authored
299 break;
300 }
301 }
302
303 if(!tail_call)
304 {
d44957b Cleaning up VM code
Slava Pestov authored
305 set_position(length);
7274aff Porting VM to C++
Slava Pestov authored
306
701dc2b @jckarter vm: emit safepoints before VM compiler prologs
jckarter authored
307 emit_epilog(safepoint, stack_frame);
6c561b5 vm: rename userenv to special_objects
Slava Pestov authored
308 emit(parent->special_objects[JIT_RETURN]);
7274aff Porting VM to C++
Slava Pestov authored
309 }
310 }
311
34a1257 @jckarter vm: factor out word_stack_frame_size
jckarter authored
312 cell quotation_jit::word_stack_frame_size(cell obj)
313 {
314 if (special_subprimitive_p(obj))
315 return SIGNAL_HANDLER_STACK_FRAME_SIZE;
316 else
317 return JIT_FRAME_SIZE;
318 }
319
7274aff Porting VM to C++
Slava Pestov authored
320 /* Allocates memory */
19835ab vm: non-optimizing compiler now compiles word definition quotations with...
Slava Pestov authored
321 code_block *factor_vm::jit_compile_quot(cell owner_, cell quot_, bool relocating)
7274aff Porting VM to C++
Slava Pestov authored
322 {
0ac2a92 vm: new implementation of modify-code-heap that doesn't use literal tabl...
Slava Pestov authored
323 data_root<object> owner(owner_,this);
b341527 vm: rename gc_root to data_root, add code_root to fix a problem where co...
Slava Pestov authored
324 data_root<quotation> quot(quot_,this);
7274aff Porting VM to C++
Slava Pestov authored
325
19835ab vm: non-optimizing compiler now compiles word definition quotations with...
Slava Pestov authored
326 quotation_jit compiler(owner.value(),true,relocating,this);
327 compiler.init_quotation(quot.value());
7c0a59f The great type renaming
Slava Pestov authored
328 compiler.iterate_quotation();
7274aff Porting VM to C++
Slava Pestov authored
329
34a1257 @jckarter vm: factor out word_stack_frame_size
jckarter authored
330 cell frame_size = compiler.word_stack_frame_size(owner_);
8981fcc @jckarter vm: frame size for signal handler code blocks
jckarter authored
331
332 code_block *compiled = compiler.to_code_block(frame_size);
7274aff Porting VM to C++
Slava Pestov authored
333
8a25e83 vm: Clean up more code duplication and rename a few methods
Slava Pestov authored
334 if(relocating) initialize_code_block(compiled);
19835ab vm: non-optimizing compiler now compiles word definition quotations with...
Slava Pestov authored
335
336 return compiled;
337 }
338
339 void factor_vm::jit_compile_quot(cell quot_, bool relocating)
340 {
341 data_root<quotation> quot(quot_,this);
7231150 vm: ensure that non-optimized calls to generic words which have not yet ...
Slava Pestov authored
342 if(!quot_compiled_p(quot.untagged()))
d2baa6d vm: move c_to_factor, lazy_jit_compile_impl, throw_impl, set_callstack a...
Slava Pestov authored
343 {
344 code_block *compiled = jit_compile_quot(quot.value(),quot.value(),relocating);
5b43301 @jckarter vm: strip out call-counting profiler
jckarter authored
345 quot.untagged()->entry_point = compiled->entry_point();
d2baa6d vm: move c_to_factor, lazy_jit_compile_impl, throw_impl, set_callstack a...
Slava Pestov authored
346 }
7274aff Porting VM to C++
Slava Pestov authored
347 }
348
6326652 @phildawes Moved PRIMITIVE and PRIMITIVE_FORWARDs to primitives.[ch]pp
phildawes authored
349 void factor_vm::primitive_jit_compile()
7274aff Porting VM to C++
Slava Pestov authored
350 {
a942e2c vm: eliminating register variables work in progress. Works on x86-32 wit...
Slava Pestov authored
351 jit_compile_quot(ctx->pop(),true);
7274aff Porting VM to C++
Slava Pestov authored
352 }
353
5b43301 @jckarter vm: strip out call-counting profiler
jckarter authored
354 void *factor_vm::lazy_jit_compile_entry_point()
d2baa6d vm: move c_to_factor, lazy_jit_compile_impl, throw_impl, set_callstack a...
Slava Pestov authored
355 {
5b43301 @jckarter vm: strip out call-counting profiler
jckarter authored
356 return untag<word>(special_objects[LAZY_JIT_COMPILE_WORD])->entry_point;
d2baa6d vm: move c_to_factor, lazy_jit_compile_impl, throw_impl, set_callstack a...
Slava Pestov authored
357 }
358
7274aff Porting VM to C++
Slava Pestov authored
359 /* push a new quotation on the stack */
6326652 @phildawes Moved PRIMITIVE and PRIMITIVE_FORWARDs to primitives.[ch]pp
phildawes authored
360 void factor_vm::primitive_array_to_quotation()
7274aff Porting VM to C++
Slava Pestov authored
361 {
7c0a59f The great type renaming
Slava Pestov authored
362 quotation *quot = allot<quotation>(sizeof(quotation));
d2baa6d vm: move c_to_factor, lazy_jit_compile_impl, throw_impl, set_callstack a...
Slava Pestov authored
363
a942e2c vm: eliminating register variables work in progress. Works on x86-32 wit...
Slava Pestov authored
364 quot->array = ctx->peek();
f0a1a3c vm: rename F to false_object, and rename T to true_object
Slava Pestov authored
365 quot->cached_effect = false_object;
366 quot->cache_counter = false_object;
5b43301 @jckarter vm: strip out call-counting profiler
jckarter authored
367 quot->entry_point = lazy_jit_compile_entry_point();
d2baa6d vm: move c_to_factor, lazy_jit_compile_impl, throw_impl, set_callstack a...
Slava Pestov authored
368
a942e2c vm: eliminating register variables work in progress. Works on x86-32 wit...
Slava Pestov authored
369 ctx->replace(tag<quotation>(quot));
7274aff Porting VM to C++
Slava Pestov authored
370 }
371
0165daf Stop wearing monocle and use the term "entry point" instead of "XT" thro...
Slava Pestov authored
372 void factor_vm::primitive_quotation_code()
7274aff Porting VM to C++
Slava Pestov authored
373 {
0165daf Stop wearing monocle and use the term "entry point" instead of "XT" thro...
Slava Pestov authored
374 quotation *quot = untag_check<quotation>(ctx->pop());
375
5b43301 @jckarter vm: strip out call-counting profiler
jckarter authored
376 ctx->push(from_unsigned_cell((cell)quot->entry_point));
377 ctx->push(from_unsigned_cell((cell)quot->code() + quot->code()->size()));
7274aff Porting VM to C++
Slava Pestov authored
378 }
379
d44957b Cleaning up VM code
Slava Pestov authored
380 /* Allocates memory */
1c5329c @phildawes renamed factorvm to factor_vm
phildawes authored
381 fixnum factor_vm::quot_code_offset_to_scan(cell quot_, cell offset)
d44957b Cleaning up VM code
Slava Pestov authored
382 {
b341527 vm: rename gc_root to data_root, add code_root to fix a problem where co...
Slava Pestov authored
383 data_root<quotation> quot(quot_,this);
384 data_root<array> array(quot->array,this);
d44957b Cleaning up VM code
Slava Pestov authored
385
9282824 @phildawes added vm member to jit classes
phildawes authored
386 quotation_jit compiler(quot.value(),false,false,this);
19835ab vm: non-optimizing compiler now compiles word definition quotations with...
Slava Pestov authored
387 compiler.init_quotation(quot.value());
72691ca Cleanups
Slava Pestov authored
388 compiler.compute_position(offset);
389 compiler.iterate_quotation();
d44957b Cleaning up VM code
Slava Pestov authored
390
72691ca Cleanups
Slava Pestov authored
391 return compiler.get_position();
d44957b Cleaning up VM code
Slava Pestov authored
392 }
1857f90 VM: use better abstractions for tagged pointers, eliminate get()/set() s...
Slava Pestov authored
393
1453154 vm: remove VM_ASM_API
Slava Pestov authored
394 cell factor_vm::lazy_jit_compile(cell quot_)
1857f90 VM: use better abstractions for tagged pointers, eliminate get()/set() s...
Slava Pestov authored
395 {
b341527 vm: rename gc_root to data_root, add code_root to fix a problem where co...
Slava Pestov authored
396 data_root<quotation> quot(quot_,this);
711d78f vm: don't recompile lazy-jit-compile more than once
Slava Pestov authored
397
00f0066 @jckarter vm: replace assert with FACTOR_ASSERT
jckarter authored
398 FACTOR_ASSERT(!quot_compiled_p(quot.untagged()));
711d78f vm: don't recompile lazy-jit-compile more than once
Slava Pestov authored
399
400 code_block *compiled = jit_compile_quot(quot.value(),quot.value(),true);
5b43301 @jckarter vm: strip out call-counting profiler
jckarter authored
401 quot.untagged()->entry_point = compiled->entry_point();
711d78f vm: don't recompile lazy-jit-compile more than once
Slava Pestov authored
402
1857f90 VM: use better abstractions for tagged pointers, eliminate get()/set() s...
Slava Pestov authored
403 return quot.value();
404 }
7f48eb2 Use C++ namespaces
Slava Pestov authored
405
1453154 vm: remove VM_ASM_API
Slava Pestov authored
406 VM_C_API cell lazy_jit_compile(cell quot, factor_vm *parent)
fd37422 @phildawes moved quotations functions to vm
phildawes authored
407 {
1453154 vm: remove VM_ASM_API
Slava Pestov authored
408 return parent->lazy_jit_compile(quot);
fd37422 @phildawes moved quotations functions to vm
phildawes authored
409 }
410
7231150 vm: ensure that non-optimized calls to generic words which have not yet ...
Slava Pestov authored
411 bool factor_vm::quot_compiled_p(quotation *quot)
412 {
5b43301 @jckarter vm: strip out call-counting profiler
jckarter authored
413 return quot->entry_point != NULL && quot->entry_point != lazy_jit_compile_entry_point();
7231150 vm: ensure that non-optimized calls to generic words which have not yet ...
Slava Pestov authored
414 }
415
6326652 @phildawes Moved PRIMITIVE and PRIMITIVE_FORWARDs to primitives.[ch]pp
phildawes authored
416 void factor_vm::primitive_quot_compiled_p()
05146c6 Remove compiled slot from quotations since its not needed
Slava Pestov authored
417 {
a942e2c vm: eliminating register variables work in progress. Works on x86-32 wit...
Slava Pestov authored
418 tagged<quotation> quot(ctx->pop());
5374022 @phildawes vm ptr passed to untag_check
phildawes authored
419 quot.untag_check(this);
7231150 vm: ensure that non-optimized calls to generic words which have not yet ...
Slava Pestov authored
420 ctx->push(tag_boolean(quot_compiled_p(quot.untagged())));
d2baa6d vm: move c_to_factor, lazy_jit_compile_impl, throw_impl, set_callstack a...
Slava Pestov authored
421 }
422
423 cell factor_vm::find_all_quotations()
424 {
425 return instances(QUOTATION_TYPE);
426 }
427
428 void factor_vm::initialize_all_quotations()
429 {
430 data_root<array> quotations(find_all_quotations(),this);
431
432 cell length = array_capacity(quotations.untagged());
433 for(cell i = 0; i < length; i++)
434 {
435 data_root<quotation> quot(array_nth(quotations.untagged(),i),this);
5b43301 @jckarter vm: strip out call-counting profiler
jckarter authored
436 if(!quot->entry_point)
437 quot.untagged()->entry_point = lazy_jit_compile_entry_point();
d2baa6d vm: move c_to_factor, lazy_jit_compile_impl, throw_impl, set_callstack a...
Slava Pestov authored
438 }
05146c6 Remove compiled slot from quotations since its not needed
Slava Pestov authored
439 }
440
7f48eb2 Use C++ namespaces
Slava Pestov authored
441 }
Something went wrong with that request. Please try again.