Skip to content

Commit 0e65c0a

Browse files
committed
Rename HLL::Compiler::SerializationContextBuilder to HLL::World. Also rename the over-long, but widely used get_object_sc_ref_past to just get_ref.
1 parent 6ad0a71 commit 0e65c0a

File tree

4 files changed

+29
-35
lines changed

4 files changed

+29
-35
lines changed

src/HLL/SerializationContextBuilder.pm renamed to src/HLL/World.pm

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
1-
# A serialization context contains a bunch of objects that we want to persist
2-
# across the compile time / run time boundary.
1+
# While the grammar represents the syntactic elements of our language and
2+
# the actions take care of building up an AST to represent the semantics
3+
# of it, the world is about the declarative aspects of a language. This
4+
# includes:
35
#
4-
# The long term goal is that we'll support actually serializing these in an
5-
# efficient way, and be able to do load-time linking between objects in
6-
# different libraries. For now, that's a lot of work, so we adopt a simpler
7-
# approach, in the hope that it will be upgradeable to a "full blown"
8-
# mechanism in the future.
6+
# * Symbol table management
7+
# * Creating meta-object instances
8+
# * Parts of library loading (most likely it delegates to an actual loader)
9+
# * Resolving references to objects, within or between compilation units
910
#
10-
# A serialization context is essentially made up of objects and "events" that
11-
# we perform on them. By performing an action on an object through the context
12-
# builder, it ensures that the action is performed both on the object now, and
13-
# also enough information is persisted to be able to re-create an object with
14-
# the same state. There are two common situations.
11+
# Just as there is one AST produced per compilation unit, there is also a
12+
# world produce per compilation unit.
1513
#
16-
# 1) We compile some code and run it straight away. In this case, the objects
17-
# have already been created, and we only need to do some fixing up.
18-
# 2) We compile some code and persist it as PIR. In this case, the objects need
19-
# to be re-created by replaying the event stream that creates them.
14+
# A world includes a serialization context. This contains a bunch of
15+
# objects - often meta-objects - that we want to persist across the
16+
# compile time / run time boundary. In the near future, we'll switch to
17+
# actually serializing these. At the moment, we instead save a series of
18+
# "events" that will be used to re-construct them.
2019
#
21-
# Essentially, we use PIR as our serialization language until we can do better.
22-
# Note that deserialization and installation aren't the same thing; the first
23-
# step sees us producing an array of objects, while the second is about putting
24-
# them in places the HLL can find them.
25-
#
26-
# It may be that this approach will also carry almost directly over to nqpclr
27-
# and nqpjvm.
20+
# Note that this reconstruction code is not generated in the case that we
21+
# are just going to immediately run.
2822

29-
class HLL::Compiler::SerializationContextBuilder {
23+
class HLL::World {
3024
# Represents an event that we need to handle when fixing up or deserializing.
3125
my class Event {
3226
# The PAST that we emit to perform the action if in deserialization mode.
@@ -73,8 +67,8 @@ class HLL::Compiler::SerializationContextBuilder {
7367
method BUILD(:$handle!, :$description!) {
7468
$!sc := pir::nqp_create_sc__PS($handle);
7569
$!handle := $handle;
76-
%!addr_to_slot := pir::new('Hash');
77-
@!event_stream := pir::new('ResizablePMCArray');
70+
%!addr_to_slot := nqp::hash();
71+
@!event_stream := nqp::list();
7872
$!sc.set_description($description);
7973
$!precomp_mode := %*COMPILING<%?OPTIONS><target> eq 'pir';
8074
}
@@ -163,7 +157,7 @@ class HLL::Compiler::SerializationContextBuilder {
163157

164158
# Gets PAST for referencing an object in a serialization context,
165159
# either the one being built or another one.
166-
method get_object_sc_ref_past($obj) {
160+
method get_ref($obj) {
167161
# Get the object's serialization context; we're stuck if it
168162
# has none.
169163
my $sc := pir::nqp_get_sc_for_object__PP($obj);

src/NQP/Actions.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ class NQP::Actions is HLL::Actions {
831831
unless $past<signature_has_invocant> {
832832
$past[0].unshift(PAST::Var.new(
833833
:name('self'), :scope('parameter'), :directaccess(1),
834-
:multitype($*SC.get_object_sc_ref_past($*PACKAGE))
834+
:multitype($*SC.get_ref($*PACKAGE))
835835
));
836836
}
837837
$past.symbol('self', :scope('lexical') );
@@ -976,7 +976,7 @@ class NQP::Actions is HLL::Actions {
976976
my $found := 0;
977977
try {
978978
my $sym := find_sym(@name, $/);
979-
make $*SC.get_object_sc_ref_past($sym);
979+
make $*SC.get_ref($sym);
980980
$found := 1;
981981
}
982982
unless $found {

src/NQP/World.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use NQPP6Regex;
22

33
# This builds upon the SerializationContextBuilder to add the specifics
44
# needed by NQP.
5-
class NQP::World is HLL::Compiler::SerializationContextBuilder {
5+
class NQP::World is HLL::World {
66
# XXX We need to load the module loader to load modules, which means we
77
# can't just use ...; it, which means we can't get the ModuleLoader symbol
88
# merged into anywhere...anyway, we chop the circularity by finding it
@@ -166,7 +166,7 @@ class NQP::World is HLL::Compiler::SerializationContextBuilder {
166166
my $how_name := @how_ns.pop();
167167
my $setup_call := PAST::Op.new(
168168
:pasttype('callmethod'), :name('new_type'),
169-
self.get_object_sc_ref_past($how)
169+
self.get_ref($how)
170170
);
171171
if pir::defined($name) {
172172
$setup_call.push(PAST::Val.new( :value($name), :named('name') ));
@@ -196,13 +196,13 @@ class NQP::World is HLL::Compiler::SerializationContextBuilder {
196196
if self.is_precompilation_mode() {
197197
my $create_call := PAST::Op.new(
198198
:pasttype('callmethod'), :name('new'),
199-
self.get_object_sc_ref_past($meta_attr)
199+
self.get_ref($meta_attr)
200200
);
201201
for %lit_args {
202202
$create_call.push(PAST::Val.new( :value($_.value), :named($_.key) ));
203203
}
204204
for %obj_args {
205-
my $lookup := self.get_object_sc_ref_past($_.value);
205+
my $lookup := self.get_ref($_.value);
206206
$lookup.named($_.key);
207207
$create_call.push($lookup);
208208
}
@@ -378,7 +378,7 @@ class NQP::World is HLL::Compiler::SerializationContextBuilder {
378378
:pasttype('callmethod'), :name($meta_method_name),
379379
PAST::Op.new( :pirop('get_how PP'), $slot_past ),
380380
$slot_past,
381-
self.get_object_sc_ref_past($to_add)
381+
self.get_ref($to_add)
382382
)));
383383
}
384384
}

tools/build/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ HLL_SOURCES = \
7272
src/HLL/Actions.pm \
7373
src/HLL/Compiler.pm \
7474
src/HLL/CommandLine.pm \
75-
src/HLL/SerializationContextBuilder.pm \
75+
src/HLL/World.pm \
7676

7777
P6REGEX_SOURCES = \
7878
src/Regex/P6Regex/Grammar.pm \

0 commit comments

Comments
 (0)