Author: coke
Date: Sun Jan 29 11:24:35 2006
New Revision: 11375

Modified:
   trunk/languages/tcl/lib/compiler.pir
   trunk/languages/tcl/lib/macros.pir
   trunk/languages/tcl/lib/tclops.pir
   trunk/languages/tcl/lib/tclvar.pir
Log:
tcl - Some cleanup for the tcl compiler.



Modified: trunk/languages/tcl/lib/compiler.pir
==============================================================================
--- trunk/languages/tcl/lib/compiler.pir        (original)
+++ trunk/languages/tcl/lib/compiler.pir        Sun Jan 29 11:24:35 2006
@@ -16,10 +16,11 @@ This is the compiler portion of ParTcl.
 
 Parses the Tcl code and returns generated PIR code.
 
-Argument register_num is the first register number that is available for use 
by the
-generated PIR.
+Argument register_num is the first register number that is available for use
+by the generated PIR.
 
-Return register_num is the register number that contains the result of this 
code.
+Return register_num is the register number that contains the result of
+this code.
 
 =cut
 
@@ -76,18 +77,14 @@ stringish:
   rquote = "\"" 
 set_args:
 
-  .local pmc printf_args
-  printf_args = new .Array
-  printf_args = 6
-  printf_args[0] = register_num
-  printf_args[1] = thing_type
-  printf_args[2] = register_num
-  printf_args[3] = lquote
-  printf_args[4] = $S0
-  printf_args[5] = rquote
- 
-  pir_code = sprintf "$P%i = new .%s\n$P%i=%s%s%s\n", printf_args
+   .local string template
+   template = <<"END_PIR"
+$P%i = new .%s
+$P%i=%s%s%s
+END_PIR
 
+  .sprintf6(pir_code, template, register_num, thing_type, register_num, 
lquote, $S0, rquote)
+ 
   # PIR's compiler can't deal with the utf16 code is generated as a result
   # of the string manipulation that brings us to this point. So, we need
   # to downcast it to ASCII. Which should be lossless, given the code that
@@ -104,6 +101,7 @@ can_compile:
 .end
 
 =item C<(pmc invokable) = pir_compiler(int register_num, string PIR)>
+
 =item C<(string code)   = pir_compiler(int register_num, string PIR, 1)>
 
 A thin wrapper for the <compreg>'d PIR compiler. 

Modified: trunk/languages/tcl/lib/macros.pir
==============================================================================
--- trunk/languages/tcl/lib/macros.pir  (original)
+++ trunk/languages/tcl/lib/macros.pir  Sun Jan 29 11:24:35 2006
@@ -163,3 +163,49 @@ Simplistic implementation of C<__clone>
 .end
 
 .endm
+
+=head1 compilation related macros
+ 
+=head2 sprintf<N>(OUT str code, IN str format, IN pmc val, ...)
+
+This isn't actually a vararg implementation - you can't vararg a macro.
+Instead, the macro name has a trailing number to indicate how many 
+C<val> arguments it's expecting.
+
+=cut
+
+.macro sprintf2(output,format,val1,val2)
+  .sym pmc    arglist 
+  .sym string argument
+  arglist = new .Array
+  arglist = 2
+  argument = .val1 
+  arglist[0] = argument
+  argument = .val2 
+  arglist[1] = argument
+  .output = sprintf .format, arglist
+.endm
+
+.macro sprintf3(output,format,val1,val2,val3)
+  .sym pmc arglist 
+  arglist = new .Array
+  arglist = 3
+  arglist[0] = .val1
+  arglist[1] = .val2
+  arglist[2] = .val3
+  .output = sprintf .format, arglist
+.endm
+
+.macro sprintf6(output,format,val1,val2,val3,val4,val5,val6)
+  .sym pmc arglist 
+  arglist = new .Array
+  arglist = 6
+  arglist[0] = .val1
+  arglist[1] = .val2
+  arglist[2] = .val3
+  arglist[3] = .val4
+  arglist[4] = .val5
+  arglist[5] = .val6
+  .output = sprintf .format, arglist
+.endm
+

Modified: trunk/languages/tcl/lib/tclops.pir
==============================================================================
--- trunk/languages/tcl/lib/tclops.pir  (original)
+++ trunk/languages/tcl/lib/tclops.pir  Sun Jan 29 11:24:35 2006
@@ -69,17 +69,10 @@ logical_not:
 done:
   (register_num,pir_code) = compile(register_num,operand)
 
-  .local pmc printf_args
-  printf_args = new .Array
-  printf_args = 3
-  inc register_num
-  printf_args[0] = register_num
-  printf_args[1] = opcode
-  dec register_num
-  printf_args[2] = register_num
-  inc register_num
+  $I0 = register_num + 1
+  .sprintf3($S0, "$P%i=%s $P%i\n", $I0, opcode, register_num)
+  register_num = $I0
 
-  $S0 = sprintf "$P%i=%s $P%i\n", printf_args
   pir_code .= $S0
 
   .return(register_num, pir_code)

Modified: trunk/languages/tcl/lib/tclvar.pir
==============================================================================
--- trunk/languages/tcl/lib/tclvar.pir  (original)
+++ trunk/languages/tcl/lib/tclvar.pir  Sun Jan 29 11:24:35 2006
@@ -22,17 +22,15 @@ Define the attributes required for the c
     .param int register_num
 
     .local string pir_code
-    pir_code = ""
-    .local pmc args
- 
-    args = new .Array
-    args = 4
-    args[0] = register_num
-    $S0 = self
-    args[1] = $S0
+    .local string template
+    template = <<"END_PIR"
+.local pmc read
+read = find_global '_Tcl', '__read'
+$P%i = read("%s")
+END_PIR
+
+     $S0 = self
+    .sprintf2(pir_code, template, register_num, $S0)
 
-    $S1 = sprintf ".local pmc read\nread=find_global \"_Tcl\", 
\"__read\"\n$P%i = read(\"%s\")\n", args
-    pir_code .= $S1 
- 
     .return (register_num,pir_code)
 .end

Reply via email to