]> gitweb.factorcode.org Git - factor.git/commitdiff
Revert "VM: undoing 0274e889b94323fdde6919a77c494ffcfbcb2166 (#1513)"
authorBjörn Lindqvist <bjourne@gmail.com>
Wed, 9 Nov 2016 01:07:56 +0000 (02:07 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Wed, 9 Nov 2016 01:07:56 +0000 (02:07 +0100)
This reverts commit a4802aba68d42186e55985e14bf41caeef6e0008.

13 files changed:
vm/alien.cpp
vm/arrays.cpp
vm/byte_arrays.cpp
vm/callbacks.cpp
vm/callstack.cpp
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 92eb85c0c3ab063428165fed1f6114f03c34da4f..894ba2d4c8fe25001055b1a79334a6c8d3da57e0 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() == 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 65479e0b587ba511357cc100dac5ced69993210a..9a32c13913b488e5e0977fca384debf41dfa0b60 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 b4da9d8dffe977811d04d8bad0488efc31ec06ff..794bd64eec01f66b2d28fe5164cb709c286d05e8 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 77a2c20689177b7f476949abc12cf5ac6851720c..492e7a9884c302b27d5b89e6d21aac619a88ccc2 100644 (file)
@@ -43,7 +43,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();
 }
@@ -88,7 +88,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 a386ed2ecac65df3e344190359485e61200ac8f6..45caa0131563baeb10143d07d3b0ed721fed0b46 100644 (file)
@@ -96,8 +96,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 c609c260ee688408526a530c1514713b51029970..09b0dc4a47806eb48694ec5c6bb775cb6a5056b8 100644 (file)
@@ -77,7 +77,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 = untag_fixnum(rels->capacity) / sizeof(relocation_entry);
index 5afac917e9b5b103af0694e979ecec857f63472c..c7169d26fd78da25120650321d616c8bf061f339 100644 (file)
@@ -70,8 +70,7 @@ void factor_vm::dispatch_resumable_signal(cell* sp, cell* pc, cell handler) {
   *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 ba8050051d3d63f709bf156a21b8cbaf8b89fcfc..6f768b034c9ef0e66b5cc22ed01ff325a048ab9f 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 36b56e5f8bfd38d67f945b1966791311973e5bb0..8a3bcf43676afd341c64ac92d7d946c12a3fbc0f 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"
@@ -122,7 +123,6 @@ namespace factor { struct factor_vm; }
 #include "callbacks.hpp"
 #include "dispatch.hpp"
 #include "vm.hpp"
-#include "tagged.hpp"
 #include "allot.hpp"
 #include "data_roots.hpp"
 #include "code_roots.hpp"
index cd4d3d487710914ed7087bfd0909d80b756dc03b..bcde346294c19ddeacda45650a5e3136bd1fb832 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 28fb12b4e249a2ec3cdc4035b0f8068da3e6ad64..c9a77da67640a17199ff42b6deb739dc80445a0b 100644 (file)
@@ -29,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)) {}
 
@@ -58,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 6169b9746d1a45d85d2aeee4f26fd3127053c510..e2a7872e412935466819202d163b1a6e977d059e 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -515,7 +515,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 bfb77cc1189714c31921e339a25aa2eecb3e5d58..cce37446ed5ce91926388172a2eb9480560aec83 100644 (file)
@@ -59,7 +59,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()));