Skip to content

Commit

Permalink
Move "invoke" to a helper class, refer to it as a WVal
Browse files Browse the repository at this point in the history
  • Loading branch information
coke committed Sep 25, 2012
1 parent cb0c0f8 commit d3368fc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
3 changes: 2 additions & 1 deletion build/Makefile.in
Expand Up @@ -101,6 +101,7 @@ GEN_SOURCES = \
src/Partcl/commands/variable.pir \
src/Partcl/commands/vwait.pir \
src/Partcl/commands/while.pir \
src/Internals.pir \
src/TclArray.pir \
src/TclLexPad.pir \
src/TclList.pir \
Expand All @@ -112,7 +113,7 @@ all: $(PARTCL_EXE) .revision

src/Partcl.pir: $(GEN_SOURCES)

src/FileGlob/Actions.pm: src/StringGlob/Actions.pir
src/FileGlob/Actions.pm: src/StringGlob/Actions.pir src/Internals.pir
src/FileGlob/Grammar.pm: src/StringGlob/Grammar.pir
src/init.pm: src/TclLexPad.pir
src/init.pm: src/TclArray.pir
Expand Down
29 changes: 29 additions & 0 deletions src/Internals.pm
@@ -0,0 +1,29 @@
class Internals {

## wrapper method for invoking tcl builtins - deals with unknown
## handling and namespace desugaring

method 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__SP(&command) eq "Undef" {
$ns := pir::get_hll_namespace__P();
&command := $ns{$command};
}

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

&command(|@args);
}
}
# vim: expandtab shiftwidth=4 ft=perl6:
2 changes: 2 additions & 0 deletions src/Partcl/Actions.pm
@@ -1,3 +1,5 @@
use src::Internals;

class Partcl::Actions is HLL::Actions {

method TOP($/) { make $<TOP_eval>.ast; }
Expand Down
28 changes: 0 additions & 28 deletions src/init.pm
Expand Up @@ -68,32 +68,4 @@ 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:

0 comments on commit d3368fc

Please sign in to comment.