]> gitweb.factorcode.org Git - factor.git/blob - vm/words.cpp
Merge branch 'master' into more_aggressive_coalescing
[factor.git] / vm / words.cpp
1 #include "master.hpp"
2
3 namespace factor
4 {
5
6 word *factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_)
7 {
8         gc_root<object> vocab(vocab_,this);
9         gc_root<object> name(name_,this);
10
11         gc_root<word> new_word(allot<word>(sizeof(word)),this);
12
13         new_word->hashcode = hashcode_;
14         new_word->vocabulary = vocab.value();
15         new_word->name = name.value();
16         new_word->def = userenv[UNDEFINED_ENV];
17         new_word->props = F;
18         new_word->counter = tag_fixnum(0);
19         new_word->pic_def = F;
20         new_word->pic_tail_def = F;
21         new_word->subprimitive = F;
22         new_word->profiling = NULL;
23         new_word->code = NULL;
24
25         jit_compile_word(new_word.value(),new_word->def,true);
26         update_word_xt(new_word.value());
27
28         if(profiling_p)
29                 relocate_code_block(new_word->profiling);
30
31         return new_word.untagged();
32 }
33
34 /* (word) ( name vocabulary hashcode -- word ) */
35 inline void factor_vm::primitive_word()
36 {
37         cell hashcode = dpop();
38         cell vocab = dpop();
39         cell name = dpop();
40         dpush(tag<word>(allot_word(name,vocab,hashcode)));
41 }
42
43 PRIMITIVE_FORWARD(word)
44
45 /* word-xt ( word -- start end ) */
46 inline void factor_vm::primitive_word_xt()
47 {
48         gc_root<word> w(dpop(),this);
49         w.untag_check(this);
50
51         if(profiling_p)
52         {
53                 dpush(allot_cell((cell)w->profiling->xt()));
54                 dpush(allot_cell((cell)w->profiling + w->profiling->size));
55         }
56         else
57         {
58                 dpush(allot_cell((cell)w->code->xt()));
59                 dpush(allot_cell((cell)w->code + w->code->size));
60         }
61 }
62
63 PRIMITIVE_FORWARD(word_xt)
64
65 /* Allocates memory */
66 void factor_vm::update_word_xt(cell w_)
67 {
68         gc_root<word> w(w_,this);
69
70         if(profiling_p)
71         {
72                 if(!w->profiling)
73                 {
74                         /* Note: can't do w->profiling = ... since if LHS
75                         evaluates before RHS, since in that case if RHS does a
76                         GC, we will have an invalid pointer on the LHS */
77                         code_block *profiling = compile_profiling_stub(w.value());
78                         w->profiling = profiling;
79                 }
80
81                 w->xt = w->profiling->xt();
82         }
83         else
84                 w->xt = w->code->xt();
85 }
86
87 inline void factor_vm::primitive_optimized_p()
88 {
89         drepl(tag_boolean(word_optimized_p(untag_check<word>(dpeek()))));
90 }
91
92 PRIMITIVE_FORWARD(optimized_p)
93
94 inline void factor_vm::primitive_wrapper()
95 {
96         wrapper *new_wrapper = allot<wrapper>(sizeof(wrapper));
97         new_wrapper->object = dpeek();
98         drepl(tag<wrapper>(new_wrapper));
99 }
100
101 PRIMITIVE_FORWARD(wrapper)
102
103 }