Skip to content

Commit

Permalink
Shuffle method-adding code into the SC builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Apr 27, 2011
1 parent 6435cc3 commit 245026d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
20 changes: 19 additions & 1 deletion src/HLL/SerializationContextBuilder.pm
Expand Up @@ -337,11 +337,29 @@ class HLL::Compiler::SerializationContextBuilder {
$create_call
)));
}

# Adds a method to the meta-object, and stores an event for the action.
# Note that methods are always subject to fixing up since the actual
# compiled code isn't available until compilation is complete.
method pkg_add_method($obj, $meta_method_name, $name, $method_past) {
# Deserializing is easy - just the straight meta-method call.
# Rest is more complex...
my $slot_past := self.get_slot_past_for_object($obj);
self.add_event(:deserialize_past(PAST::Op.new(
:pasttype('callmethod'), :name($meta_method_name),
PAST::Op.new( :pirop('get_how PP'), $slot_past ),
$slot_past,
$name,
PAST::Val.new( :value($method_past) )
)),
# TODO...
:fixup_past(PAST::Op.new(
:pasttype('callmethod'), :name($meta_method_name),
PAST::Op.new( :pirop('get_how PP'), $slot_past ),
$slot_past,
$name,
PAST::Val.new( :value($method_past) )
)));
}

# Adds a parent or role to the meta-object, and stores an event for
Expand Down
16 changes: 3 additions & 13 deletions src/NQP/Actions.pm
Expand Up @@ -823,20 +823,10 @@ class NQP::Actions is HLL::Actions {
if $*MULTINESS eq 'multi' { attach_multi_signature($past); }

# Insert it into the method table.
if pir::defined($*PACKAGE-SETUP) {
$*PACKAGE-SETUP.push(PAST::Op.new(
:pasttype('callmethod'), :name($*MULTINESS eq 'multi' ?? 'add_multi_method' !! 'add_method'),
PAST::Op.new(
# XXX Should be nqpop at some point.
:pirop('get_how PP'),
PAST::Var.new( :name('type_obj'), :scope('register') )
),
PAST::Var.new( :name('type_obj'), :scope('register') ),
PAST::Val.new( :value($name) ),
PAST::Val.new( :value($past) )
));
}
my $meta_meth := $*MULTINESS eq 'multi' ?? 'add_multi_method' !! 'add_method';
$*SC.pkg_add_method($*PACKAGE, $meta_meth, $name, $past);

# Install it in the package also if needed.
if $*SCOPE eq 'our' {
$*SC.install_package_routine($*PACKAGE, $name, $past);
}
Expand Down

0 comments on commit 245026d

Please sign in to comment.