Permalink
Browse files

Eliminate Beta as a separate pass, inline subs during the parse

  • Loading branch information...
1 parent 583ebc1 commit 612a7b74095d79fa248a9bb3baa61c027e62b2b1 @sorear committed Jun 11, 2011
Showing with 47 additions and 96 deletions.
  1. +5 −6 Makefile
  2. +7 −12 src/NieczaActions.pm6
  3. +8 −10 src/Op.pm6
  4. +11 −34 src/{NieczaPassBeta.pm6 → OptBeta.pm6}
  5. +16 −34 src/niecza
View
@@ -18,9 +18,9 @@ csxdr=CrossDomainReceiver.cs
libunits=CORE JSYNC
srcunits=CClass CgOp Op OpHelpers Sig RxOp NAME Stash STD NieczaGrammar \
Metamodel OptRxSimple NAMOutput Operator NieczaActions \
- NieczaFrontendSTD NieczaPassBeta NieczaPassSimplifier \
- NieczaPathSearch NieczaBackendNAM NieczaBackendDotnet \
- NieczaBackendClisp NieczaBackendHoopl NieczaCompiler GetOptLong
+ NieczaFrontendSTD NieczaPassSimplifier OptBeta NieczaPathSearch \
+ NieczaBackendNAM NieczaBackendDotnet NieczaBackendClisp \
+ NieczaBackendHoopl NieczaCompiler GetOptLong
all: run/Niecza.exe obj/Kernel.dll obj/CORE.nam obj/CLRBackend.exe
@git describe --tags > VERSION
@@ -125,7 +125,7 @@ help:
@echo 'help this list of targets'
@echo ''
-# grep -r '^use' src/*.pm6 | sed 's|src/\(.*\)\.pm6:use \(.*\);|boot/obj/\1.nam: boot/obj/\2.nam|'
+# grep -r '^use' src/*.pm6 | sed 's|src/\(.*\)\.pm6:use \(.*\);|boot/obj/\1.nam: boot/obj/\2.nam|' | grep -v MONKEY_TYPING
boot/obj/Metamodel.nam: boot/obj/NAME.nam
boot/obj/Metamodel.nam: boot/obj/Stash.nam
boot/obj/NAMOutput.nam: boot/obj/JSYNC.nam
@@ -135,7 +135,6 @@ boot/obj/NieczaActions.nam: boot/obj/Op.nam
boot/obj/NieczaActions.nam: boot/obj/RxOp.nam
boot/obj/NieczaActions.nam: boot/obj/Sig.nam
boot/obj/NieczaActions.nam: boot/obj/CClass.nam
-boot/obj/NieczaActions.nam: boot/obj/OptRxSimple.nam
boot/obj/NieczaActions.nam: boot/obj/OpHelpers.nam
boot/obj/NieczaActions.nam: boot/obj/Operator.nam
boot/obj/NieczaBackendClisp.nam: boot/obj/NieczaBackendNAM.nam
@@ -149,10 +148,10 @@ boot/obj/NieczaFrontendSTD.nam: boot/obj/Stash.nam
boot/obj/NieczaFrontendSTD.nam: boot/obj/NieczaGrammar.nam
boot/obj/NieczaFrontendSTD.nam: boot/obj/NieczaActions.nam
boot/obj/NieczaGrammar.nam: boot/obj/STD.nam
-boot/obj/NieczaPassBeta.nam: boot/obj/CgOp.nam
boot/obj/Operator.nam: boot/obj/Sig.nam
boot/obj/Operator.nam: boot/obj/OpHelpers.nam
boot/obj/Op.nam: boot/obj/CgOp.nam
+boot/obj/OptBeta.nam: boot/obj/CgOp.nam
boot/obj/OptRxSimple.nam: boot/obj/RxOp.nam
boot/obj/RxOp.nam: boot/obj/CgOp.nam
boot/obj/RxOp.nam: boot/obj/CClass.nam
View
@@ -4,7 +4,6 @@ use Op;
use RxOp;
use Sig;
use CClass;
-use OptRxSimple;
use OpHelpers;
use Operator;
@@ -281,7 +280,7 @@ method op_for_regex($/, $rxop) {
my $*endsym;
$rxop.check
}
- my ($orxop, $mb) = OptRxSimple.run($rxop);
+ my ($orxop, $mb) = ::GLOBAL::OptRxSimple.run($rxop);
self.block_expr($/, self.thunk_sub(::Op::RegexBody.new(|node($/),
canback => $mb, pre => @lift, rxop => $orxop),
class => 'Regex', params => ['self']));
@@ -303,7 +302,7 @@ method encapsulate_regex($/, $rxop, :$goal, :$passcut = False,
:$passcap = False) {
my @lift = $rxop.oplift;
my $lad = $rxop.lad;
- my ($nrxop, $mb) = OptRxSimple.run($rxop);
+ my ($nrxop, $mb) = ::GLOBAL::OptRxSimple.run($rxop);
if defined $goal {
unshift @lift, ::Op::Bind.new(|node($/), readonly => True,
lhs => mklex($/, '$*GOAL'),
@@ -399,8 +398,8 @@ method regex_def($/) {
$ast.check;
}
my @lift = $ast.oplift;
- $*CURLEX<!sub>.ltm = OptRxSimple.run_lad($ast.lad);
- ($ast, my $mb) = OptRxSimple.run($ast);
+ $*CURLEX<!sub>.ltm = ::GLOBAL::OptRxSimple.run_lad($ast.lad);
+ ($ast, my $mb) = ::GLOBAL::OptRxSimple.run($ast);
$*CURLEX<!sub>.add_my_name('$*/');
$*CURLEX<!sub>.code = ::Op::RegexBody.new(|node($/), pre => @lift,
name => ($*CURLEX<!name> // ''), rxop => $ast, canback => $mb);
@@ -1075,8 +1074,7 @@ method circumfix:sym<{ }> ($/) {
if self.check_hash($/) {
make mkcall($/, '&_hash_constructor',
- ::Op::CallSub.new(|node($/),
- invocant => ::Op::SubDef.new(symbol=>$var, :once)))
+ ::GLOBAL::OptBeta.make_call($var));
}
}
@@ -2741,8 +2739,7 @@ method statement_control:loop ($/) {
method statement_control:for ($/) {
make ::Op::ForLoop.new(|node($/), source => $<xblock>.ast[0],
- sink => ::Op::SubDef.new(:once, symbol =>
- self.block_expr($/, $<xblock>.ast[1]).name));
+ sink => self.block_expr($/, $<xblock>.ast[1]).name);
}
method statement_control:given ($/) {
@@ -3028,9 +3025,7 @@ method block_expr($/, $pb) {
method inliney_call($/, $block, *@parms) {
my $sym = self.gensym;
$*CURLEX<!sub>.add_my_sub_child($sym, $block);
- ::Op::CallSub.new(|node($/),
- invocant => ::Op::SubDef.new(symbol => $sym, :once),
- positionals => @parms);
+ ::GLOBAL::OptBeta.make_call($sym, @parms);
}
# this is intended to be called after parsing the longname for a sub,
View
@@ -423,24 +423,22 @@ class GeneralLoop is Op {
}
class ForLoop is Op {
- has $.source = die "ForLoop.source required"; # Op
- has $.sink = die "ForLoop.sink required"; # Op
+ has Op $.source = die "ForLoop.source required";
+ has Str $.sink = die "ForLoop.sink required";
method zyg() { $.source, $.sink }
method code($body) {
- CgOp.methodcall(
- CgOp.subcall(CgOp.fetch(CgOp.corelex('&flat')),
- $.source.cgop($body)), 'map', $.sink.cgop($body));
+ CgOp.methodcall(CgOp.subcall(CgOp.fetch(CgOp.corelex('&flat')),
+ $.source.cgop($body)), 'map', CgOp.scopedlex($!sin));
}
method statement_level() {
- my $body = $*CURLEX<!sub>.find_lex($!sink.symbol).body;
+ my $body = $*CURLEX<!sub>.find_lex($!sink).body;
my $var = [ map { ::GLOBAL::NieczaActions.gensym },
0 ..^ +$body.signature.params ];
- $!sink.once = True;
::Op::ImmedForLoop.new(source => $!source, var => $var,
- sink => ::Op::CallSub.new(invocant => $!sink,
- positionals => [ map { ::Op::LetVar.new(name => $_) }, @$var]));
+ sink => ::GLOBAL::OptBeta.make_call($!sink,
+ map { ::Op::LetVar.new(name => $_) }, @$var));
}
}
@@ -623,7 +621,7 @@ class BareBlock is Op {
$body.run_once = $body.outer.run_once;
}
- ::Op::CallSub.new(invocant => ::Op::SubDef.new(:once, symbol => $!var));
+ ::GLOBAL::OptBeta.make_call($!var);
}
}
@@ -1,43 +1,20 @@
-class NieczaPassBeta;
+class OptBeta;
use CgOp;
# A simple Perl6 compiler generates a lot of expressions of the form
# (-> $x { block })($y), due to control structures and regexes. Try to clean
# that up here.
-method invoke($*unit) {
- # XXX enter and sigs need love
- $*unit.visit_local_subs_postorder(-> $su {
- $su.code = run_optree($su, $su.code)
- });
- $*unit;
-}
-
-sub run_optree($body, $op) {
-
- for $op.zyg {
- $_ = run_optree($body, $_);
- }
-
- return $op unless $op.^isa(::Op::CallSub) && no_named_params($op);
- my $inv = $op.invocant;
- return $op unless $inv.^isa(::Op::SubDef) && $inv.once;
- my $cbody = $body.find_lex($inv.symbol) or return $op;
+method make_call($var, *@params) {
+ my $nonopt = ::Op::CallSub.new(
+ positionals => [ @params ],
+ invocant => ::Op::Lexical.new(name => $var));
+ my $cbody = $*CURLEX<!sub>.find_lex($var) or return $nonopt;
$cbody = $cbody.body;
- return $op unless is_removable_body($cbody);
+ return $nonopt unless is_removable_body($cbody);
- beta_optimize($body, $op, $inv, $cbody);
-}
-
-sub no_named_params($op) {
- if defined $op.args {
- for @( $op.args ) {
- # XXX flattening check?
- return False if $_.^isa(::Op::SimplePair);
- }
- }
- return True;
+ beta_optimize($*CURLEX<!sub>, $var, $cbody, @params);
}
sub is_removable_body($body) {
@@ -73,12 +50,12 @@ sub is_removable_body($body) {
}
# Applicability already checked
-sub beta_optimize($body, $op, $inv, $cbody) {
+sub beta_optimize($body, $symbol, $cbody, @inpos) {
# Bind the arguments to gensyms so they won't be shadowed by anything in
# the function
- my @args = map { [ $_, ::GLOBAL::NieczaActions.gensym ] }, @( $op.positionals );
+ my @args = map { [ $_, ::GLOBAL::NieczaActions.gensym ] }, @inpos;
- $body.delete_lex($inv.symbol);
+ $body.delete_lex($symbol);
$*unit.xref.[$cbody.xref[1]] = Any;
{
my $c = $cbody.outer.zyg;
View
@@ -1,30 +1,28 @@
-use Metamodel;
-use Op;
-use RxOp;
+use MONKEY_TYPING;
use CClass;
use CgOp;
+use GetOptLong;
use JSYNC;
+use Metamodel;
use NAMOutput;
-use NieczaFrontendSTD;
-use NieczaPassBeta;
-use NieczaPassSimplifier;
-use NieczaBackendNAM;
-use NieczaBackendDotnet;
+use NieczaActions;
use NieczaBackendClisp;
+use NieczaBackendDotnet;
use NieczaBackendHoopl;
-use NieczaPathSearch;
+use NieczaBackendNAM;
use NieczaCompiler;
-
-use MONKEY_TYPING;
-
-use GetOptLong;
-use NieczaActions;
-use OpHelpers;
+use NieczaFrontendSTD;
+use NieczaPassSimplifier;
+use NieczaPathSearch;
+use Op;
use Operator;
+use OpHelpers;
+use OptBeta;
use OptRxSimple;
-use STD;
-use Stash;
+use RxOp;
use Sig;
+use Stash;
+use STD;
CgOp._register_ops: <
>;
@@ -102,22 +100,6 @@ else {
exit 1;
}
-my $stages;
-if $bcnd eq 'clisp' {
- $stages = [
- NieczaPassSimplifier.new,
- ];
-} elsif $bcnd eq 'hoopl' {
- $stages = [
- NieczaPassSimplifier.new,
- ];
-} else {
- $stages = [
- NieczaPassBeta.new,
- NieczaPassSimplifier.new,
- ];
-}
-
my $c = NieczaCompiler.new(
module_finder => NieczaPathSearch.new(
path => @lib,
@@ -126,7 +108,7 @@ my $c = NieczaCompiler.new(
lang => $lang,
safemode => $safe,
),
- stages => $stages,
+ stages => [ NieczaPassSimplifier.new ],
backend => $backend,
verbose => $verb,
);

0 comments on commit 612a7b7

Please sign in to comment.