Skip to content

Commit

Permalink
[tcl]:
Browse files Browse the repository at this point in the history
 * Finish cleaning up tools/gen_builtins.pl and runtime/builtins.pir.


git-svn-id: https://svn.parrot.org/parrot/trunk@12660 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
mdiep committed May 14, 2006
1 parent bc9e315 commit 27e2478
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 44 deletions.
11 changes: 11 additions & 0 deletions languages/tcl/runtime/tcllib.pir
Expand Up @@ -78,6 +78,17 @@ providing a compreg-compatible method.
# all the builtin commands
.include 'languages/tcl/runtime/builtins.pir'

# library files
.include 'languages/tcl/runtime/conversions.pir'
.include 'languages/tcl/runtime/expression.pir'
.include 'languages/tcl/runtime/list.pir'
.include 'languages/tcl/runtime/list_to_string.pir'
.include 'languages/tcl/runtime/string.pir'
.include 'languages/tcl/runtime/string_to_list.pir'
.include 'languages/tcl/runtime/variables.pir'
.include 'languages/tcl/src/compiler.pir'
.include 'languages/tcl/src/parser.pir'

.HLL 'Tcl', 'tcl_group'
.HLL '_Tcl', ''

Expand Down
86 changes: 42 additions & 44 deletions languages/tcl/tools/gen_builtins.pl
Expand Up @@ -2,68 +2,54 @@
use strict;
use lib qw(lib);

my $static_dir = "runtime/builtin";
my $dynamic_dir = "src/builtin";

print <<EOH;
# This file automatically generated by $0.
EOH

# commands that are in Tcl's :: namespace directly
my $command_dir = "runtime/builtin";
opendir(CMDDIR,$command_dir);
my @cmd_files = readdir(CMDDIR);
closedir(CMDDIR);

my @static_cmds = pir_cmds_in_dir($static_dir);
# subroutines that generate the PIR for Tcl commands
# (including templates)
my $builtins_dir = "src/builtin";
opendir(CMDDIR,$builtins_dir);
my @blt_files = readdir(CMDDIR);
closedir(CMDDIR);

my @cmd_includes = map {"$command_dir/$_"} grep {m/\.pir$/} @cmd_files;
my @blt_includes = map {"$builtins_dir/$_"} grep {m/\.pir$/} @blt_files;

# remove extensions from @cmd_files and @blt_files
# (this uses $_ as an alias -- somewhat subtle and evil)
my @commands = grep {s/\.(pir|tmt)$//} @cmd_files, @blt_files;

my $lib_dir = "runtime";
opendir(LIBDIR,$lib_dir) or die;
my @libs = map {"$lib_dir/$_"} grep {m/\.pir$/} grep {! m/^(builtins|tcllib)\.pir$/} readdir(LIBDIR);
closedir(LIBDIR);

my $src_dir = "src";
opendir(SRCDIR,$src_dir) or die;
my @srcs = map {"$src_dir/$_"} grep {! m/^(tclsh|macros|returncodes).pir$/} grep {m/\.pir$/} readdir(SRCDIR);
closedir(SRCDIR);

print ".HLL 'tcl', 'tcl_group'\n";
print ".namespace ['']\n";

for my $file (@cmd_includes, @blt_includes, @libs, @srcs) {
print " .include 'languages/tcl/$file\'\n";
}
my @dynamic_cmds = pir_cmds_in_dir($dynamic_dir);

print <<"END_PIR";
.HLL 'tcl', 'tcl_group'
.namespace ['']
END_PIR

print " .include 'languages/tcl/$static_dir/$_.pir'\n"
for @static_cmds;
print " .include 'languages/tcl/$dynamic_dir/$_.pir'\n"
for @dynamic_cmds;



# For every builtin with an inline'd version and no interpreted version,
# create a shim for the interpreted version that automatically calls
# the inline'd version, compiles the result and invokes it.

my @fallbacks = @blt_files;
foreach my $cmd (@cmd_files) {
@fallbacks = grep { $_ ne $cmd } @fallbacks;
}
print <<"END_PIR";
print ".HLL 'Tcl', ''\n";
.HLL 'Tcl', ''
.namespace ['']
for my $fallback (@fallbacks) {
print <<"END_PIR"
# fallback for interpreter: call the inlined version
END_PIR

.sub "&$fallback"
my %static_cmds = map { $_ => 1 } @static_cmds;
for my $cmd (@dynamic_cmds) {
# skip if there's a static version
next if $static_cmds{$cmd};

print <<"END_PIR";
.sub "&$cmd"
.param pmc argv :slurpy
.local pmc inlined, pir_compiler, invokable
.get_from_HLL(inlined, '_tcl';'builtins', '$fallback')
.get_from_HLL(inlined, '_tcl';'builtins', '$cmd')
.local string pir_code
.local int register_num
(register_num,pir_code) = inlined(0,argv)
Expand All @@ -72,4 +58,16 @@
.return invokable()
.end
END_PIR

}

sub pir_cmds_in_dir {
my ($dir) = @_;

opendir(DIR,$dir);
# only return pir files (and strip the extension)
my @files = grep {s/\.pir$//} readdir(DIR);
closedir(DIR);

return @files;
}

0 comments on commit 27e2478

Please sign in to comment.