forked from pmichaud/pmtcl
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Austin-ize [info] subcommands, cleaning up arg handling.
- Loading branch information
Showing
2 changed files
with
216 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,206 @@ | ||
our sub info(*@args) { | ||
if +@args < 1 { | ||
Info::dispatch_command(|@args); | ||
} | ||
|
||
module Info; | ||
|
||
our %Arg_limits; | ||
our %Info_funcs; | ||
|
||
INIT { | ||
%Info_funcs<args> := Info::args; | ||
%Arg_limits<args> := [1, 1, 'procname']; | ||
|
||
%Info_funcs<body> := Info::body; | ||
%Arg_limits<body> := [1, 1, 'procname']; | ||
|
||
%Info_funcs<cmdcount> := Info::cmdcount; | ||
%Arg_limits<cmdcount> := [0, 0, '']; | ||
|
||
%Info_funcs<commands> := Info::commands; | ||
%Arg_limits<commands> := [0, 1, '?pattern?']; | ||
|
||
%Info_funcs<complete> := Info::complete; | ||
%Arg_limits<complete> := [1, 1, 'complete']; | ||
|
||
%Info_funcs<default> := Info::default; | ||
%Arg_limits<default> := [3, 3, 'procname arg varname']; | ||
|
||
%Info_funcs<exists> := Info::exists; | ||
%Arg_limits<exists> := [1, 1, 'varName']; | ||
|
||
%Info_funcs<frame> := Info::frame; | ||
%Arg_limits<frame> := [0, 1, '?number?']; | ||
|
||
%Info_funcs<functions> := Info::functions; | ||
%Arg_limits<functions> := [0, 1, '?pattern?']; | ||
|
||
%Info_funcs<globals> := Info::globals; | ||
%Arg_limits<globals> := [0, 1, '?pattern?']; | ||
|
||
%Info_funcs<hostname> := Info::hostname; | ||
%Arg_limits<hostname> := [0, 0, '']; | ||
|
||
%Info_funcs<level> := Info::level; | ||
%Arg_limits<level> := [0, 1, '?number?']; | ||
|
||
%Info_funcs<library> := Info::library; | ||
%Arg_limits<library> := [0, 0, '']; | ||
|
||
%Info_funcs<loaded> := Info::loaded; | ||
%Arg_limits<loaded> := [0, 1, '?interp?']; | ||
|
||
%Info_funcs<locals> := Info::locals; | ||
%Arg_limits<locals> := [0, 1, '?pattern?']; | ||
|
||
%Info_funcs<nameofexecutable> := Info::nameofexecutable; | ||
%Arg_limits<nameofexecutable> := [0, 0, '']; | ||
|
||
%Info_funcs<patchlevel> := Info::patchlevel; | ||
%Arg_limits<patchlevel> := [0, 0, '']; | ||
|
||
%Info_funcs<procs> := Info::procs; | ||
%Arg_limits<procs> := [0, 1, '?pattern?']; | ||
|
||
%Info_funcs<script> := Info::script; | ||
%Arg_limits<script> := [0, 1, '?filename?']; | ||
|
||
%Info_funcs<sharedlibextension> := Info::sharedlibextension; | ||
%Arg_limits<sharedlibextension> := [0, 0, '']; | ||
|
||
%Info_funcs<tclversion> := Info::tclversion; | ||
%Arg_limits<tclversion> := [0, 0, '']; | ||
|
||
%Info_funcs<vars> := Info::vars; | ||
%Arg_limits<vars> := [0, 1, '?pattern?']; | ||
} | ||
|
||
# Handle wrong # args, bad option errors. | ||
# dispatch to internal NQP subs for actual work. | ||
|
||
our sub dispatch_command(*@args) { | ||
my $argc := +@args; | ||
|
||
if $argc-- < 1 { | ||
error('wrong # args: should be "info subcommand ?argument ...?"'); | ||
} | ||
my $cmd := @args.shift(); | ||
|
||
if $cmd eq 'args' { | ||
return ''; | ||
} elsif $cmd eq 'body' { | ||
return ''; | ||
} elsif $cmd eq 'cmdcount' { | ||
return ''; | ||
} elsif $cmd eq 'commands' { | ||
# XXX globbing | ||
# XXX other NS. | ||
my $pattern := @args[0]; | ||
my $globalNS := pir::get_root_global__PS('tcl'); | ||
try { | ||
my $result := $globalNS{$pattern}; | ||
return $pattern; | ||
CATCH { | ||
return ''; | ||
} | ||
} | ||
} elsif $cmd eq 'complete' { | ||
return ''; | ||
} elsif $cmd eq 'default' { | ||
if pir::defined(@args[2]) { | ||
set(@args[2], ''); # XXX placeholder | ||
|
||
my @opts := <args body cmdcount commands complete default exists frame functions globals hostname level library loaded locals nameofexecutable patchlevel procs script sharedlibextension tclversion vars>; | ||
|
||
my $cmd := _tcl::select_option(@opts, @args.shift, 'subcommand'); | ||
|
||
my @limits := %Arg_limits{$cmd}; | ||
|
||
if $argc > @limits[1] || $argc < @limits[0] { | ||
my $msg := @limits[2]; | ||
$msg := ' ' ~ $msg if $msg ne ''; | ||
error("wrong # args: should be \"info $cmd$msg\"") | ||
} | ||
|
||
my &subcommand := %Info_funcs{$cmd}; | ||
&subcommand(|@args); | ||
} | ||
|
||
my sub args($procname) { | ||
''; | ||
} | ||
|
||
my sub body($procname) { | ||
''; | ||
} | ||
|
||
my sub cmdcount() { | ||
0; | ||
} | ||
|
||
my sub commands($pattern = '*') { | ||
# XXX globbing | ||
# XXX other NS. | ||
|
||
my $globalNS := pir::get_root_global__PS('tcl'); | ||
try { | ||
my $result := $globalNS{$pattern}; | ||
return $pattern; | ||
CATCH { | ||
return ''; | ||
} | ||
return ''; | ||
} elsif $cmd eq 'exists' { | ||
return 0; | ||
} elsif $cmd eq 'frame' { | ||
return ''; | ||
} elsif $cmd eq 'functions' { | ||
return ''; | ||
} elsif $cmd eq 'globals' { | ||
return ''; | ||
} elsif $cmd eq 'hostname' { | ||
return ''; | ||
} elsif $cmd eq 'level' { | ||
return ''; | ||
} elsif $cmd eq 'library' { | ||
our %GLOBALS; | ||
return %GLOBALS<tcl_library>; | ||
} elsif $cmd eq 'loaded' { | ||
return ''; | ||
} elsif $cmd eq 'locals' { | ||
return ''; | ||
} elsif $cmd eq 'nameofexecutable' { | ||
return 'partcl'; | ||
} elsif $cmd eq 'patchlevel' { | ||
our %GLOBALS; | ||
return %GLOBALS<tcl_patchLevel>; | ||
} elsif $cmd eq 'procs' { | ||
return ''; | ||
} elsif $cmd eq 'script' { | ||
return ''; | ||
} elsif $cmd eq 'sharedlibextension' { | ||
return ''; | ||
} elsif $cmd eq 'tclversion' { | ||
our %GLOBALS; | ||
return %GLOBALS<tcl_version>; | ||
} elsif $cmd eq 'vars' { | ||
return ''; | ||
} | ||
} | ||
|
||
my sub complete($command) { | ||
0; | ||
} | ||
|
||
my sub default($procname, $arg, $varname) { | ||
set($varname, ''); # XXX placeholder | ||
0; | ||
} | ||
|
||
my sub exists($varname) { | ||
0; | ||
} | ||
|
||
my sub frame($number?) { | ||
0; | ||
} | ||
|
||
my sub functions($pattern = '*') { | ||
''; | ||
} | ||
|
||
my sub globals($pattern = '*') { | ||
''; | ||
} | ||
|
||
my sub hostname() { | ||
''; | ||
} | ||
|
||
my sub level($number?) { | ||
''; | ||
} | ||
|
||
my sub library() { | ||
my %GLOBALS := pir::get_hll_global__ps('%GLOBALS'); | ||
%GLOBALS<tcl_library>; | ||
} | ||
|
||
my sub loaded($interp?) { | ||
''; | ||
} | ||
|
||
my sub locals($pattern = '*') { | ||
''; | ||
} | ||
|
||
my sub nameofexecutable() { | ||
''; | ||
} | ||
|
||
my sub patchlevel() { | ||
my %GLOBALS := pir::get_hll_global__ps('%GLOBALS'); | ||
%GLOBALS<tcl_patchLevel>; | ||
} | ||
|
||
my sub procs($pattern = '*') { | ||
''; | ||
} | ||
|
||
my sub tclversion() { | ||
my %GLOBALS := pir::get_hll_global__ps('%GLOBALS'); | ||
%GLOBALS<tcl_version>; | ||
} | ||
|
||
my sub script($filename?) { | ||
''; | ||
} | ||
|
||
my sub sharedlibextension() { | ||
''; | ||
} | ||
|
||
# invalid subcommand. | ||
error("unknown or ambiguous subcommand \"$cmd\": must be args, body, cmdcount, commands, complete, default, exists, frame, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars"); | ||
my sub vars($pattern = '*') { | ||
''; | ||
} | ||
|
||
# vim: filetype=perl6: |
Oops, something went wrong.