]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/tuples.cpp
io.streams.256color: faster by caching styles
[factor.git] / vm / tuples.cpp
index 8e77bfaee19b7318e1fb8e6040b470226875ede8..b15914f62ce6ca27ad9ce0865a7efbec02437d76 100644 (file)
@@ -1,32 +1,32 @@
 #include "master.hpp"
 
-/* push a new tuple on the stack */
-F_TUPLE *allot_tuple(CELL layout_)
-{
-       gc_root<F_TUPLE_LAYOUT> layout(layout_);
-       gc_root<F_TUPLE> tuple(allot<F_TUPLE>(tuple_size(layout.untagged())));
-       tuple->layout = layout.value();
-       return tuple.untagged();
+namespace factor {
+
+// push a new tuple on the stack, filling its slots with f
+// Allocates memory
+void factor_vm::primitive_tuple() {
+  data_root<tuple_layout> layout(ctx->pop(), this);
+  tagged<tuple> t(allot<tuple>(tuple_size(layout.untagged())));
+  t->layout = layout.value();
+
+  memset_cell(t->data(), false_object,
+              tuple_size(layout.untagged()) - sizeof(cell));
+
+  ctx->push(t.value());
 }
 
-void primitive_tuple(void)
-{
-       gc_root<F_TUPLE_LAYOUT> layout(dpop());
-       F_TUPLE *tuple = allot_tuple(layout.value());
-       F_FIXNUM i;
-       for(i = tuple_size(layout.untagged()) - 1; i >= 0; i--)
-               put(AREF(tuple,i),F);
+// push a new tuple on the stack, filling its slots from the stack
+// Allocates memory
+void factor_vm::primitive_tuple_boa() {
+  data_root<tuple_layout> layout(ctx->pop(), this);
+  tagged<tuple> t(allot<tuple>(tuple_size(layout.untagged())));
+  t->layout = layout.value();
+
+  cell size = untag_fixnum(layout.untagged()->size) * sizeof(cell);
+  memcpy(t->data(), (cell*)(ctx->datastack - size + sizeof(cell)), size);
+  ctx->datastack -= size;
 
-       dpush(tag<F_TUPLE>(tuple));
+  ctx->push(t.value());
 }
 
-/* push a new tuple on the stack, filling its slots from the stack */
-void primitive_tuple_boa(void)
-{
-       gc_root<F_TUPLE_LAYOUT> layout(dpop());
-       gc_root<F_TUPLE> tuple(allot_tuple(layout.value()));
-       CELL size = untag_fixnum(layout.untagged()->size) * CELLS;
-       memcpy(tuple.untagged() + 1,(CELL *)(ds - (size - CELLS)),size);
-       ds -= size;
-       dpush(tuple.value());
 }