Skip to content

Commit

Permalink
[common] Add a VERY hacky but working version of method addition and …
Browse files Browse the repository at this point in the history
…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 4356d78
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions common/NQP/NQPSetting.pm
Expand Up @@ -301,6 +301,7 @@ knowhow NQPClassHOW {

method BUILD() {
$!composed := 0;
%!methods := NQPHash.new;
self;
}

Expand All @@ -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.

Expand All @@ -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.
Expand Down

0 comments on commit 4356d78

Please sign in to comment.