]> gitweb.factorcode.org Git - factor.git/blob - vm/words.cpp
xmode.rules: removing test no longer needed
[factor.git] / vm / words.cpp
1 #include "master.hpp"
2
3 namespace factor {
4
5 // Compile a word definition with the non-optimizing compiler.
6 // Allocates memory
7 void factor_vm::jit_compile_word(cell word_, cell def_, bool relocating) {
8   data_root<word> word(word_, this);
9   data_root<quotation> def(def_, this);
10
11   // Refuse to compile this word more than once, because quot_compiled_p()
12   // depends on the identity of its code block
13   if (word->entry_point &&
14       word.value() == special_objects[LAZY_JIT_COMPILE_WORD])
15     return;
16
17   code_block* compiled =
18       jit_compile_quotation(word.value(), def.value(), relocating);
19   word->entry_point = compiled->entry_point();
20
21   if (to_boolean(word->pic_def))
22     jit_compile_quotation(word->pic_def, relocating);
23   if (to_boolean(word->pic_tail_def))
24     jit_compile_quotation(word->pic_tail_def, relocating);
25 }
26
27 // Allocates memory
28 word* factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_) {
29   data_root<object> vocab(vocab_, this);
30   data_root<object> name(name_, this);
31
32   data_root<word> new_word(allot<word>(sizeof(word)), this);
33
34   new_word->hashcode = hashcode_;
35   new_word->vocabulary = vocab.value();
36   new_word->name = name.value();
37   new_word->def = special_objects[OBJ_UNDEFINED];
38   new_word->props = false_object;
39   new_word->pic_def = false_object;
40   new_word->pic_tail_def = false_object;
41   new_word->subprimitive = false_object;
42   new_word->entry_point = 0;
43
44   jit_compile_word(new_word.value(), new_word->def, true);
45
46   return new_word.untagged();
47 }
48
49 // (word) ( name vocabulary hashcode -- word )
50 // Allocates memory
51 void factor_vm::primitive_word() {
52   cell hashcode = ctx->pop();
53   cell vocab = ctx->pop();
54   cell name = ctx->pop();
55   ctx->push(tag<word>(allot_word(name, vocab, hashcode)));
56 }
57
58 // word-code ( word -- start end )
59 // Allocates memory (from_unsigned_cell allocates)
60 void factor_vm::primitive_word_code() {
61   data_root<word> w(ctx->pop(), this);
62   check_tagged(w);
63
64   ctx->push(from_unsigned_cell(w->entry_point));
65   ctx->push(from_unsigned_cell((cell)w->code() + w->code()->size()));
66 }
67
68 void factor_vm::primitive_word_optimized_p() {
69   word* w = untag_check<word>(ctx->peek());
70   cell t = w->code()->type();
71   ctx->replace(tag_boolean(t == CODE_BLOCK_OPTIMIZED));
72 }
73
74 // Allocates memory
75 void factor_vm::primitive_wrapper() {
76   wrapper* new_wrapper = allot<wrapper>(sizeof(wrapper));
77   new_wrapper->object = ctx->peek();
78   ctx->replace(tag<wrapper>(new_wrapper));
79 }
80
81 }