]> gitweb.factorcode.org Git - factor.git/blob - vm/tuples.cpp
Merge branch 'master' of git://factorcode.org/git/factor
[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 inline void factorvm::vmprim_tuple()
16 {
17         gc_root<tuple_layout> layout(dpop(),this);
18         tuple *t = allot_tuple(layout.value());
19         fixnum i;
20         for(i = tuple_size(layout.untagged()) - 1; i >= 0; i--)
21                 t->data()[i] = F;
22
23         dpush(tag<tuple>(t));
24 }
25
26 PRIMITIVE(tuple)
27 {
28         PRIMITIVE_GETVM()->vmprim_tuple();
29 }
30
31 /* push a new tuple on the stack, filling its slots from the stack */
32 inline void factorvm::vmprim_tuple_boa()
33 {
34         gc_root<tuple_layout> layout(dpop(),this);
35         gc_root<tuple> t(allot_tuple(layout.value()),this);
36         cell size = untag_fixnum(layout.untagged()->size) * sizeof(cell);
37         memcpy(t->data(),(cell *)(ds - (size - sizeof(cell))),size);
38         ds -= size;
39         dpush(t.value());
40 }
41
42 PRIMITIVE(tuple_boa)
43 {
44         PRIMITIVE_GETVM()->vmprim_tuple_boa();
45 }
46
47 }