Skip to content

Commit 2d6a387

Browse files
committed
add --target=pbc to nqp
the factoring of the code isn't perfect, but it does work
1 parent 2e66d67 commit 2d6a387

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

src/HLL/Compiler.pm

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class HLL::Compiler {
3030

3131
method BUILD() {
3232
# Default stages.
33-
@!stages := nqp::split(' ', 'start parse past post pir packfile');
34-
33+
@!stages := nqp::split(' ', 'start parse past post pir pbc init');
34+
3535
# Command options and usage.
3636
@!cmdoptions := nqp::split(' ', 'e=s help|h target=s dumper=s trace|t=s encoding=s output|o=s combine version|v show-config verbose-config|V stagestats=s? ll-exception rxtrace nqpevent=s profile profile-compile');
3737
$!usage := "This compiler is based on HLL::Compiler.\n\nOptions:\n";
@@ -224,8 +224,9 @@ class HLL::Compiler {
224224

225225
%adverbs.update(%opts);
226226
self.usage($program-name) if %adverbs<help> || %adverbs<h>;
227-
228-
if !nqp::existskey(%adverbs, 'precomp') && %adverbs<target> eq 'pir' {
227+
228+
if !nqp::existskey(%adverbs, 'precomp')
229+
&& (%adverbs<target> eq 'pir' || %adverbs<target> eq 'pbc') {
229230
%adverbs<precomp> := 1;
230231
}
231232

@@ -430,19 +431,32 @@ class HLL::Compiler {
430431
~ ".include 'datatypes.pasm'\n"
431432
~ ".include 'libpaths.pasm'\n"
432433
}
433-
434+
434435
method pir($source, *%adverbs) {
435436
self.pirbegin() ~ $source.pir()
436437
}
437438

438-
method packfile($source, *%adverbs) {
439-
my $compiler := pir::compreg__Ps('PIR');
440-
my $packfile := $compiler.compile($source);
439+
method pbc($source, *%adverbs) {
440+
my $packfile := pir::compreg__Ps('PIR').compile($source);
441+
my $output := %adverbs<output> || %adverbs<o>;
442+
$packfile.write_to_file($output) if $output;
443+
$packfile
444+
}
445+
446+
method init($source, *%adverbs) {
447+
self.init_packfile($source)
448+
}
449+
450+
method init_packfile($packfile) {
441451
for $packfile.subs_by_tag('init') -> $sub { $sub(); }
442452
$packfile.mark_initialized('init');
443453
$packfile
444454
}
445455

456+
method compile_and_init($source) {
457+
self.init_packfile(pir::compreg__Ps('PIR').compile($source))
458+
}
459+
446460
method dumper($obj, $name, *%options) {
447461
if nqp::can($obj, 'dump') {
448462
nqp::print($obj.dump());

src/NQP/World.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class NQP::World is HLL::World {
240240
my $nqpcomp := nqp::getcomp('nqp');
241241
my $post := $nqpcomp.post(QAST::CompUnit.new( :hll('nqp'), $past ));
242242
my $pir := $nqpcomp.pir($post);
243-
my $compiled := $nqpcomp.packfile($pir);
243+
my $compiled := $nqpcomp.compile_and_init($pir);
244244

245245
# Fix up any code objects holding stubs with the real compiled thing.
246246
my @all_subs := $compiled.all_subs();

t/qast/pirt.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sub is_pirt_result($producer, $expected, $desc) {
66
my $pirt := $producer();
77
my $pir := $pirt.pir();
88
#say($pir);
9-
my $sub := QAST::Compiler.packfile($pir).main_sub();
9+
my $sub := QAST::Compiler.compile_and_init($pir).main_sub();
1010
ok($sub() eq $expected, $desc);
1111
}
1212

t/qast/qast.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sub compile_qast($qast) {
77
my $*QAST_BLOCK_NO_CLOSE := 1;
88
my $pirt := QAST::Compiler.as_post($qast);
99
my $pir := $pirt.pir();
10-
QAST::Compiler.packfile($pir).main_sub();
10+
QAST::Compiler.compile_and_init($pir).main_sub();
1111
}
1212
sub is_qast($qast, $value, $desc) {
1313
try {

0 commit comments

Comments
 (0)