Permalink
Browse files

[common] Add a VERY hacky but working version of method addition and …

…dispatch into ClassHOW. Not even any inheritance yet. Mostly, it's got lots of TODOs for stuff I need to do next.
  • Loading branch information...
jnthn committed Oct 22, 2010
1 parent 52f9692 commit 4356d783155f5e28970cb7469e5371613367fa4c
Showing with 28 additions and 0 deletions.
  1. +28 −0 common/NQP/NQPSetting.pm
View
@@ -301,6 +301,7 @@ knowhow NQPClassHOW {
method BUILD() {
$!composed := 0;
+ %!methods := NQPHash.new;
self;
}
@@ -313,6 +314,14 @@ knowhow NQPClassHOW {
nqp::type_object_for($metaclass, 'P6opaque');
}
+ method add_method($obj, $name, $code_obj) {
+ # XXX TODO This crashes due to lack of auto-viv. :/
+ #if %!methods{$name} {
+ # die("This class already has a method named " ~ $name);
+ #}
+ %!methods{$name} := $code_obj;
+ }
+
method compose($obj) {
# XXX TODO: Compose roles, compose attributes.
@@ -333,6 +342,25 @@ knowhow NQPClassHOW {
@mro[0] := $obj;
@mro;
}
+
+ ##
+ ## Introspecty
+ ##
+
+ method method_table($obj) {
+ %!methods
+ }
+
+ ##
+ ## Dispatchy
+ ##
+
+ method find_method($obj, $name) {
+ # XXX TODO Epic cheat, replace with that's in the ClassHOW that we
+ # run on Parrot. Needs auto-viv, .defined, return.
+ my %meths := @!mro[0].HOW.method_table($obj);
+ %meths{$name}
+ }
}
# XXX Bad hack, we'll replace this later.

0 comments on commit 4356d78

Please sign in to comment.