Permalink
Browse files

Mergeback

  • Loading branch information...
1 parent 34b68ce commit 02ec23fe8b9b71768bbd110d95dd3ab7e2b84e89 @sorear committed May 30, 2011
Showing with 173 additions and 950 deletions.
  1. +71 −295 src/CgOp.pm6
  2. +14 −12 src/NieczaActions.pm6
  3. +11 −15 src/Op.pm6
  4. +2 −3 src/RxOp.pm6
  5. +68 −73 src/STD.pm6
  6. +7 −4 src/Sig.pm6
  7. +0 −548 src/niecza
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -146,7 +146,7 @@ method dec_number ($/) {
method number($/) {
my $child = $<integer> // $<dec_number> // $<rad_number>;
make (defined($child) ?? $child.ast !!
- $child eq 'NaN' ?? NaN !! Inf);
+ $/ eq 'NaN' ?? (0e0/0e0) !! Inf);
}
# Value :: Op
@@ -194,7 +194,7 @@ method unqual_longname($/, $what, $clean?) {
method simple_longname($/) {
my $r = self.mangle_longname($/);
- ($r<rest>:exists) ?? [ @($r<rest>), $r<name> ] !! [ 'MY', $r<name> ];
+ ($r<path>:exists) ?? [ @($r<path>), $r<name> ] !! [ 'MY', $r<name> ];
}
method mangle_longname($/, $clean?) {
@@ -1442,9 +1442,9 @@ method colonpair($/) {
if $tv ~~ Str {
if substr($<v>,1,1) eq '<' {
- $tv = ::Op::CallMethod.new(name => 'at-key',
- receiver => ::Op::ContextVar.new(name => '$*/'),
- args => [::Op::StringLiteral.new(text => ~$<k>)]);
+ $tv = mkcall($/, '&postcircumfix:<{ }>',
+ ::Op::ContextVar.new(name => '$*/'),
+ ::Op::StringLiteral.new(text => ~$<k>));
} else {
$tv = self.do_variable_reference($/,
{ sigil => ~$<v><sigil>,
@@ -1669,17 +1669,17 @@ method variable($/) {
$twigil = '*' if $name eq '/' or $name eq '!';
} elsif $<index> {
make { capid => $<index>.ast, term =>
- ::Op::CallMethod.new(|node($/), name => 'at-pos',
- receiver => ::Op::ContextVar.new(name => '$*/'),
- positionals => [ ::Op::Num.new(value => $<index>.ast) ])
+ mkcall($/, '&postcircumfix:<[ ]>',
+ ::Op::ContextVar.new(name => '$*/'),
+ ::Op::Num.new(value => $<index>.ast))
};
return Nil;
} elsif $<postcircumfix> {
if $<postcircumfix>[0].reduced eq 'postcircumfix:sym<< >>' { #XXX fiddly
make { capid => $<postcircumfix>[0].ast.args[0].text, term =>
- ::Op::CallMethod.new(|node($/), name => 'at-key',
- receiver => ::Op::ContextVar.new(name => '$*/'),
- positionals => $<postcircumfix>[0].ast.args)
+ mkcall($/, '&postcircumfix:<{ }>',
+ ::Op::ContextVar.new(name => '$*/'),
+ @( $<postcircumfix>[0].ast.args))
};
return;
} else {
@@ -1760,6 +1760,7 @@ method param_var($/) {
# :: Sig::Parameter
method parameter($/) {
my $rw = False;
+ my $copy = False;
my $sorry;
my $slurpy = False;
my $slurpycap = False;
@@ -1773,6 +1774,7 @@ method parameter($/) {
for @( $<trait> ) -> $trait {
if $trait.ast<rw> { $rw = True }
+ elsif $trait.ast<copy> { $copy = True }
elsif $trait.ast<parcel> { $rwt = True }
elsif $trait.ast<readonly> { $rw = False }
else {
@@ -1807,7 +1809,7 @@ method parameter($/) {
make ::Sig::Parameter.new(name => ~$/, :$default,
:$optional, :$slurpy, :$rw, type => ($type // 'Any'),
- :$slurpycap, rwtrans => $rwt, |$p.ast);
+ :$slurpycap, rwtrans => $rwt, is_copy => $copy, |$p.ast);
}
# signatures exist in several syntactic contexts so just make an object for now
View
@@ -212,8 +212,7 @@ class SimplePair is Op {
method zyg() { $.value }
method code($body) {
- CgOp.subcall(CgOp.fetch(CgOp.corelex('&infix:<=>>')),
- CgOp.string_var($.key), $.value.cgop($body));
+ CgOp.bif_pair(CgOp.const(CgOp.string_var($.key)), $.value.cgop($body));
}
}
@@ -226,8 +225,7 @@ class SimpleParcel is Op {
}
method code($body) {
- CgOp.subcall(CgOp.fetch(CgOp.corelex('&infix:<,>')),
- map { $_.cgop($body) }, @$.items);
+ CgOp.bif_comma(map { $_.cgop($body) }, @$.items);
}
}
@@ -322,19 +320,19 @@ class ShortCircuitAssign is Op {
my $cassn;
if $.kind eq '&&' {
- $cassn = CgOp.ternary(CgOp.obj_getbool($cond), $assn, CgOp.noop);
+ $cassn = CgOp.ternary(CgOp.obj_getbool($cond), $assn, $cond);
}
elsif $.kind eq '||' {
- $cassn = CgOp.ternary(CgOp.obj_getbool($cond), CgOp.noop, $assn);
+ $cassn = CgOp.ternary(CgOp.obj_getbool($cond), $cond, $assn);
}
elsif $.kind eq 'andthen' {
- $cassn = CgOp.ternary(CgOp.obj_getdef($cond), $assn, CgOp.noop);
+ $cassn = CgOp.ternary(CgOp.obj_getdef($cond), $assn, $cond);
}
elsif $.kind eq '//' {
- $cassn = CgOp.ternary(CgOp.obj_getdef($cond), CgOp.noop, $assn);
+ $cassn = CgOp.ternary(CgOp.obj_getdef($cond), $cond, $assn);
}
- CgOp.letn($sym, $.lhs.cgop($body), $cassn, $cond);
+ CgOp.letn($sym, $.lhs.cgop($body), $cassn);
}
}
@@ -457,10 +455,8 @@ class ImmedForLoop is Op {
my $id = ::GLOBAL::NieczaActions.genid;
CgOp.rnull(CgOp.letn(
- "!iter$id", CgOp.vvarlist_new_empty,
+ "!iter$id", CgOp.start_iter($.source.cgop($body)),
(map { $_, CgOp.null('var') }, @$.var),
- CgOp.vvarlist_push(CgOp.letvar("!iter$id"),
- $.source.cgop($body)),
CgOp.whileloop(0, 0,
CgOp.iter_hasflat(CgOp.letvar("!iter$id")),
CgOp.prog(
@@ -521,8 +517,8 @@ class Start is Op {
CgOp.obj_getbool(CgOp.scopedlex($.condvar)),
CgOp.corelex('Nil'),
CgOp.prog(
- CgOp.assign(CgOp.scopedlex($.condvar),
- CgOp.box('Bool', CgOp.bool(1))),
+ CgOp.sink(CgOp.assign(CgOp.scopedlex($.condvar),
+ CgOp.box('Bool', CgOp.bool(1)))),
$.body.cgop($body)));
}
}
@@ -880,7 +876,7 @@ class Assign is Op {
method zyg() { $.lhs, $.rhs }
method code($body) {
- CgOp.rnull(CgOp.assign($.lhs.cgop($body), $.rhs.cgop($body)));
+ CgOp.assign($.lhs.cgop($body), $.rhs.cgop($body));
}
}
View
@@ -625,10 +625,9 @@ class ProtoRedis is RxOp {
CgOp.compare('>=', CgOp.letvar("i"),
CgOp.mrl_count(CgOp.letvar("fns")))),
CgOp.rxpushb('LTM', 'nextfn'),
- CgOp.letvar("ks", CgOp.vvarlist_new_singleton(
+ CgOp.letvar("ks", CgOp.start_iter(
CgOp.subcall(CgOp.mrl_index(CgOp.letvar("i"),
- CgOp.letvar("fns")), CgOp.newscalar(CgOp.rxcall(
- 'MakeCursor'))))),
+ CgOp.letvar("fns")), CgOp.rxcall('MakeCursorV')))),
CgOp.letvar("i", CgOp.arith('+', CgOp.letvar("i"), CgOp.int(1))),
CgOp.label('nextcsr'),
CgOp.ncgoto('backtrack', CgOp.iter_hasflat(CgOp.letvar('ks'))),
View
@@ -426,54 +426,51 @@ method nibble ($lang) {
}
# note: polymorphic over many quote languages, we hope
-token nibbler {
- :my $text = '';
- :my $from = self.pos;
- :my $to = $from;
- :my @nibbles = ();
- :my $multiline = 0;
- [ <!before <stopper> >
- [
- || <starter> <nibbler> <stopper>
- {
- push @nibbles, Match.synthetic(:cursor(self), :from($from), :to($to), :method<Str>, :captures()) if $from != $to;
+method nibbler() {
+ my @nibbles;
+ my $from = self.pos;
+ my $to = $from;
- my $n = $<nibbler>[*-1]<nibbles>;
- my @n = @$n;
+ loop {
+ my $here = self.cursor($to);
+ last if head($here.stopper);
- push @nibbles, $<starter>;
- push @nibbles, @n;
- push @nibbles, $<stopper>;
+ if head($here.starter) -> $starter {
+ push @nibbles, Match.synthetic(:cursor(self), :$from, :$to,
+ :method<Str>, :captures()) if $from != $to;
- $text = '';
- $to = $from =.pos;
- }
- || <escape> {
- push @nibbles, Match.synthetic(:cursor(self), :from($from), :to($to), :method<Str>, :captures()) if $from != $to;
- push @nibbles, $<escape>[*-1];
- $text = '';
- $to = $from =.pos;
- }
- || .
- {
- my $ch = substr(self.orig, $¢.pos-1, 1);
- $text ~= $ch;
- $to =.pos;
- if $ch ~~ "\n" {
- $multiline++;
- }
- }
- ]
- ]*
- {
- push @nibbles, Match.synthetic(:cursor(self), :from($from), :to($to),
- :method<Str>, :captures()) if $from != $to or !@nibbles;
- $*LAST_NIBBLE =.pos;
- $*LAST_NIBBLE_START = self.pos;
- $*LAST_NIBBLE_MULTILINE =.pos if $multiline;
- $*LAST_NIBBLE_MULTILINE_START =.pos if $multiline;
- }
- $<nibbles> = {@nibbles}
+ my $nibbler = head(self.cursor($starter.to).nibbler) or return ();
+ my $stopper = head(self.cursor($nibbler.to).stopper) or return ();
+
+ $from = $to = $stopper.to;
+ push @nibbles, $starter;
+ push @nibbles, @( $nibbler<nibbles> );
+ push @nibbles, $stopper;
+ }
+ elsif head($here.escape) -> $escape {
+ push @nibbles, Match.synthetic(:cursor(self), :$from, :$to,
+ :method<Str>, :captures()) if $from != $to;
+
+ $from = $to = $escape.to;
+ push @nibbles, $escape;
+ }
+ else {
+ $to++;
+ }
+ }
+
+ push @nibbles, Match.synthetic(:cursor(self), :$from, :$to,
+ :method<Str>, :captures()) if $from != $to || !@nibbles;
+
+ $*LAST_NIBBLE = $to;
+ $*LAST_NIBBLE_START = self.pos;
+ if defined substr(self.orig, self.pos, $to - self.pos).index("\n") {
+ $*LAST_NIBBLE_MULTILINE = $to;
+ $*LAST_NIBBLE_MULTILINE_START = self.pos;
+ }
+
+ Match.synthetic(:cursor(self), from => self.pos, :$to, :method<nibbler>,
+ :captures(nibbles => @nibbles))
}
token babble ($l) {
@@ -595,36 +592,33 @@ token circumfix:sym«< >» { :dba('quote words') '<' ~ '>'
# Lexer routines #
##################
-token ws {
+token ws () {
:my $startpos = Q:CgOp { (box Num (cast num (cursor_pos (cast cursor (@ {self}))))) };
:my $stub = return self if @*MEMOS[$startpos]<ws> :exists; #OK
-
:dba('whitespace')
- \h+ <![\#\s\\]> { @*MEMOS[ Q:CgOp { (box Num (cast num (cursor_pos (cast cursor (@ {$¢}))))) } ]<ws> = $startpos; } # common case
+ [
+ || \h+ <![\#\s\\]> { @*MEMOS[ Q:CgOp { (box Num (cast num (cursor_pos (cast cursor (@ {$¢}))))) } ]<ws> = $startpos; } # common case
|| <?before \w> <?after \w> :::
{ @*MEMOS[$startpos]<ws>:delete; }
<.sorry: "Whitespace is required between alphanumeric tokens"> # must \s+ between words
- ||
- [
- | <.unsp>
- | <.vws> <.heredoc>
- | <.unv>
- # | $ { $¢.moreinput } NIECZA break inf loop
- ]*
-
- # NOTE that this is only used in the slow path! The || above is the
- # top level separator.
- {
- my $pos = Q:CgOp { (box Num (cast num (cursor_pos (cast cursor (@ {$¢}))))) };
- if ($pos == $startpos) {
- @*MEMOS[$pos]<ws>:delete;
- }
- else {
- @*MEMOS[$pos]<ws> = $startpos;
- @*MEMOS[$pos]<endstmt> = @*MEMOS[$startpos]<endstmt>
- if @*MEMOS[$startpos]<endstmt> :exists;
- }
- }
+ || [ <.unsp>
+ | <.vws> <.heredoc>
+ | <.unv>
+ # | $ { $¢.moreinput } NIECZA break inf loop
+ ]*
+
+ {
+ my $pos = Q:CgOp { (box Num (cast num (cursor_pos (cast cursor (@ {$¢}))))) };
+ if ($pos == $startpos) {
+ @*MEMOS[$pos]<ws>:delete;
+ }
+ else {
+ @*MEMOS[$pos]<ws> = $startpos;
+ @*MEMOS[$pos]<endstmt> = @*MEMOS[$startpos]<endstmt>
+ if @*MEMOS[$startpos]<endstmt> :exists;
+ }
+ }
+ ]
}
token unsp {
@@ -1075,7 +1069,8 @@ grammar P6 is STD {
# Note: we only check for the stopper. We don't check for ^ because
# we might be embedded in something else.
- rule comp_unit {
+ # note: until %*LANG is initialized we can't use <.ws>
+ token comp_unit {
:my $*DEBUG = $GLOBAL::DEBUG_STD // 0;
:my $*begin_compunit = 1;
:my $*endargs = -1;
@@ -1129,7 +1124,7 @@ grammar P6 is STD {
$ALL.<UNIT> = $*UNIT;
self.finishlex;
# $¢ = self.cursor_fresh($*CURLEX<$?LANGNAME>);
- }
+ }:s
<.unitstart>
<statementlist>
[ <?unitstopper> || <.panic: "Confused"> ]
@@ -3158,9 +3153,9 @@ grammar P6 is STD {
}
token infixish ($in_meta?) {
- :my ($infix, $O, $sym);
+ :my ($O, $sym);
:temp $*IN_META;
- :my $stub = ($*IN_META = $*IN_META // $in_meta); #OK not used
+ :my $stub = ($*IN_META = $in_meta // $*IN_META); #OK not used
<!stdstopper>
<!infixstopper>
:dba('infix or meta-infix')
View
@@ -53,7 +53,7 @@ class Parameter {
$!list ?? CgOp._cgop("newarray") !!
CgOp._cgop("newtypedscalar",
CgOp.class_ref("mo", @( $!tclass // 'Any' ))))),
- CgOp.assign(CgOp.scopedlex($!slot), $val))
+ CgOp.sink(CgOp.assign(CgOp.scopedlex($!slot), $val)))
}
method bind_inline($body, @posr) {
@@ -63,9 +63,12 @@ class Parameter {
self.single_get_inline($body, @posr);
if (defined $!slot) {
- CgOp.scopedlex($!slot, $!rwtrans ?? $get !!
- $!is_copy ?? self.do_copy($get) !!
- CgOp.newboundvar(+(!$!rw), +$!list, $get));
+ if $!is_copy {
+ self.do_copy($get);
+ } else {
+ CgOp.scopedlex($!slot, $!rwtrans ?? $get !!
+ CgOp.newboundvar(+(!$!rw), +$!list, $get));
+ }
} else {
CgOp.sink($get);
}
Oops, something went wrong.

0 comments on commit 02ec23f

Please sign in to comment.