Skip to content

Commit 80b8275

Browse files
committed
First bits towards SC cross-referencing. Not able to use it just yet, due to issues with bootstrap layer reificationa and separate compilation. :/
1 parent c8c7a6f commit 80b8275

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/HLL/SerializationContextBuilder.pm

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,30 @@ class HLL::Compiler::SerializationContextBuilder {
117117
));
118118
}
119119

120+
# Gets PAST for referencing an object in a serialization context,
121+
# either the one being built or another one.
122+
method get_object_sc_ref_past($obj) {
123+
# Get the object's serialization context; we're stuck if it
124+
# has none.
125+
my $sc := pir::nqp_get_sc_for_object__PP($obj);
126+
if pir::isnull__IP($sc) {
127+
pir::die("Object of type '" ~ $obj.HOW.name($obj) ~
128+
"' cannot be referenced without having been " ~
129+
"assigned a serialization context");
130+
}
131+
132+
# If it's this context, dead easy. Otherwise, need to build a
133+
# cross-reference.
134+
if $sc =:= $!sc {
135+
self.get_slot_past_for_object($obj);
136+
}
137+
else {
138+
PAST::Op.new( :pirop('nqp_get_sc_object Psi'),
139+
$sc.handle, $sc.slot_index_for($obj)
140+
)
141+
}
142+
}
143+
120144
# Loads the setting and emits code
121145
method load_setting($setting_name) {
122146
# Do nothing for the NULL setting.
@@ -161,8 +185,9 @@ class HLL::Compiler::SerializationContextBuilder {
161185
my $how_name := @how_ns.pop();
162186
my $setup_call := PAST::Op.new(
163187
:pasttype('callmethod'), :name('new_type'),
164-
# XXX Should be an SC cross-reference
165188
PAST::Var.new( :name($how_name), :namespace(@how_ns), :scope('package') )
189+
# XXX Not ready to do this quite yet...
190+
# self.get_object_sc_ref_past($how)
166191
);
167192
if pir::defined($name) {
168193
$setup_call.push(PAST::Val.new( :value($name), :named('name') ));

0 commit comments

Comments
 (0)