]> gitweb.factorcode.org Git - factor.git/blob - vm/tuples.cpp
Use C++ namespaces
[factor.git] / vm / tuples.cpp
1 #include "master.hpp"
2
3 namespace factor
4 {
5
6 /* push a new tuple on the stack */
7 F_TUPLE *allot_tuple(CELL layout_)
8 {
9         gc_root<F_TUPLE_LAYOUT> layout(layout_);
10         gc_root<F_TUPLE> tuple(allot<F_TUPLE>(tuple_size(layout.untagged())));
11         tuple->layout = layout.value();
12         return tuple.untagged();
13 }
14
15 PRIMITIVE(tuple)
16 {
17         gc_root<F_TUPLE_LAYOUT> layout(dpop());
18         F_TUPLE *tuple = allot_tuple(layout.value());
19         F_FIXNUM i;
20         for(i = tuple_size(layout.untagged()) - 1; i >= 0; i--)
21                 tuple->data()[i] = F;
22
23         dpush(tag<F_TUPLE>(tuple));
24 }
25
26 /* push a new tuple on the stack, filling its slots from the stack */
27 PRIMITIVE(tuple_boa)
28 {
29         gc_root<F_TUPLE_LAYOUT> layout(dpop());
30         gc_root<F_TUPLE> tuple(allot_tuple(layout.value()));
31         CELL size = untag_fixnum(layout.untagged()->size) * CELLS;
32         memcpy(tuple->data(),(CELL *)(ds - (size - CELLS)),size);
33         ds -= size;
34         dpush(tuple.value());
35 }
36
37 }