]> gitweb.factorcode.org Git - factor.git/blob - vm/tuples.cpp
added vm member to gc_root and growable arrays
[factor.git] / vm / tuples.cpp
1 #include "master.hpp"
2
3 namespace factor
4 {
5
6 /* push a new tuple on the stack */
7 tuple *factorvm::allot_tuple(cell layout_)
8 {
9         gc_root<tuple_layout> layout(layout_,this);
10         gc_root<tuple> t(allot<tuple>(tuple_size(layout.untagged())),this);
11         t->layout = layout.value();
12         return t.untagged();
13 }
14
15 tuple *allot_tuple(cell layout_)
16 {
17         return vm->allot_tuple(layout_);
18 }
19
20 inline void factorvm::vmprim_tuple()
21 {
22         gc_root<tuple_layout> layout(dpop(),this);
23         tuple *t = allot_tuple(layout.value());
24         fixnum i;
25         for(i = tuple_size(layout.untagged()) - 1; i >= 0; i--)
26                 t->data()[i] = F;
27
28         dpush(tag<tuple>(t));
29 }
30
31 PRIMITIVE(tuple)
32 {
33         PRIMITIVE_GETVM()->vmprim_tuple();
34 }
35
36 /* push a new tuple on the stack, filling its slots from the stack */
37 inline void factorvm::vmprim_tuple_boa()
38 {
39         gc_root<tuple_layout> layout(dpop(),this);
40         gc_root<tuple> t(allot_tuple(layout.value()),this);
41         cell size = untag_fixnum(layout.untagged()->size) * sizeof(cell);
42         memcpy(t->data(),(cell *)(ds - (size - sizeof(cell))),size);
43         ds -= size;
44         dpush(t.value());
45 }
46
47 PRIMITIVE(tuple_boa)
48 {
49         PRIMITIVE_GETVM()->vmprim_tuple_boa();
50 }
51
52 }