Skip to content

Commit

Permalink
Mergeback
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed May 30, 2011
1 parent 34b68ce commit 02ec23f
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 950 deletions.
366 changes: 71 additions & 295 deletions src/CgOp.pm6

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions src/NieczaActions.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?) {
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
26 changes: 11 additions & 15 deletions src/Op.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)));
}
}
Expand Down Expand Up @@ -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));
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/RxOp.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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'))),
Expand Down
141 changes: 68 additions & 73 deletions src/STD.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1129,7 +1124,7 @@ grammar P6 is STD {
$ALL.<UNIT> = $*UNIT;
self.finishlex;
# $¢ = self.cursor_fresh($*CURLEX<$?LANGNAME>);
}
}:s
<.unitstart>
<statementlist>
[ <?unitstopper> || <.panic: "Confused"> ]
Expand Down Expand Up @@ -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')
Expand Down
11 changes: 7 additions & 4 deletions src/Sig.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit 02ec23f

Please sign in to comment.