]> gitweb.factorcode.org Git - factor.git/blob - vm/tuples.cpp
Clean up untag_* and tag_* inline functions in favor of more idiomatic C++
[factor.git] / vm / tuples.cpp
1 #include "master.hpp"
2
3 /* push a new tuple on the stack */
4 F_TUPLE *allot_tuple(CELL layout_)
5 {
6         gc_root<F_TUPLE_LAYOUT> layout(layout_);
7         gc_root<F_TUPLE> tuple(allot<F_TUPLE>(tuple_size(layout.untagged())));
8         tuple->layout = layout.value();
9         return tuple.untagged();
10 }
11
12 void primitive_tuple(void)
13 {
14         gc_root<F_TUPLE_LAYOUT> layout(dpop());
15         F_TUPLE *tuple = allot_tuple(layout.value());
16         F_FIXNUM i;
17         for(i = tuple_size(layout.untagged()) - 1; i >= 0; i--)
18                 put(AREF(tuple,i),F);
19
20         dpush(tag<F_TUPLE>(tuple));
21 }
22
23 /* push a new tuple on the stack, filling its slots from the stack */
24 void primitive_tuple_boa(void)
25 {
26         gc_root<F_TUPLE_LAYOUT> layout(dpop());
27         gc_root<F_TUPLE> tuple(allot_tuple(layout.value()));
28         CELL size = untag_fixnum(layout.untagged()->size) * CELLS;
29         memcpy(tuple.untagged() + 1,(CELL *)(ds - (size - CELLS)),size);
30         ds -= size;
31         dpush(tuple.value());
32 }