]> gitweb.factorcode.org Git - factor.git/blob - vm/words.cpp
vm: change code heap layout somewhat, remove unused allocation bitmap from mark_bits
[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 = false_object;
18         new_word->counter = tag_fixnum(0);
19         new_word->pic_def = false_object;
20         new_word->pic_tail_def = false_object;
21         new_word->subprimitive = false_object;
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 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 /* word-xt ( word -- start end ) */
44 void factor_vm::primitive_word_xt()
45 {
46         gc_root<word> w(dpop(),this);
47         w.untag_check(this);
48
49         if(profiling_p)
50         {
51                 dpush(allot_cell((cell)w->profiling->xt()));
52                 dpush(allot_cell((cell)w->profiling + w->profiling->size()));
53         }
54         else
55         {
56                 dpush(allot_cell((cell)w->code->xt()));
57                 dpush(allot_cell((cell)w->code + w->code->size()));
58         }
59 }
60
61 /* Allocates memory */
62 void factor_vm::update_word_xt(cell w_)
63 {
64         gc_root<word> w(w_,this);
65
66         if(profiling_p)
67         {
68                 if(!w->profiling)
69                 {
70                         /* Note: can't do w->profiling = ... since if LHS
71                         evaluates before RHS, since in that case if RHS does a
72                         GC, we will have an invalid pointer on the LHS */
73                         code_block *profiling = compile_profiling_stub(w.value());
74                         w->profiling = profiling;
75                 }
76
77                 w->xt = w->profiling->xt();
78         }
79         else
80                 w->xt = w->code->xt();
81 }
82
83 void factor_vm::primitive_optimized_p()
84 {
85         word *w = untag_check<word>(dpeek());
86         drepl(tag_boolean(w->code->optimized_p()));
87 }
88
89 void factor_vm::primitive_wrapper()
90 {
91         wrapper *new_wrapper = allot<wrapper>(sizeof(wrapper));
92         new_wrapper->object = dpeek();
93         drepl(tag<wrapper>(new_wrapper));
94 }
95
96 }