Permalink
Browse files

Merge branch 'cpp' of git@github.com:evanphx/rubinius into cpp

  • Loading branch information...
2 parents 574448c + 27eff18 commit 940478093dee1270a3515e62aae59d9bc95a3dd7 Ryan Davis committed Sep 12, 2008
Showing with 1,938 additions and 1,549 deletions.
  1. +4 −0 kernel/bootstrap/vm.rb
  2. +1 −0 kernel/common/signal.rb
  3. +1 −1 kernel/common/string.rb
  4. +2 −0 kernel/loader.rb
  5. +1 −1 lib/compiler/init.rb
  6. +1 −1 vm/builtin/access_variable.cpp
  7. +11 −2 vm/builtin/access_variable.hpp
  8. +21 −21 vm/builtin/array.cpp
  9. +16 −5 vm/builtin/array.hpp
  10. +1 −1 vm/builtin/bignum.cpp
  11. +17 −17 vm/builtin/block_environment.cpp
  12. +18 −5 vm/builtin/block_environment.hpp
  13. +1 −1 vm/builtin/bytearray.cpp
  14. +9 −9 vm/builtin/channel.cpp
  15. +11 −2 vm/builtin/channel.hpp
  16. +11 −12 vm/builtin/class.cpp
  17. +26 −9 vm/builtin/class.hpp
  18. +1 −1 vm/builtin/compactlookuptable.cpp
  19. +27 −31 vm/builtin/compiledmethod.cpp
  20. +34 −15 vm/builtin/compiledmethod.hpp
  21. +44 −36 vm/builtin/contexts.cpp
  22. +28 −9 vm/builtin/contexts.hpp
  23. +9 −9 vm/builtin/dir.cpp
  24. +10 −2 vm/builtin/dir.hpp
  25. +12 −2 vm/builtin/exception.hpp
  26. +15 −3 vm/builtin/executable.hpp
  27. +1 −1 vm/builtin/float.cpp
  28. +21 −21 vm/builtin/io.cpp
  29. +28 −8 vm/builtin/io.hpp
  30. +2 −2 vm/builtin/iseq.cpp
  31. +11 −2 vm/builtin/iseq.hpp
  32. +29 −29 vm/builtin/list.cpp
  33. +24 −7 vm/builtin/list.hpp
  34. +25 −25 vm/builtin/lookuptable.cpp
  35. +14 −5 vm/builtin/lookuptable.hpp
  36. +1 −1 vm/builtin/memorypointer.cpp
  37. +2 −2 vm/builtin/methodvisibility.cpp
  38. +14 −5 vm/builtin/methodvisibility.hpp
  39. +19 −19 vm/builtin/module.cpp
  40. +25 −7 vm/builtin/module.hpp
  41. +10 −10 vm/builtin/nativefunction.cpp
  42. +15 −4 vm/builtin/nativefunction.hpp
  43. +36 −25 vm/builtin/object.cpp
  44. +40 −1 vm/builtin/object.hpp
  45. +11 −11 vm/builtin/regexp.cpp
  46. +28 −8 vm/builtin/regexp.hpp
  47. +7 −7 vm/builtin/selector.cpp
  48. +12 −4 vm/builtin/selector.hpp
  49. +15 −15 vm/builtin/sendsite.cpp
  50. +17 −5 vm/builtin/sendsite.hpp
  51. +1 −1 vm/builtin/staticscope.cpp
  52. +11 −2 vm/builtin/staticscope.hpp
  53. +55 −55 vm/builtin/string.cpp
  54. +20 −7 vm/builtin/string.hpp
  55. +132 −125 vm/builtin/task.cpp
  56. +33 −14 vm/builtin/task.hpp
  57. +5 −5 vm/builtin/taskprobe.cpp
  58. +5 −5 vm/builtin/thread.cpp
  59. +13 −4 vm/builtin/thread.hpp
  60. +6 −6 vm/builtin/time.cpp
  61. +13 −3 vm/builtin/time.hpp
  62. +14 −16 vm/codegen/field_extract.rb
  63. +4 −4 vm/codegen/instructions_gen.rb
  64. +4 −5 vm/compiled_file.cpp
  65. +3 −3 vm/context_cache.cpp
  66. +3 −1 vm/context_cache.hpp
  67. +7 −7 vm/environment.cpp
  68. +1 −1 vm/event.cpp
  69. +5 −8 vm/gc.cpp
  70. +6 −7 vm/gc_baker.cpp
  71. +1 −7 vm/gc_marksweep.cpp
  72. +1 −1 vm/global_cache.hpp
  73. +224 −224 vm/instructions.rb
  74. +2 −2 vm/llvm.cpp
  75. +3 −3 vm/llvm/instructions.cpp
  76. +18 −18 vm/marshal.cpp
  77. +3 −3 vm/message.cpp
  78. +9 −7 vm/objectmemory.cpp
  79. +2 −10 vm/objectmemory.hpp
  80. +11 −12 vm/ontology.cpp
  81. +13 −0 vm/oop.cpp
  82. +4 −2 vm/oop.hpp
  83. +11 −11 vm/test/test_access_variable.hpp
  84. +1 −1 vm/test/test_array.hpp
  85. +14 −14 vm/test/test_bytearray.hpp
  86. +8 −8 vm/test/test_channel.hpp
  87. +6 −7 vm/test/test_class.hpp
  88. +5 −9 vm/test/test_compiled_file.hpp
  89. +2 −2 vm/test/test_compiledmethod.hpp
  90. +4 −4 vm/test/test_contexts.hpp
  91. +3 −3 vm/test/test_dir.hpp
  92. +2 −2 vm/test/test_event.hpp
  93. +2 −2 vm/test/test_io.hpp
  94. +19 −19 vm/test/test_lookuptable.hpp
  95. +1 −1 vm/test/test_marshal.hpp
  96. +5 −5 vm/test/test_message.hpp
  97. +4 −4 vm/test/test_module.hpp
  98. +22 −22 vm/test/test_nativefunction.hpp
  99. +44 −44 vm/test/test_object.hpp
  100. +40 −30 vm/test/test_objectmemory.hpp
  101. +30 −30 vm/test/test_ontology.hpp
  102. +23 −23 vm/test/test_regexp.hpp
  103. +5 −5 vm/test/test_selector.hpp
  104. +6 −6 vm/test/test_sendsite.hpp
  105. +28 −28 vm/test/test_string.hpp
  106. +207 −207 vm/test/test_task.hpp
  107. +2 −2 vm/test/test_thread.hpp
  108. +17 −17 vm/test/test_time.hpp
  109. +18 −18 vm/test/test_unmarshal.hpp
  110. +1 −1 vm/test/test_vm.hpp
  111. +8 −8 vm/test/test_vmmethod.hpp
  112. +3 −3 vm/type_info.cpp
  113. +14 −14 vm/vm.cpp
  114. +4 −4 vm/vmaccess_variable.cpp
  115. +7 −7 vm/vmmethod.cpp
  116. +1 −1 vm/vmnativefunction.cpp
