Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Rubinius::Mirror.

  • Loading branch information...
commit 8fc982929ad026f4a91e2c20d5d43c9fd0e29d6b 1 parent 054ec76
@brixen brixen authored
View
2  kernel/common/load_order18.txt
@@ -1,3 +1,5 @@
+mirror.rbc
+string_mirror.rbc
class.rbc
class18.rbc
binding.rbc
View
2  kernel/common/load_order19.txt
@@ -1,4 +1,6 @@
basicobject.rbc
+mirror.rbc
+string_mirror.rbc
class.rbc
class19.rbc
binding.rbc
View
2  kernel/common/load_order20.txt
@@ -1,4 +1,6 @@
basicobject.rbc
+mirror.rbc
+string_mirror.rbc
class.rbc
class19.rbc
binding.rbc
View
12 kernel/common/mirror.rb
@@ -0,0 +1,12 @@
+module Rubinius
+ class Mirror
+ def self.reflect(obj)
+ klass = Rubinius.invoke_primitive :module_mirror, obj
+ klass.new obj if klass
+ end
+
+ def initialize(obj)
+ @object = obj
+ end
+ end
+end
View
6 kernel/common/string_mirror.rb
@@ -0,0 +1,6 @@
+module Rubinius
+ class Mirror
+ class String < Mirror
+ end
+ end
+end
View
11 lib/compiler/ast/constants.rb
@@ -14,6 +14,17 @@ def bytecode(g)
end
end
+ class MirrorConstant < Node
+ def initialize(line)
+ @line = line
+ end
+
+ def bytecode(g)
+ pos(g)
+ g.push_mirror
+ end
+ end
+
class ScopedConstant < Node
attr_accessor :parent, :name
View
14 lib/melbourne/processor.rb
@@ -127,10 +127,16 @@ def process_class(line, name, superclass, body)
def process_colon2(line, outer, name)
if outer
- if name == :Type and
- outer.kind_of? AST::ConstantAccess and
- outer.name == :Rubinius
- AST::TypeConstant.new line
+ if outer.kind_of? AST::ConstantAccess and
+ outer.name == :Rubinius
+ case name
+ when :Type
+ AST::TypeConstant.new line
+ when :Mirror
+ AST::MirrorConstant.new line
+ else
+ AST::ScopedConstant.new line, outer, name
+ end
else
AST::ScopedConstant.new line, outer, name
end
View
22 vm/builtin/module.cpp
@@ -18,6 +18,8 @@
#include "on_stack.hpp"
+#include <string>
+
namespace rubinius {
void Module::bootstrap_methods(STATE) {
@@ -379,6 +381,26 @@ namespace rubinius {
return NULL;
}
+ Class* Module::mirror(STATE, Object* obj) {
+ if(!mirror_->nil_p()) return mirror_;
+
+ Symbol* name = module_name();
+ if(name->nil_p()) return nil<Class>();
+
+ std::string class_name = name->cpp_str(state);
+ size_t k = class_name.rfind("::");
+ if(k != std::string::npos) {
+ class_name = class_name.substr(k);
+ }
+
+ bool found;
+ Object* klass = G(rubinius)->get_const(state, state->symbol(class_name), &found);
+
+ if(found) return as<Class>(klass);
+
+ return nil<Class>();
+ }
+
std::string Module::debug_str(STATE) {
Symbol* name = module_name();
View
15 vm/builtin/module.hpp
@@ -14,11 +14,12 @@ namespace rubinius {
const static object_type type = ModuleType;
private:
- MethodTable* method_table_; // slot
- Symbol* module_name_; // slot
- LookupTable* constant_table_; // slot
- Module* superclass_; // slot
- Array* seen_ivars_; // slot
+ MethodTable* method_table_; // slot
+ Symbol* module_name_; // slot
+ LookupTable* constant_table_; // slot
+ Module* superclass_; // slot
+ Array* seen_ivars_; // slot
+ Class* mirror_; // slot
public:
/* accessors */
@@ -28,6 +29,7 @@ namespace rubinius {
attr_accessor(constant_table, LookupTable);
attr_accessor(superclass, Module);
attr_accessor(seen_ivars, Array);
+ attr_accessor(mirror, Class);
LookupTable* constants() {
return constant_table();
@@ -70,6 +72,9 @@ namespace rubinius {
// Rubinius.primitive :module_cvar_remove
Object* cvar_remove(STATE, Symbol* name);
+ // Rubinius.primitive :module_mirror
+ Class* mirror(STATE, Object* obj);
+
void setup(STATE);
void setup(STATE, std::string name, Module* under = NULL);
void set_const(STATE, Object* sym, Object* val);
View
4 vm/globals.hpp
@@ -113,6 +113,7 @@ namespace rubinius {
TypedRoot<Module*> type;
TypedRoot<Class*> vm_class;
TypedRoot<Class*> atomic_ref;
+ TypedRoot<Class*> mirror;
/* Add new globals above this line. */
@@ -223,7 +224,8 @@ namespace rubinius {
encoding(&roots),
type(&roots),
vm_class(&roots),
- atomic_ref(&roots)
+ atomic_ref(&roots),
+ mirror(&roots)
/* Add initialize of globals above this line. */
{ }
View
11 vm/instructions.def
@@ -2226,7 +2226,7 @@ instruction invoke_primitive(literal count) [ +count -- value ]
end
# [Description]
-# Pushes the top-level global `Rubinius` constant onto the stack. Generally
+# Pushes the top-level global `Rubinius` constant onto the stack. Generally
# this is done to call a utility method.
instruction push_rubinius() [ -- constant ]
@@ -2287,7 +2287,16 @@ instruction meta_to_s(literal) [ object -- string ] => send
}
end
+# [Description]
+# Pushes the distinguished module `Rubinius::Type` onto the stack.
+
instruction push_type() [ -- constant ]
stack_push(G(type));
end
+# [Description]
+# Pushes the distinguished class `Rubinius::Mirror` onto the stack.
+
+instruction push_mirror() [ -- constant ]
+ stack_push(G(mirror));
+end
View
2  vm/llvm/jit_util.cpp
@@ -1026,6 +1026,8 @@ extern "C" {
return G(rubinius);
case 2:
return G(type);
+ case 3:
+ return G(mirror);
default:
return cNil;
}
View
12 vm/llvm/jit_visit.hpp
@@ -418,8 +418,12 @@ namespace rubinius {
flush_stack();
}
- /* push a global constant onto the stack */
- /* 0:cpath_top, 1:rubinius */
+ /* push a global constant onto the stack
+ * 0 : cpath_top (Object)
+ * 1 : Rubinius module
+ * 2 : Rubinius::Type module
+ * 3 : Rubinius::Mirror class
+ */
void push_system_object(int which) {
// we're calling something that returns an Object
Signature sig(ls_, ObjType);
@@ -3304,6 +3308,10 @@ namespace rubinius {
stack_push(val, type::KnownType::type());
}
+ void visit_push_mirror() {
+ push_system_object(3);
+ }
+
void visit_push_ivar(opcode which) {
Symbol* name = as<Symbol>(literal(which));
View
1  vm/llvm/offset.hpp
@@ -58,6 +58,7 @@ namespace Module {
const static int constants = 3;
const static int superclass = 4;
const static int seen_ivars = 5;
+ const static int mirror = 6;
}
namespace Array {
const static int header = 0;
View
4 vm/llvm/types.cpp.gen
@@ -130,6 +130,9 @@ StructTy_struct_rubinius__Array->setBody(StructTy_struct_rubinius__Array_fields,
PointerType* PointerTy_8 = PointerType::get(StructTy_struct_rubinius__Array, 0);
StructTy_struct_rubinius__Module_fields.push_back(PointerTy_8);
+PointerType* PointerTy_4 = PointerType::get(StructTy_struct_rubinius__Class, 0);
+
+StructTy_struct_rubinius__Module_fields.push_back(PointerTy_4);
if (StructTy_struct_rubinius__Module->isOpaque()) {
StructTy_struct_rubinius__Module->setBody(StructTy_struct_rubinius__Module_fields, /*isPacked=*/false);
}
@@ -156,7 +159,6 @@ if (StructTy_struct_rubinius__Class->isOpaque()) {
StructTy_struct_rubinius__Class->setBody(StructTy_struct_rubinius__Class_fields, /*isPacked=*/false);
}
-PointerType* PointerTy_4 = PointerType::get(StructTy_struct_rubinius__Class, 0);
StructTy_struct_rubinius__ObjectHeader_fields.push_back(PointerTy_4);
StructTy_struct_rubinius__ObjectHeader_fields.push_back(PointerTy_3);
View
3  vm/llvm/types.ll
@@ -212,7 +212,8 @@ declare void @output19(%"struct.rubinius::Float"*)
%"struct.rubinius::Symbol"*, ; module_name
%"struct.rubinius::LookupTable"*, ; constants
%"struct.rubinius::Module"*, ; superclass
- %"struct.rubinius::Array"* ; seen_ivars
+ %"struct.rubinius::Array"*, ; seen_ivars
+ %"struct.rubinius::Class"* ; mirror
}
declare void @output20(%"struct.rubinius::Module"*)
View
1  vm/ontology.cpp
@@ -379,6 +379,7 @@ namespace rubinius {
GO(vm_class).set(ontology::new_class_under(state, "VM", G(rubinius)));
GO(type).set(ontology::new_module(state, "Type", G(rubinius)));
+ GO(mirror).set(ontology::new_class(state, "Mirror", G(object), G(rubinius)));
System::bootstrap_methods(state);
Module::bootstrap_methods(state);
View
17 web/_includes/instructions.markdown
@@ -2147,7 +2147,7 @@
</table>
<h3><a class="instruction" name="push_rubinius">push_rubinius()</a></h3>
- Pushes the top-level global `Rubinius` constant onto the stack. Generally
+ Pushes the top-level global `Rubinius` constant onto the stack. Generally
this is done to call a utility method.
@@ -2210,6 +2210,21 @@
<h3><a class="instruction" name="push_type">push_type()</a></h3>
+ Pushes the distinguished module `Rubinius::Type` onto the stack.
+
+
+<table class="stack_effect">
+<thead>
+<tr><th>Before</th><th>After</th></tr>
+</thead>
+<tbody>
+<tr><td>...</td><td>constant</td></tr>
+<tr><td></td><td>...</td></tr>
+</tbody>
+</table>
+<h3><a class="instruction" name="push_mirror">push_mirror()</a></h3>
+
+ Pushes the distinguished class `Rubinius::Mirror` onto the stack.
<table class="stack_effect">
Please sign in to comment.
Something went wrong with that request. Please try again.