-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean Array by using a Reflector (simple mirror)
Array left it's guts exposed to deal with the way that data has to be exposed in ruby. To clean things up, I've introduce a Reflector class which is a simple mirror. This can easily access the internal data of an object. Additionally, rather than using instance_variable_[get|set] the JIT can make access quite fast because it doesn't have to deal with any edgecases.
- Loading branch information
Showing
15 changed files
with
187 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Rubinius | ||
class Reflector | ||
|
||
def self.new(target) | ||
Rubinius.primitive :reflector_create | ||
raise PrimitiveFailure, "Reflector.new failed" | ||
end | ||
|
||
def get(ivar) | ||
Rubinius.primitive :reflector_get | ||
raise PrimitiveFailure, "Reflector#get failed" | ||
end | ||
|
||
def set(ivar, name) | ||
Rubinius.primitive :reflector_set | ||
raise TypeError, "'#{name}' is not a ivar name" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "vm.hpp" | ||
#include "vm/object_utils.hpp" | ||
|
||
#include "builtin/object.hpp" | ||
|
||
#include "builtin/reflector.hpp" | ||
|
||
#include "ontology.hpp" | ||
#include "builtin/class.hpp" | ||
#include "builtin/symbol.hpp" | ||
#include "primitives.hpp" | ||
|
||
namespace rubinius { | ||
void Reflector::init(STATE) { | ||
GO(reflector).set(ontology::new_class(state, "Reflector", | ||
G(object), G(rubinius))); | ||
G(reflector)->set_object_type(state, Reflector::type); | ||
} | ||
|
||
Reflector* Reflector::create(STATE, Object* target) { | ||
Reflector* ref = state->new_object<Reflector>(G(reflector)); | ||
ref->target(state, target); | ||
return ref; | ||
} | ||
|
||
Object* Reflector::get(STATE, Symbol* name) { | ||
if(name->is_ivar_p(state)->false_p()) return cNil; | ||
return target_->get_ivar(state, name); | ||
} | ||
|
||
Object* Reflector::set(STATE, Symbol* name, Object* val) { | ||
if(name->is_ivar_p(state)->false_p()) { | ||
return Primitives::failure(); | ||
} | ||
|
||
target_->check_frozen(state); | ||
target_->set_ivar(state, name, val); | ||
|
||
return val; | ||
} | ||
} |
Oops, something went wrong.