View
4 kernel/bootstrap/vm.rb
@@ -8,6 +8,10 @@ def self.write_error(str)
Ruby.primitive :vm_write_error
end
+ def self.show_backtrace(ctx)
+ Ruby.primitive :vm_show_backtrace
+ end
+
def self.load_library(path, name)
Ruby.primitive :load_library
raise PrimitiveFailure, "primitive failed"
View
1 kernel/common/signal.rb
@@ -46,6 +46,7 @@ def self.trap(sig, prc=nil, pass_ctx=false, &block)
thr = Thread.new do
while true
ctx = chan.receive
+ ctx.__show__
# Run the handler in a new thread so chan.receive doesn't
# block signals during handler execution, e.g., a SIGINT
View
2 kernel/common/string.rb
@@ -23,7 +23,7 @@ def self.allocate
end
def self.from_bytearray(ba, count)
- str = super()
+ str = allocate()
str.data = ba
str.num_bytes = count
return str
View
2 kernel/loader.rb
@@ -12,6 +12,7 @@
exit 2
end
+if false
# Set up a handler for SIGINT that raises Interrupt on the main thread
Signal.action("INT") do |_|
thread = Thread.main
@@ -24,6 +25,7 @@
exit! 1
end
end
+end
# This is the end of the kernel and the beginning of specified
# code. We read out of ARGV to figure out what the user is
View
2 lib/compiler/init.rb
@@ -2,7 +2,7 @@
# When the compiler is compiled into an rba, use the modtime of
# compiler.rba as the version number
-if defined? RUBY_ENGINE and RUBY_ENGINE == "rbx"
+if false # defined? RUBY_ENGINE and RUBY_ENGINE == "rbx"
hints = __METHOD__.hints
if hints and hints[:source] == :rba
if path = $:.detect { |m| m.suffix? "compiler.rba" }
View
2 vm/builtin/access_variable.cpp
@@ -8,7 +8,7 @@ namespace rubinius {
// HACK test superclass of AccessVariable
GO(access_variable).set(state->new_class("AccessVariable", G(executable),
AccessVariable::fields));
- G(access_variable)->set_object_type(AccessVariableType);
+ G(access_variable)->set_object_type(state, AccessVariableType);
}
AccessVariable* AccessVariable::allocate(STATE) {
View
13 vm/builtin/access_variable.hpp
@@ -16,8 +16,17 @@ namespace rubinius {
const static size_t fields = Executable::fields + 2;
const static object_type type = AccessVariableType;
- SYMBOL name; // slot
- OBJECT write; // slot
+ private:
+ SYMBOL name_; // slot
+ OBJECT write_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(name, Symbol);
+ attr_accessor(write, Object);
+
+ /* interface */
static void init(STATE);
// Ruby.primitive :accessvariable_allocate
View
42 vm/builtin/array.cpp
@@ -17,11 +17,11 @@ namespace rubinius {
void Array::init(STATE) {
GO(array).set(state->new_class("Array", G(object), Array::fields));
- G(array)->set_object_type(ArrayType);
+ G(array)->set_object_type(state, ArrayType);
}
size_t Array::size() {
- return total->to_native();
+ return total_->to_native();
}
Array* Array::create(STATE, size_t idx) {
@@ -45,15 +45,15 @@ namespace rubinius {
}
void Array::setup(STATE, size_t size) {
- SET(this, tuple, Tuple::create(state, size));
- SET(this, start, Fixnum::from(0));
- SET(this, total, Fixnum::from(0));
+ this->tuple(state, Tuple::create(state, size));
+ this->start(state, Fixnum::from(0));
+ this->total(state, Fixnum::from(0));
}
OBJECT Array::aref(STATE, Fixnum* idx) {
native_int index = idx->to_native();
- if(index < 0 || index >= total->to_native()) {
+ if(index < 0 || index >= total_->to_native()) {
PrimitiveFailed::raise();
}
@@ -65,23 +65,23 @@ namespace rubinius {
}
OBJECT Array::get(STATE, size_t idx) {
- if(idx >= (size_t)total->to_native()) {
+ if(idx >= (size_t)total_->to_native()) {
return Qnil;
}
- idx += start->to_native();
+ idx += start_->to_native();
- return tuple->at(idx);
+ return tuple_->at(idx);
}
OBJECT Array::set(STATE, size_t idx, OBJECT val) {
size_t cur, oidx;
- Tuple* tup = tuple;
+ Tuple* tup = tuple_;
cur = tup->field_count;
oidx = idx;
- idx += start->to_native();
+ idx += start_->to_native();
if(idx >= cur) {
size_t new_size = (cur == 0) ? 1 : cur;
@@ -96,41 +96,41 @@ namespace rubinius {
nt->put(state, i, tup->at(i));
}
- SET(this, tuple, nt);
+ tuple(state, nt);
tup = nt;
}
tup->put(state, idx, val);
- if((size_t)total->to_native() <= oidx) {
- total = Fixnum::from(oidx+1);
+ if((size_t)total_->to_native() <= oidx) {
+ total(state, Fixnum::from(oidx+1));
}
return val;
}
void Array::unshift(STATE, OBJECT val) {
- size_t new_size = total->to_native() + 1;
+ size_t new_size = total_->to_native() + 1;
Tuple* nt = Tuple::create(state, new_size);
- for(size_t i = 0; i < (size_t)total->to_native(); i++) {
+ for(size_t i = 0; i < (size_t)total_->to_native(); i++) {
nt->put(state, i + 1, get(state, i));
}
nt->put(state, 0, val);
- total = Fixnum::from(new_size);
- start = Fixnum::from(0);
+ total(state, Fixnum::from(new_size));
+ start(state, Fixnum::from(0));
- tuple = nt;
+ tuple(state, nt);
}
OBJECT Array::append(STATE, OBJECT val) {
- set(state, (size_t)total->to_native(), val);
+ set(state, (size_t)total_->to_native(), val);
return val;
}
bool Array::includes_p(STATE, OBJECT val) {
size_t max = size();
for(size_t i = 0; i < max; i++) {
- if(tuple->at(i) == val) return true;
+ if(tuple_->at(i) == val) return true;
}
return false;
View
21 vm/builtin/array.hpp
@@ -9,14 +9,25 @@ namespace rubinius {
class Tuple;
class Array : public Object {
- public:
+ public:
const static size_t fields = 4;
const static object_type type = ArrayType;
- INTEGER total; // slot
- Tuple* tuple; // slot
- INTEGER start; // slot
- OBJECT shared; // slot
+ private:
+ INTEGER total_; // slot
+ Tuple* tuple_; // slot
+ INTEGER start_; // slot
+ OBJECT shared_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(total, Integer);
+ attr_accessor(tuple, Tuple);
+ attr_accessor(start, Integer);
+ attr_accessor(shared, Object);
+
+ /* interface */
size_t size();
static void init(STATE);
View
2 vm/builtin/bignum.cpp
@@ -209,7 +209,7 @@ namespace rubinius {
void Bignum::init(STATE) {
GO(bignum).set(state->new_class("Bignum", G(integer)));
- G(bignum)->set_object_type(BignumType);
+ G(bignum)->set_object_type(state, BignumType);
state->add_type_info(new Bignum::Info(Bignum::type));
}
View
34 vm/builtin/block_environment.cpp
@@ -19,7 +19,7 @@ namespace rubinius {
void BlockEnvironment::init(STATE) {
GO(blokenv).set(state->new_class("BlockEnvironment", G(object),
BlockEnvironment::fields));
- G(blokenv)->set_object_type(BlockEnvType);
+ G(blokenv)->set_object_type(state, BlockEnvType);
}
void BlockEnvironment::call(STATE, Task* task, size_t args) {
@@ -35,7 +35,7 @@ namespace rubinius {
val = Qnil;
}
task->pop(); // Remove this from the stack.
- BlockContext* ctx = create_context(state, task->active);
+ BlockContext* ctx = create_context(state, task->active());
task->make_active(ctx);
task->push(val);
}
@@ -53,7 +53,7 @@ namespace rubinius {
val = Qnil;
}
task->pop(); // Remove this from the stack.
- BlockContext* ctx = create_context(state, task->active);
+ BlockContext* ctx = create_context(state, task->active());
task->make_active(ctx);
task->push(val);
}
@@ -69,16 +69,16 @@ namespace rubinius {
* locals the method requires.
*/
BlockContext* BlockEnvironment::create_context(STATE, MethodContext* sender) {
- BlockContext* ctx = BlockContext::create(state, method->stack_size->to_native());
- SET(ctx, sender, sender);
- SET(ctx, block, this);
- SET(ctx, cm, method);
- SET(ctx, home, home);
+ BlockContext* ctx = BlockContext::create(state, method_->stack_size()->to_native());
+ ctx->sender(state, sender);
+ ctx->block(state, this);
+ ctx->cm(state, method_);
+ ctx->home(state, home_);
ctx->vmm = vmm;
ctx->ip = 0;
// HACK dup'd from MethodContext
- ctx->position_stack(method->number_of_locals() - 1);
+ ctx->position_stack(method_->number_of_locals() - 1);
return ctx;
}
@@ -98,10 +98,10 @@ namespace rubinius {
active->vmm->blocks[index] = vmm;
}
- SET(be, home, parent);
- SET(be, home_block, active);
- SET(be, method, cm);
- SET(be, local_count, cm->local_count);
+ be->home(state, parent);
+ be->home_block(state, active);
+ be->method(state, cm);
+ be->local_count(state, cm->local_count());
be->vmm = vmm;
return be;
@@ -111,10 +111,10 @@ namespace rubinius {
BlockEnvironment* be = as<BlockEnvironment>(self);
class_header(state, self);
- indent_attribute(++level, "home"); be->home->show(state, level);
- indent_attribute(level, "home_block"); be->home_block->show(state, level);
- indent_attribute(level, "local_count"); be->local_count->show(state, level);
- indent_attribute(level, "method"); be->method->show(state, level);
+ indent_attribute(++level, "home"); be->home()->show(state, level);
+ indent_attribute(level, "home_block"); be->home_block()->show(state, level);
+ indent_attribute(level, "local_count"); be->local_count()->show(state, level);
+ indent_attribute(level, "method"); be->method()->show(state, level);
close_body(level);
}
}
View
23 vm/builtin/block_environment.hpp
@@ -14,16 +14,29 @@ namespace rubinius {
class VMExecutable;
class BlockEnvironment : public Object {
- public:
+ public:
const static size_t fields = 5;
const static object_type type = BlockEnvType;
- MethodContext* home; // slot
- MethodContext* home_block; // slot
- OBJECT local_count; // slot
- CompiledMethod* method; // slot
+ private:
+ MethodContext* home_; // slot
+ MethodContext* home_block_; // slot
+ OBJECT local_count_; // slot
+ CompiledMethod* method_; // slot
+
+ public:
+ // TODO: fix up data members that aren't slots
VMMethod* vmm;
+ public:
+ /* accessors */
+ attr_accessor(home, MethodContext);
+ attr_accessor(home_block, MethodContext);
+ attr_accessor(local_count, Object);
+ attr_accessor(method, CompiledMethod);
+
+ /* interface */
+
static void init(STATE);
static BlockEnvironment* under_context(STATE, CompiledMethod* cm,
MethodContext* parent, MethodContext* active, size_t index);
View
2 vm/builtin/bytearray.cpp
@@ -12,7 +12,7 @@ namespace rubinius {
void ByteArray::init(STATE) {
GO(bytearray).set(state->new_class("ByteArray"));
- G(bytearray)->set_object_type(ByteArrayType);
+ G(bytearray)->set_object_type(state, ByteArrayType);
}
ByteArray* ByteArray::create(STATE, size_t bytes) {
View
18 vm/builtin/channel.cpp
@@ -16,31 +16,31 @@
namespace rubinius {
Channel* Channel::create(STATE) {
Channel* chan = (Channel*)state->new_object(G(channel));
- SET(chan, waiting, List::create(state));
+ chan->waiting(state, List::create(state));
return chan;
}
OBJECT Channel::send(STATE, OBJECT val) {
- if(!waiting->empty_p()) {
- Thread* thr = as<Thread>(waiting->shift(state));
+ if(!waiting_->empty_p()) {
+ Thread* thr = as<Thread>(waiting_->shift(state));
thr->set_top(state, val);
state->queue_thread(thr);
return Qnil;
}
- if(value->nil_p()) {
+ if(value_->nil_p()) {
List* lst = List::create(state);
lst->append(state, val);
- value = lst;
+ value(state, lst);
}
return Qnil;
}
OBJECT Channel::receive(STATE) {
- if(!value->nil_p()) {
- OBJECT val = as<List>(value)->shift(state);
+ if(!value_->nil_p()) {
+ OBJECT val = as<List>(value_)->shift(state);
state->return_value(val);
return Qnil;
}
@@ -49,13 +49,13 @@ namespace rubinius {
state->return_value(Qfalse);
G(current_thread)->sleep_for(state, this);
- waiting->append(state, G(current_thread));
+ waiting_->append(state, G(current_thread));
state->run_best_thread();
return Qnil;
}
bool Channel::has_readers_p() {
- return !waiting->empty_p();
+ return !waiting_->empty_p();
}
class SendToChannel : public ObjectCallback {
View
13 vm/builtin/channel.hpp
@@ -18,8 +18,17 @@ namespace rubinius {
const static size_t fields = 2;
const static object_type type = ChannelType;
- OBJECT value; // slot
- List* waiting; // slot
+ private:
+ OBJECT value_; // slot
+ List* waiting_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(value, Object);
+ attr_accessor(waiting, List);
+
+ /* interface */
// Ruby.primitive :channel_new
static Channel* create(STATE);
View
23 vm/builtin/class.cpp
@@ -33,11 +33,10 @@ namespace rubinius {
Class* Class::create(STATE, Class* super) {
Class* cls = (Class*)state->new_object(G(klass));
- SET(cls, name, Qnil);
- SET(cls, instance_fields, super->instance_fields);
- SET(cls, has_ivars, super->has_ivars);
- SET(cls, instance_type, super->instance_type);
- SET(cls, superclass, super);
+ cls->name(state, (SYMBOL)Qnil);
+ cls->instance_fields(state, super->instance_fields());
+ cls->instance_type(state, super->instance_type());
+ cls->superclass(state, super);
cls->setup(state);
@@ -54,22 +53,22 @@ namespace rubinius {
MetaClass *meta;
meta = (MetaClass*)state->new_object(G(metaclass));
- if(!sup) { sup = obj->klass; }
+ if(!sup) { sup = obj->klass(); }
meta->IsMeta = TRUE;
- SET(meta, attached_instance, obj);
+ meta->attached_instance(state, obj);
meta->setup(state);
- SET(meta, superclass, sup);
- SET(obj, klass, meta);
+ meta->superclass(state, (Module*)sup);
+ obj->klass(state, meta);
return meta;
}
void MetaClass::Info::show(STATE, OBJECT self, int level) {
MetaClass* cls = as<MetaClass>(self);
- Module* mod = as<Module>(cls->attached_instance);
+ Module* mod = as<Module>(cls->attached_instance());
- const char* name = mod->name == Qnil ? "<anonymous>" : mod->name->c_str(state);
- std::cout << "#<" << self->class_object(state)->name->c_str(state) <<
+ const char* name = mod->name()->nil_p() ? "<anonymous>" : mod->name()->c_str(state);
+ std::cout << "#<" << self->class_object(state)->name()->c_str(state) <<
" " << name << ":" << (void*)self << ">" << std::endl;
}
}
View
35 vm/builtin/class.hpp
@@ -10,17 +10,26 @@ namespace rubinius {
class LookupTable;
class Class : public Module {
- public:
+ public:
const static size_t fields = Module::fields + 4;
const static object_type type = ClassType;
- FIXNUM instance_fields; // slot
- OBJECT has_ivars; // slot
- OBJECT needs_cleanup; // slot
- FIXNUM instance_type; // slot
+ private:
+ FIXNUM instance_fields_; // slot
+ OBJECT needs_cleanup_; // slot
+ FIXNUM instance_type_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(instance_fields, Fixnum);
+ attr_accessor(needs_cleanup, Object);
+ attr_accessor(instance_type, Fixnum);
+
+ /* interface */
- void set_object_type(size_t type) {
- instance_type = Fixnum::from(type);
+ void set_object_type(STATE, size_t type) {
+ instance_type(state, Fixnum::from(type));
}
static Class* create(STATE, Class* super);
@@ -35,11 +44,19 @@ namespace rubinius {
};
class MetaClass : public Class {
- public:
+ public:
const static size_t fields = Class::fields + 1;
const static object_type type = MetaclassType;
- OBJECT attached_instance; // slot
+ private:
+ OBJECT attached_instance_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(attached_instance, Object);
+
+ /* interface */
static MetaClass* attach(STATE, OBJECT obj, OBJECT sup = NULL);
View
2 vm/builtin/compactlookuptable.cpp
@@ -13,7 +13,7 @@ namespace rubinius {
void CompactLookupTable::init(STATE) {
GO(compactlookuptable).set(state->new_class("CompactLookupTable",
G(tuple), CompactLookupTable::fields));
- G(compactlookuptable)->set_object_type(CompactLookupTableType);
+ G(compactlookuptable)->set_object_type(state, CompactLookupTableType);
}
CompactLookupTable* CompactLookupTable::create(STATE) {
View
58 vm/builtin/compiledmethod.cpp
@@ -18,34 +18,34 @@ namespace rubinius {
void CompiledMethod::init(STATE) {
GO(cmethod).set(state->new_class("CompiledMethod", G(executable), CompiledMethod::fields));
- G(cmethod)->set_object_type(CMethodType);
+ G(cmethod)->set_object_type(state, CMethodType);
GO(cmethod_vis).set(state->new_class("Visibility", G(object),
MethodVisibility::fields, G(cmethod)));
- G(cmethod_vis)->set_object_type(CMVisibilityType);
+ G(cmethod_vis)->set_object_type(state, CMVisibilityType);
}
CompiledMethod* CompiledMethod::create(STATE) {
CompiledMethod* cm = (CompiledMethod*)state->new_object(G(cmethod));
- SET(cm, local_count, Fixnum::from(0));
+ cm->local_count(state, Fixnum::from(0));
cm->executable = NULL;
return cm;
}
CompiledMethod* CompiledMethod::generate_tramp(STATE, size_t stack_size) {
CompiledMethod* cm = CompiledMethod::create(state);
- SET(cm, stack_size, Fixnum::from(stack_size));
- SET(cm, required_args, Fixnum::from(0));
- SET(cm, total_args, cm->required_args);
- SET(cm, name, state->symbol("__halt__"));
+ cm->stack_size(state, Fixnum::from(stack_size));
+ cm->required_args(state, Fixnum::from(0));
+ cm->total_args(state, cm->required_args());
+ cm->name(state, state->symbol("__halt__"));
- SET(cm, iseq, InstructionSequence::create(state, 1));
- cm->iseq->opcodes->put(state, 0, Fixnum::from(InstructionSequence::insn_halt));
+ cm->iseq(state, InstructionSequence::create(state, 1));
+ cm->iseq()->opcodes()->put(state, 0, Fixnum::from(InstructionSequence::insn_halt));
StaticScope* ss = StaticScope::create(state);
- SET(ss, module, G(object));
- SET(cm, scope, ss);
+ ss->module(state, G(object));
+ cm->scope(state, ss);
cm->formalize(state, false);
@@ -58,8 +58,8 @@ namespace rubinius {
// initialized to nil. CompiledMethod::allocate needs to be a primitive
// that gets things setup properly.
if(!executable || (OBJECT)executable == Qnil) {
- if(!primitive->nil_p()) {
- if(SYMBOL name = try_as<Symbol>(primitive)) {
+ if(!primitive()->nil_p()) {
+ if(SYMBOL name = try_as<Symbol>(primitive())) {
//std::cout << "resolving: "; name->show(state);
executor func = Primitives::resolve_primitive(state, name);
@@ -105,30 +105,26 @@ namespace rubinius {
}
size_t CompiledMethod::number_of_locals() {
- return local_count->to_native();
- }
-
- void CompiledMethod::set_scope(StaticScope* scope) {
- this->scope = scope;
+ return local_count_->to_native();
}
void CompiledMethod::Info::show(STATE, OBJECT self, int level) {
CompiledMethod* cm = as<CompiledMethod>(self);
class_header(state, self);
- indent_attribute(++level, "exceptions"); cm->exceptions->show_simple(state, level);
- indent_attribute(level, "file"); cm->file->show(state, level);
- indent_attribute(level, "iseq"); cm->iseq->show(state, level);
- indent_attribute(level, "lines"); cm->lines->show_simple(state, level);
- indent_attribute(level, "literals"); cm->literals->show_simple(state, level);
- indent_attribute(level, "local_count"); cm->local_count->show(state, level);
- indent_attribute(level, "local_names"); cm->local_names->show_simple(state, level);
- indent_attribute(level, "name"); cm->name->show(state, level);
- indent_attribute(level, "required_args"); cm->required_args->show(state, level);
- indent_attribute(level, "scope"); cm->scope->show(state, level);
- indent_attribute(level, "splat"); cm->splat->show(state, level);
- indent_attribute(level, "stack_size"); cm->stack_size->show(state, level);
- indent_attribute(level, "total_args"); cm->total_args->show(state, level);
+ indent_attribute(++level, "exceptions"); cm->exceptions()->show_simple(state, level);
+ indent_attribute(level, "file"); cm->file()->show(state, level);
+ indent_attribute(level, "iseq"); cm->iseq()->show(state, level);
+ indent_attribute(level, "lines"); cm->lines()->show_simple(state, level);
+ indent_attribute(level, "literals"); cm->literals()->show_simple(state, level);
+ indent_attribute(level, "local_count"); cm->local_count()->show(state, level);
+ indent_attribute(level, "local_names"); cm->local_names()->show_simple(state, level);
+ indent_attribute(level, "name"); cm->name()->show(state, level);
+ indent_attribute(level, "required_args"); cm->required_args()->show(state, level);
+ indent_attribute(level, "scope"); cm->scope()->show(state, level);
+ indent_attribute(level, "splat"); cm->splat()->show(state, level);
+ indent_attribute(level, "stack_size"); cm->stack_size()->show(state, level);
+ indent_attribute(level, "total_args"); cm->total_args()->show(state, level);
close_body(level);
}
}
View
49 vm/builtin/compiledmethod.hpp
@@ -12,24 +12,44 @@ namespace rubinius {
class StaticScope;
class CompiledMethod : public Executable {
- public:
+ public:
const static size_t fields = 18;
const static object_type type = CMethodType;
const static size_t saved_fields = 16;
- SYMBOL name; // slot
- InstructionSequence* iseq; // slot
- FIXNUM stack_size; // slot
- FIXNUM local_count; // slot
- FIXNUM required_args; // slot
- FIXNUM total_args; // slot
- OBJECT splat; // slot
- Tuple* literals; // slot
- Tuple* exceptions; // slot
- Tuple* lines; // slot
- Tuple* local_names; // slot
- SYMBOL file; // slot
- StaticScope* scope; // slot
+ private:
+ SYMBOL name_; // slot
+ InstructionSequence* iseq_; // slot
+ FIXNUM stack_size_; // slot
+ FIXNUM local_count_; // slot
+ FIXNUM required_args_; // slot
+ FIXNUM total_args_; // slot
+ OBJECT splat_; // slot
+ Tuple* literals_; // slot
+ Tuple* exceptions_; // slot
+ Tuple* lines_; // slot
+ Tuple* local_names_; // slot
+ SYMBOL file_; // slot
+ StaticScope* scope_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(name, Symbol);
+ attr_accessor(iseq, InstructionSequence);
+ attr_accessor(stack_size, Fixnum);
+ attr_accessor(local_count, Fixnum);
+ attr_accessor(required_args, Fixnum);
+ attr_accessor(total_args, Fixnum);
+ attr_accessor(splat, Object);
+ attr_accessor(literals, Tuple);
+ attr_accessor(exceptions, Tuple);
+ attr_accessor(lines, Tuple);
+ attr_accessor(local_names, Tuple);
+ attr_accessor(file, Symbol);
+ attr_accessor(scope, StaticScope);
+
+ /* interface */
static void init(STATE);
@@ -41,7 +61,6 @@ namespace rubinius {
void post_marshal(STATE);
size_t number_of_locals();
- void set_scope(StaticScope*);
VMMethod* formalize(STATE, bool ondemand=true);
void specialize(TypeInfo* ti);
View
80 vm/builtin/contexts.cpp
@@ -22,10 +22,10 @@ namespace rubinius {
void MethodContext::init(STATE) {
GO(methctx).set(state->new_class("MethodContext", G(object)));
- G(methctx)->set_object_type(MContextType);
+ G(methctx)->set_object_type(state, MContextType);
GO(blokctx).set(state->new_class("BlockContext", G(methctx)));
- G(blokctx)->set_object_type(BContextType);
+ G(blokctx)->set_object_type(state, BContextType);
}
/* Calculate how much big of an object (in bytes) to allocate
@@ -37,14 +37,14 @@ namespace rubinius {
/* Initialize +ctx+'s fields */
static void init_context(STATE, MethodContext* ctx, size_t stack) {
ctx->ip = 0;
- SET(ctx, block, Qnil);
- SET(ctx, name, Qnil);
- SET(ctx, home, Qnil);
- SET(ctx, ivars, Qnil);
- SET(ctx, sender, Qnil);
- SET(ctx, self, Qnil);
- SET(ctx, cm, Qnil);
- SET(ctx, module, Qnil);
+ ctx->block(state, Qnil);
+ ctx->name(state, Qnil);
+ ctx->home(state, (MethodContext*)Qnil);
+ ctx->ivars(state, Qnil);
+ ctx->sender(state, (MethodContext*)Qnil);
+ ctx->self(state, Qnil);
+ ctx->cm(state, (CompiledMethod*)Qnil);
+ ctx->module(state, (Module*)Qnil);
ctx->stack_size = stack;
for(size_t i = 0; i < stack; i++) {
@@ -80,7 +80,7 @@ namespace rubinius {
}
if((ctx = state->context_cache->get(which_cache)) != NULL) {
- ctx->obj_type = (object_type)cls->instance_type->to_native();
+ ctx->obj_type = (object_type)cls->instance_type()->to_native();
goto initialize;
}
@@ -95,18 +95,17 @@ namespace rubinius {
}
int MethodContext::line() {
- if(this->cm->nil_p()) return -2; // trampoline context
- if(this->cm->lines->nil_p()) return -3;
+ if(cm_->nil_p()) return -2; // trampoline context
+ if(cm_->lines()->nil_p()) return -3;
- for(size_t i = 0; i < this->cm->lines->field_count; i++) {
- Tuple* entry = as<Tuple>(this->cm->lines->at(i));
+ for(size_t i = 0; i < cm_->lines()->field_count; i++) {
+ Tuple* entry = as<Tuple>(cm_->lines()->at(i));
FIXNUM start_ip = as<Fixnum>(entry->at(0));
FIXNUM end_ip = as<Fixnum>(entry->at(1));
FIXNUM line = as<Fixnum>(entry->at(2));
- if(start_ip->to_native() <= this->ip &&
- end_ip->to_native() >= this->ip)
+ if(start_ip->to_native() <= ip && end_ip->to_native() >= ip)
return line->to_native();
}
@@ -116,6 +115,9 @@ 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) {
+ assert(this->home() == old);
+ }
}
/* Attempt to recycle +this+ context into the context cache, based
@@ -135,7 +137,9 @@ namespace rubinius {
which = LargeContextSize;
}
- state->context_cache->add(which, this);
+ // HACK this is broken. It's adding context which
+ // are still live into the cache (busting those contexts)
+ // state->context_cache->add(state, which, this);
return true;
}
@@ -169,13 +173,13 @@ namespace rubinius {
* expected to SET any fields it needs to, e.g. +module+
*/
MethodContext* MethodContext::create(STATE, OBJECT recv, CompiledMethod* meth) {
- MethodContext* ctx = MethodContext::create(state, meth->stack_size->to_native());
+ MethodContext* ctx = MethodContext::create(state, meth->stack_size()->to_native());
- SET(ctx, sender, (MethodContext*)Qnil);
- SET(ctx, self, recv);
- SET(ctx, cm, meth);
- SET(ctx, module, G(object));
- SET(ctx, home, ctx);
+ ctx->sender(state, (MethodContext*)Qnil);
+ ctx->self(state, recv);
+ ctx->cm(state, meth);
+ ctx->module(state, G(object));
+ ctx->home(state, ctx);
ctx->vmm = (VMMethod*)meth->executable;
ctx->position_stack(meth->number_of_locals() - 1);
@@ -186,7 +190,7 @@ namespace rubinius {
/* Retrieve the BlockEnvironment from +this+ BlockContext. We reuse the
* block field from MethodContext and use a type-safe cast. */
BlockEnvironment* BlockContext::env() {
- return as<BlockEnvironment>(block);
+ return as<BlockEnvironment>(block());
}
/* Called as the block_context_env primitive
@@ -227,6 +231,10 @@ namespace rubinius {
MethodContext* ctx = as<MethodContext>(obj);
+ if(ctx->obj_type == MContextType) {
+ assert(ctx->home() == obj);
+ }
+
/* Now also mark the stack */
OBJECT stack_obj, marked;
for(size_t i = 0; i < ctx->stack_size; i++) {
@@ -243,23 +251,23 @@ namespace rubinius {
MethodContext* ctx = as<MethodContext>(self);
class_header(state, self);
- indent_attribute(++level, "name"); ctx->name->show(state, level);
+ indent_attribute(++level, "name"); ctx->name()->show(state, level);
indent_attribute(level, "sender");
- if(ctx->sender == Qnil) {
- ctx->sender->show(state, level);
+ if(ctx->sender()->nil_p()) {
+ ctx->sender()->show(state, level);
} else {
- class_info(state, ctx->sender, true);
+ class_info(state, ctx->sender(), true);
}
indent_attribute(level, "home");
- if(ctx->home == Qnil) {
- ctx->home->show(state, level);
+ if(ctx->home()->nil_p()) {
+ ctx->home()->show(state, level);
} else {
- class_info(state, ctx->home, true);
+ class_info(state, ctx->home(), true);
}
- indent_attribute(level, "self"); ctx->self->show(state, level);
- indent_attribute(level, "cm"); ctx->cm->show(state, level);
- indent_attribute(level, "module"); ctx->module->show(state, level);
- indent_attribute(level, "block"); ctx->block->show(state, level);
+ indent_attribute(level, "self"); ctx->self()->show(state, level);
+ indent_attribute(level, "cm"); ctx->cm()->show(state, level);
+ indent_attribute(level, "module"); ctx->module()->show(state, level);
+ indent_attribute(level, "block"); ctx->block()->show(state, level);
close_body(level);
}
}
View
37 vm/builtin/contexts.hpp
@@ -16,30 +16,49 @@ namespace rubinius {
class Module;
class MethodContext : public Object {
- public:
+ public:
// fields is 0 because it is dynamically calculated
const static size_t fields = 0;
const static object_type type = MContextType;
- MethodContext* sender; // slot
- MethodContext* home; // slot
- OBJECT self; // slot
+ private:
+ MethodContext* sender_; // slot
+ MethodContext* home_; // slot
+ OBJECT self_; // slot
- CompiledMethod* cm; // slot
- VMMethod* vmm;
+ CompiledMethod* cm_; // slot
- Module* module; // slot
+ Module* module_; // slot
+ OBJECT block_; // slot
+ OBJECT name_; // slot
+
+ public:
+ // TODO: fix up data members that aren't slots
+ VMMethod* vmm;
+ public:
+ // TODO: fix up data members that aren't slots
struct jit_state js;
int ip;
size_t args;
- OBJECT block; // slot
- OBJECT name; // slot
size_t stack_size;
// MUST BE AT THE LAST DATA MEMBER
OBJECT stk[];
+ public:
+ /* accessors */
+
+ attr_accessor(sender, MethodContext);
+ attr_accessor(home, MethodContext);
+ attr_accessor(self, Object);
+ attr_accessor(cm, CompiledMethod);
+ attr_accessor(module, Module);
+ attr_accessor(block, Object);
+ attr_accessor(name, Object);
+
+ /* interface */
+
static void init(STATE);
static MethodContext* create(STATE, size_t stack_size);
static MethodContext* create(STATE, OBJECT recv, CompiledMethod* meth);
View
18 vm/builtin/dir.cpp
@@ -14,19 +14,19 @@
namespace rubinius {
void Dir::init(STATE) {
GO(dir).set(state->new_class("Dir", G(object), Dir::fields));
- G(dir)->set_object_type(DirType);
+ G(dir)->set_object_type(state, DirType);
}
Dir* Dir::create(STATE) {
Dir* d = (Dir*)state->om->new_object(G(dir), Dir::fields);
- SET(d, data, Qnil);
+ d->data(state, (MemoryPointer*)Qnil);
return d;
}
void Dir::guard(STATE) {
// TODO: raise IOError, "closed directory" (RAISE_FROM_ERRNO)
- if(data->nil_p()) {
+ if(data_->nil_p()) {
throw std::runtime_error("dir->data is nil");
}
}
@@ -35,17 +35,17 @@ namespace rubinius {
DIR* d = opendir(path->c_str());
if(!d) state->raise_from_errno("Unable to open directory");
- SET(this, data, MemoryPointer::create(state, d));
+ data(state, MemoryPointer::create(state, d));
return Qnil;
}
OBJECT Dir::close(STATE) {
guard(state);
- DIR* d = (DIR*)data->pointer;
+ DIR* d = (DIR*)data_->pointer;
if(d) {
- SET(this, data, Qnil);
+ data(state, (MemoryPointer*)Qnil);
closedir(d);
return Qtrue;
}
@@ -54,13 +54,13 @@ namespace rubinius {
}
OBJECT Dir::closed_p(STATE) {
- return data->nil_p() ? Qtrue : Qfalse;
+ return data_->nil_p() ? Qtrue : Qfalse;
}
OBJECT Dir::read(STATE) {
guard(state);
- DIR* d = (DIR*)data->pointer;
+ DIR* d = (DIR*)data_->pointer;
struct dirent *ent = readdir(d);
if(!ent) return Qnil;
@@ -71,7 +71,7 @@ namespace rubinius {
OBJECT Dir::control(STATE, FIXNUM kind, INTEGER pos) {
guard(state);
- DIR* d = (DIR*)data->pointer;
+ DIR* d = (DIR*)data_->pointer;
switch(kind->to_native()) {
case 0:
View
12 vm/builtin/dir.hpp
@@ -9,11 +9,19 @@ namespace rubinius {
class String;
class Dir : public Object {
- public:
+ public:
const static size_t fields = 1;
const static object_type type = DirType;
- MemoryPointer* data; // slot
+ private:
+ MemoryPointer* data_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(data, MemoryPointer);
+
+ /* interface */
static void init(STATE);
static Dir* create(STATE);
View
14 vm/builtin/exception.hpp
@@ -13,9 +13,19 @@ namespace rubinius {
const static size_t fields = 2;
const static object_type type = ExceptionType;
+ private:
+ String* message_; // slot
+ MethodContext* context_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(message, String);
+ attr_accessor(context, MethodContext);
+
+ /* interface */
+
static Exception* create(STATE);
- String* message; // slot
- MethodContext* context; // slot
class Info : public TypeInfo {
public:
View
18 vm/builtin/executable.hpp
@@ -10,14 +10,26 @@ namespace rubinius {
class MemoryPointer;
class Executable : public Object {
- public:
+ public:
const static size_t fields = 3;
const static object_type type = ExecutableType;
- SYMBOL primitive; // slot
- FIXNUM serial; // slot
+ private:
+ SYMBOL primitive_; // slot
+ FIXNUM serial_; // slot
+
+ public:
+ // TODO: fix up data members that aren't slots
VMExecutable* executable;
+ public:
+ /* accessors */
+
+ attr_accessor(primitive, Symbol);
+ attr_accessor(serial, Fixnum);
+
+ /* interface */
+
static void init(STATE);
bool execute(STATE, Task* task, Message& msg) {
View
2 vm/builtin/float.cpp
@@ -13,7 +13,7 @@ namespace rubinius {
void Float::init(STATE) {
GO(floatpoint).set(state->new_class("Float", G(numeric)));
- G(floatpoint)->set_object_type(FloatType);
+ G(floatpoint)->set_object_type(state, FloatType);
}
Float* Float::create(STATE, double val) {
View
42 vm/builtin/io.cpp
@@ -14,24 +14,24 @@
namespace rubinius {
void IO::init(STATE) {
GO(io).set(state->new_class("IO", G(object), IO::fields));
- G(io)->set_object_type(IOType);
+ G(io)->set_object_type(state, IOType);
GO(iobuffer).set(state->new_class("Buffer", G(object), IOBuffer::fields, G(io)));
- G(iobuffer)->set_object_type(IOBufferType);
+ G(iobuffer)->set_object_type(state, IOBufferType);
}
IOBuffer* IOBuffer::create(STATE, size_t bytes) {
IOBuffer* buf = (IOBuffer*)state->new_object(G(iobuffer));
- SET(buf, storage, ByteArray::create(state, bytes));
- SET(buf, total, Fixnum::from(bytes));
- SET(buf, used, Fixnum::from(0));
+ buf->storage(state, ByteArray::create(state, bytes));
+ buf->total(state, Fixnum::from(bytes));
+ buf->used(state, Fixnum::from(0));
return buf;
}
IO* IO::create(STATE, int fd) {
IO* io = (IO*)state->new_object(G(io));
- SET(io, descriptor, Integer::from(state, fd));
+ io->descriptor(state, Fixnum::from(fd));
return io;
}
@@ -41,7 +41,7 @@ namespace rubinius {
}
INTEGER IO::seek(STATE, INTEGER amount, FIXNUM whence) {
- int fd = descriptor->to_native();
+ int fd = descriptor_->to_native();
off_t position;
if(fd == -1) {
@@ -59,29 +59,29 @@ namespace rubinius {
}
OBJECT IO::close(STATE) {
- int fd = descriptor->to_native();
+ int fd = descriptor_->to_native();
if(fd == -1) {
PrimitiveFailed::raise();
} else if(::close(fd)) {
PrimitiveFailed::raise();
} else {
// HACK todo clear any events for this IO
- SET(this, descriptor, Fixnum::from(-1));
+ descriptor(state, Fixnum::from(-1));
}
return Qnil;
}
void IO::initialize(STATE, int fd, char* mode) {
- SET(this, descriptor, Integer::from(state, fd));
- SET(this, mode, String::create(state, mode));
+ this->descriptor(state, Fixnum::from(fd));
+ this->mode(state, String::create(state, mode));
}
native_int IO::to_fd() {
- return descriptor->to_native();
+ return descriptor_->to_native();
}
OBJECT IO::write(STATE, String* buf) {
- ssize_t cnt = ::write(this->to_fd(), buf->data->bytes, buf->size());
+ ssize_t cnt = ::write(this->to_fd(), buf->data()->bytes, buf->size());
// TODO: RAISE_FROM_ERRNO
if(cnt == -1) {
@@ -94,14 +94,14 @@ namespace rubinius {
OBJECT IO::blocking_read(STATE, FIXNUM bytes) {
String* str = String::allocate(state, bytes);
- ssize_t cnt = ::read(this->to_fd(), str->data->bytes, bytes->to_native());
+ ssize_t cnt = ::read(this->to_fd(), str->data()->bytes, bytes->to_native());
if(cnt == -1) {
PrimitiveFailed::raise();
} else if(cnt == 0) {
return Qnil;
}
- SET(str, num_bytes, Fixnum::from(cnt));
+ str->num_bytes(state, Fixnum::from(cnt));
return str;
}
@@ -120,21 +120,21 @@ namespace rubinius {
}
}
- void IOBuffer::read_bytes(size_t bytes) {
- used = Fixnum::from(used->to_native() + bytes);
+ void IOBuffer::read_bytes(STATE, size_t bytes) {
+ used(state, Fixnum::from(used_->to_native() + bytes));
}
char* IOBuffer::byte_address() {
- return (char*)storage->bytes;
+ return (char*)storage_->bytes;
}
size_t IOBuffer::left() {
- return total->to_native() - used->to_native();
+ return total_->to_native() - used_->to_native();
}
char* IOBuffer::at_unused() {
- char* start = (char*)storage->bytes;
- start += used->to_native();
+ char* start = (char*)storage_->bytes;
+ start += used_->to_native();
return start;
}
};
View
36 vm/builtin/io.hpp
@@ -8,13 +8,23 @@ namespace rubinius {
class String;
class IO : public Object {
- public:
+ public:
const static size_t fields = 3;
const static object_type type = IOType;
- FIXNUM descriptor; // slot
- OBJECT buffer; // slot
- OBJECT mode; // slot
+ private:
+ FIXNUM descriptor_; // slot
+ OBJECT buffer_; // slot
+ OBJECT mode_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(descriptor, Fixnum);
+ attr_accessor(buffer, Object);
+ attr_accessor(mode, Object);
+
+ /* interface */
native_int to_fd();
@@ -52,17 +62,27 @@ namespace rubinius {
const static size_t fields = 3;
const static object_type type = IOBufferType;
- OBJECT storage; // slot
- INTEGER total; // slot
- INTEGER used; // slot
+ private:
+ OBJECT storage_; // slot
+ INTEGER total_; // slot
+ INTEGER used_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(storage, Object);
+ attr_accessor(total, Integer);
+ attr_accessor(used, Integer);
+
+ /* interface */
static IOBuffer* create(STATE, size_t bytes);
void reset(STATE);
String* drain(STATE);
char* byte_address();
size_t left();
char* at_unused();
- void read_bytes(size_t bytes);
+ void read_bytes(STATE, size_t bytes);
class Info : public TypeInfo {
public:
View
4 vm/builtin/iseq.cpp
@@ -7,12 +7,12 @@
namespace rubinius {
void InstructionSequence::init(STATE) {
GO(iseq).set(state->new_class("InstructionSequence", G(object), InstructionSequence::fields));
- G(iseq)->set_object_type(ISeqType);
+ G(iseq)->set_object_type(state, ISeqType);
}
InstructionSequence* InstructionSequence::create(STATE, size_t instructions) {
InstructionSequence* is = (InstructionSequence*)state->new_object(G(iseq));
- is->opcodes = Tuple::create(state, instructions);
+ is->opcodes(state, Tuple::create(state, instructions));
return is;
}
View
13 vm/builtin/iseq.hpp
@@ -12,8 +12,17 @@ namespace rubinius {
const static size_t fields = 2;
const static object_type type = ISeqType;
- Tuple* opcodes; // slot
- FIXNUM stack_depth; // slot
+ private:
+ Tuple* opcodes_; // slot
+ FIXNUM stack_depth_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(opcodes, Tuple);
+ attr_accessor(stack_depth, Fixnum);
+
+ /* interface */
static void init(STATE);
static InstructionSequence* create(STATE, size_t instructions);
View
58 vm/builtin/list.cpp
@@ -9,83 +9,83 @@ namespace rubinius {
/* Returns true if the List is empty, contains no elements. */
bool List::empty_p() {
- return count->to_native() == 0;
+ return count_->to_native() == 0;
}
/* Returns the number of elements in the List. */
size_t List::size() {
- return count->to_native();
+ return count_->to_native();
}
/* Register the List and List::Node classes as globals */
void List::init(STATE) {
Class* cls;
cls = state->new_class("List", G(object), List::fields);
GO(list).set(cls);
- cls->set_object_type(ListType);
+ cls->set_object_type(state, ListType);
GO(list_node).set(state->new_class("Node", G(object),
ListNode::fields, cls));
- G(list_node)->set_object_type(ListNodeType);
+ G(list_node)->set_object_type(state, ListNodeType);
}
/* Create a new List object, containing no elements. */
List* List::create(STATE) {
List* list = (List*)state->new_object(G(list));
- SET(list, count, Fixnum::from(0));
+ list->count(state, Fixnum::from(0));
return list;
}
/* Append +obj+ to the current List. */
void List::append(STATE, OBJECT obj) {
ListNode* node = (ListNode*)state->new_object(G(list_node));
- SET(node, object, obj);
- ListNode* cur_last = last;
+ node->object(state, obj);
+ ListNode* cur_last = last_;
if(!cur_last->nil_p()) {
- SET(cur_last, next, node);
+ cur_last->next(state, node);
}
- SET(this, last, node);
+ last(state, node);
- if(first->nil_p()) {
- SET(this, first, node);
+ if(first_->nil_p()) {
+ first(state, node);
}
- SET(this, count, Integer::from(state, count->to_native() + 1));
+ count(state, Integer::from(state, count_->to_native() + 1));
}
/* Return the +index+ numbered element from the beginning. */
OBJECT List::locate(STATE, size_t index) {
- ListNode* cur = first;
+ ListNode* cur = first_;
while(index > 0) {
if(cur->nil_p()) return Qnil;
- cur = cur->next;
+ cur = cur->next();
index--;
}
if(cur->nil_p()) return Qnil;
- return cur->object;
+ return cur->object();
}
/* Return the first element in the list and remove it, moving all
* other elements forward. */
OBJECT List::shift(STATE) {
if(empty_p()) return Qnil;
- SET(this, count, Integer::from(state, count->to_native() - 1));
- ListNode* n = first;
- SET(this, first, first->next);
+ count(state, Integer::from(state, count_->to_native() - 1));
+ ListNode* n = first_;
+ first(state, first_->next());
- if(last == n) {
- SET(this, last, Qnil);
+ if(last_ == n) {
+ last(state, (ListNode*)Qnil);
}
- return n->object;
+ return n->object();
}
/* Search the List for +obj+ and remove all instances of it.
@@ -96,23 +96,23 @@ namespace rubinius {
size_t deleted = 0, counted = 0;
- ListNode* node = first;
+ ListNode* node = first_;
ListNode* lst = (ListNode*)Qnil;
ListNode* nxt = (ListNode*)Qnil;
while(!node->nil_p()) {
- nxt = node->next;
+ nxt = node->next();
- if(node->object == obj) {
+ if(node->object() == obj) {
deleted++;
if(lst->nil_p()) {
- SET(this, first, nxt);
+ first(state, nxt);
} else {
- SET(lst, next, nxt);
+ lst->next(state, nxt);
}
- if(last == node) {
- SET(this, last, lst);
+ if(last_ == node) {
+ last(state, lst);
}
lst = (ListNode*)Qnil;
@@ -124,7 +124,7 @@ namespace rubinius {
node = nxt;
}
- SET(this, count, Integer::from(state, counted));
+ count(state, Integer::from(state, counted));
return deleted;
}
View
31 vm/builtin/list.hpp
@@ -8,12 +8,20 @@ namespace rubinius {
class ListNode : public Object {
public:
-
const static size_t fields = 2;
const static object_type type = ListNodeType;
- OBJECT object; // slot
- ListNode* next; // slot
+ private:
+ OBJECT object_; // slot
+ ListNode* next_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(object, Object);
+ attr_accessor(next, ListNode);
+
+ /* interface */
class Info : public TypeInfo {
public:
@@ -24,13 +32,22 @@ namespace rubinius {
class List : public Object {
public:
-
const static size_t fields = 3;
const static object_type type = ListType;
- INTEGER count; // slot
- ListNode* first; // slot
- ListNode* last; // slot
+ private:
+ INTEGER count_; // slot
+ ListNode* first_; // slot
+ ListNode* last_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(count, Integer);
+ attr_accessor(first, ListNode);
+ attr_accessor(last, ListNode);
+
+ /* interface */
bool empty_p();
size_t size();
View
50 vm/builtin/lookuptable.cpp
@@ -37,9 +37,9 @@ namespace rubinius {
void LookupTable::setup(STATE, size_t sz = 0) {
if(!sz) sz = LOOKUPTABLE_MIN_SIZE;
- SET(this, values, Tuple::create(state, sz));
- SET(this, bins, Fixnum::from(sz));
- SET(this, entries, Fixnum::from(0));
+ values(state, Tuple::create(state, sz));
+ bins(state, Fixnum::from(sz));
+ entries(state, Fixnum::from(0));
}
/* The LookupTable.allocate primitive. */
@@ -51,10 +51,10 @@ namespace rubinius {
size_t size, i;
LookupTable *dup;
- size = bins->to_native();
+ size = bins_->to_native();
dup = LookupTable::create(state, size);
state->om->set_class(dup, class_object(state));
- size_t num = entries->to_native();
+ size_t num = entries_->to_native();
Array* entries = all_entries(state);
for(i = 0; i < num; i++) {
@@ -89,11 +89,11 @@ namespace rubinius {
}
void LookupTable::redistribute(STATE, size_t size) {
- size_t num = bins->to_native();
+ size_t num = bins_->to_native();
Tuple* new_values = Tuple::create(state, size);
for(size_t i = 0; i < num; i++) {
- Tuple* entry = try_as<Tuple>(values->at(i));
+ Tuple* entry = try_as<Tuple>(values_->at(i));
while(entry) {
Tuple* link = try_as<Tuple>(entry->at(2));
@@ -112,8 +112,8 @@ namespace rubinius {
}
}
- SET(this, values, new_values);
- bins = Fixnum::from(size);
+ values(state, new_values);
+ bins(state, Fixnum::from(size));
}
OBJECT LookupTable::store(STATE, OBJECT key, OBJECT val) {
@@ -123,15 +123,15 @@ namespace rubinius {
Tuple* entry;
key_to_sym(key);
- num_entries = entries->to_native();
- num_bins = bins->to_native();
+ num_entries = entries_->to_native();
+ num_bins = bins_->to_native();
if(max_density_p(num_entries, num_bins)) {
redistribute(state, num_bins <<= 1);
}
bin = find_bin(key_hash(key), num_bins);
- cur = entry = try_as<Tuple>(values->at(bin));
+ cur = entry = try_as<Tuple>(values_->at(bin));
while(entry) {
if(entry->at(0) == key) {
@@ -146,10 +146,10 @@ namespace rubinius {
if(cur) {
cur->put(state, 2, new_ent);
} else {
- values->put(state, bin, new_ent);
+ values_->put(state, bin, new_ent);
}
- entries = Fixnum::from(num_entries + 1);
+ entries(state, Fixnum::from(num_entries + 1));
return val;
}
@@ -158,10 +158,10 @@ namespace rubinius {
Tuple* entry;
key_to_sym(key);
- bin = find_bin(key_hash(key), bins->to_native());
+ bin = find_bin(key_hash(key), bins_->to_native());
/* HACK: This should be fixed by not storing NULLs */
- Object* data = values->at(bin);
+ Object* data = values_->at(bin);
if (!data) return NULL;
@@ -214,15 +214,15 @@ namespace rubinius {
key_to_sym(key);
- size_t num_entries = entries->to_native();
- size_t num_bins = bins->to_native();
+ size_t num_entries = entries_->to_native();
+ size_t num_bins = bins_->to_native();
if(min_density_p(num_entries, num_bins) && (num_bins >> 1) >= LOOKUPTABLE_MIN_SIZE) {
redistribute(state, num_bins >>= 1);
}
bin = find_bin(key_hash(key), num_bins);
- entry = try_as<Tuple>(values->at(bin));
+ entry = try_as<Tuple>(values_->at(bin));
lst = NULL;
@@ -234,9 +234,9 @@ namespace rubinius {
if(lst) {
lst->put(state, 2, link);
} else {
- values->put(state, bin, link);
+ values_->put(state, bin, link);
}
- entries = Fixnum::from(entries->to_native() - 1);
+ entries(state, Fixnum::from(entries_->to_native() - 1));
return val;
}
@@ -259,9 +259,9 @@ namespace rubinius {
Tuple* values;
Tuple* entry;
- Array* ary = Array::create(state, tbl->entries->to_native());
- size_t num_bins = tbl->bins->to_native();
- values = tbl->values;
+ Array* ary = Array::create(state, tbl->entries()->to_native());
+ size_t num_bins = tbl->bins()->to_native();
+ values = tbl->values();
for(i = j = 0; i < num_bins; i++) {
entry = try_as<Tuple>(values->at(i));
@@ -300,7 +300,7 @@ namespace rubinius {
void LookupTable::Info::show(STATE, OBJECT self, int level) {
LookupTable* tbl = as<LookupTable>(self);
- size_t size = tbl->entries->to_native();
+ size_t size = tbl->entries()->to_native();
Array* keys = tbl->all_keys(state);
if(size == 0) {
View
19 vm/builtin/lookuptable.hpp
@@ -10,15 +10,24 @@ namespace rubinius {
#define LOOKUPTABLE_MIN_SIZE 16
class LookupTable : public Object {
- public:
+ public:
const static size_t fields = 3;
const static object_type type = LookupTableType;
- Tuple* values; // slot
- INTEGER bins; // slot
- INTEGER entries; // slot
+ private:
+ Tuple* values_; // slot
+ INTEGER bins_; // slot
+ INTEGER entries_; // slot
+
+ public:
+ /* accessors */
+
+ attr_accessor(values, Tuple);
+ attr_accessor(bins, Integer);
+ attr_accessor(entries, Integer);
+
+ /* interface */
- /* Prototypes */
static LookupTable* create(STATE, size_t sz = LOOKUPTABLE_MIN_SIZE);
void setup(STATE, size_t sz);
View
2 vm/builtin/memorypointer.cpp
@@ -32,7 +32,7 @@ namespace rubinius {
void MemoryPointer::init(STATE) {
GO(memory_pointer).set(state->new_class("MemoryPointer"));
- G(memory_pointer)->set_object_type(MemPtrType);
+ G(memory_pointer)->set_object_type(state, MemPtrType);
}
MemoryPointer* MemoryPointer::create(STATE, void* ptr) {
View
4 vm/builtin/methodvisibility.cpp
@@ -17,8 +17,8 @@ namespace rubinius {
MethodVisibility* mv = as<MethodVisibility>(self);
class_header(state, self);
- indent_attribute(++level, "visibility"); mv->visibility->show(state, level);
- indent_attribute(level, "method"); mv->method->show(state, level);
+ indent_attribute(++level, "visibility"); mv->visibility()->show(state, level);
+ indent_attribute(level, "method"); mv->method()->show(state, level);
close_body(level);
}
};
View
19 vm/builtin/methodvisibility.hpp
@@ -11,21 +11,30 @@ namespace rubinius {
const static size_t fields = 2;
const static object_type type = CMVisibilityType;
- SYMBOL visibility; // slot
- Executable* method; // slot
+ private:
+ SYMBOL visibility_; // slot
+ Executable* method_; // slot
+
+ public:
+ /* accessors */
+
+