Skip to content

Commit 00ec5f3

Browse files
committed
Do initial meta-object instantiation via the serialization context builder.
1 parent c35442c commit 00ec5f3

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/HLL/SerializationContextBuilder.pm

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class HLL::Compiler::SerializationContextBuilder {
7171
method slot_for_object($obj) {
7272
my $slot := %!addr_to_slot{addr($obj)};
7373
unless pir::defined($slot) {
74-
pir::die('slot_for called on object no in context');
74+
pir::die('slot_for_object called on object not in context');
7575
}
7676
$slot
7777
}
@@ -87,11 +87,23 @@ class HLL::Compiler::SerializationContextBuilder {
8787

8888
# Utility sub to wrap PAST with slot setting.
8989
method set_slot_past($slot, $past_to_set) {
90-
return PAST::Op.new( :pirop('nqp_set_sc_object vsiP'), $!handle, $slot, $past_to_set );
90+
return PAST::Op.new( :pirop('nqp_set_sc_object vsiP'),
91+
$!handle, $slot, $past_to_set);
92+
}
93+
94+
# Used when deserializing. Makes sure the object being
95+
# deserialized has the current SC set.
96+
method set_cur_sc($to_wrap) {
97+
PAST::Op.new(
98+
:pirop('nqp_set_sc_for_object__0PP'),
99+
$to_wrap,
100+
PAST::Var.new( :name('cur_sc'), :scope('register') )
101+
)
91102
}
92103

93104
# Adds an object to the root set, along with a mapping.
94105
method add_object($obj) {
106+
pir::nqp_set_sc_for_object__vPP($obj, $!sc);
95107
my $idx := $!sc.elems();
96108
$!sc[$idx] := $obj;
97109
%!addr_to_slot{addr($obj)} := $idx;
@@ -158,8 +170,8 @@ class HLL::Compiler::SerializationContextBuilder {
158170
if pir::defined($repr) {
159171
$setup_call.push(PAST::Val.new( :value($repr), :named('repr') ));
160172
}
161-
# XXX Not quite ready to really do this yet...
162-
#self.add_event(:deserialize_past(self.set_slot_past($slot, $setup_call)));
173+
self.add_event(:deserialize_past(
174+
self.set_slot_past($slot, self.set_cur_sc($setup_call))));
163175

164176
# Result is just the object.
165177
return $mo;
@@ -211,7 +223,11 @@ class HLL::Compiler::SerializationContextBuilder {
211223
PAST::Stmts.new(
212224
PAST::Op.new( :pirop('nqp_dynop_setup v') ),
213225
PAST::Op.new( :pirop('load_bytecode vs'), 'nqpmo.pbc' ),
214-
PAST::Op.new( :pirop('nqp_create_sc Ps'), $!handle ),
226+
PAST::Op.new(
227+
:pasttype('bind'),
228+
PAST::Var.new( :name('cur_sc'), :scope('register'), :isdecl(1) ),
229+
PAST::Op.new( :pirop('nqp_create_sc Ps'), $!handle )
230+
),
215231
$des
216232
),
217233
$fix

src/NQP/Actions.pm

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,7 @@ method package_def($/) {
421421
$*PACKAGE-SETUP.unshift(PAST::Stmts.new(
422422
PAST::Op.new( :pasttype('bind'),
423423
PAST::Var.new( :name('type_obj'), :scope('register'), :isdecl(1) ),
424-
PAST::Op.new(
425-
:pasttype('callmethod'), :name('new_type'),
426-
PAST::Var.new( :name($how.HOW.name($how)), :namespace(''), :scope('package') ),
427-
PAST::Val.new( :value($name), :named('name') )
428-
)
424+
$*SC.get_slot_past_for_object($*PKGMETA)
429425
),
430426
PAST::Op.new( :pasttype('bind'),
431427
PAST::Var.new( :name($name), :namespace(@ns), :scope('package') ),
@@ -437,13 +433,6 @@ method package_def($/) {
437433
)
438434
));
439435

440-
# Pass along a custom REPR if one is selected.
441-
if $<repr> {
442-
my $repr_name := $<repr>[0].ast;
443-
$repr_name.named('repr');
444-
$*PACKAGE-SETUP[0][0][1].push($repr_name);
445-
}
446-
447436
# Evaluate everything in the package in-line unless this is a generic
448437
# type in which case it needs delayed evaluation. Normally, $?CLASS is
449438
# a lexical that is set (XXX currently package-scoped as Parrot does not

0 commit comments

Comments
 (0)