]> gitweb.factorcode.org Git - factor.git/blob - vm/words.cpp
Merge branch 'simd-cleanup' of git://factorcode.org/git/factor into simd-cleanup
[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         data_root<object> vocab(vocab_,this);
9         data_root<object> name(name_,this);
10
11         data_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 = special_objects[OBJ_UNDEFINED];
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         if(profiling_p)
27         {
28                 code_block *profiling_block = compile_profiling_stub(new_word.value());
29                 new_word->profiling = profiling_block;
30                 initialize_code_block(new_word->profiling);
31         }
32
33         update_word_xt(new_word.untagged());
34
35         return new_word.untagged();
36 }
37
38 /* (word) ( name vocabulary hashcode -- word ) */
39 void factor_vm::primitive_word()
40 {
41         cell hashcode = dpop();
42         cell vocab = dpop();
43         cell name = dpop();
44         dpush(tag<word>(allot_word(name,vocab,hashcode)));
45 }
46
47 /* word-xt ( word -- start end ) */
48 void factor_vm::primitive_word_xt()
49 {
50         data_root<word> w(dpop(),this);
51         w.untag_check(this);
52
53         if(profiling_p)
54         {
55                 dpush(allot_cell((cell)w->profiling->xt()));
56                 dpush(allot_cell((cell)w->profiling + w->profiling->size()));
57         }
58         else
59         {
60                 dpush(allot_cell((cell)w->code->xt()));
61                 dpush(allot_cell((cell)w->code + w->code->size()));
62         }
63 }
64
65 void factor_vm::update_word_xt(word *w)
66 {
67         if(profiling_p && w->profiling)
68                 w->xt = w->profiling->xt();
69         else
70                 w->xt = w->code->xt();
71 }
72
73 void factor_vm::primitive_optimized_p()
74 {
75         word *w = untag_check<word>(dpeek());
76         drepl(tag_boolean(w->code->optimized_p()));
77 }
78
79 void factor_vm::primitive_wrapper()
80 {
81         wrapper *new_wrapper = allot<wrapper>(sizeof(wrapper));
82         new_wrapper->object = dpeek();
83         drepl(tag<wrapper>(new_wrapper));
84 }
85
86 }