VM: Refactor tuples.cpp/hpp to Factor style

db4
Erik Charlebois 2013-05-11 22:30:22 -04:00
parent 93b586da31
commit 5b1a9d753e
2 changed files with 20 additions and 24 deletions

View File

@ -1,34 +1,32 @@
#include "master.hpp" #include "master.hpp"
namespace factor namespace factor {
{
/* push a new tuple on the stack, filling its slots with f */ /* push a new tuple on the stack, filling its slots with f */
/* Allocates memory */ /* Allocates memory */
void factor_vm::primitive_tuple() void factor_vm::primitive_tuple() {
{ data_root<tuple_layout> layout(ctx->pop(), this);
data_root<tuple_layout> layout(ctx->pop(),this); tagged<tuple> t(allot<tuple>(tuple_size(layout.untagged())));
tagged<tuple> t(allot<tuple>(tuple_size(layout.untagged()))); t->layout = layout.value();
t->layout = layout.value();
memset_cell(t->data(),false_object,tuple_size(layout.untagged()) - sizeof(cell)); memset_cell(t->data(), false_object,
tuple_size(layout.untagged()) - sizeof(cell));
ctx->push(t.value()); ctx->push(t.value());
} }
/* push a new tuple on the stack, filling its slots from the stack */ /* push a new tuple on the stack, filling its slots from the stack */
/* Allocates memory */ /* Allocates memory */
void factor_vm::primitive_tuple_boa() void factor_vm::primitive_tuple_boa() {
{ data_root<tuple_layout> layout(ctx->pop(), this);
data_root<tuple_layout> layout(ctx->pop(),this); tagged<tuple> t(allot<tuple>(tuple_size(layout.untagged())));
tagged<tuple> t(allot<tuple>(tuple_size(layout.untagged()))); t->layout = layout.value();
t->layout = layout.value();
cell size = untag_fixnum(layout.untagged()->size) * sizeof(cell); cell size = untag_fixnum(layout.untagged()->size) * sizeof(cell);
memcpy(t->data(),(cell *)(ctx->datastack - size + sizeof(cell)),size); memcpy(t->data(), (cell*)(ctx->datastack - size + sizeof(cell)), size);
ctx->datastack -= size; ctx->datastack -= size;
ctx->push(t.value()); ctx->push(t.value());
} }
} }

View File

@ -1,10 +1,8 @@
namespace factor namespace factor {
{
inline static cell tuple_size(const tuple_layout *layout) inline static cell tuple_size(const tuple_layout* layout) {
{ cell size = untag_fixnum(layout->size);
cell size = untag_fixnum(layout->size); return sizeof(tuple) + size * sizeof(cell);
return sizeof(tuple) + size * sizeof(cell);
} }
} }