Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

API cleanup: move new_(class|module) out of VM

  • Loading branch information...
commit 380797fc490da190e007c3104c266827a29e0781 1 parent 1956797
@evanphx evanphx authored
Showing with 257 additions and 156 deletions.
  1. +4 −1 vm/builtin/access_variable.cpp
  2. +4 −1 vm/builtin/alias.cpp
  3. +3 −1 vm/builtin/array.cpp
  4. +3 −1 vm/builtin/autoload.cpp
  5. +3 −1 vm/builtin/bignum.cpp
  6. +3 −1 vm/builtin/block_environment.cpp
  7. +4 −1 vm/builtin/bytearray.cpp
  8. +4 −1 vm/builtin/channel.cpp
  9. +4 −1 vm/builtin/chararray.cpp
  10. +3 −1 vm/builtin/compactlookuptable.cpp
  11. +4 −1 vm/builtin/compiledmethod.cpp
  12. +3 −1 vm/builtin/data.cpp
  13. +3 −1 vm/builtin/dir.cpp
  14. +4 −2 vm/builtin/encoding.cpp
  15. +3 −1 vm/builtin/exception.cpp
  16. +3 −1 vm/builtin/executable.cpp
  17. +3 −1 vm/builtin/ffi_pointer.cpp
  18. +3 −1 vm/builtin/fiber.cpp
  19. +3 −1 vm/builtin/fixnum.cpp
  20. +3 −1 vm/builtin/float.cpp
  21. +4 −1 vm/builtin/global_cache_entry.cpp
  22. +5 −2 vm/builtin/io.cpp
  23. +4 −1 vm/builtin/iseq.cpp
  24. +5 −2 vm/builtin/list.cpp
  25. +4 −1 vm/builtin/location.cpp
  26. +4 −3 vm/builtin/nativefunction.cpp
  27. +4 −1 vm/builtin/nativemethod.cpp
  28. +3 −1 vm/builtin/proc.cpp
  29. +4 −1 vm/builtin/randomizer.cpp
  30. +4 −2 vm/builtin/regexp.cpp
  31. +4 −1 vm/builtin/staticscope.cpp
  32. +3 −1 vm/builtin/string.cpp
  33. +3 −1 vm/builtin/symbol.cpp
  34. +3 −1 vm/builtin/thread.cpp
  35. +3 −1 vm/builtin/time.cpp
  36. +4 −1 vm/builtin/variable_scope.cpp
  37. +3 −1 vm/builtin/weakref.cpp
  38. +3 −1 vm/ffi.cpp
  39. +8 −15 vm/objectmemory.cpp
  40. +2 −0  vm/objectmemory.hpp
  41. +78 −27 vm/ontology.cpp
  42. +26 −0 vm/ontology.hpp
  43. +3 −1 vm/test/test_array.hpp
  44. +3 −1 vm/test/test_lookuptable.hpp
  45. +3 −1 vm/test/test_regexp.hpp
  46. +0 −49 vm/vm.cpp
  47. +0 −18 vm/vm.hpp
