Skip to content

Commit

Permalink
instead of directly invoking .subs, go through a helper sub so we can do
Browse files Browse the repository at this point in the history
some extra handling.
  • Loading branch information
coke committed Aug 19, 2010
1 parent 63f2bf6 commit 27478ef
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 14 deletions.
5 changes: 0 additions & 5 deletions docs/todo.pod
Expand Up @@ -6,11 +6,6 @@ Document how to contribute to this version - ast, tcl, nqp ...

=over 4

=item [unknown] {t/tcl_misc.t; t/tcl_catch.t}

Invoking a non-existant command should
result in a tcl error, not a parrot error.

=item [proc] {t/cmd_continue.t; t/cmd_break.t}

User-defined procs should catch continue/break and complain about them, as
Expand Down
4 changes: 2 additions & 2 deletions src/Partcl/Actions.pm
Expand Up @@ -71,8 +71,8 @@ method script($/) {
}

method command($/) {
my $past := PAST::Op.new( :name(~$<word>[0].ast), :node($/) );
my $i := 1;
my $past := PAST::Op.new( :name('invoke'), :node($/) );
my $i := 0;
my $n := +$<word>;
while $i < $n {
$past.push($<word>[$i].ast);
Expand Down
1 change: 1 addition & 0 deletions src/Partcl/commands/proc.pm
Expand Up @@ -63,6 +63,7 @@ our sub proc(*@args) {
pir::setprop($thing, 'args', @argsInfo);
pir::setprop($thing, 'defaults', %defaults);
pir::setprop($thing, 'body', $body);

'';
}

Expand Down
28 changes: 28 additions & 0 deletions src/init.pm
Expand Up @@ -76,4 +76,32 @@ sub dumper($what, $label = 'VAR1') {
&dumper($what, $label);
}
## wrapper sub for invoking tcl builtins - deals with unknown handling and
## namespace desugaring; use a pointy block to avoid tampering with CONTROLs.
INIT {
GLOBAL::invoke := -> $command, *@args {

## Get our caller's namespace, do the lookup from there.
my $ns := Q:PIR {
$P1 = getinterp
%r = $P1['sub'; 1]
}.get_namespace();
my &command := $ns{$command};

## if that didn't work, check in the root ns.
if pir::typeof(&command) eq "Undef" {
$ns := pir::get_hll_namespace__p();
&command := $ns{$command};
}

if pir::typeof(&command) eq "Undef" {
error("invalid command name \"$command\"");
}

&command(|@args);
}
}

# vim: expandtab shiftwidth=4 ft=perl6:
2 changes: 1 addition & 1 deletion t/cmd_catch.t
Expand Up @@ -52,7 +52,7 @@ eval_is {
eval_is {
set a [catch blorg var]
list $a $var
} {1 {invalid command name "blorg"}} {error, invalid command} {TODO NQPRX}
} {1 {invalid command name "blorg"}} {error, invalid command}

eval_is {catch} \
{wrong # args: should be "catch script ?resultVarName? ?optionVarName?"} \
Expand Down
2 changes: 1 addition & 1 deletion t/cmd_foreach.t
Expand Up @@ -80,7 +80,7 @@ eval_is {

eval_is {
foreach name {a b c d} { aputs }
} {invalid command name "aputs"} {inner exception} {TODO NQPRX}
} {invalid command name "aputs"} {inner exception}

is [
set x {}
Expand Down
8 changes: 5 additions & 3 deletions t/tcl_misc.t
@@ -1,7 +1,7 @@
# Copyright (C) 2004-2007, The Parrot Foundation.

source lib/test_more.tcl
plan 27
plan 26

eval_is {
set a Parsing
Expand Down Expand Up @@ -34,7 +34,7 @@ is [set x ";"] {;} {; doesn't end command in the middle of a string}
eval_is {
set a 2
a
} {invalid command name "a"} {variables can't be used as commands} {TODO NQPRX}
} {invalid command name "a"} {variables can't be used as commands}

eval_is {
# commment
Expand Down Expand Up @@ -77,10 +77,12 @@ eval_is {
set a [set b 1; set c 2]
} 2 {subcommands with semicolons}

if 0 { ## SKIP NQP-RX
eval_is {
proc {} {} {return ok}
{}
} ok {empty proc name ok.} {TODO NQPRX}
}

eval_is {
proc lreverse {} { return ok }
Expand Down Expand Up @@ -119,7 +121,7 @@ proc Default {{verify {boom}}} {
[$verify]
}
Default
} {invalid command name "boom"} {failure to find a dynamic command'} {TODO NQPRX}
} {invalid command name "boom"} {failure to find a dynamic command'}

set a 4; incr a
is [lindex $a 0] 5 {can we convert integers into lists?}
Expand Down
4 changes: 2 additions & 2 deletions t/tcl_namespace.t
Expand Up @@ -14,12 +14,12 @@ is [{}] ok {command name, all colons}
eval_is {
:set c ok
} {invalid command name ":set"}\
{not enough colons, explicit global command} {TODO NQPRX}
{not enough colons, explicit global command}

eval_is {
foo::bar
} {invalid command name "foo::bar"} \
{invalid ns command} {TODO NQPRX}
{invalid ns command}

eval_is {
proc test {} {return ok1}
Expand Down

0 comments on commit 27478ef

Please sign in to comment.