data_root<object> delegate(delegate_, this);
data_root<alien> new_alien(allot<alien>(sizeof(alien)), this);
- if (delegate.type() == ALIEN_TYPE) {
+ if (TAG(delegate_) == ALIEN_TYPE) {
tagged<alien> delegate_alien = delegate.as<alien>();
displacement += delegate_alien->displacement;
new_alien->base = delegate_alien->base;
// Allocates memory
void factor_vm::primitive_dlopen() {
data_root<byte_array> path(ctx->pop(), this);
- path.untag_check(this);
+ check_tagged(path);
data_root<dll> library(allot<dll>(sizeof(dll)), this);
library->path = path.value();
ffi_dlopen(library.untagged());
void factor_vm::primitive_dlsym() {
data_root<object> library(ctx->pop(), this);
data_root<byte_array> name(ctx->peek(), this);
- name.untag_check(this);
+ check_tagged(name);
symbol_char* sym = name->data<symbol_char>();
void factor_vm::primitive_dlsym_raw() {
data_root<object> library(ctx->pop(), this);
data_root<byte_array> name(ctx->peek(), this);
- name.untag_check(this);
+ check_tagged(name);
symbol_char* sym = name->data<symbol_char>();
// Allocates memory
void factor_vm::primitive_resize_array() {
data_root<array> a(ctx->pop(), this);
- a.untag_check(this);
+ check_tagged(a);
cell capacity = unbox_array_size();
ctx->push(tag<array>(reallot_array(a.untagged(), capacity)));
}
// Allocates memory
void factor_vm::primitive_resize_byte_array() {
data_root<byte_array> array(ctx->pop(), this);
- array.untag_check(this);
+ check_tagged(array);
cell capacity = unbox_array_size();
ctx->push(tag<byte_array>(reallot_array(array.untagged(), capacity)));
}
}
void callback_heap::update(code_block* stub) {
- word* w = (word*)UNTAG(stub->owner);
+ word* w = untag<word>(stub->owner);
store_callback_operand(stub, 1, w->entry_point);
stub->flush_icache();
}
void factor_vm::primitive_callback() {
cell return_rewind = to_cell(ctx->pop());
tagged<word> w(ctx->pop());
- w.untag_check(this);
+ check_tagged(w);
cell func = callbacks->add(w.value(), return_rewind)->entry_point();
CODE_TO_FUNCTION_POINTER_CALLBACK(this, func);
data_root<callstack> stack(ctx->pop(), this);
data_root<quotation> quot(ctx->pop(), this);
- stack.untag_check(this);
- quot.untag_check(this);
+ check_tagged(stack);
+ check_tagged(quot);
jit_compile_quotation(quot.value(), true);
if (!to_boolean(relocation))
return;
- byte_array* rels = (byte_array*)UNTAG(relocation);
+ byte_array* rels = untag<byte_array>(relocation);
cell index = 0;
cell length = untag_fixnum(rels->capacity) / sizeof(relocation_entry);
*sp = new_sp;
*(cell*)new_sp = *pc;
- tagged<word> handler_word = tagged<word>(special_objects[index]);
- *pc = (cell)handler_word->entry_point;
+ *pc = untag<word>(special_objects[index])->entry_point;
}
void factor_vm::dispatch_signal_handler(cell* sp, cell* pc, cell handler) {
void factor_vm::primitive_fopen() {
data_root<byte_array> mode(ctx->pop(), this);
data_root<byte_array> path(ctx->pop(), this);
- mode.untag_check(this);
- path.untag_check(this);
+ check_tagged(mode);
+ check_tagged(path);
FILE* file;
file = safe_fopen((char*)(path.untagged() + 1),
#include "bignum.hpp"
#include "booleans.hpp"
#include "instruction_operands.hpp"
+#include "tagged.hpp"
#include "code_blocks.hpp"
#include "bump_allocator.hpp"
#include "bitwise_hacks.hpp"
#include "callbacks.hpp"
#include "dispatch.hpp"
#include "vm.hpp"
-#include "tagged.hpp"
#include "allot.hpp"
#include "data_roots.hpp"
#include "code_roots.hpp"
// Allocates memory
void factor_vm::primitive_resize_string() {
data_root<string> str(ctx->pop(), this);
- str.untag_check(this);
+ check_tagged(str);
cell capacity = unbox_array_size();
ctx->push(tag<string>(reallot_string(str.untagged(), capacity)));
}
return (Type*)(UNTAG(value_));
}
- Type* untag_check(factor_vm* parent) const {
- if (!type_p())
- parent->type_error(Type::type_number, value_);
- return untagged();
- }
-
explicit tagged(cell tagged) : value_(tagged) {}
explicit tagged(Type* untagged) : value_(factor::tag(untagged)) {}
}
};
-template <typename Type> Type* factor_vm::untag_check(cell value) {
- return tagged<Type>(value).untag_check(this);
-}
-
template <typename Type> Type* untag(cell value) {
return tagged<Type>(value).untagged();
}
inline double fixnum_to_float(cell tagged);
// tagged
- template <typename Type> Type* untag_check(cell value);
+ template <typename Type> void check_tagged(tagged<Type> t) {
+ if (!t.type_p())
+ type_error(Type::type_number, t.value_);
+ }
+
+ template <typename Type> Type* untag_check(cell value) {
+ tagged<Type> t(value);
+ check_tagged(t);
+ return t.untagged();
+ }
// io
void init_c_io();
// Allocates memory (from_unsigned_cell allocates)
void factor_vm::primitive_word_code() {
data_root<word> w(ctx->pop(), this);
- w.untag_check(this);
+ check_tagged(w);
ctx->push(from_unsigned_cell(w->entry_point));
ctx->push(from_unsigned_cell((cell)w->code() + w->code()->size()));