char-rename
Björn Lindqvist 2016-11-08 13:37:52 +01:00
parent 2308ca06e0
commit a4802aba68
13 changed files with 29 additions and 27 deletions

View File

@ -32,7 +32,7 @@ cell factor_vm::allot_alien(cell delegate_, cell displacement) {
data_root<object> delegate(delegate_, this); data_root<object> delegate(delegate_, this);
data_root<alien> new_alien(allot<alien>(sizeof(alien)), this); data_root<alien> new_alien(allot<alien>(sizeof(alien)), this);
if (TAG(delegate_) == ALIEN_TYPE) { if (delegate.type() == ALIEN_TYPE) {
tagged<alien> delegate_alien = delegate.as<alien>(); tagged<alien> delegate_alien = delegate.as<alien>();
displacement += delegate_alien->displacement; displacement += delegate_alien->displacement;
new_alien->base = delegate_alien->base; new_alien->base = delegate_alien->base;
@ -99,7 +99,7 @@ EACH_ALIEN_PRIMITIVE(DEFINE_ALIEN_ACCESSOR)
// Allocates memory // Allocates memory
void factor_vm::primitive_dlopen() { void factor_vm::primitive_dlopen() {
data_root<byte_array> path(ctx->pop(), this); data_root<byte_array> path(ctx->pop(), this);
check_tagged(path); path.untag_check(this);
data_root<dll> library(allot<dll>(sizeof(dll)), this); data_root<dll> library(allot<dll>(sizeof(dll)), this);
library->path = path.value(); library->path = path.value();
ffi_dlopen(library.untagged()); ffi_dlopen(library.untagged());
@ -111,7 +111,7 @@ void factor_vm::primitive_dlopen() {
void factor_vm::primitive_dlsym() { void factor_vm::primitive_dlsym() {
data_root<object> library(ctx->pop(), this); data_root<object> library(ctx->pop(), this);
data_root<byte_array> name(ctx->peek(), this); data_root<byte_array> name(ctx->peek(), this);
check_tagged(name); name.untag_check(this);
symbol_char* sym = name->data<symbol_char>(); symbol_char* sym = name->data<symbol_char>();
@ -131,7 +131,7 @@ void factor_vm::primitive_dlsym() {
void factor_vm::primitive_dlsym_raw() { void factor_vm::primitive_dlsym_raw() {
data_root<object> library(ctx->pop(), this); data_root<object> library(ctx->pop(), this);
data_root<byte_array> name(ctx->peek(), this); data_root<byte_array> name(ctx->peek(), this);
check_tagged(name); name.untag_check(this);
symbol_char* sym = name->data<symbol_char>(); symbol_char* sym = name->data<symbol_char>();

View File

@ -35,7 +35,7 @@ cell factor_vm::allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_) {
// Allocates memory // Allocates memory
void factor_vm::primitive_resize_array() { void factor_vm::primitive_resize_array() {
data_root<array> a(ctx->pop(), this); data_root<array> a(ctx->pop(), this);
check_tagged(a); a.untag_check(this);
cell capacity = unbox_array_size(); cell capacity = unbox_array_size();
ctx->push(tag<array>(reallot_array(a.untagged(), capacity))); ctx->push(tag<array>(reallot_array(a.untagged(), capacity)));
} }

View File

@ -24,7 +24,7 @@ void factor_vm::primitive_uninitialized_byte_array() {
// Allocates memory // Allocates memory
void factor_vm::primitive_resize_byte_array() { void factor_vm::primitive_resize_byte_array() {
data_root<byte_array> array(ctx->pop(), this); data_root<byte_array> array(ctx->pop(), this);
check_tagged(array); array.untag_check(this);
cell capacity = unbox_array_size(); cell capacity = unbox_array_size();
ctx->push(tag<byte_array>(reallot_array(array.untagged(), capacity))); ctx->push(tag<byte_array>(reallot_array(array.untagged(), capacity)));
} }

View File

@ -43,7 +43,7 @@ void callback_heap::store_callback_operand(code_block* stub, cell index,
} }
void callback_heap::update(code_block* stub) { void callback_heap::update(code_block* stub) {
word* w = untag<word>(stub->owner); word* w = (word*)UNTAG(stub->owner);
store_callback_operand(stub, 1, w->entry_point); store_callback_operand(stub, 1, w->entry_point);
stub->flush_icache(); stub->flush_icache();
} }
@ -88,7 +88,7 @@ code_block* callback_heap::add(cell owner, cell return_rewind) {
void factor_vm::primitive_callback() { void factor_vm::primitive_callback() {
cell return_rewind = to_cell(ctx->pop()); cell return_rewind = to_cell(ctx->pop());
tagged<word> w(ctx->pop()); tagged<word> w(ctx->pop());
check_tagged(w); w.untag_check(this);
cell func = callbacks->add(w.value(), return_rewind)->entry_point(); cell func = callbacks->add(w.value(), return_rewind)->entry_point();
CODE_TO_FUNCTION_POINTER_CALLBACK(this, func); CODE_TO_FUNCTION_POINTER_CALLBACK(this, func);

View File

@ -96,8 +96,8 @@ void factor_vm::primitive_set_innermost_stack_frame_quotation() {
data_root<callstack> stack(ctx->pop(), this); data_root<callstack> stack(ctx->pop(), this);
data_root<quotation> quot(ctx->pop(), this); data_root<quotation> quot(ctx->pop(), this);
check_tagged(stack); stack.untag_check(this);
check_tagged(quot); quot.untag_check(this);
jit_compile_quotation(quot.value(), true); jit_compile_quotation(quot.value(), true);

View File

@ -77,7 +77,7 @@ struct code_block {
if (!to_boolean(relocation)) if (!to_boolean(relocation))
return; return;
byte_array* rels = untag<byte_array>(relocation); byte_array* rels = (byte_array*)UNTAG(relocation);
cell index = 0; cell index = 0;
cell length = untag_fixnum(rels->capacity) / sizeof(relocation_entry); cell length = untag_fixnum(rels->capacity) / sizeof(relocation_entry);

View File

@ -70,7 +70,8 @@ void factor_vm::dispatch_resumable_signal(cell* sp, cell* pc, cell handler) {
*sp = new_sp; *sp = new_sp;
*(cell*)new_sp = *pc; *(cell*)new_sp = *pc;
*pc = untag<word>(special_objects[index])->entry_point; tagged<word> handler_word = tagged<word>(special_objects[index]);
*pc = (cell)handler_word->entry_point;
} }
void factor_vm::dispatch_signal_handler(cell* sp, cell* pc, cell handler) { void factor_vm::dispatch_signal_handler(cell* sp, cell* pc, cell handler) {

View File

@ -162,8 +162,8 @@ void factor_vm::safe_fflush(FILE* stream) {
void factor_vm::primitive_fopen() { void factor_vm::primitive_fopen() {
data_root<byte_array> mode(ctx->pop(), this); data_root<byte_array> mode(ctx->pop(), this);
data_root<byte_array> path(ctx->pop(), this); data_root<byte_array> path(ctx->pop(), this);
check_tagged(mode); mode.untag_check(this);
check_tagged(path); path.untag_check(this);
FILE* file; FILE* file;
file = safe_fopen((char*)(path.untagged() + 1), file = safe_fopen((char*)(path.untagged() + 1),

View File

@ -103,7 +103,6 @@ namespace factor { struct factor_vm; }
#include "bignum.hpp" #include "bignum.hpp"
#include "booleans.hpp" #include "booleans.hpp"
#include "instruction_operands.hpp" #include "instruction_operands.hpp"
#include "tagged.hpp"
#include "code_blocks.hpp" #include "code_blocks.hpp"
#include "bump_allocator.hpp" #include "bump_allocator.hpp"
#include "bitwise_hacks.hpp" #include "bitwise_hacks.hpp"
@ -123,6 +122,7 @@ namespace factor { struct factor_vm; }
#include "callbacks.hpp" #include "callbacks.hpp"
#include "dispatch.hpp" #include "dispatch.hpp"
#include "vm.hpp" #include "vm.hpp"
#include "tagged.hpp"
#include "allot.hpp" #include "allot.hpp"
#include "data_roots.hpp" #include "data_roots.hpp"
#include "code_roots.hpp" #include "code_roots.hpp"

View File

@ -100,7 +100,7 @@ string* factor_vm::reallot_string(string* str_, cell capacity) {
// Allocates memory // Allocates memory
void factor_vm::primitive_resize_string() { void factor_vm::primitive_resize_string() {
data_root<string> str(ctx->pop(), this); data_root<string> str(ctx->pop(), this);
check_tagged(str); str.untag_check(this);
cell capacity = unbox_array_size(); cell capacity = unbox_array_size();
ctx->push(tag<string>(reallot_string(str.untagged(), capacity))); ctx->push(tag<string>(reallot_string(str.untagged(), capacity)));
} }

View File

@ -29,6 +29,12 @@ template <typename Type> struct tagged {
return (Type*)(UNTAG(value_)); 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(cell tagged) : value_(tagged) {}
explicit tagged(Type* untagged) : value_(factor::tag(untagged)) {} explicit tagged(Type* untagged) : value_(factor::tag(untagged)) {}
@ -52,6 +58,10 @@ template <typename Type> struct tagged {
} }
}; };
template <typename Type> Type* factor_vm::untag_check(cell value) {
return tagged<Type>(value).untag_check(this);
}
template <typename Type> Type* untag(cell value) { template <typename Type> Type* untag(cell value) {
return tagged<Type>(value).untagged(); return tagged<Type>(value).untagged();
} }

View File

@ -515,16 +515,7 @@ struct factor_vm {
inline double fixnum_to_float(cell tagged); inline double fixnum_to_float(cell tagged);
// tagged // tagged
template <typename Type> void check_tagged(tagged<Type> t) { template <typename Type> Type* untag_check(cell value);
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 // io
void init_c_io(); void init_c_io();

View File

@ -59,7 +59,7 @@ void factor_vm::primitive_word() {
// Allocates memory (from_unsigned_cell allocates) // Allocates memory (from_unsigned_cell allocates)
void factor_vm::primitive_word_code() { void factor_vm::primitive_word_code() {
data_root<word> w(ctx->pop(), this); data_root<word> w(ctx->pop(), this);
check_tagged(w); w.untag_check(this);
ctx->push(from_unsigned_cell(w->entry_point)); ctx->push(from_unsigned_cell(w->entry_point));
ctx->push(from_unsigned_cell((cell)w->code() + w->code()->size())); ctx->push(from_unsigned_cell((cell)w->code() + w->code()->size()));