Permalink
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...
1 parent d69cfff commit 8d2c2b9ea32933ccf03ac0e560233d082a87b5dd Evan Phoenix committed Sep 22, 2008
@@ -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) {
@@ -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
@@ -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
@@ -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
@@ -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) {
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;
@@ -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;
@@ -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;
@@ -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);
@@ -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
@@ -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
@@ -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;
@@ -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
@@ -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 */
@@ -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);
}
}
Oops, something went wrong.

0 comments on commit 8d2c2b9

Please sign in to comment.