From 4772c46ce3d676e649a13ddb5ac9b39ee2f747dd Mon Sep 17 00:00:00 2001 From: Jonathan Worthington Date: Thu, 21 Oct 2010 00:05:44 +0200 Subject: [PATCH] Start trying to get our lexical vs package lookup story straighter. --- dotnet/compiler/Actions.pm | 66 ++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/dotnet/compiler/Actions.pm b/dotnet/compiler/Actions.pm index e441d6d..53fb915 100644 --- a/dotnet/compiler/Actions.pm +++ b/dotnet/compiler/Actions.pm @@ -365,7 +365,7 @@ sub package($/) { PAST::Var.new( :name('type_obj'), :scope('register'), :isdecl(1) ), PAST::Op.new( :pasttype('callmethod'), :name('new_type'), - PAST::Var.new( :name(%*HOW{~$}), :scope('package') ) + PAST::Var.new( :name(%*HOW{~$}), :scope('lexical') ) ) ), PAST::Op.new( :pasttype('bind'), @@ -459,7 +459,7 @@ method variable_declarator($/) { PAST::Var.new( :name('type_obj'), :scope('register') ), PAST::Op.new( :pasttype('callmethod'), :name('new'), - PAST::Var.new( :name($meta-attr-type), :scope('package') ), + PAST::Var.new( :name($meta-attr-type), :scope('lexical') ), PAST::Val.new( :value($name), :named('name') ) ) )); @@ -619,12 +619,47 @@ method parameter($/) { } method typename($/) { - my @name := HLL::Compiler.parse_name(~$/); - make PAST::Var.new( - :name(@name.pop), - :namespace(@name), - :scope('package') - ); + if is_lexical(~$/) { + make PAST::Var.new( + :name(~$/), + :scope('lexical') + ); + } + else { + my @name := HLL::Compiler.parse_name(~$/); + make PAST::Var.new( + :name(@name.pop), + :namespace(@name), + :scope('package') + ); + } +} + +# Check if something is a lexical or not. +sub is_lexical($name) { + # XXX Big hack for now, until we can really look at the contents + # of the setting. + my %setting_names; + %setting_names := 1; + %setting_names := 1; + %setting_names := 1; + %setting_names := 1; + %setting_names := 1; + %setting_names := 1; + %setting_names := 1; + %setting_names := 1; + if %setting_names{$name} { + return 1; + } + for @BLOCK { + my %sym := $_.symbol($name); + if %sym { + if %sym eq 'lexical' { + return 1; + } + } + } + return 0; } method param_var($/) { @@ -739,11 +774,16 @@ method term:sym($/) { } method term:sym($/) { - my @ns := pir::clone__PP($); - my $name := @ns.pop; - @ns.shift if @ns && @ns[0] eq 'GLOBAL'; - my $var := - PAST::Var.new( :name(~$name), :namespace(@ns), :scope('package') ); + my $var; + if is_lexical(~$) { + $var := PAST::Var.new( :name(~$), :scope('lexical') ); + } + else { + my @ns := pir::clone__PP($); + my $name := @ns.pop; + @ns.shift if @ns && @ns[0] eq 'GLOBAL'; + $var := PAST::Var.new( :name(~$name), :namespace(@ns), :scope('package') ); + } my $past := $var; if $ { $past := $[0].ast;