Author: coke Date: Sat Oct 8 07:30:45 2005 New Revision: 9408 Modified: trunk/languages/tcl/TODO trunk/languages/tcl/lib/parser.pir trunk/languages/tcl/tcl.pir Log: tcl: Make --dump generate runnable code.
Modified: trunk/languages/tcl/TODO ============================================================================== --- trunk/languages/tcl/TODO (original) +++ trunk/languages/tcl/TODO Sat Oct 8 07:30:45 2005 @@ -10,9 +10,6 @@ http://cvs.sourceforge.net/viewcvs.py/tc This will require a lot of work. On the plus side, we'll be passing a lot more tests by then. =-) -Also on the table right now is converting to a compiler. This is mostly done, -with a few caveats and TODOs. - =over 4 =item 0 @@ -22,8 +19,9 @@ to the compiled version, and then remove =item 1 -Generate compiler-variants for several builtins, esp. the flow control -commands like C<while>. +Generate compiler-variants for several builtins, esp. those used by +examples/bench.tcl + Modify the compiler for tclcommand to generate the inline version if it's available. (C<proc> and C<expr> should also be straightforward, as they already compile anyway.) [Completed: incr, break, continue, for, while] @@ -41,8 +39,8 @@ this counter whenever they are called. =item 3 -Add compiled TclComment objects, which do nothing other than generate PIR comments with -the same text. +Add compiled TclComment objects, which do nothing other than generate +PIR comments with the same text. =back Modified: trunk/languages/tcl/lib/parser.pir ============================================================================== --- trunk/languages/tcl/lib/parser.pir (original) +++ trunk/languages/tcl/lib/parser.pir Sat Oct 8 07:30:45 2005 @@ -96,19 +96,24 @@ done: .end =item C<(pmc invokable) = pir_compiler(string PIR, int register_num)> +=item C<(string code) = pir_compiler(string PIR, int register_num, 1)> A thin wrapper for the <compreg>'d PIR compiler. -Given PIR code, wrap it in anonymous subroutine, compile to bytecode, and return the -compiled, anonymous sub. +Given inline PIR code, wrap it in anonymous subroutine and return the +fully qualified PIR. -Argument register_num is the first register number that is available for use by the -generated PIR. +If the third argument is present, don't compile the wrapper sub, just +return the wrapped code. + +Argument register_num is the first register number that is available for +use by the generated PIR. =cut .sub pir_compiler .param int result_reg .param string pir_code + .param int code_only :optional .local pmc compiled_num compiled_num = find_global "_Tcl", "compiled_num" @@ -121,16 +126,21 @@ generated PIR. $P1[2] = result_reg $S0 = <<"END_PIR" +.HLL 'tcl', 'tcl_group' .pragma n_operators 1 .sub compiled_tcl_sub%i :anon +load_bytecode 'languages/tcl/lib/tcllib.pbc' %s -.return ($P%s) +.return ($P%i) .end END_PIR - sprintf pir_code, $S0, $P1 - #print pir_code + pir_code = sprintf $S0, $P1 + + unless code_only goto compile_it + .return (pir_code) +compile_it: .local pmc pir_compiler pir_compiler = compreg "PIR" Modified: trunk/languages/tcl/tcl.pir ============================================================================== --- trunk/languages/tcl/tcl.pir (original) +++ trunk/languages/tcl/tcl.pir Sat Oct 8 07:30:45 2005 @@ -121,12 +121,14 @@ loop: goto loop gotfile: - ($I0,$S1) = compiler(0,contents) unless dump_only goto run_file + ($I0,$S0) = compiler(0,contents) + $S1 = pir_compiler($I0,$S0,1) print $S1 goto done run_file: + ($I0,$S1) = compiler(0,contents) $P2 = pir_compiler($I0,$S1) push_eh file_error $P2() @@ -154,9 +156,10 @@ oneliner: oneliner_dump: $P1 = find_global "_Tcl", "compile" - $P2 = find_global "_Tcl", "pir_compiler" - ($I0, $S1) = $P1(0,tcl_code) - print $S1 + $P2 = find_global "_Tcl", "pir_compiler" + ($I0, $S1) = $P1(0,tcl_code,1) + $S2 = $P2($I0,$S1,1) + print $S2 done: end