View
5 vm/builtin/access_variable.cpp
@@ -12,11 +12,14 @@
#include "dispatch.hpp"
#include "arguments.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
void AccessVariable::init(STATE) {
// HACK test superclass of AccessVariable
- GO(access_variable).set(state->vm()->new_class("AccessVariable", G(executable), G(rubinius)));
+ GO(access_variable).set(ontology::new_class(state,
+ "AccessVariable", G(executable), G(rubinius)));
G(access_variable)->set_object_type(state, AccessVariableType);
G(access_variable)->name(state, state->symbol("Rubinius::AccessVariable"));
}
View
5 vm/builtin/alias.cpp
@@ -2,9 +2,12 @@
#include "builtin/class.hpp"
#include "builtin/exception.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
void Alias::init(STATE) {
- GO(alias).set(state->vm()->new_class("Alias", G(executable), G(rubinius)));
+ GO(alias).set(ontology::new_class(state, "Alias",
+ G(executable), G(rubinius)));
G(alias)->set_object_type(state, AliasType);
}
View
4 vm/builtin/array.cpp
@@ -12,6 +12,8 @@
#include "arguments.hpp"
#include "dispatch.hpp"
+#include "ontology.hpp"
+
#include <iostream>
#include <math.h>
@@ -23,7 +25,7 @@
namespace rubinius {
void Array::init(STATE) {
- GO(array).set(state->vm()->new_class("Array", G(object)));
+ GO(array).set(ontology::new_class(state, "Array", G(object)));
G(array)->set_object_type(state, ArrayType);
}
View
4 vm/builtin/autoload.cpp
@@ -3,13 +3,15 @@
#include "builtin/class.hpp"
#include "builtin/autoload.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
Autoload* Autoload::create(STATE) {
return state->new_object<Autoload>(G(autoload));
}
void Autoload::init(STATE) {
- GO(autoload).set(state->vm()->new_class("Autoload"));
+ GO(autoload).set(ontology::new_class(state, "Autoload"));
G(autoload)->set_object_type(state, AutoloadType);
}
View
4 vm/builtin/bignum.cpp
@@ -18,6 +18,8 @@
#include "builtin/bytearray.hpp"
#include "configuration.hpp"
+#include "ontology.hpp"
+
#include "missing/math.h"
#define BASIC_CLASS(blah) G(blah)
@@ -193,7 +195,7 @@ namespace rubinius {
}
void Bignum::init(STATE) {
- GO(bignum).set(state->vm()->new_class("Bignum", G(integer)));
+ GO(bignum).set(ontology::new_class(state, "Bignum", G(integer)));
G(bignum)->set_object_type(state, BignumType);
}
View
4 vm/builtin/block_environment.cpp
@@ -27,6 +27,8 @@
#include "configuration.hpp"
#include "on_stack.hpp"
+#include "ontology.hpp"
+
#ifdef RBX_WINDOWS
#include <malloc.h>
#endif
@@ -40,7 +42,7 @@
namespace rubinius {
void BlockEnvironment::init(STATE) {
- GO(blokenv).set(state->vm()->new_class("BlockEnvironment", G(object),
+ GO(blokenv).set(ontology::new_class(state, "BlockEnvironment", G(object),
G(rubinius)));
G(blokenv)->set_object_type(state, BlockEnvironmentType);
G(blokenv)->name(state, state->symbol("Rubinius::BlockEnvironment"));
View
5 vm/builtin/bytearray.cpp
@@ -14,10 +14,13 @@
#include "object_utils.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
void ByteArray::init(STATE) {
- GO(bytearray).set(state->vm()->new_class_under("ByteArray", G(rubinius)));
+ GO(bytearray).set(ontology::new_class_under(state,
+ "ByteArray", G(rubinius)));
G(bytearray)->set_object_type(state, ByteArrayType);
G(bytearray)->name(state, state->symbol("Rubinius::ByteArray"));
}
View
5 vm/builtin/channel.cpp
@@ -19,12 +19,15 @@
#include "on_stack.hpp"
+#include "ontology.hpp"
+
#include <sys/time.h>
namespace rubinius {
void Channel::init(STATE) {
- GO(channel).set(state->vm()->new_class("Channel", G(object), G(rubinius)));
+ GO(channel).set(ontology::new_class(state, "Channel",
+ G(object), G(rubinius)));
G(channel)->set_object_type(state, Channel::type);
G(channel)->name(state, state->symbol("Rubinius::Channel"));
}
View
5 vm/builtin/chararray.cpp
@@ -14,10 +14,13 @@
#include "object_utils.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
void CharArray::init(STATE) {
- GO(chararray).set(state->vm()->new_class_under("CharArray", G(rubinius)));
+ GO(chararray).set(ontology::new_class_under(state,
+ "CharArray", G(rubinius)));
G(chararray)->set_object_type(state, CharArrayType);
G(chararray)->name(state, state->symbol("Rubinius::CharArray"));
}
View
4 vm/builtin/compactlookuptable.cpp
@@ -8,11 +8,13 @@
#include "builtin/lookuptable.hpp"
#include "builtin/symbol.hpp"
+#include "ontology.hpp"
+
#include <iostream>
namespace rubinius {
void CompactLookupTable::init(STATE) {
- GO(compactlookuptable).set(state->vm()->new_class("CompactLookupTable",
+ GO(compactlookuptable).set(ontology::new_class(state, "CompactLookupTable",
G(tuple), G(rubinius)));
G(compactlookuptable)->set_object_type(state, CompactLookupTableType);
G(compactlookuptable)->name(state, state->symbol("Rubinius::CompactLookupTable"));
View
5 vm/builtin/compiledmethod.cpp
@@ -29,6 +29,8 @@
#include "on_stack.hpp"
+#include "ontology.hpp"
+
#ifdef ENABLE_LLVM
#include "llvm/state.hpp"
#include "llvm/jit_compiler.hpp"
@@ -38,7 +40,8 @@
namespace rubinius {
void CompiledMethod::init(STATE) {
- GO(cmethod).set(state->vm()->new_class("CompiledMethod", G(executable), G(rubinius)));
+ GO(cmethod).set(ontology::new_class(state,
+ "CompiledMethod", G(executable), G(rubinius)));
G(cmethod)->set_object_type(state, CompiledMethodType);
G(cmethod)->name(state, state->symbol("Rubinius::CompiledMethod"));
}
View
4 vm/builtin/data.cpp
@@ -7,10 +7,12 @@
#include "capi/capi.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
void Data::init(STATE) {
- GO(data).set(state->vm()->new_class("Data", G(object)));
+ GO(data).set(ontology::new_class(state, "Data", G(object)));
G(data)->set_object_type(state, DataType);
}
View
4 vm/builtin/dir.cpp
@@ -10,12 +10,14 @@
#include "object_utils.hpp"
+#include "ontology.hpp"
+
#include <sys/types.h>
#include <dirent.h>
namespace rubinius {
void Dir::init(STATE) {
- GO(dir).set(state->vm()->new_class("Dir", G(object)));
+ GO(dir).set(ontology::new_class(state, "Dir", G(object)));
G(dir)->set_object_type(state, DirType);
}
View
6 vm/builtin/encoding.cpp
@@ -8,6 +8,8 @@
#include "object_utils.hpp"
+#include "ontology.hpp"
+
#include <ctype.h>
extern OnigEncodingType OnigEncodingASCII;
@@ -17,10 +19,10 @@ namespace rubinius {
void Encoding::init(STATE) {
onig_init(); // in regexp.cpp too, but idempotent.
- Class* enc = state->vm()->new_class_under("Encoding", G(rubinius));
+ Class* enc = ontology::new_class_under(state, "Encoding", G(rubinius));
enc->name(state, state->symbol("Rubinius::Encoding"));
- GO(encoding).set(state->vm()->new_class_under("Encoding", enc));
+ GO(encoding).set(ontology::new_class_under(state, "Encoding", enc));
G(encoding)->set_object_type(state, EncodingType);
G(encoding)->name(state, state->symbol("Encoding"));
View
4 vm/builtin/exception.cpp
@@ -20,11 +20,13 @@
#include "configuration.hpp"
+#include "ontology.hpp"
+
#include <iostream>
namespace rubinius {
void Exception::init(STATE) {
- GO(exception).set(state->vm()->new_class("Exception", G(object)));
+ GO(exception).set(ontology::new_class(state, "Exception", G(object)));
G(exception)->set_object_type(state, ExceptionType);
}
View
4 vm/builtin/executable.cpp
@@ -12,10 +12,12 @@
#include "call_frame.hpp"
#include "objectmemory.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
void Executable::init(STATE) {
- GO(executable).set(state->vm()->new_class("Executable", G(object), G(rubinius)));
+ GO(executable).set(ontology::new_class(state, "Executable", G(object), G(rubinius)));
G(executable)->set_object_type(state, ExecutableType);
G(executable)->name(state, state->symbol("Rubinius::Executable"));
}
View
4 vm/builtin/ffi_pointer.cpp
@@ -30,13 +30,15 @@
#include "arguments.hpp"
#include "dispatch.hpp"
+#include "ontology.hpp"
+
#include "windows_compat.h"
namespace rubinius {
void Pointer::init(STATE) {
Module* ffi = as<Module>(G(object)->get_const(state, "FFI"));
- GO(ffi_pointer).set(state->vm()->new_class_under("Pointer", ffi));
+ GO(ffi_pointer).set(ontology::new_class_under(state, "Pointer", ffi));
G(ffi_pointer)->set_object_type(state, PointerType);
G(ffi_pointer)->set_const(state, "CURRENT_PROCESS",
View
4 vm/builtin/fiber.cpp
@@ -16,6 +16,8 @@
#include "call_frame.hpp"
#include "arguments.hpp"
+#include "ontology.hpp"
+
#include "on_stack.hpp"
#ifdef FIBER_NATIVE
@@ -122,7 +124,7 @@ struct fiber_context_t {
namespace rubinius {
void Fiber::init(STATE) {
- GO(fiber).set(state->vm()->new_class("Fiber", G(object), G(rubinius)));
+ GO(fiber).set(ontology::new_class(state, "Fiber", G(object), G(rubinius)));
G(fiber)->set_object_type(state, FiberType);
#ifdef FIBER_ENABLED
View
4 vm/builtin/fixnum.cpp
@@ -10,12 +10,14 @@
#include "vm/object_utils.hpp"
#include "vm/configuration.hpp"
+#include "ontology.hpp"
+
#include <iostream>
namespace rubinius {
void Fixnum::init(STATE) {
- GO(fixnum_class).set(state->vm()->new_class("Fixnum", G(integer)));
+ GO(fixnum_class).set(ontology::new_class(state, "Fixnum", G(integer)));
G(fixnum_class)->set_object_type(state, FixnumType);
G(fixnum_class)->set_const(state, "MIN", Fixnum::from(FIXNUM_MIN));
View
4 vm/builtin/float.cpp
@@ -10,6 +10,8 @@
#include "primitives.hpp"
#include "configuration.hpp"
+#include "ontology.hpp"
+
#include <gdtoa.h>
#include <string.h>
@@ -22,7 +24,7 @@
namespace rubinius {
void Float::init(STATE) {
- GO(floatpoint).set(state->vm()->new_class("Float", G(numeric)));
+ GO(floatpoint).set(ontology::new_class(state, "Float", G(numeric)));
G(floatpoint)->set_object_type(state, FloatType);
G(floatpoint)->set_const(state, "RADIX", Fixnum::from(FLT_RADIX));
View
5 vm/builtin/global_cache_entry.cpp
@@ -2,10 +2,13 @@
#include "builtin/class.hpp"
#include "builtin/staticscope.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
void GlobalCacheEntry::init(STATE) {
GO(global_cache_entry).set(
- state->vm()->new_class("GlobalCacheEntry", G(object), G(rubinius)));
+ ontology::new_class(state, "GlobalCacheEntry",
+ G(object), G(rubinius)));
}
GlobalCacheEntry* GlobalCacheEntry::create(STATE, Object *value,
View
7 vm/builtin/io.cpp
@@ -38,14 +38,17 @@
#include "capi/handle.hpp"
+#include "ontology.hpp"
+
#include "windows_compat.h"
namespace rubinius {
void IO::init(STATE) {
- GO(io).set(state->vm()->new_class("IO", G(object)));
+ GO(io).set(ontology::new_class(state, "IO", G(object)));
G(io)->set_object_type(state, IOType);
- GO(iobuffer).set(state->vm()->new_class("InternalBuffer", G(object), G(io)));
+ GO(iobuffer).set(ontology::new_class(state, "InternalBuffer",
+ G(object), G(io)));
G(iobuffer)->set_object_type(state, IOBufferType);
}
View
5 vm/builtin/iseq.cpp
@@ -2,11 +2,14 @@
#include "builtin/iseq.hpp"
#include "builtin/tuple.hpp"
+#include "ontology.hpp"
+
#include "vm.hpp"
namespace rubinius {
void InstructionSequence::init(STATE) {
- GO(iseq).set(state->vm()->new_class("InstructionSequence", G(object), G(rubinius)));
+ GO(iseq).set(ontology::new_class(state,
+ "InstructionSequence", G(object), G(rubinius)));
G(iseq)->set_object_type(state, InstructionSequenceType);
}
View
7 vm/builtin/list.cpp
@@ -6,6 +6,8 @@
#include "builtin/class.hpp"
#include "builtin/fixnum.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
/* Returns true if the List is empty, contains no elements. */
@@ -21,13 +23,14 @@ namespace rubinius {
/* Register the List and List::Node classes as globals */
void List::init(STATE) {
Class* cls;
- cls = state->vm()->new_class_under("List", G(rubinius));
+ cls = ontology::new_class_under(state, "List", G(rubinius));
GO(list).set(cls);
cls->set_object_type(state, ListType);
G(list)->name(state, state->symbol("Rubinius::List"));
- GO(list_node).set(state->vm()->new_class("Node", G(object), cls));
+ GO(list_node).set(ontology::new_class_under(state,
+ "Node", cls));
G(list_node)->set_object_type(state, ListNodeType);
}
View
5 vm/builtin/location.cpp
@@ -10,11 +10,14 @@
#include "call_frame.hpp"
+#include "ontology.hpp"
+
#include <sstream>
namespace rubinius {
void Location::init(STATE) {
- GO(location).set(state->vm()->new_class("Location", G(object), G(rubinius)));
+ GO(location).set(ontology::new_class(state, "Location",
+ G(object), G(rubinius)));
G(location)->set_object_type(state, LocationType);
G(location)->name(state, state->symbol("Rubinius::Location"));
}
View
7 vm/builtin/nativefunction.cpp
@@ -31,6 +31,8 @@
#include "builtin/location.hpp"
#include "builtin/nativemethod.hpp"
+#include "ontology.hpp"
+
#include "ffi_util.hpp"
#include "arguments.hpp"
#include "dispatch.hpp"
@@ -42,9 +44,8 @@
namespace rubinius {
void NativeFunction::init(STATE) {
- GO(native_function).set(state->vm()->new_class("NativeFunction",
- G(executable),
- G(rubinius)));
+ GO(native_function).set(ontology::new_class(state,
+ "NativeFunction", G(executable), G(rubinius)));
G(native_function)->set_object_type(state, NativeFunctionType);
}
View
5 vm/builtin/nativemethod.cpp
@@ -24,6 +24,8 @@
#include "instruments/tooling.hpp"
+#include "ontology.hpp"
+
#include "capi/capi.hpp"
#include "capi/handle.hpp"
@@ -181,7 +183,8 @@ namespace rubinius {
}
void NativeMethod::init(STATE) {
- GO(nmethod).set(state->vm()->new_class("NativeMethod", G(executable), G(rubinius)));
+ GO(nmethod).set(ontology::new_class(state, "NativeMethod",
+ G(executable), G(rubinius)));
G(nmethod)->set_object_type(state, NativeMethodType);
init_thread(state);
View
4 vm/builtin/proc.cpp
@@ -17,10 +17,12 @@
#include "call_frame.hpp"
#include "configuration.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
void Proc::init(STATE) {
- GO(proc).set(state->vm()->new_class("Proc", G(object)));
+ GO(proc).set(ontology::new_class(state, "Proc", G(object)));
G(proc)->set_object_type(state, ProcType);
}
View
5 vm/builtin/randomizer.cpp
@@ -13,6 +13,8 @@
#include "object_utils.hpp"
+#include "ontology.hpp"
+
/*
* For gen_seed:
*/
@@ -233,7 +235,8 @@ namespace rubinius {
void Randomizer::init(STATE) {
- GO(randomizer).set(state->vm()->new_class("Randomizer", G(object), G(rubinius)));
+ GO(randomizer).set(ontology::new_class(state,
+ "Randomizer", G(object), G(rubinius)));
G(randomizer)->set_object_type(state, RandomizerType);
}
View
6 vm/builtin/regexp.cpp
@@ -21,6 +21,8 @@
#include "util/atomic.hpp"
+#include "ontology.hpp"
+
#define OPTION_IGNORECASE ONIG_OPTION_IGNORECASE
#define OPTION_EXTENDED ONIG_OPTION_EXTEND
#define OPTION_MULTILINE ONIG_OPTION_MULTILINE
@@ -39,10 +41,10 @@ namespace rubinius {
void Regexp::init(STATE) {
onig_init();
- GO(regexp).set(state->vm()->new_class("Regexp", G(object), 0));
+ GO(regexp).set(ontology::new_class(state, "Regexp", G(object), 0));
G(regexp)->set_object_type(state, RegexpType);
- GO(matchdata).set(state->vm()->new_class("MatchData", G(object), 0));
+ GO(matchdata).set(ontology::new_class(state, "MatchData", G(object), 0));
G(matchdata)->set_object_type(state, MatchDataType);
}
View
5 vm/builtin/staticscope.cpp
@@ -9,11 +9,14 @@
#include "call_frame.hpp"
+#include "ontology.hpp"
+
#include <sstream>
namespace rubinius {
void StaticScope::init(STATE) {
- GO(staticscope).set(state->vm()->new_class("StaticScope", G(object), G(rubinius)));
+ GO(staticscope).set(ontology::new_class(state,
+ "StaticScope", G(object), G(rubinius)));
G(staticscope)->set_object_type(state, StaticScopeType);
G(staticscope)->name(state, state->symbol("Rubinius::StaticScope"));
}
View
4 vm/builtin/string.cpp
@@ -18,6 +18,8 @@
#include "windows_compat.h"
+#include "ontology.hpp"
+
#include <gdtoa.h>
#include <unistd.h>
@@ -29,7 +31,7 @@
namespace rubinius {
void String::init(STATE) {
- GO(string).set(state->vm()->new_class("String", G(object)));
+ GO(string).set(ontology::new_class(state, "String", G(object)));
G(string)->set_object_type(state, StringType);
}
View
4 vm/builtin/symbol.cpp
@@ -9,6 +9,8 @@
#include "vm/object_utils.hpp"
#include "objectmemory.hpp"
+#include "ontology.hpp"
+
#include <iostream>
#define StartSize 16
@@ -16,7 +18,7 @@
namespace rubinius {
void Symbol::init(STATE) {
- GO(symbol).set(state->vm()->new_class("Symbol"));
+ GO(symbol).set(ontology::new_class(state, "Symbol"));
G(symbol)->set_object_type(state, Symbol::type);
}
View
4 vm/builtin/thread.cpp
@@ -22,6 +22,8 @@
#include "on_stack.hpp"
+#include "ontology.hpp"
+
#include "windows_compat.h"
#include <sys/time.h>
@@ -50,7 +52,7 @@ static intptr_t thread_debug_id(pthread_t thr) {
namespace rubinius {
void Thread::init(STATE) {
- GO(thread).set(state->vm()->new_class("Thread", G(object)));
+ GO(thread).set(ontology::new_class(state, "Thread", G(object)));
G(thread)->set_object_type(state, Thread::type);
}
View
4 vm/builtin/time.cpp
@@ -12,6 +12,8 @@
#include "builtin/string.hpp"
#include "builtin/time.hpp"
+#include "ontology.hpp"
+
#include "util/time.h"
#include <sys/time.h>
@@ -21,7 +23,7 @@
namespace rubinius {
void Time::init(STATE) {
- GO(time_class).set(state->vm()->new_class("Time", G(object)));
+ GO(time_class).set(ontology::new_class(state, "Time", G(object)));
G(time_class)->set_object_type(state, TimeType);
}
View
5 vm/builtin/variable_scope.cpp
@@ -9,9 +9,12 @@
#include "builtin/system.hpp"
#include "builtin/tuple.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
void VariableScope::init(STATE) {
- GO(variable_scope).set(state->vm()->new_class("VariableScope", G(object), G(rubinius)));
+ GO(variable_scope).set(ontology::new_class(state,
+ "VariableScope", G(object), G(rubinius)));
G(variable_scope)->set_object_type(state, VariableScopeType);
G(variable_scope)->name(state, state->symbol("Rubinius::VariableScope"));
}
View
4 vm/builtin/weakref.cpp
@@ -4,9 +4,11 @@
#include "object_utils.hpp"
#include "gc/gc.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
void WeakRef::init(STATE) {
- GO(cls_weakref).set(state->vm()->new_class("WeakRef", G(object)));
+ GO(cls_weakref).set(ontology::new_class(state, "WeakRef", G(object)));
G(cls_weakref)->set_object_type(state, WeakRefType);
}
View
4 vm/ffi.cpp
@@ -27,10 +27,12 @@
#include "ffi_util.hpp"
#include "arguments.hpp"
+#include "ontology.hpp"
+
namespace rubinius {
void VM::init_ffi(STATE) {
- Module* mod = new_module("FFI");
+ Module* mod = ontology::new_module(state, "FFI");
mod->set_const(state, "TYPE_OBJECT", Fixnum::from(RBX_FFI_TYPE_OBJECT));
mod->set_const(state, "TYPE_CHAR", Fixnum::from(RBX_FFI_TYPE_CHAR));
mod->set_const(state, "TYPE_UCHAR", Fixnum::from(RBX_FFI_TYPE_UCHAR));
View
23 vm/objectmemory.cpp
@@ -56,6 +56,7 @@ namespace rubinius {
, running_finalizers_(false)
, added_finalizers_(false)
, finalizer_thread_(state, nil<Thread>())
+ , shared_(state->shared)
, collect_young_now(false)
, collect_mature_now(false)
@@ -416,7 +417,7 @@ namespace rubinius {
if(Object* obj = young_->raw_allocate(bytes, &collect_young_now)) {
gc_stats.young_object_allocated(bytes);
- if(collect_young_now) root_state_->shared.gc_soon();
+ if(collect_young_now) shared_.gc_soon();
obj->init_header(cls, YoungObjectZone, type);
return obj;
} else {
@@ -876,15 +877,13 @@ namespace rubinius {
gc_stats.mature_object_allocated(bytes);
- if(collect_mature_now) {
- root_state_->shared.gc_soon();
- }
+ if(collect_mature_now) shared_.gc_soon();
} else {
obj = young_->allocate(bytes, &collect_young_now);
if(unlikely(obj == NULL)) {
collect_young_now = true;
- root_state_->shared.gc_soon();
+ shared_.gc_soon();
obj = immix_->allocate(bytes);
@@ -894,9 +893,7 @@ namespace rubinius {
gc_stats.mature_object_allocated(bytes);
- if(collect_mature_now) {
- root_state_->shared.gc_soon();
- }
+ if(collect_mature_now) shared_.gc_soon();
} else {
gc_stats.young_object_allocated(bytes);
}
@@ -929,9 +926,7 @@ namespace rubinius {
gc_stats.mature_object_allocated(bytes);
}
- if(collect_mature_now) {
- root_state_->shared.gc_soon();
- }
+ if(collect_mature_now) shared_.gc_soon();
#ifdef ENABLE_OBJECT_WATCH
if(watched_p(obj)) {
@@ -988,9 +983,7 @@ namespace rubinius {
Object* obj = mark_sweep_->allocate(bytes, &collect_mature_now);
gc_stats.mature_object_allocated(bytes);
- if(collect_mature_now) {
- root_state_->shared.gc_soon();
- }
+ if(collect_mature_now) shared_.gc_soon();
#ifdef ENABLE_OBJECT_WATCH
if(watched_p(obj)) {
@@ -1398,7 +1391,7 @@ namespace rubinius {
};
void ObjectMemory::find_referers(Object* target, ObjectArray& result) {
- ObjectMemory::GCInhibit inhibitor(root_state_->om);
+ ObjectMemory::GCInhibit inhibitor(this);
ObjectWalker walker(root_state_->om);
GCData gc_data(root_state_);
View
2  vm/objectmemory.hpp
@@ -184,6 +184,8 @@ namespace rubinius {
TypedRoot<Thread*> finalizer_thread_;
+ SharedState& shared_;
+
public:
/// Flag indicating whether a young collection should be performed soon
bool collect_young_now;
View
105 vm/ontology.cpp
@@ -44,15 +44,63 @@
#include "builtin/fiber.hpp"
#include "builtin/alias.hpp"
#include "builtin/randomizer.hpp"
+#include "builtin/module.hpp"
+#include "builtin/class.hpp"
#include "configuration.hpp"
#include "config.h"
#include "revision.h"
+#include "ontology.hpp"
+
#define SPECIAL_CLASS_MASK 0x1f
#define SPECIAL_CLASS_SIZE 32
namespace rubinius {
+ namespace ontology {
+ Class* new_basic_class(STATE, Class* sup) {
+ Class *cls = state->memory()->new_object_enduring<Class>(state, G(klass));
+ cls->init(state->shared().inc_class_count(state));
+
+ if(sup->nil_p()) {
+ cls->instance_type(state, Fixnum::from(ObjectType));
+ cls->set_type_info(state->vm()->find_type(ObjectType));
+ } else {
+ cls->instance_type(state, sup->instance_type());
+ cls->set_type_info(sup->type_info());
+ }
+ cls->superclass(state, sup);
+
+ return cls;
+ }
+
+ Class* new_class(STATE, const char* name) {
+ return new_class(state, name, G(object), G(object));
+ }
+
+ Class* new_class(STATE, const char* name, Class* sup,
+ Module* under)
+ {
+ if(!under) under = G(object);
+
+ Class* cls = new_basic_class(state, sup);
+ cls->setup(state, name, under);
+
+ // HACK test that we've got the MOP setup properly
+ SingletonClass::attach(state, cls, sup->singleton_class(state));
+ return cls;
+ }
+
+ Class* new_class_under(STATE, const char* name, Module* under) {
+ return new_class(state, name, G(object), under);
+ }
+
+ Module* new_module(STATE, const char* name, Module* under) {
+ Module *mod = state->new_object<Module>(G(module));
+ mod->setup(state, name, under);
+ return mod;
+ }
+ }
// Reset macros since we're inside state
#undef G
@@ -76,7 +124,7 @@ namespace rubinius {
cls->set_obj_type(ClassType);
cls->set_object_type(state, ClassType);
- cls->set_class_id(shared.inc_class_count(state));
+ cls->set_class_id(state->shared().inc_class_count(state));
cls->set_packed_size(0);
// Set Class into the globals
@@ -86,43 +134,43 @@ namespace rubinius {
Class* basicobject = 0;
Class* object;
if(!LANGUAGE_18_ENABLED(state)) {
- basicobject = new_basic_class(force_as<Class>(Qnil));
+ basicobject = ontology::new_basic_class(state, force_as<Class>(Qnil));
GO(basicobject).set(basicobject);
basicobject->set_object_type(state, BasicObjectType);
- object = new_basic_class(basicobject);
+ object = ontology::new_basic_class(state, basicobject);
} else {
- object = new_basic_class(nil<Class>());
+ object = ontology::new_basic_class(state, nil<Class>());
}
GO(object).set(object);
object->set_object_type(state, ObjectType);
// Now Module
- GO(module).set(new_basic_class(object));
+ GO(module).set(ontology::new_basic_class(state, object));
G(module)->set_object_type(state, ModuleType);
// Fixup Class's superclass to be Module
cls->superclass(state, G(module));
// Create Tuple
- GO(tuple).set(new_basic_class(object));
+ GO(tuple).set(ontology::new_basic_class(state, object));
G(tuple)->set_object_type(state, TupleType);
// Create LookupTable
- GO(lookuptable).set(new_basic_class(object));
+ GO(lookuptable).set(ontology::new_basic_class(state, object));
G(lookuptable)->set_object_type(state, LookupTableType);
// Create LookupTableBucket
- GO(lookuptablebucket).set(new_basic_class(object));
+ GO(lookuptablebucket).set(ontology::new_basic_class(state, object));
G(lookuptablebucket)->set_object_type(state, LookupTableBucketType);
// Create MethodTable
- GO(methtbl).set(new_basic_class(object));
+ GO(methtbl).set(ontology::new_basic_class(state, object));
G(methtbl)->set_object_type(state, MethodTableType);
// Create MethodTableBucket
- GO(methtblbucket).set(new_basic_class(object));
+ GO(methtblbucket).set(ontology::new_basic_class(state, object));
G(methtblbucket)->set_object_type(state, MethodTableBucketType);
/* Now, we have:
@@ -188,7 +236,7 @@ namespace rubinius {
G(module)->setup(state, "Module");
// Create the namespace for various implementation classes
- GO(rubinius).set(new_module("Rubinius"));
+ GO(rubinius).set(ontology::new_module(state, "Rubinius"));
// Finish initializing the rest of the special 8
G(tuple)->setup(state, "Tuple", G(rubinius));
@@ -207,21 +255,21 @@ namespace rubinius {
void VM::initialize_builtin_classes(STATE) {
// Create the immediate classes.
- GO(nil_class).set(new_class("NilClass"));
+ GO(nil_class).set(ontology::new_class(state, "NilClass"));
G(nil_class)->set_object_type(state, NilType);
GO(nil_class)->type_info()->allow_user_allocate = false;
- GO(true_class).set(new_class("TrueClass"));
+ GO(true_class).set(ontology::new_class(state, "TrueClass"));
G(true_class)->set_object_type(state, TrueType);
GO(true_class)->type_info()->allow_user_allocate = false;
- GO(false_class).set(new_class("FalseClass"));
+ GO(false_class).set(ontology::new_class(state, "FalseClass"));
G(false_class)->set_object_type(state, FalseType);
GO(false_class)->type_info()->allow_user_allocate = false;
- Class* numeric = new_class("Numeric");
+ Class* numeric = ontology::new_class(state, "Numeric");
GO(numeric).set(numeric);
- Class* integer = new_class("Integer", numeric);
+ Class* integer = ontology::new_class(state, "Integer", numeric);
GO(integer).set(integer);
Fixnum::init(state);
Symbol::init(state);
@@ -243,7 +291,8 @@ namespace rubinius {
globals().special_classes[(uintptr_t)Qtrue ] = GO(true_class);
/* Create IncludedModule */
- GO(included_module).set(new_class("IncludedModule", G(module), G(rubinius)));
+ GO(included_module).set(ontology::new_class(state,
+ "IncludedModule", G(module), G(rubinius)));
G(included_module)->set_object_type(state, IncludedModuleType);
G(included_module)->name(state, symbol("Rubinius::IncludedModule"));
@@ -327,10 +376,10 @@ namespace rubinius {
Object* undef = new_object<Object>(G(object));
GO(undefined).set(undef);
- GO(vm).set(new_class_under("VM", G(rubinius)));
+ GO(vm).set(ontology::new_class_under(state, "VM", G(rubinius)));
G(vm)->name(state, state->symbol("Rubinius::VM"));
- GO(type).set(new_module("Type", G(rubinius)));
+ GO(type).set(ontology::new_module(state, "Type", G(rubinius)));
G(type)->name(state, state->symbol("Rubinius::Type"));
System::bootstrap_methods(state);
@@ -458,7 +507,7 @@ namespace rubinius {
if(found) {
ern->set_const(state, symbol(name), current);
} else {
- Class* cls = state->vm()->new_class(name, sce, ern);
+ Class* cls = ontology::new_class(state, name, sce, ern);
// new_class has simply name setting logic that doesn't take into account
// being not under Object. So we set it again using the smart method.
@@ -474,7 +523,7 @@ namespace rubinius {
Class *exc, *scp, *std, *arg, *nam, *loe, *rex, *stk, *sxp, *sce, *type, *lje, *vme;
Class *rng, *rte;
-#define dexc(name, sup) new_class(#name, sup)
+#define dexc(name, sup) ontology::new_class(state, #name, sup)
exc = G(exception);
scp = dexc(ScriptError, exc);
@@ -498,14 +547,16 @@ namespace rubinius {
GO(jump_error).set(lje);
- GO(exc_vm_internal).set(new_class("Internal", exc, G(rubinius)));
+ GO(exc_vm_internal).set(ontology::new_class(state,
+ "Internal", exc, G(rubinius)));
GO(exc_vm_bad_bytecode).set(
- new_class("InvalidBytecode", G(exc_vm_internal), G(rubinius)));
+ ontology::new_class(state, "InvalidBytecode",
+ G(exc_vm_internal), G(rubinius)));
// Some special exceptions scoped under the Rubinius module
- vme = new_class("VMException", exc, G(rubinius));
- new_class("AssertionError", vme, G(rubinius));
- new_class("ObjectBoundsExceededError", vme, G(rubinius));
+ vme = ontology::new_class(state, "VMException", exc, G(rubinius));
+ ontology::new_class(state, "AssertionError", vme, G(rubinius));
+ ontology::new_class(state, "ObjectBoundsExceededError", vme, G(rubinius));
// Create the stack error object now, since we probably wont be
// able to later.
@@ -522,7 +573,7 @@ namespace rubinius {
GO(exc_segfault).set(dexc(MemorySegmentionError, exc));
- Module* ern = new_module("Errno");
+ Module* ern = ontology::new_module(state, "Errno");
GO(errno_mapping).set(LookupTable::create(state));
View
26 vm/ontology.hpp
@@ -0,0 +1,26 @@
+#ifndef RBX_VM_ONTOLOGPY_HPP
+#define RBX_VM_ONTOLOGPY_HPP
+
+namespace rubinius {
+ class Class;
+ class Module;
+
+ namespace ontology {
+ /// Create an uninitialized Class object
+ Class* new_basic_class(STATE, Class* sup);
+
+ /// Create a Class of name +name+ as an Object subclass
+ Class* new_class(STATE, const char* name);
+
+ /// Create a Class of name +name+ as a subclass of +super_class+
+ Class* new_class(STATE, const char* name, Class* super_class,
+ Module* under = 0);
+
+ /// Create a Class of name +name+ under +under+
+ Class* new_class_under(STATE, const char* name, Module* under);
+
+ Module* new_module(STATE, const char* name, Module* under = NULL);
+ }
+}
+
+#endif
View
4 vm/test/test_array.hpp
@@ -6,6 +6,8 @@
#include "ffi_util.hpp"
+#include "ontology.hpp"
+
class TestArray : public CxxTest::TestSuite, public VMTest {
public:
@@ -18,7 +20,7 @@ class TestArray : public CxxTest::TestSuite, public VMTest {
}
void test_allocate() {
- Class* sub = state->vm()->new_class("ArraySub", G(array), 0);
+ Class* sub = ontology::new_class(state, "ArraySub", G(array), 0);
Array* ary = Array::allocate(state, sub);
TS_ASSERT_EQUALS(ary->klass(), sub);
View
4 vm/test/test_lookuptable.hpp
@@ -1,5 +1,7 @@
#include "vm/test/test.hpp"
+#include "ontology.hpp"
+
class TestLookupTable : public CxxTest::TestSuite, public VMTest {
public:
@@ -20,7 +22,7 @@ class TestLookupTable : public CxxTest::TestSuite, public VMTest {
}
void test_allocate() {
- Class* sub = state->vm()->new_class("LookupTableSub", G(lookuptable), 0);
+ Class* sub = ontology::new_class(state, "LookupTableSub", G(lookuptable), 0);
LookupTable* tbl = LookupTable::allocate(state, sub);
TS_ASSERT_EQUALS(tbl->klass(), sub);
View
4 vm/test/test_regexp.hpp
@@ -2,6 +2,8 @@
#include "builtin/regexp.hpp"
+#include "ontology.hpp"
+
class TestRegexp : public CxxTest::TestSuite, public VMTest {
public:
@@ -35,7 +37,7 @@ class TestRegexp : public CxxTest::TestSuite, public VMTest {
}
void test_allocate() {
- Class* sub = state->vm()->new_class("RegexpSub", G(regexp), 0);
+ Class* sub = ontology::new_class(state, "RegexpSub", G(regexp), 0);
Regexp* re = Regexp::allocate(state, sub);
TS_ASSERT_EQUALS(re->klass(), sub);
View
49 vm/vm.cpp
@@ -230,55 +230,6 @@ namespace rubinius {
return new_object_typed(cls, ti->instance_size, ti->type);
}
- Class* VM::new_basic_class(Class* sup) {
- State state(this);
-
- Class *cls = om->new_object_enduring<Class>(&state, G(klass));
- cls->init(shared.inc_class_count(&state));
-
- if(sup->nil_p()) {
- cls->instance_type(this, Fixnum::from(ObjectType));
- cls->set_type_info(find_type(ObjectType));
- } else {
- cls->instance_type(this, sup->instance_type()); // HACK test that this is always true
- cls->set_type_info(sup->type_info());
- }
- cls->superclass(this, sup);
-
- return cls;
- }
-
- Class* VM::new_class(const char* name) {
- return new_class(name, G(object), G(object));
- }
-
- Class* VM::new_class(const char* name, Class* super_class) {
- return new_class(name, super_class, G(object));
- }
-
- Class* VM::new_class(const char* name, Class* sup, Module* under) {
- State state(this);
-
- Class* cls = new_basic_class(sup);
- cls->setup(&state, name, under);
-
- // HACK test that we've got the MOP setup properly
- SingletonClass::attach(&state, cls, sup->singleton_class(&state));
- return cls;
- }
-
- Class* VM::new_class_under(const char* name, Module* under) {
- return new_class(name, G(object), under);
- }
-
- Module* VM::new_module(const char* name, Module* under) {
- State state(this);
-
- Module *mod = new_object<Module>(G(module));
- mod->setup(&state, name, under);
- return mod;
- }
-
Symbol* VM::symbol(const char* str) {
return shared.symbols.lookup(str, strlen(str));
}
View
18 vm/vm.hpp
@@ -312,24 +312,6 @@ namespace rubinius {
/// Create a Tuple in the young GC space, return NULL if not possible.
Tuple* new_young_tuple_dirty(size_t fields);
- /// Create an uninitialized Class object
- Class* new_basic_class(Class* sup);
-
- /// Create a Class of name +name+ as an Object subclass
- Class* new_class(const char* name);
-
- /// Create a Class of name +name+ as a subclass of +super_class+
- Class* new_class(const char* name, Class* super_class);
-
- /// Create a Class of name +name+ as a subclass of +sup+
- /// under Module +under+
- Class* new_class(const char* name, Class* sup, Module* under);
-
- /// Create a Class of name +name+ under +under+
- Class* new_class_under(const char* name, Module* under);
-
- Module* new_module(const char* name, Module* under = NULL);
-
Symbol* symbol(const char* str);
Symbol* symbol(std::string str);
Symbol* symbol(String* str);
Please sign in to comment.
Something went wrong with that request. Please try again.