Skip to content

Commit 245026d

Browse files
committed
Shuffle method-adding code into the SC builder.
1 parent 6435cc3 commit 245026d

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/HLL/SerializationContextBuilder.pm

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,29 @@ class HLL::Compiler::SerializationContextBuilder {
337337
$create_call
338338
)));
339339
}
340-
340+
341341
# Adds a method to the meta-object, and stores an event for the action.
342342
# Note that methods are always subject to fixing up since the actual
343343
# compiled code isn't available until compilation is complete.
344344
method pkg_add_method($obj, $meta_method_name, $name, $method_past) {
345+
# Deserializing is easy - just the straight meta-method call.
346+
# Rest is more complex...
347+
my $slot_past := self.get_slot_past_for_object($obj);
348+
self.add_event(:deserialize_past(PAST::Op.new(
349+
:pasttype('callmethod'), :name($meta_method_name),
350+
PAST::Op.new( :pirop('get_how PP'), $slot_past ),
351+
$slot_past,
352+
$name,
353+
PAST::Val.new( :value($method_past) )
354+
)),
355+
# TODO...
356+
:fixup_past(PAST::Op.new(
357+
:pasttype('callmethod'), :name($meta_method_name),
358+
PAST::Op.new( :pirop('get_how PP'), $slot_past ),
359+
$slot_past,
360+
$name,
361+
PAST::Val.new( :value($method_past) )
362+
)));
345363
}
346364

347365
# Adds a parent or role to the meta-object, and stores an event for

src/NQP/Actions.pm

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -823,20 +823,10 @@ class NQP::Actions is HLL::Actions {
823823
if $*MULTINESS eq 'multi' { attach_multi_signature($past); }
824824

825825
# Insert it into the method table.
826-
if pir::defined($*PACKAGE-SETUP) {
827-
$*PACKAGE-SETUP.push(PAST::Op.new(
828-
:pasttype('callmethod'), :name($*MULTINESS eq 'multi' ?? 'add_multi_method' !! 'add_method'),
829-
PAST::Op.new(
830-
# XXX Should be nqpop at some point.
831-
:pirop('get_how PP'),
832-
PAST::Var.new( :name('type_obj'), :scope('register') )
833-
),
834-
PAST::Var.new( :name('type_obj'), :scope('register') ),
835-
PAST::Val.new( :value($name) ),
836-
PAST::Val.new( :value($past) )
837-
));
838-
}
826+
my $meta_meth := $*MULTINESS eq 'multi' ?? 'add_multi_method' !! 'add_method';
827+
$*SC.pkg_add_method($*PACKAGE, $meta_meth, $name, $past);
839828

829+
# Install it in the package also if needed.
840830
if $*SCOPE eq 'our' {
841831
$*SC.install_package_routine($*PACKAGE, $name, $past);
842832
}

0 commit comments

Comments
 (0)