Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Automate object_type enum and kind_of<>

* object_type is now automatically generate from the field_extract data.
* kind_of<> specializations are now autogenerated from field_extract
  data.
  • Loading branch information...
commit 8d2c2b9ea32933ccf03ac0e560233d082a87b5dd 1 parent d69cfff
Evan Phoenix authored
Showing with 158 additions and 384 deletions.
  1. +1 −1  vm/builtin/block_environment.cpp
  2. +1 −1  vm/builtin/block_environment.hpp
  3. +0 −17 vm/builtin/class.cpp
  4. +1 −1  vm/builtin/class.hpp
  5. +3 −3 vm/builtin/compiledmethod.cpp
  6. +1 −1  vm/builtin/compiledmethod.hpp
  7. +4 −12 vm/builtin/contexts.cpp
  8. +2 −2 vm/builtin/contexts.hpp
  9. +0 −12 vm/builtin/executable.cpp
  10. +0 −24 vm/builtin/fixnum.cpp
  11. +1 −1  vm/builtin/float.hpp
  12. +0 −22 vm/builtin/immediates.cpp
  13. +0 −9 vm/builtin/integer.cpp
  14. +1 −1  vm/builtin/iseq.cpp
  15. +1 −1  vm/builtin/iseq.hpp
  16. +0 −7 vm/builtin/lookuptable.cpp
  17. +2 −2 vm/builtin/memorypointer.cpp
  18. +1 −1  vm/builtin/memorypointer.hpp
  19. +1 −1  vm/builtin/methodtable.hpp
  20. +1 −1  vm/builtin/methodvisibility.hpp
  21. +1 −1  vm/builtin/module.hpp
  22. +2 −2 vm/builtin/nativefunction.cpp
  23. +1 −1  vm/builtin/nativefunction.hpp
  24. +2 −2 vm/builtin/nativemethod.hpp
  25. +2 −2 vm/builtin/nativemethodcontext.cpp
  26. +2 −2 vm/builtin/nativemethodcontext.hpp
  27. +1 −131 vm/builtin/object.cpp
  28. +0 −2  vm/builtin/object.hpp
  29. +0 −6 vm/builtin/symbol.cpp
  30. +0 −8 vm/builtin/tuple.cpp
  31. +63 −1 vm/codegen/field_extract.rb
  32. +31 −20 vm/object.hpp
  33. +1 −59 vm/object_types.hpp
  34. +2 −2 vm/ontology.cpp
  35. +2 −0  vm/oop.hpp
  36. +2 −2 vm/test/test_memorypointer.hpp
  37. +20 −20 vm/test/test_nativefunction.hpp
  38. +2 −2 vm/test/test_ontology.hpp
  39. +3 −1 vm/vmmethod.cpp
