Created
February 19, 2013 19:21
-
-
Save gerdr/4988971 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/HLL/Compiler.pm b/src/HLL/Compiler.pm | |
index f9869b3..0981ee3 100644 | |
--- a/src/HLL/Compiler.pm | |
+++ b/src/HLL/Compiler.pm | |
@@ -78,7 +78,7 @@ class HLL::Compiler { | |
$stdin.encoding($encoding); | |
} | |
- my $target := nqp::lc(%adverbs<target>); | |
+ my $target := %adverbs<target>; | |
my $save_ctx; | |
while 1 { | |
last unless $stdin; | |
@@ -212,10 +212,18 @@ class HLL::Compiler { | |
my %opts := $res.options; | |
my @a := $res.arguments; | |
+ # fixup options | |
+ %opts<target> := nqp::lc(%opts<target>); | |
+ %opts<help> := %opts<h> unless %opts<help>; | |
+ %opts<output> := %opts<o> unless %opts<output>; | |
+ %opts<version> := %opts<v> unless %opts<version>; | |
+ %opts<verbose-config> := %opts<V> unless %opts<verbose-config>; | |
+ | |
%adverbs.update(%opts); | |
- self.usage($program-name) if %adverbs<help> || %adverbs<h>; | |
- | |
- if !nqp::existskey(%adverbs, 'precomp') && %adverbs<target> eq 'pir' { | |
+ self.usage($program-name) if %adverbs<help>; | |
+ | |
+ if !nqp::existskey(%adverbs, 'precomp') | |
+ && (%adverbs<target> eq 'pir' || %adverbs<target> eq 'pbc') { | |
%adverbs<precomp> := 1; | |
} | |
@@ -227,36 +235,42 @@ class HLL::Compiler { | |
method command_eval(*@a, *%adverbs) { | |
- self.version if %adverbs<version> || %adverbs<v>; | |
- self.verbose-config if %adverbs<verbose-config> || %adverbs<V> | |
- || %adverbs<show-config>; | |
+ self.version if %adverbs<version>; | |
+ self.verbose-config if %adverbs<verbose-config> || %adverbs<show-config>; | |
self.nqpevent(%adverbs<nqpevent>) if %adverbs<nqpevent>; | |
my $result; | |
my $error; | |
my $has_error := 0; | |
- my $target := nqp::lc(%adverbs<target>); | |
+ my $target := %adverbs<target>; | |
try { | |
if nqp::defined(%adverbs<e>) { | |
$!user_progname := '-e'; | |
my $?FILES := '-e'; | |
$result := self.eval(%adverbs<e>, '-e', |@a, |%adverbs); | |
- unless $target eq '' || $target eq 'pir' || %adverbs<output> { | |
- self.dumper($result, $target, |%adverbs); | |
- } | |
+ unless $target eq '' || $target eq 'pir' || $target eq 'pbc' | |
+ || %adverbs<output> { | |
+ self.dumper($result, $target, |%adverbs); | |
+ } | |
} | |
elsif !@a { $result := self.interactive(|%adverbs) } | |
elsif %adverbs<combine> { $result := self.evalfiles(@a, |%adverbs) } | |
else { $result := self.evalfiles(@a[0], |@a, |%adverbs) } | |
- if !nqp::isnull($result) && ($target eq 'pir' || %adverbs<output>) { | |
- my $output := %adverbs<output>; | |
- my $fh := ($output eq '' || $output eq '-') | |
- ?? pir::getinterp__P().stdout_handle() | |
- !! pir::new__Ps('FileHandle').open($output, 'w'); | |
- self.panic("Cannot write to $output") unless $fh; | |
- $fh.print($result); | |
- $fh.close() | |
+ if !nqp::isnull($result) && $target ne '' { | |
+ if $target eq 'pbc' { | |
+ my $output := %adverbs<output>; | |
+ $result.write_to_file($output) if $output; | |
+ } | |
+ else { | |
+ my $output := %adverbs<output>; | |
+ my $fh := ($output eq '' || $output eq '-') | |
+ ?? pir::getinterp__P().stdout_handle() | |
+ !! pir::new__Ps('FileHandle').open($output, 'w'); | |
+ self.panic("Cannot write to $output") unless $fh; | |
+ $fh.print($result); | |
+ $fh.close(); | |
+ } | |
} | |
CATCH { | |
$has_error := 1; | |
@@ -314,7 +328,7 @@ class HLL::Compiler { | |
} | |
method evalfiles($files, *@args, *%adverbs) { | |
- my $target := nqp::lc(%adverbs<target>); | |
+ my $target := %adverbs<target>; | |
my $encoding := %adverbs<encoding>; | |
my @files := nqp::islist($files) ?? $files !! [$files]; | |
$!user_progname := nqp::join(',', @files); | |
@@ -348,7 +362,7 @@ class HLL::Compiler { | |
method compile($source, *%adverbs) { | |
my %*COMPILING<%?OPTIONS> := %adverbs; | |
- my $target := nqp::lc(%adverbs<target>); | |
+ my $target := %adverbs<target>; | |
my $result := $source; | |
my $stderr := pir::getinterp__P().stderr_handle; | |
my $stdin := pir::getinterp__P().stdin_handle; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/QRegex/Cursor.nqp b/src/QRegex/Cursor.nqp | |
index 1a93813..d00c453 100755 | |
--- a/src/QRegex/Cursor.nqp | |
+++ b/src/QRegex/Cursor.nqp | |
@@ -727,7 +727,8 @@ class NQPCursor does NQPCursorRole { | |
my $res := []; | |
for $var { | |
my $elem := $_; | |
- $elem := $rxcompiler.compile($elem) unless nqp::isinvokable($elem); | |
+ $elem := $rxcompiler.compile($elem) | |
+ unless nqp::isinvokable($elem); | |
nqp::push($res, $elem); | |
} | |
$var := $res; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/HLL/Compiler.pm b/src/HLL/Compiler.pm | |
index f9869b3..0981ee3 100644 | |
--- a/src/HLL/Compiler.pm | |
+++ b/src/HLL/Compiler.pm | |
@@ -30,8 +30,8 @@ class HLL::Compiler { | |
method BUILD() { | |
# Default stages. | |
- @!stages := nqp::split(' ', 'start parse past post pir evalpmc'); | |
- | |
+ @!stages := nqp::split(' ', 'start parse past post pir pbc init'); | |
+ | |
# Command options and usage. | |
@!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'); | |
$!usage := "This compiler is based on HLL::Compiler.\n\nOptions:\n"; | |
@@ -420,14 +434,26 @@ class HLL::Compiler { | |
~ ".include 'datatypes.pasm'\n" | |
~ ".include 'libpaths.pasm'\n" | |
} | |
- | |
+ | |
method pir($source, *%adverbs) { | |
self.pirbegin() ~ $source.pir() | |
} | |
- method evalpmc($source, *%adverbs) { | |
- my $compiler := pir::compreg__Ps('PIR'); | |
- $compiler($source) | |
+ method pbc($source, *%adverbs) { | |
+ pir::compreg__Ps('PIR').compile($source) | |
+ } | |
+ | |
+ method init($source, *%adverbs) { | |
+ unless $source.is_initialized('init') { | |
+ for $source.subs_by_tag('init') -> $sub { $sub() } | |
+ $source.mark_initialized('init'); | |
+ } | |
+ | |
+ # FIXME: should use a custom tag | |
+ # changes to code generator still pending | |
+ # | |
+ # $source.single_sub_by_tag('mainline') | |
+ $source.first_sub_in_const_table() | |
} | |
method dumper($obj, $name, *%options) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/t/qast/pirt.t b/t/qast/pirt.t | |
index deb2ba1..4712c83 100644 | |
--- a/t/qast/pirt.t | |
+++ b/t/qast/pirt.t | |
@@ -6,8 +6,9 @@ sub is_pirt_result($producer, $expected, $desc) { | |
my $pirt := $producer(); | |
my $pir := $pirt.pir(); | |
#say($pir); | |
- my $pbc := QAST::Compiler.evalpmc($pir); | |
- ok($pbc() eq $expected, $desc); | |
+ my $pbc := QAST::Compiler.pbc($pir); | |
+ my $sub := QAST::Compiler.init($pbc); | |
+ ok($sub() eq $expected, $desc); | |
} | |
is_pirt_result({ | |
diff --git a/t/qast/qast.t b/t/qast/qast.t | |
index 13026cf..b87207c 100644 | |
--- a/t/qast/qast.t | |
+++ b/t/qast/qast.t | |
@@ -7,7 +7,8 @@ sub compile_qast($qast) { | |
my $*QAST_BLOCK_NO_CLOSE := 1; | |
my $pirt := QAST::Compiler.as_post($qast); | |
my $pir := $pirt.pir(); | |
- QAST::Compiler.evalpmc($pir); | |
+ my $pbc := QAST::Compiler.pbc($pir); | |
+ QAST::Compiler.init($pbc); | |
} | |
sub is_qast($qast, $value, $desc) { | |
try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/NQP/World.pm b/src/NQP/World.pm | |
index f8d5460..05d25d1 100644 | |
--- a/src/NQP/World.pm | |
+++ b/src/NQP/World.pm | |
@@ -240,26 +240,28 @@ class NQP::World is HLL::World { | |
my $nqpcomp := nqp::getcomp('nqp'); | |
my $post := $nqpcomp.post(QAST::CompUnit.new( :hll('nqp'), $past )); | |
my $pir := $nqpcomp.pir($post); | |
- my $compiled := $nqpcomp.evalpmc($pir); | |
+ my $pbc := $nqpcomp.pbc($pir); | |
+ my $mainline := $nqpcomp.init($pbc); | |
# Fix up any code objects holding stubs with the real compiled thing. | |
- my $c := nqp::elems($compiled); | |
+ my @all_subs := $pbc.all_subs(); | |
+ my $c := nqp::elems(@all_subs); | |
my $i := 0; | |
while $i < $c { | |
- my $subid := $compiled[$i].get_subid(); | |
+ my $subid := @all_subs[$i].get_subid(); | |
if nqp::existskey(%!code_objects_to_fix_up, $subid) { | |
# First, go over the code objects. Update the $!do, and the | |
# entry in the SC. Make sure the newly compiled code is marked | |
# as a static code ref. | |
my $static := %!code_objects_to_fix_up{$subid}.shift(); | |
- nqp::bindattr($static, %!code_object_types{$subid}, '$!do', $compiled[$i]); | |
+ nqp::bindattr($static, %!code_object_types{$subid}, '$!do', @all_subs[$i]); | |
nqp::bindattr($static, %!code_object_types{$subid}, '$!clone_callback', nqp::null()); | |
for %!code_objects_to_fix_up{$subid} { | |
- nqp::bindattr($_, %!code_object_types{$subid}, '$!do', nqp::clone($compiled[$i])); | |
+ nqp::bindattr($_, %!code_object_types{$subid}, '$!do', nqp::clone(@all_subs[$i])); | |
nqp::bindattr($_, %!code_object_types{$subid}, '$!clone_callback', nqp::null()); | |
} | |
- pir::setprop__vPsP($compiled[$i], 'STATIC_CODE_REF', $compiled[$i]); | |
- self.update_root_code_ref(%!code_stub_sc_idx{$subid}, $compiled[$i]); | |
+ pir::setprop__vPsP(@all_subs[$i], 'STATIC_CODE_REF', @all_subs[$i]); | |
+ self.update_root_code_ref(%!code_stub_sc_idx{$subid}, @all_subs[$i]); | |
# Clear up the fixup statements. | |
my $fixup_stmts := %!code_object_fixup_list{$subid}; | |
@@ -268,7 +270,7 @@ class NQP::World is HLL::World { | |
$i := $i + 1; | |
} | |
- $compiled(|@args, |%named); | |
+ $mainline(|@args, |%named); | |
}; | |
# Create code object, if we'll need one. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment