Permalink
Browse files

Merge branch 'sigilless' into nom

  • Loading branch information...
2 parents c07eba2 + 4e5da28 commit 633c7edfda36c9a62126213600c28db73e361a6c @moritz moritz committed Aug 15, 2012
View
@@ -81,7 +81,7 @@ Language Features
2 *** new syntax/semantics for coercion (jnthn)
2 ** MAIN and USAGE (japhb)
2 ** Failure changes (japhb)
-2 ** sigilless variables and parameters
+2 * sigilless variables
2 ? coercion types
2 * improved hash/block disambiguation
3 *** domain specific languages -- slang and grammar tweaks
View
@@ -2819,21 +2819,7 @@ class Perl6::Actions is HLL::Actions {
if $twigil eq '' || $twigil eq '*' {
# Need to add the name.
if $<name> {
- my $cur_pad := $*W.cur_lexpad();
- if $cur_pad.symbol(~$/) {
- $*W.throw($/, ['X', 'Redeclaration'], symbol => ~$/);
- }
- if nqp::existskey(%*PARAM_INFO, 'nominal_type') {
- $cur_pad[0].push(QAST::Var.new( :name(~$/), :scope('lexical'),
- :decl('var'), :returns(%*PARAM_INFO<nominal_type>) ));
- %*PARAM_INFO<container_descriptor> := $*W.create_container_descriptor(
- %*PARAM_INFO<nominal_type>, 0, %*PARAM_INFO<variable_name>);
- $cur_pad.symbol(%*PARAM_INFO<variable_name>, :descriptor(%*PARAM_INFO<container_descriptor>),
- :type(%*PARAM_INFO<nominal_type>));
- } else {
- $cur_pad[0].push(QAST::Var.new( :name(~$/), :scope('lexical'), :decl('var') ));
- }
- $cur_pad.symbol(~$/, :scope('lexical'));
+ self.declare_param($/, ~$/);
}
}
elsif $twigil eq '!' {
@@ -2866,13 +2852,39 @@ class Perl6::Actions is HLL::Actions {
}
}
+ method declare_param($/, $name) {
+ my $cur_pad := $*W.cur_lexpad();
+ if $cur_pad.symbol($name) {
+ $*W.throw($/, ['X', 'Redeclaration'], symbol => $name);
+ }
+ if nqp::existskey(%*PARAM_INFO, 'nominal_type') {
+ $cur_pad[0].push(QAST::Var.new( :$name, :scope('lexical'),
+ :decl('var'), :returns(%*PARAM_INFO<nominal_type>) ));
+ %*PARAM_INFO<container_descriptor> := $*W.create_container_descriptor(
+ %*PARAM_INFO<nominal_type>, 0, %*PARAM_INFO<variable_name>);
+ $cur_pad.symbol(%*PARAM_INFO<variable_name>, :descriptor(%*PARAM_INFO<container_descriptor>),
+ :type(%*PARAM_INFO<nominal_type>));
+ } else {
+ $cur_pad[0].push(QAST::Var.new( :name(~$/), :scope('lexical'), :decl('var') ));
+ }
+ $cur_pad.symbol(~$/, :scope('lexical'));
+ }
+
method named_param($/) {
%*PARAM_INFO<named_names> := %*PARAM_INFO<named_names> || [];
if $<name> { %*PARAM_INFO<named_names>.push(~$<name>); }
elsif $<param_var><name> { %*PARAM_INFO<named_names>.push(~$<param_var><name>[0]); }
else { %*PARAM_INFO<named_names>.push(''); }
}
+ method defterm($/) {
+ my $name := ~$<identifier>;
+ %*PARAM_INFO<variable_name> := $name;
+ %*PARAM_INFO<desigilname> := $name;
+ %*PARAM_INFO<sigil> := '';
+ self.declare_param($/, $name);
+ }
+
method default_value($/) {
make $<EXPR>.ast;
}
@@ -3521,6 +3533,11 @@ class Perl6::Actions is HLL::Actions {
elsif $*W.is_pseudo_package(@name[0]) {
$past := $*W.symbol_lookup(@name, $/);
}
+ elsif +@name == 1 && $*W.is_name(@name)
+ && !$*W.symbol_has_compile_time_value(@name) {
+ # it's a sigilless param or variable
+ $past := make_variable_from_parts($/, @name, '', '', @name[0]);
+ }
else {
$past := instantiated_type(@name, $/);
}
View
@@ -1747,11 +1747,18 @@ grammar Perl6::Grammar is HLL::Grammar {
[
| <type_constraint>+
[
- | $<quant>=['**'|'*'|'\\'|'|'] <param_var>
+ | $<quant>=['**'|'*'] <param_var>
+ | $<quant>=['\\'|'|'] <param_var>
+# { pir::getstderr__P().print("Obsolete use of | or \\ with sigil on param { $<param_var> }\n") }
+ | $<quant>=['\\'|'|'] <defterm>?
+
| [ <param_var> | <named_param> ] $<quant>=['?'|'!'|<?>]
| <?>
]
- | $<quant>=['**'|'*'|'\\'|'|'] <param_var>
+ | $<quant>=['**'|'*'] <param_var>
+ | $<quant>=['\\'|'|'] <param_var>
+# { pir::getstderr__P().print("Obsolete use of | or \\ with sigil on param { $<param_var> }\n") }
+ | $<quant>=['\\'|'|'] <defterm>?
| [ <param_var> | <named_param> ] $<quant>=['?'|'!'|<?>]
| <longname> <.panic('Invalid typename in parameter declaration')>
]
@@ -1789,6 +1796,10 @@ grammar Perl6::Grammar is HLL::Grammar {
}
}
+ token defterm {
+ <identifier>
+ }
+
token param_var {
| '[' ~ ']' <signature>
| '(' ~ ')' <signature>
View
@@ -1620,7 +1620,16 @@ class Perl6::World is HLL::World {
$is_name := 1;
}
}
- $is_name
+ $is_name || +@name == 1 && self.is_lexical(@name[0])
+ }
+
+ method symbol_has_compile_time_value(@name) {
+ my $has_ctv := 0;
+ try {
+ self.find_symbol(@name);
+ $has_ctv := 1;
+ }
+ $has_ctv;
}
# Checks if a given symbol is declared and a type object.
@@ -2,15 +2,15 @@ sub restricted($what) {
die "$what is disallowed in restricted setting"
}
-sub open(|$) { restricted('open') }
-sub unlink(|$) { restricted('unlink') }
-sub shell(|$) { restricted('shell') }
-sub run(|$) { restricted('run') }
-sub QX(|$) { restricted('qx, qqx') }
-sub mkdir(|$) { restricted('mkdir') }
-sub rmdir(|$) { restricted('rmdir') }
-sub rename(|$) { restricted('rename') }
-sub copy(|$) { restricted('copy') }
+sub open(|) { restricted('open') }
+sub unlink(|) { restricted('unlink') }
+sub shell(|) { restricted('shell') }
+sub run(|) { restricted('run') }
+sub QX(|) { restricted('qx, qqx') }
+sub mkdir(|) { restricted('mkdir') }
+sub rmdir(|) { restricted('rmdir') }
+sub rename(|) { restricted('rename') }
+sub copy(|) { restricted('copy') }
my class IO { }
IO.^add_fallback(
View
@@ -4,15 +4,15 @@ sub restricted($what) {
die "$what is disallowed in safe mode"
}
-sub open(|$) { restricted('open') }
-sub unlink(|$) { restricted('unlink') }
-sub shell(|$) { restricted('shell') }
-sub run(|$) { restricted('run') }
-sub QX(|$) { restricted('qx, qqx') }
-sub mkdir(|$) { restricted('mkdir') }
-sub rmdir(|$) { restricted('rmdir') }
-sub rename(|$) { restricted('rename') }
-sub copy(|$) { restricted('copy') }
+sub open(|) { restricted('open') }
+sub unlink(|) { restricted('unlink') }
+sub shell(|) { restricted('shell') }
+sub run(|) { restricted('run') }
+sub QX(|) { restricted('qx, qqx') }
+sub mkdir(|) { restricted('mkdir') }
+sub rmdir(|) { restricted('rmdir') }
+sub rename(|) { restricted('rename') }
+sub copy(|) { restricted('copy') }
my class IO { }
IO.^add_fallback(
Oops, something went wrong.

0 comments on commit 633c7ed

Please sign in to comment.