Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mergeback
  • Loading branch information
sorear committed Oct 27, 2011
1 parent 9c51257 commit 9f04acf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 607 deletions.
55 changes: 28 additions & 27 deletions src/NieczaActions.pm6
Expand Up @@ -580,8 +580,8 @@ method metachar:unsp ($/) { make ::RxOp::Sequence.new }

method metachar:sym<{ }> ($/) {
$/.CURSOR.trymop({
$<embeddedblock>.ast.set_signature(Sig.simple(''));
$<embeddedblock>.ast.add_my_name('', :noinit, |mnode($/));
$<embeddedblock>.ast.set_signature(Sig.simple(''));
});

make ::RxOp::VoidBlock.new(block => self.inliney_call($/,
Expand All @@ -602,8 +602,8 @@ method metachar:sym<[ ]> ($/) {
}

method metachar:sym<( )> ($/) {
make self.rxcapturize($/, Any, self.encapsulate_regex($/, $<nibbler>.ast,
passcut => True));
make self.rxcapturize($/, %*RX<paren>++,
self.encapsulate_regex($/, $<nibbler>.ast, passcut => True));
}

method metachar:sym« <( » ($/) { make ::RxOp::MarkFrom.new }
Expand Down Expand Up @@ -657,6 +657,7 @@ method metachar:sym<" "> ($/) {
}
method metachar:var ($/) {
sub _isnum { $_ ~~ /^\d+$/ }
if $<binding> {
my $a = $<binding><quantified_atom>.ast.uncut;
my $cid = $<variable>.ast.<capid>;
Expand All @@ -672,23 +673,27 @@ method metachar:var ($/) {
return Nil;
}
if _isnum($cid) {
%*RX<paren> = $cid + 1;
}
make self.rxcapturize($/, $cid, $a);
return Nil;
}
make ::RxOp::VarString.new(param => ~$<variable>,
ops => self.rxembed($/, self.do_variable_reference($/, $<variable>.ast), True));
}
method rxcapturize($/, $name, $_rxop) {
my $rxop = $_rxop;
method rxcapturize($M, $name, $rxop is copy) {
if !$rxop.^isa(::RxOp::Capturing) {
# $<foo>=[...]
$rxop = self.encapsulate_regex($/, $rxop, passcut => True,
$rxop = self.encapsulate_regex($M, $rxop, passcut => True,
passcap => True);
}
# $<foo>=(...)
if +$rxop.captures == 1 && !defined($rxop.captures.[0]) {
# XXX might not quite be right
if +$rxop.captures == 1 && $rxop.captures.[0] ~~ /^\d+$/ {
return $rxop.clone(captures => [$name]);
}
Expand Down Expand Up @@ -817,8 +822,8 @@ method assertion:sym<!> ($/) {

method assertion:sym<{ }> ($/) {
$/.CURSOR.trymop({
$<embeddedblock>.set_signature(Sig.simple(''));
$<embeddedblock>.ast.add_my_name('', :noinit, |mnode($/));
$<embeddedblock>.ast.set_signature(Sig.simple(''));
});

make ::RxOp::CheckBlock.new(block => self.inliney_call($/,
Expand Down Expand Up @@ -1110,9 +1115,7 @@ method check_hash($/) {

return True if @bits[0].^isa(::Op::SimplePair);

if @bits[0].^isa(::Op::CallSub) &&
@bits[0].invocant.^isa(::Op::Lexical) &&
@bits[0].invocant.name eq '&infix:<=>>' {
if @bits[0].^isa(::Op::Builtin) && @bits[0].name eq 'pair' {
return True;
}

Expand Down Expand Up @@ -1394,8 +1397,7 @@ method methodop($/) {
$/.CURSOR.sorry("Indirectly named method calls NYI");
return;
}
make ::Operator::Method.new(name => $c<name>,
package => $c<pkg> && $c<pkg>.xref);
make ::Operator::Method.new(name => $c<name>, package => $c<pkg>);
} elsif $<quote> {
make ::Operator::Method.new(name => $<quote>.ast);
} elsif $<variable> {
Expand Down Expand Up @@ -1720,6 +1722,10 @@ method do_variable_reference($M, $v) {
::Op::Num.new(|node($M), value => [10, ~$M.to]));
} elsif $tw eq '?' && $sl eq '$?LINE' {
::Op::Num.new(|node($M), value => [10, ~$M.cursor.lineof($M.from)]);
} elsif $tw eq '?' && $sl eq '$?FILE' {
::Op::StringLiteral.new(|node($M), text => $*FILE<name>);
} elsif $tw eq '?' && $sl eq '$?ORIG' {
::Op::StringLiteral.new(|node($M), text => $M.orig);
} elsif $tw eq '?' && $sl eq '&?BLOCK' {
$*CURLEX<!sub>.noninlinable;
::Op::GetBlock.new(|node($M))
Expand Down Expand Up @@ -2140,8 +2146,7 @@ method blockoid($/) {
# XXX horrible cheat, but my data structures aren't up to the task of
# $::UNIT being a class body &c.
if $/ eq '{YOU_ARE_HERE}' {
$*unit.bottom_ref = $*CURLEX<!sub>.xref;
$*CURLEX<!sub>.strong_used = True;
$*unit.set_bottom($*CURLEX<!sub>);
$*CURLEX<!sub>.create_static_pad;

loop (my $l = $*CURLEX<!sub>; $l; $l.=outer) {
Expand Down Expand Up @@ -2631,7 +2636,6 @@ method process_block_traits($/, @tr) {
} elsif !$pack && $tr<export> {
my @exports = @( $tr<export> );
$sub.outer.add_exports('&'~$sub.name, $sub, @exports);
$sub.strong_used = True;
$sub.outer.create_static_pad;
$/.CURSOR.mark_used($sub.outervar)
if defined $sub.outervar;
Expand Down Expand Up @@ -2947,24 +2951,21 @@ method statement_control:use ($/) {

my $module = $u2.mainline.compile_get_pkg($name.split('::'));
my $exp;
try $exp = $*unit.get_pkg($module, 'EXPORT', 'DEFAULT');
try $exp = $*unit.rel_pkg($module, 'EXPORT', 'DEFAULT');

# in the :: case, $module will usually be visible via GLOBAL
if !defined($name.index('::')) {
$*CURLEX<!sub>.add_my_stash($name, $module.xref);
$*CURLEX<!sub>.add_my_stash($name, $module);
}

return unless $exp;

my $h = $/.CURSOR;
for $*unit.list_stash($exp) -> $tup {
my $uname = $tup.key;
my $obj = $tup.value && $*unit.deref($tup.value);

if !$obj || $obj ~~ ::Metamodel::StaticSub {
$*CURLEX<!sub>.add_common_name($uname, $exp.xref, $uname);
for $*unit.list_stash($exp.who) -> $uname, $obj {
if !$obj || $obj.kind eq 'sub' {
$*CURLEX<!sub>.add_common_name($uname, $exp, $uname);
} else {
$*CURLEX<!sub>.add_my_stash($uname, $obj.xref);
$*CURLEX<!sub>.add_my_stash($uname, $obj);
}
$h.check_categorical($uname);
$h = $h.cursor_fresh(%*LANG<MAIN>);
Expand Down Expand Up @@ -3026,7 +3027,7 @@ method do_new_package($/, :$sub = $*CURLEX<!sub>, :$scope!, :$name!, :$class!,
?? $head !! self.gensym;

$sub.add_my_stash($lexname, $npkg, |mnode($/));
$sub.add_exports($head, $npkg, $exports) if $exports;
$sub.add_exports($head, $npkg, @$exports) if $exports;
});

$lexname, $npkg
Expand Down Expand Up @@ -3411,7 +3412,7 @@ method method_def_2 ($, $/ = $*cursor) {
if $<multisig> > 1 {
$/.CURSOR.sorry("You may only use *one* signature");
}
$*CURLEX<!sub>.set_signature(<multisig> ?? $<multisig>[0].ast !! Any);
$*CURLEX<!sub>.set_signature($<multisig> ?? $<multisig>[0].ast !! Any);
self.process_block_traits($/, $<trait>);
}

Expand Down
11 changes: 2 additions & 9 deletions src/Op.pm6
Expand Up @@ -170,7 +170,7 @@ class CallMethod is CallLike {
my $meta = $!ismeta // '';
if $.private {
CgOp.subcall(CgOp.stab_privatemethod(
CgOp.class_ref('mo', @( $.pclass )), $name),
CgOp.class_ref('mo', $!pclass), $name),
$.receiver.cgop($body), self.argblock($body));
} elsif $meta eq '^' {
CgOp.let($.receiver.cgop($body), -> $r {
Expand Down Expand Up @@ -605,14 +605,7 @@ class BareBlock is Op {
method code($) { CgOp.scopedlex($!var) }

method statement_level() {
# This cheat relies on the fact that we can't have any lexicals put
# into this block until after the compile is done, so the usual
# issues with changing lexical representation don't apply :)
my $body = $*CURLEX<!sub>.find_lex($!var).body;
if $body.code ~~ ::Op::YouAreHere {
$body.run_once = $body.outer.run_once;
}

$*CURLEX<!sub>.lookup_lex($!var).[4].set_run_once;
::GLOBAL::OptBeta.make_call($!var);
}
}
Expand Down
21 changes: 11 additions & 10 deletions src/STD.pm6
Expand Up @@ -426,6 +426,7 @@ token escape:none { <!> }

# and this is what makes nibbler polymorphic...
method nibble ($lang) {
temp %*RX; # prevent up-vars from leaking
self.cursor_fresh($lang).nibbler;
}

Expand Down Expand Up @@ -4665,7 +4666,7 @@ grammar Regex is STD {
};
[ <.normspace>? < || | && & > ]?
<EXPR>
{ CALLER::CALLER::<%*RX>.<paren> = %*RX<maxparen> max %*RX<paren>; }
{ CALLER::CALLER::<%*RX>.<paren> = %*RX<maxparen> max %*RX<paren> unless $reset }
[
|| <?infixstopper>
|| $$ <.panic: "Regex not terminated">
Expand Down Expand Up @@ -5186,11 +5187,11 @@ method is_name($longname, $curlex = $*CURLEX) {
$pkg = $*unit.abs_pkg(shift @parts);
goto "packagey";
}
when 'MY' { $sub = $curlex<!sub>; goto "lexy"; }
when 'OUTER' { $sub = $curlex<!sub>.?outer; goto "lexy"; }
when 'UNIT' { $sub = $curlex<!sub>.?to_unit; goto "lexy"; }
when 'CORE' { $sub = $curlex<!sub>.?true_setting; goto "lexy"; }
when 'SETTING' { $sub = $curlex<!sub>.?to_unit.?outer; goto "lexy"; }
when 'MY' { $sub = $curlex<!sub>; goto "lexy"; }
when 'OUTER' { $sub = $curlex<!sub>.outer; goto "lexy"; }
when 'UNIT' { $sub = $curlex<!sub>.to_unit; goto "lexy"; }
when 'CORE' { $sub = $curlex<!sub>.true_setting; goto "lexy"; }
when 'SETTING' { $sub = $curlex<!sub>.to_unit.outer; goto "lexy"; }

when 'COMPILING' | 'DYNAMIC' | 'CALLER' | 'CLR' { return True }

Expand All @@ -5216,13 +5217,13 @@ lexy:
return False unless $sub;
return True unless @parts;
given @parts[0] {
when 'OUTER' { $sub = $sub.?outer; goto "lexy"; }
when 'UNIT' { $sub = $sub.?to_unit; goto "lexy"; }
when 'SETTING' { $sub = $sub.?to_unit.?outer; goto "lexy"; }
when 'OUTER' { $sub = $sub.outer; goto "lexy"; }
when 'UNIT' { $sub = $sub.to_unit; goto "lexy"; }
when 'SETTING' { $sub = $sub.to_unit.outer; goto "lexy"; }
when 'CALLER' { return True; }
}

my @lex = self.lookup_lex(@parts[0], $sub);
my @lex = $sub.lookup_lex(@parts[0], $*FILE<name>, self.lineof(self.pos));
unless @lex {
self.deb("Lexical @parts[0] not found") if $deb;
return False;
Expand Down

0 comments on commit 9f04acf

Please sign in to comment.