]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/tuples.cpp
audio.engine.test: cleanup using
[factor.git] / vm / tuples.cpp
index 520bc55d4d6243c6bf98179fc6f3a60d791c9077..b15914f62ce6ca27ad9ce0865a7efbec02437d76 100644 (file)
@@ -1,47 +1,32 @@
 #include "master.hpp"
 
-namespace factor
-{
-
-/* push a new tuple on the stack */
-tuple *factorvm::allot_tuple(cell layout_)
-{
-       gc_root<tuple_layout> layout(layout_,this);
-       gc_root<tuple> t(allot<tuple>(tuple_size(layout.untagged())),this);
-       t->layout = layout.value();
-       return t.untagged();
-}
+namespace factor {
 
-inline void factorvm::vmprim_tuple()
-{
-       gc_root<tuple_layout> layout(dpop(),this);
-       tuple *t = allot_tuple(layout.value());
-       fixnum i;
-       for(i = tuple_size(layout.untagged()) - 1; i >= 0; i--)
-               t->data()[i] = F;
+// 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();
 
-       dpush(tag<tuple>(t));
-}
+  memset_cell(t->data(), false_object,
+              tuple_size(layout.untagged()) - sizeof(cell));
 
-PRIMITIVE(tuple)
-{
-       PRIMITIVE_GETVM()->vmprim_tuple();
+  ctx->push(t.value());
 }
 
-/* push a new tuple on the stack, filling its slots from the stack */
-inline void factorvm::vmprim_tuple_boa()
-{
-       gc_root<tuple_layout> layout(dpop(),this);
-       gc_root<tuple> t(allot_tuple(layout.value()),this);
-       cell size = untag_fixnum(layout.untagged()->size) * sizeof(cell);
-       memcpy(t->data(),(cell *)(ds - (size - sizeof(cell))),size);
-       ds -= size;
-       dpush(t.value());
-}
+// 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;
 
-PRIMITIVE(tuple_boa)
-{
-       PRIMITIVE_GETVM()->vmprim_tuple_boa();
+  ctx->push(t.value());
 }
 
 }