]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: refactor tagged.hpp so it's not dependent on the factor_vm class
authorBjörn Lindqvist <bjourne@gmail.com>
Tue, 24 Nov 2015 15:00:50 +0000 (16:00 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Tue, 24 Nov 2015 15:00:50 +0000 (16:00 +0100)
this way untag<byte_array>(relocation) can be used in code_blocks.hpp

14 files changed:
vm/alien.cpp
vm/arrays.cpp
vm/byte_arrays.cpp
vm/callbacks.cpp
vm/callstack.cpp
vm/callstack.hpp
vm/code_blocks.hpp
vm/cpu-x86.cpp
vm/io.cpp
vm/master.hpp
vm/strings.cpp
vm/tagged.hpp
vm/vm.hpp
vm/words.cpp

index 7fe30bb69dec14697a7733b4bd630a12a9d494e2..5a99e9accef23c685d950bfad7c083872553acac 100644 (file)
@@ -32,7 +32,7 @@ cell factor_vm::allot_alien(cell delegate_, cell displacement) {
   data_root<object> delegate(delegate_, this);
   data_root<alien> new_alien(allot<alien>(sizeof(alien)), this);
 
-  if (delegate.type_p(ALIEN_TYPE)) {
+  if (TAG(delegate_) == ALIEN_TYPE) {
     tagged<alien> delegate_alien = delegate.as<alien>();
     displacement += delegate_alien->displacement;
     new_alien->base = delegate_alien->base;
@@ -99,7 +99,7 @@ EACH_ALIEN_PRIMITIVE(DEFINE_ALIEN_ACCESSOR)
 /* 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());
@@ -111,7 +111,7 @@ void factor_vm::primitive_dlopen() {
 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>();
 
@@ -131,7 +131,7 @@ void factor_vm::primitive_dlsym() {
 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>();
 
index 2c0808b6a314b43f7f4a3c2fdd741a9ee5ab591c..646ac60223297e59d553ddaf2a6ce47715ecdf4c 100644 (file)
@@ -35,7 +35,7 @@ cell factor_vm::allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_) {
 /* 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)));
 }
index 4f7f6f0f1625f56ff05c35ea0352193dac776062..acaf85b66670f31f6164ebf6de670b29fb80434e 100644 (file)
@@ -24,7 +24,7 @@ void factor_vm::primitive_uninitialized_byte_array() {
 /* 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)));
 }
index 5a86cbf3f46ac4dcab7fcd53c26f2adb22c6b132..4e627c51bafc94dae67bdccbe59aeedd6db44622 100644 (file)
@@ -47,7 +47,7 @@ void callback_heap::store_callback_operand(code_block* stub, cell index,
 }
 
 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();
 }
@@ -92,8 +92,7 @@ code_block* callback_heap::add(cell owner, cell return_rewind) {
 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);
index 52a2b20c76d9cd636e72597b57cf5d251625bed5..104225f086753d2b2115675470b9126a08df84c0 100644 (file)
@@ -100,8 +100,8 @@ void factor_vm::primitive_set_innermost_stack_frame_quotation() {
   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);
 
index 425ddc157f1421c207727750037673cf15742754..a91aa482e9321ce00d0193228ab2b03e0c9bf755 100644 (file)
@@ -5,7 +5,7 @@ inline static cell callstack_object_size(cell size) {
 }
 
 /* This is a little tricky. The iterator may allocate memory, so we
-keep the callstack in a GC root and use relative offsets */
+   keep the callstack in a GC root and use relative offsets */
 /* Allocates memory */
 template <typename Iterator, typename Fixup>
 inline void factor_vm::iterate_callstack_object(callstack* stack_,
index 00c97985a8f5e928e1dbf4b2f1ad39e3f14476de..e43c32cfac2a1cf410a85afce5213041513fd41d 100644 (file)
@@ -79,7 +79,7 @@ struct code_block {
     if (!to_boolean(relocation))
       return;
 
-    byte_array* rels = (byte_array*)UNTAG(relocation);
+    byte_array* rels = untag<byte_array>(relocation);
 
     cell index = 0;
     cell length = (rels->capacity >> TAG_BITS) / sizeof(relocation_entry);
index 494ce6fa8f67260f8fba53e0a8c976e78ac0e7f0..7803aa0813d5c8fff93f126a03a02c2bd78e192a 100644 (file)
@@ -69,8 +69,8 @@ void factor_vm::dispatch_resumable_signal(cell* sp, cell* pc, cell handler) {
   cell new_sp = *sp - delta;
   *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) {
index 9ca273d5cc070c4b33bd80b6ca41b7feb3644b0f..6710a82de9c2b8c1d0c81e82425ce72330c078e3 100644 (file)
--- a/vm/io.cpp
+++ b/vm/io.cpp
@@ -162,8 +162,8 @@ void factor_vm::safe_fflush(FILE* stream) {
 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),
index 0355485ba55d304a17f48d593e0c4c8207c0fcd4..ede79126a5486be36a1177b6bf16a3992073364b 100644 (file)
@@ -103,6 +103,7 @@ namespace factor { struct factor_vm; }
 #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"
@@ -125,7 +126,6 @@ namespace factor { struct factor_vm; }
 #include "safepoints.hpp"
 #include "vm.hpp"
 #include "allot.hpp"
-#include "tagged.hpp"
 #include "data_roots.hpp"
 #include "code_roots.hpp"
 #include "generic_arrays.hpp"
index 7c262514bd18b2c108b43c3b7493a42b85804383..61edab54069eddc5dd8c34861e4206f567bd245a 100644 (file)
@@ -100,7 +100,7 @@ string* factor_vm::reallot_string(string* str_, cell capacity) {
 /* 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)));
 }
index 4ec0f7e93493c01b6661a91e998269a6374e7798..c9a77da67640a17199ff42b6deb739dc80445a0b 100644 (file)
@@ -13,13 +13,10 @@ template <typename Type> struct tagged {
 
   cell type() const { return TAG(value_); }
 
-  bool type_p(cell type_) const { return type() == type_; }
-
   bool type_p() const {
     if (Type::type_number == TYPE_COUNT)
       return true;
-    else
-      return type_p(Type::type_number);
+    return type() == Type::type_number;
   }
 
   cell value() const {
@@ -32,12 +29,6 @@ template <typename Type> struct tagged {
     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)) {}
 
@@ -61,10 +52,6 @@ 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) {
   return tagged<Type>(value).untagged();
 }
index 5c94db010e85ea6233faabb85749b95d81c066bb..496d20f3871a24f3a14b698f418dcf213a9dd857 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -537,7 +537,16 @@ struct factor_vm {
   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();
index f171868d0e34d3d174bd13d95ddb60705ff399e7..9ea29007e5e08cb5d59293cccaf566cb30039d6d 100644 (file)
@@ -75,7 +75,7 @@ void factor_vm::primitive_word() {
 /* 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()));