View
2  vm/builtin/block_environment.cpp
@@ -22,7 +22,7 @@ namespace rubinius {
void BlockEnvironment::init(STATE) {
GO(blokenv).set(state->new_class("BlockEnvironment", G(object),
BlockEnvironment::fields));
- G(blokenv)->set_object_type(state, BlockEnvType);
+ G(blokenv)->set_object_type(state, BlockEnvironmentType);
}
void BlockEnvironment::call(STATE, Task* task, size_t args) {
View
2  vm/builtin/block_environment.hpp
@@ -16,7 +16,7 @@ namespace rubinius {
class BlockEnvironment : public Object {
public:
const static size_t fields = 5;
- const static object_type type = BlockEnvType;
+ const static object_type type = BlockEnvironmentType;
private:
MethodContext* home_; // slot
View
17 vm/builtin/class.cpp
@@ -13,23 +13,6 @@
namespace rubinius {
- template <>
- bool kind_of<Class>(OBJECT obj) {
- return obj->obj_type == ClassType ||
- obj->obj_type == MetaclassType ||
- obj->obj_type == IncModType;
- }
-
- template <>
- bool kind_of<Module>(OBJECT obj) {
- return obj->reference_p() &&
- (obj->obj_type == Module::type ||
- obj->obj_type == Class::type ||
- obj->obj_type == MetaClass::type ||
- obj->obj_type == IncludedModule::type);
- }
-
-
Class* Class::create(STATE, Class* super) {
Class* cls = (Class*)state->new_object(G(klass));
View
2  vm/builtin/class.hpp
@@ -46,7 +46,7 @@ namespace rubinius {
class MetaClass : public Class {
public:
const static size_t fields = Class::fields + 1;
- const static object_type type = MetaclassType;
+ const static object_type type = MetaClassType;
private:
OBJECT attached_instance_; // slot
View
6 vm/builtin/compiledmethod.cpp
@@ -18,11 +18,11 @@ namespace rubinius {
void CompiledMethod::init(STATE) {
GO(cmethod).set(state->new_class("CompiledMethod", G(executable), CompiledMethod::fields));
- G(cmethod)->set_object_type(state, CMethodType);
+ G(cmethod)->set_object_type(state, CompiledMethodType);
GO(cmethod_vis).set(state->new_class("Visibility", G(object),
MethodVisibility::fields, G(cmethod)));
- G(cmethod_vis)->set_object_type(state, CMVisibilityType);
+ G(cmethod_vis)->set_object_type(state, MethodVisibilityType);
}
CompiledMethod* CompiledMethod::create(STATE) {
@@ -63,7 +63,7 @@ namespace rubinius {
VMMethod* CompiledMethod::formalize(STATE, bool ondemand) {
if(!backend_method_) {
- VMMethod* vmm;
+ VMMethod* vmm = NULL;
/* Controls whether we use LLVM out of the gate or not. */
if(state->config.compile_up_front) {
if(ondemand) {
View
2  vm/builtin/compiledmethod.hpp
@@ -14,7 +14,7 @@ namespace rubinius {
class CompiledMethod : public Executable {
public:
const static size_t fields = 18;
- const static object_type type = CMethodType;
+ const static object_type type = CompiledMethodType;
const static size_t saved_fields = 16;
private:
View
16 vm/builtin/contexts.cpp
@@ -15,20 +15,12 @@
namespace rubinius {
- template <>
- bool kind_of<MethodContext>(OBJECT obj) {
- return obj->obj_type == MethodContext::type
- || obj->obj_type == BlockContext::type
- || obj->obj_type == NativeMethodContext::type
- ;
- }
-
void MethodContext::init(STATE) {
GO(methctx).set(state->new_class("MethodContext", G(object)));
- G(methctx)->set_object_type(state, MContextType);
+ G(methctx)->set_object_type(state, MethodContextType);
GO(blokctx).set(state->new_class("BlockContext", G(methctx)));
- G(blokctx)->set_object_type(state, BContextType);
+ G(blokctx)->set_object_type(state, BlockContextType);
}
/* Calculate how much big of an object (in bytes) to allocate
@@ -118,7 +110,7 @@ namespace rubinius {
void MethodContext::post_copy(MethodContext* old) {
this->position_stack(old->calculate_sp());
this->js.stack_top = this->stk + this->stack_size;
- if(this->obj_type == MContextType) {
+ if(this->obj_type == MethodContextType) {
assert(this->home() == old);
}
}
@@ -234,7 +226,7 @@ namespace rubinius {
MethodContext* ctx = as<MethodContext>(obj);
- if(ctx->obj_type == MContextType) {
+ if(ctx->obj_type == MethodContextType) {
assert(ctx->home() == obj);
}
View
4 vm/builtin/contexts.hpp
@@ -19,7 +19,7 @@ namespace rubinius {
public:
// fields is 0 because it is dynamically calculated
const static size_t fields = 0;
- const static object_type type = MContextType;
+ const static object_type type = MethodContextType;
private:
MethodContext* sender_; // slot
@@ -143,7 +143,7 @@ namespace rubinius {
public:
// fields is 0 because it is dynamically calculated
const static size_t fields = 0;
- const static object_type type = BContextType;
+ const static object_type type = BlockContextType;
BlockEnvironment* env();
View
12 vm/builtin/executable.cpp
@@ -10,18 +10,6 @@
#include "objectmemory.hpp"
namespace rubinius {
- template <>
- bool kind_of<Executable>(OBJECT obj) {
- if(obj->obj_type == Executable::type ||
- obj->obj_type == AccessVariableType ||
- obj->obj_type == CMethodType ||
- obj->obj_type == NativeFuncType ||
- obj->obj_type == NMethodType) {
- return true;
- }
-
- return false;
- }
void Executable::init(STATE) {
GO(executable).set(state->new_class("Executable", G(object), Executable::fields));
View
24 vm/builtin/fixnum.cpp
@@ -8,30 +8,6 @@
#include <iostream>
namespace rubinius {
-
- /* See t1 */
- template <>
- bool kind_of<Integer>(OBJECT obj) {
- return obj->fixnum_p() || (obj->reference_p() && obj->obj_type == Bignum::type);
- }
-
- template <>
- bool kind_of<Fixnum>(OBJECT obj) {
- return obj->fixnum_p();
- }
-
- /* For some reason, the as<> template doesn't pick up the
- * specialized kind_of<>, until we figure out why, just special as<>
- * too. */
- template <>
- INTEGER as<Integer>(OBJECT obj) {
- if(!kind_of<Integer>(obj)) {
- TypeError::raise(obj->obj_type, obj, "can't be cast as an Integer");
- }
- return (Integer*)obj;
- }
-
-
/* WARNING. Do not use this version if +num+ has the chance of being
* greater than FIXNUM_MAX or less than FIXNUM_MIN. */
FIXNUM Fixnum::from(native_int num) {
View
2  vm/builtin/float.hpp
@@ -16,7 +16,7 @@
namespace rubinius {
class Array;
- class Float : public Object {
+ class Float : public Numeric {
public:
const static size_t fields = 0;
const static object_type type = FloatType;
View
22 vm/builtin/immediates.cpp
@@ -4,28 +4,6 @@
namespace rubinius {
- /* NOTE(t1):
- * This looks scary, but it's pretty simple. We're specializing
- * the kind_of when passed NilClass to just test using nil_p().
- * This makes kind_of smarter, letting us use it everywhere for
- * type checks. */
- template <>
- bool kind_of<NilClass>(OBJECT obj) {
- return obj == Qnil;
- }
-
- /* See t1 */
- template <>
- bool kind_of<TrueClass>(OBJECT obj) {
- return obj == Qtrue;
- }
-
- /* See t1 */
- template <>
- bool kind_of<FalseClass>(OBJECT obj) {
- return obj == Qfalse;
- }
-
void FalseClass::Info::mark(OBJECT t, ObjectMark& mark) { }
void FalseClass::Info::show(STATE, OBJECT self, int level) {
View
9 vm/builtin/integer.cpp
@@ -20,15 +20,6 @@ namespace rubinius {
return as<Bignum>(this)->to_long_long();
}
- // TODO: double check that this links. Evan says it doesn't. I'll
- // check my Meiers books when I get home
- template <>
- bool kind_of<Numeric>(OBJECT obj) {
- return obj->fixnum_p() ||
- (obj->reference_p() && (obj->obj_type == Bignum::type ||
- obj->obj_type == Float::type));
- }
-
INTEGER Integer::from(STATE, int num) {
#if (CONFIG_WORDSIZE != 64)
if(num > FIXNUM_MAX || num < FIXNUM_MIN) {
View
2  vm/builtin/iseq.cpp
@@ -7,7 +7,7 @@
namespace rubinius {
void InstructionSequence::init(STATE) {
GO(iseq).set(state->new_class("InstructionSequence", G(object), InstructionSequence::fields));
- G(iseq)->set_object_type(state, ISeqType);
+ G(iseq)->set_object_type(state, InstructionSequenceType);
}
InstructionSequence* InstructionSequence::create(STATE, size_t instructions) {
View
2  vm/builtin/iseq.hpp
@@ -10,7 +10,7 @@ namespace rubinius {
class InstructionSequence : public Object {
public:
const static size_t fields = 2;
- const static object_type type = ISeqType;
+ const static object_type type = InstructionSequenceType;
private:
Tuple* opcodes_; // slot
View
7 vm/builtin/lookuptable.cpp
@@ -26,13 +26,6 @@
namespace rubinius {
- template <>
- bool kind_of<LookupTable>(OBJECT obj) {
- return obj->reference_p() &&
- (obj->obj_type == LookupTable::type ||
- obj->obj_type == MTType);
- }
-
LookupTable* LookupTable::create(STATE, size_t size) {
LookupTable *tbl;
View
4 vm/builtin/memorypointer.cpp
@@ -30,7 +30,7 @@ namespace rubinius {
void MemoryPointer::init(STATE) {
GO(memory_pointer).set(state->new_class("MemoryPointer"));
- G(memory_pointer)->set_object_type(state, MemPtrType);
+ G(memory_pointer)->set_object_type(state, MemoryPointerType);
}
MemoryPointer* MemoryPointer::create(STATE, void* ptr) {
@@ -299,7 +299,7 @@ namespace rubinius {
WRITE(void*, NULL);
} else {
MemoryPointer *mp = as<MemoryPointer>(val);
- type_assert(val, MemPtrType, "converting to pointer");
+ type_assert(val, MemoryPointerType, "converting to pointer");
WRITE(void*, mp->pointer);
}
break;
View
2  vm/builtin/memorypointer.hpp
@@ -8,7 +8,7 @@ namespace rubinius {
class MemoryPointer : public Object {
public:
const static size_t fields = 0;
- const static object_type type = MemPtrType;
+ const static object_type type = MemoryPointerType;
void* pointer;
bool autorelease;
View
2  vm/builtin/methodtable.hpp
@@ -6,7 +6,7 @@
namespace rubinius {
class MethodTable : public LookupTable {
public:
- const static object_type type = MTType;
+ const static object_type type = MethodTableType;
static MethodTable* create(STATE);
View
2  vm/builtin/methodvisibility.hpp
@@ -9,7 +9,7 @@ namespace rubinius {
class MethodVisibility : public Object {
public:
const static size_t fields = 2;
- const static object_type type = CMVisibilityType;
+ const static object_type type = MethodVisibilityType;
private:
SYMBOL visibility_; // slot
View
2  vm/builtin/module.hpp
@@ -54,7 +54,7 @@ namespace rubinius {
class IncludedModule : public Module {
public:
const static size_t fields = Module::fields + 1;
- const static object_type type = IncModType;
+ const static object_type type = IncludedModuleType;
private:
OBJECT module_; // slot
View
4 vm/builtin/nativefunction.cpp
@@ -64,7 +64,7 @@ namespace rubinius {
void NativeFunction::init(STATE) {
GO(native_function).set(state->new_class("NativeFunction", G(executable),
NativeFunction::fields));
- G(native_function)->set_object_type(state, NativeFuncType);
+ G(native_function)->set_object_type(state, NativeFunctionType);
G(rubinius)->set_const(state, "LIBSUFFIX", String::create(state, LIBSUFFIX));
}
@@ -505,7 +505,7 @@ namespace rubinius {
*tmp = NULL;
} else {
MemoryPointer *mp = as<MemoryPointer>(obj);
- type_assert(obj, MemPtrType, "converting to pointer");
+ type_assert(obj, MemoryPointerType, "converting to pointer");
*tmp = mp->pointer;
}
values[i] = tmp;
View
2  vm/builtin/nativefunction.hpp
@@ -9,7 +9,7 @@ namespace rubinius {
class NativeFunction : public Executable {
public:
static const size_t fields = 7;
- static const object_type type = NativeFuncType;
+ static const object_type type = NativeFunctionType;
private:
OBJECT name_; // slot
View
4 vm/builtin/nativemethod.hpp
@@ -87,12 +87,12 @@ namespace rubinius {
public: /* Ruby slots and bookkeeping */
const static size_t fields = 5;
- const static object_type type = NMethodType;
+ const static object_type type = NativeMethodType;
static void register_class_with(VM* state)
{
state->globals.nmethod.set(state->new_class("NativeMethod", state->globals.executable.get(), NativeMethod::fields));
- state->globals.nmethod.get()->set_object_type(state, NMethodType);
+ state->globals.nmethod.get()->set_object_type(state, NativeMethodType);
}
private: /* Instance vars */
View
4 vm/builtin/nativemethodcontext.cpp
@@ -41,7 +41,7 @@ namespace rubinius {
this->module(my_state, my_message->module);
- this->name(my_state, as<Object>(my_message->name));
+ this->name(my_state, my_message->name);
// my_stack_size = DEFAULT_STACK_SIZE;
// my_stack = new char[my_stack_size];
@@ -97,7 +97,7 @@ namespace rubinius {
*/
void NativeMethodContext::register_class_with(VM* state) {
state->globals.nativectx.set(state->new_class("NativeMethodContext", state->globals.methctx.get()));
- state->globals.nativectx.get()->set_object_type(state, NContextType);
+ state->globals.nativectx.get()->set_object_type(state, NativeMethodContextType);
}
}
View
4 vm/builtin/nativemethodcontext.hpp
@@ -50,7 +50,7 @@ namespace rubinius {
: my_index(0)
, my_storage(&storage)
{
- my_storage->push_back(as<Object>(obj));
+ my_storage->push_back(obj);
my_index = my_storage->size() - 1;
}
@@ -178,7 +178,7 @@ namespace rubinius {
public: /* Slots and bookkeeping. */
const static size_t fields = 0; // TODO: Check this
- const static object_type type = NContextType;
+ const static object_type type = NativeMethodContextType;
/* OK, these are the slots we get from MethodContext (and all we really need.)
View
132 vm/builtin/object.cpp
@@ -24,50 +24,6 @@
namespace rubinius {
- template <>
- bool kind_of<Object>(OBJECT obj) {
- return true;
- }
-
- template <>
- bool instance_of<Object>(OBJECT obj) {
- return obj->get_type() == ObjectType;
- }
-
- /**
- * Cast any class into an Object (specialised.)
- *
- * Specialised version of as().
- *
- * Everything but NULL pointers can be cast into Objects.
- * NULLs cause an assertion.
- *
- * @see vm/object.hpp for the general version.
- */
- template <>
- Object* as<Object>(OBJECT obj)
- {
- sassert(obj);
- return obj;
- }
-
- /**
- * Cast any class into an Object (specialised.)
- *
- * Specialised version of try_as().
- *
- * Everything but NULL pointers can be cast into Objects.
- * NULLs cause an assertion.
- *
- * @see vm/object.hpp for the general version.
- */
- template <>
- Object* try_as<Object>(OBJECT obj)
- {
- sassert(obj);
- return obj;
- }
-
bool Object::fixnum_p() {
return FIXNUM_P(this);
}
@@ -217,92 +173,6 @@ namespace rubinius {
}
}
- const char* Object::type_to_name(object_type t) {
- const char* type;
-
- switch(t) {
- case ObjectType:
- type = "Object";
- break;
- case MContextType:
- type = "MethodContext";
- break;
- case BContextType:
- type = "BlockContext";
- break;
- case NContextType:
- type = "NativeMethodContext";
- break;
- case ClassType:
- type = "Class";
- break;
- case MetaclassType:
- type = "Metaclass";
- break;
- case MTType:
- type = "MethodTable";
- break;
- case WrapsStructType:
- type = "SubtendCStructure";
- break;
- case IncModType:
- type = "included Module";
- break;
- case TaskType:
- type = "Task";
- break;
- case FixnumType:
- type = "Fixnum";
- break;
- case BignumType:
- type = "Bignum";
- break;
- case FloatType:
- type = "Float";
- break;
- case MemPtrType:
- type = "MemoryPointer";
- break;
- case StringType:
- type = "String";
- break;
- case SymbolType:
- type = "Symbol";
- break;
- case CMethodType:
- type = "CompiledMethod";
- break;
- case NativeFuncType:
- type = "NativeFunction";
- break;
- case NMethodType:
- type = "NativeMethod";
- break;
- case NilType:
- type = "nil";
- break;
- case LookupTableType:
- type = "LookupTable";
- break;
- case DirType:
- type = "Dir";
- break;
- case CompactLookupTableType:
- type = "CompactLookupTable";
- break;
- case TimeType:
- type = "Time";
- break;
- case TaskProbeType:
- type = "TaskProbe";
- break;
- default:
- type = "unknown";
- break;
- }
- return type;
- }
-
Class* Object::class_object(STATE) {
if(reference_p()) {
Class* cls = klass_;
@@ -378,7 +248,7 @@ namespace rubinius {
found = (Class*)found->superclass();
if(found == cls) return true;
- if(found->reference_p() && found->obj_type == IncModType) {
+ if(found->reference_p() && found->obj_type == IncludedModuleType) {
if(((IncludedModule*)found)->module() == cls) return true;
}
}
View
2  vm/builtin/object.hpp
@@ -168,8 +168,6 @@ namespace rubinius {
void copy_ivars(STATE, OBJECT other);
void copy_metaclass(STATE, OBJECT other);
- static const char* type_to_name(object_type type);
-
/* VM level primitives. It's dumb to have them here, but it's more
* complicated to make field_extract parse non-Object classes. */
View
6 vm/builtin/symbol.cpp
@@ -14,12 +14,6 @@
#define Increments 32
namespace rubinius {
- /* See Note(t1) in immediates.cpp */
- template <>
- bool kind_of<Symbol>(OBJECT obj) {
- return obj->symbol_p();
- }
-
void Symbol::init(STATE) {
GO(symbol).set(state->new_class("Symbol"));
}
View
8 vm/builtin/tuple.cpp
@@ -8,14 +8,6 @@
#include <iostream>
namespace rubinius {
-
- template <>
- bool kind_of<Tuple>(OBJECT obj) {
- return obj->reference_p() && (
- obj->obj_type == Tuple::type ||
- obj->obj_type == CompactLookupTable::type);
- }
-
OBJECT Tuple::at(size_t index) {
if(num_fields() <= index) {
ObjectBoundsExceeded::raise(this, index);
View
64 vm/codegen/field_extract.rb
@@ -141,9 +141,11 @@ def initialize(name)
@flags = {}
@primitives = {}
@num_fields = 0
+ @subclasses = []
end
attr_accessor :name, :super, :fields, :primitives, :flags, :num_fields
+ attr_accessor :subclasses
def add_field(idx, name, type, flag=nil)
if flag
@@ -308,6 +310,42 @@ def generate_mark
str
end
+
+ def kind_of_code(what)
+ case @name
+ when "Fixnum"
+ return "FIXNUM_P(#{what})"
+ when "Symbol"
+ return "SYMBOL_P(#{what})"
+ when "TrueClass"
+ return "#{what} == Qtrue"
+ when "FalseClass"
+ return "#{what} == Qfalse"
+ when "NilClass"
+ return "#{what} == Qnil"
+ else
+ return "(REFERENCE_P(#{what}) && #{what}->obj_type == #{@name}Type)"
+ end
+ end
+
+ def kind_of_conditions(what)
+ [kind_of_code(what)] + @subclasses.map do |cpp|
+ cpp.kind_of_conditions(what)
+ end
+ end
+
+ def generate_kind_of
+ checks = kind_of_conditions("obj")
+
+ # We forward declare the class in here to keep everything happy
+ str = <<-CPP
+template <>
+static bool kind_of<#{@name}>(Object* obj) {
+ return #{checks.join(' || ')};
+}
+
+ CPP
+ end
end
class CPPParser
@@ -374,6 +412,7 @@ def parse_stream(f)
if sup = @classes[m[2]]
cpp = CPPClass.new(m[1])
cpp.super = sup
+ sup.subclasses << cpp
else
next
end
@@ -490,7 +529,7 @@ def write_if_new(path)
yield f
end
- File.rename tmp_path, path unless system("diff -q #{path} #{tmp_path} 2>&1")
+ File.rename tmp_path, path unless system("diff -q #{path} #{tmp_path} > /dev/null 2>&1")
ensure
File.unlink tmp_path if File.exist? tmp_path
end
@@ -585,6 +624,29 @@ def write_if_new(path)
end
end
+write_if_new "vm/gen/object_types.hpp" do |f|
+ f.puts "typedef enum {"
+ f.puts " InvalidType = 0,"
+ f.puts " NilType,"
+ f.puts " TrueType,"
+ f.puts " FalseType,"
+ parser.classes.map { |n, cpp| cpp.name}.sort.each do |name|
+ f.puts " #{name}Type,"
+ end
+ f.puts " LastObjectType"
+ f.puts "} object_type;"
+ f.puts
+end
+
+write_if_new "vm/gen/kind_of.hpp" do |f|
+
+ parser.classes.each do |n, cpp|
+ next if cpp.name == "Object"
+ f.puts "class #{cpp.name};"
+ f.puts cpp.generate_kind_of
+ end
+end
+
write_if_new "vm/gen/primitives_glue.gen.cpp" do |f|
names = []
parser.classes.sort_by { |name,| name }.each do |n, cpp|
View
51 vm/object.hpp
@@ -21,20 +21,28 @@
namespace rubinius {
+#define sassert(cond) if(!(cond)) Assertion::raise(#cond)
+
/**
* Ruby type system subtype check.
*
* Given builtin-class +T+, return true if +obj+ is of class +T+
*/
template <class T>
- bool kind_of(OBJECT obj) {
- if(obj->reference_p()) {
+ static bool kind_of(Object* obj) {
+ if(REFERENCE_P(obj)) {
return obj->obj_type == T::type;
}
return false;
}
- template <> bool kind_of<Object>(OBJECT obj);
+ /**
+ * A specialized version for completeness.
+ */
+ template <>
+ static bool kind_of<Object>(Object* obj) {
+ return true;
+ }
/**
* Ruby type system class check.
@@ -44,16 +52,20 @@ namespace rubinius {
* one.
*/
template <class T>
- bool instance_of(OBJECT obj) {
- if(obj->reference_p()) {
+ static bool instance_of(Object* obj) {
+ if(REFERENCE_P(obj)) {
return obj->obj_type == T::type;
}
return false;
}
- template <> bool instance_of<Object>(OBJECT obj);
-
-#define sassert(cond) if (!(cond)) Assertion::raise(#cond)
+ /**
+ * A specialized version for completeness.
+ */
+ template <>
+ static bool instance_of<Object>(Object* obj) {
+ return obj->reference_p() && (obj->get_type() == ObjectType);
+ }
/*
* There is NO reason why as() or try_as() should be getting
@@ -70,7 +82,7 @@ namespace rubinius {
* @see builtin/object.cpp has specialised versions.
*/
template <class T>
- T* as(OBJECT obj) {
+ static T* as(Object* obj) {
sassert(NULL != obj);
if(!kind_of<T>(obj))
@@ -79,11 +91,13 @@ namespace rubinius {
return static_cast<T*>(obj);
}
- /** Specialised cast to always succeed if not NULL.
- *
- * Implemented in builtin/object.cpp.
+ /**
+ * A specialized version for completeness.
*/
- template <> Object* as<Object>(OBJECT obj);
+ template <>
+ static Object* as<Object>(Object* obj) {
+ return obj;
+ }
/**
* Non-raising version of as().
@@ -94,7 +108,7 @@ namespace rubinius {
* @see builtin/object.cpp has specialised versions.
*/
template <class T>
- T* try_as(OBJECT obj) {
+ static T* try_as(Object* obj) {
sassert(NULL != obj);
if(!kind_of<T>(obj))
@@ -103,11 +117,6 @@ namespace rubinius {
return static_cast<T*>(obj);
}
- /** Specialised cast to always succeed if not NULL.
- *
- * Implemented in builtin/object.cpp.
- */
- template <> Object* try_as<Object>(OBJECT obj);
void type_assert(OBJECT obj, object_type type, const char* reason);
@@ -135,6 +144,8 @@ namespace rubinius {
if(s->free != NULL) { s->free(s->ptr); } \
} while (0)
-};
+#include "gen/kind_of.hpp"
+
+}
#endif
View
60 vm/object_types.hpp
@@ -2,65 +2,7 @@
#define RBX_VM_OBJECT_TYPES_HPP
namespace rubinius {
- /* rubinius_object types, takes up 3 bits */
- typedef enum
- {
- InvalidType = 0,
- NumericType ,
- IntegerType ,
- FalseType ,
- TrueType ,
- NilType ,
- ObjectType ,
- MContextType ,
- BContextType ,
- ClassType ,
- MetaclassType ,
- MTType ,
- WrapsStructType ,
- IncModType ,
- TaskType ,
- FixnumType ,
- BignumType ,
- FloatType ,
- MemPtrType ,
- StringType ,
- SymbolType ,
- CMethodType ,
- BlockEnvType ,
- TupleType ,
- ArrayType ,
- RegexpDataType ,
- RegexpType ,
- ByteArrayType ,
- ISeqType ,
- ChannelType ,
- ThreadType ,
- ModuleType ,
- SendSiteType ,
- SelectorType ,
- LookupTableType ,
- IOBufferType ,
- StaticScopeType ,
- MatchDataType ,
- ExceptionType ,
- IOType ,
- ExecutableType ,
- CMVisibilityType,
- ListType ,
- ListNodeType ,
- NativeFuncType ,
- DirType ,
- CompactLookupTableType,
- AccessVariableType,
- TimeType ,
- TaskProbeType ,
-
- NMethodType ,
- NContextType ,
-
- LastObjectType // must remain at end
- } object_type;
+ #include "gen/object_types.hpp"
}
#endif
View
4 vm/ontology.cpp
@@ -84,7 +84,7 @@ namespace rubinius {
/* Create MetaClass */
GO(metaclass).set(new_basic_class(cls, MetaClass::fields));
- G(metaclass)->set_object_type(state, MetaclassType);
+ G(metaclass)->set_object_type(state, MetaClassType);
/* Create Tuple */
GO(tuple).set(new_basic_class(object, Tuple::fields));
@@ -96,7 +96,7 @@ namespace rubinius {
/* Create MethodTable */
GO(methtbl).set(new_basic_class(G(lookuptable), MethodTable::fields));
- G(methtbl)->set_object_type(state, MTType);
+ G(methtbl)->set_object_type(state, MethodTableType);
/* Now, we have:
* Class
View
2  vm/oop.hpp
@@ -4,6 +4,7 @@
#include <cstddef>
#include <ctype.h>
#include <stdint.h>
+
#include "object_types.hpp"
namespace rubinius {
@@ -181,4 +182,5 @@ to be a simple test for that bit pattern.
}
+
#endif
View
4 vm/test/test_memorypointer.hpp
@@ -272,7 +272,7 @@ class TestMemoryPointer : public CxxTest::TestSuite {
MemoryPointer* ptr = MemoryPointer::create(state, &val);
OBJECT obj = ptr->get_field(state, 0, RBX_FFI_TYPE_PTR);
- TS_ASSERT(obj->check_type(MemPtrType));
+ TS_ASSERT(obj->check_type(MemoryPointerType));
TS_ASSERT_EQUALS(as<MemoryPointer>(obj)->pointer, val);
}
@@ -323,7 +323,7 @@ class TestMemoryPointer : public CxxTest::TestSuite {
String *so = as<String>(ary->get(state, 0));
TS_ASSERT(!strncmp(str, so->byte_address(), 4));
- TS_ASSERT(ary->get(state, 1)->check_type(MemPtrType));
+ TS_ASSERT(ary->get(state, 1)->check_type(MemoryPointerType));
MemoryPointer* mp = as<MemoryPointer>(ary->get(state, 1));
TS_ASSERT_EQUALS(mp->pointer, str);
}
View
40 vm/test/test_nativefunction.hpp
@@ -91,7 +91,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, name);
@@ -116,7 +116,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 2);
input->set(state, 0, Qnil);
@@ -140,7 +140,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, Fixnum::from(13));
@@ -164,7 +164,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, Fixnum::from(13));
@@ -188,7 +188,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, Fixnum::from(13));
@@ -212,7 +212,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 2);
input->set(state, 0, Fixnum::from(0));
@@ -245,7 +245,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, Fixnum::from(13));
@@ -279,7 +279,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, Fixnum::from(13));
@@ -313,7 +313,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, Fixnum::from(13));
@@ -347,7 +347,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, Fixnum::from(13));
@@ -381,7 +381,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, Fixnum::from(13));
@@ -415,7 +415,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, Fixnum::from(13));
@@ -448,7 +448,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Message* msg = new Message(state);
@@ -468,7 +468,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
char buffer[1];
buffer[0] = 0;
@@ -505,7 +505,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, Float::create(state, 13.2));
@@ -530,7 +530,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, Float::create(state, 13.2));
@@ -554,7 +554,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, String::create(state, "whatever"));
@@ -587,7 +587,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
input->set(state, 0, String::create(state, "whatever"));
@@ -632,7 +632,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Array* input = Array::create(state, 1);
OBJECT obj = state->om->new_object(G(object), Object::fields);
@@ -668,7 +668,7 @@ class TestNativeFunction : public CxxTest::TestSuite {
NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);
TS_ASSERT(!func->nil_p());
- TS_ASSERT(func->data()->check_type(MemPtrType));
+ TS_ASSERT(func->data()->check_type(MemoryPointerType));
Message* msg = new Message(state);
View
4 vm/test/test_ontology.hpp
@@ -62,7 +62,7 @@ class TestObjects : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(meta->class_object(state), G(klass));
TS_ASSERT_EQUALS(meta->superclass(), G(klass));
- TS_ASSERT_EQUALS(meta->instance_type(), Fixnum::from(MetaclassType));
+ TS_ASSERT_EQUALS(meta->instance_type(), Fixnum::from(MetaClassType));
check_const(metaclass, "MetaClass");
}
@@ -96,7 +96,7 @@ class TestObjects : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(cls->class_object(state), G(klass));
TS_ASSERT_EQUALS(cls->superclass(), G(lookuptable));
- TS_ASSERT_EQUALS((object_type)cls->instance_type()->to_native(), MTType);
+ TS_ASSERT_EQUALS((object_type)cls->instance_type()->to_native(), MethodTableType);
check_const(methtbl, "MethodTable");
}
View
4 vm/vmmethod.cpp
@@ -33,8 +33,10 @@ namespace rubinius {
opcodes = new opcode[total];
+ Tuple* ops = meth->iseq()->opcodes();
+ OBJECT val;
for(size_t index = 0; index < total; index++) {
- OBJECT val = meth->iseq()->opcodes()->at(index);
+ val = ops->at(index);
if(val->nil_p()) {
opcodes[index] = 0;
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.