Permalink
Browse files

Fix binding to existing @vars

  • Loading branch information...
1 parent 44f7995 commit 904bb14c1df5762919652dc99ecf9e9a92cee94c @sorear committed Jun 8, 2011
Showing with 64 additions and 7 deletions.
  1. +1 −7 TODO
  2. +59 −0 src/niecza
  3. +4 −0 test2.pl
View
@@ -18,8 +18,6 @@ EASY
Character class expressions like [[a .. A] & [\W]]
- Binding to values like @PROCESS::ARGS doesn't contextualize correctly. Fix.
-
Fudge and run your favorite spectest file.
Stuff spectests are blocking on: "closure for",
@@ -45,8 +43,6 @@ MEDIUM
*Find out what readonly subs are supposed to do with lists, etc and implement
that. Also add return-rw, take-rw, and the is rw trait for subs and attrs.
- *Implement BUILD submethod calling.
-
Methods with variable names need to call the correct action method. (See
the horrible hack in NieczaActions.FALLBACK).
@@ -56,8 +52,6 @@ MEDIUM
HARD
- + subset declarations.
-
Design and implement some sort of NFG thing that allows use codes, graphs,
etc and handles canonical equivalence in regexes.
@@ -70,7 +64,7 @@ HARD
*Parallel hyperops! Read the Cilk papers, they seem to have a data
parallelism model most similar to what Perl 6 needs.
- Understand the Str/Stringy distinctions, and improve stringification
+ *Understand the Str/Stringy distinctions, and improve stringification
and numification handling for Any. Develop a warning system.
*Explicitly imprecise error reporting. In many circumstances niecza
View
@@ -29,6 +29,65 @@ use STD;
use Sig;
augment class NieczaActions {
+method do_variable_reference($M, $v) {
+ if $v<term> {
+ return $v<term>;
+ }
+
+ my $tw = $v<twigil>;
+ my $sl = $v<sigil> ~ $tw ~ $v<name>;
+
+ if defined($v<rest>) && $tw ~~ /<[*=~?^:]>/ {
+ $M.CURSOR.sorry("Twigil $tw cannot be used with qualified names");
+ return ::Op::StatementList.new;
+ }
+
+ if $tw eq '!' {
+ self.docontext($M, $v<sigil>, ::Op::CallMethod.new(|node($M),
+ name => $v<name>, private => True, receiver => mklex($M, 'self'),
+ ppath => $v<rest>));
+ }
+ elsif $tw eq '.' {
+ if defined $v<rest> {
+ $M.CURSOR.sorry('$.Foo::bar syntax NYI');
+ return ::Op::StatementList.new;
+ }
+
+ self.docontext($M, $v<sigil>, ::Op::CallMethod.new(|node($M),
+ name => $v<name>, receiver => mklex($M, 'self')));
+ }
+ # no twigil in lex name for these
+ elsif $tw eq '^' || $tw eq ':' {
+ ::Op::Lexical.new(|node($M), name => $v<sigil> ~ $v<name>,
+ hash => ($v<sigil> eq '%'), list => ($v<sigil> eq '@'));
+ }
+ elsif $tw eq '*' {
+ ::Op::ContextVar.new(|node($M), name => $sl);
+ }
+ elsif $tw eq '' || $tw eq '?' {
+ if defined($v<rest>) {
+ ::Op::PackageVar.new(path => $v<rest>, name => $sl,
+ hash => ($v<sigil> eq '%'), list => ($v<sigil> eq '@'),
+ slot => self.gensym, |node($M));
+ } elsif $tw eq '?' && $sl eq '$?POSITION' {
+ mkcall($M, '&infix:<..^>',
+ ::Op::Num.new(|node($M), value => [10, ~$M.from]),
+ ::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 '&?BLOCK' {
+ ::Op::GetBlock.new(|node($M))
+ } elsif $tw eq '?' && $sl eq '&?ROUTINE' {
+ ::Op::GetBlock.new(|node($M), :routine)
+ } else {
+ ::Op::Lexical.new(|node($M), name => $sl,
+ hash => ($v<sigil> eq '%'), list => ($v<sigil> eq '@'));
+ }
+ }
+ else {
+ $M.CURSOR.sorry("Unhandled reference twigil $tw");
+ }
+}
method infix:sym<...> ($/) {
# STD parses ...^ in the ... rule
make Operator.funop('&infix:<' ~ $/ ~ '>', 2);
View
@@ -16,6 +16,10 @@
}
is SubBT.new(x => 5, y => 2).get_pie, 5, "superclass' BUILD in subclass";
is SubBT.new(x => 5, y => 2).get_pie2, 2, "subclass' BUILD in subclass";
+
+ my @l;
+ @l := [1,2,3];
+ is +[@l], 3, 'binding to existing list vars works';
}
is [ 1,2,3 ... 10 ], [1..10];

0 comments on commit 904bb14

Please sign in to comment.