From 63f2bf612463ac8595c3db4e07ad165beed1da14 Mon Sep 17 00:00:00 2001 From: Coke Date: Wed, 18 Aug 2010 12:32:18 -0400 Subject: [PATCH] fix [namespace eval foo { proc ...}]. --- src/Partcl/Actions.pm | 2 +- src/Partcl/commands/proc.pm | 10 ++++++++-- t/cmd_foreach.t | 2 +- t/cmd_if.t | 4 ++-- t/cmd_namespace.t | 8 ++------ 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Partcl/Actions.pm b/src/Partcl/Actions.pm index 4768cff..3bb2350 100644 --- a/src/Partcl/Actions.pm +++ b/src/Partcl/Actions.pm @@ -42,7 +42,7 @@ sub lex_block($past) { :viviself( PAST::Op.new( :pasttype, :name, - PAST::Var.new( :name, :scope ), + PAST::Var.new( :name, :scope, :namespace<> ), PAST::Op.new(:pirop('find_dynamic_lex Ps'), '%LEXPAD') ) ) diff --git a/src/Partcl/commands/proc.pm b/src/Partcl/commands/proc.pm index e020f4b..8a0ebb4 100644 --- a/src/Partcl/commands/proc.pm +++ b/src/Partcl/commands/proc.pm @@ -52,8 +52,14 @@ our sub proc(*@args) { } $block.name($name); $block.control('return_pir'); - PAST::Compiler.compile($block); - my $thing := pir::get_hll_global__PS($name); + + if ! pir::isnull(pir::find_dynamic_lex('@*PARTCL_COMPILER_NAMESPACE')) { + $block.namespace(@*PARTCL_COMPILER_NAMESPACE); + } + + ## compile() returns an Eval. extract out the first sub, which is our proc. + my $thing := PAST::Compiler.compile($block)[0]; + pir::setprop($thing, 'args', @argsInfo); pir::setprop($thing, 'defaults', %defaults); pir::setprop($thing, 'body', $body); diff --git a/t/cmd_foreach.t b/t/cmd_foreach.t index 51be055..8b58640 100755 --- a/t/cmd_foreach.t +++ b/t/cmd_foreach.t @@ -95,6 +95,6 @@ eval_is { proc a {} {error ok} foreach n 1 a } -} ok {namespace resolution in body} {TODO NQPRX} +} ok {namespace resolution in body} # vim: filetype=tcl: diff --git a/t/cmd_if.t b/t/cmd_if.t index 79ffd7a..e47fd66 100755 --- a/t/cmd_if.t +++ b/t/cmd_if.t @@ -131,7 +131,7 @@ eval_is { proc a {} {error ok} if {[a]} {} } -} ok {namespace resolution in cond} {TODO NQPRX} +} ok {namespace resolution in cond} eval_is { namespace eval lib { @@ -139,7 +139,7 @@ eval_is { proc a {} {error ok} if 1 a } -} ok {namespace resolution in body} {TODO NQPRX} +} ok {namespace resolution in body} eval_is {if {}} \ {empty expression diff --git a/t/cmd_namespace.t b/t/cmd_namespace.t index 271675c..031b126 100755 --- a/t/cmd_namespace.t +++ b/t/cmd_namespace.t @@ -78,14 +78,12 @@ eval_is {namespace eval foo} \ {wrong # args: should be "namespace eval name arg ?arg...?"} \ {namespace eval: too few args} -if 0 { namespace eval foo { proc bar {} {return ok} namespace eval bar { proc baz {} {return ok} } } -} ;# SKIP for now as namespace eval is a work in progress.. is [namespace exists foo] 1 {namespace eval foo: namespace exists} {TODO NQPRX} eval_is {foo::bar} ok {namespace eval foo: proc} {TODO NQPRX} @@ -124,7 +122,6 @@ is [namespace parent ""] {} {namespace parent: ::} is [namespace parent foo] :: {namespace parent: ::foo (explicit)} {TODO NQPRX} is [namespace eval foo {namespace parent}] :: {namespace parent: ::foo (implicit)} {TODO NQPRX} -if 0 { namespace eval perl6 { proc passthrough {val} { return $val @@ -133,16 +130,15 @@ namespace eval perl6 { passthrough 3 } } -} ;# SKIP for now as namespace eval is a work in progress.. eval_is {perl6::pi} 3 \ {do procs in namespace default to that namespace when looking for commands?} {TODO NQPRX} -if 0 { +if 0 { ## SKIP NQP-RX namespace eval perl6 { namespace export pi } -} ;# SKIP for now as namespace eval is a work in progress.. +} namespace import perl6::pi eval_is {pi} 3 {simple import test} {TODO NQPRX}