The simple version of the compiler is now mostly done in my sandbox:

Failed Test       Stat Wstat Total Fail  Failed  List of Failed
------------------------------------------------------------------------ -------
t/cmd_global.t       3   768     6    3  50.00%  2-4
t/cmd_proc.t         4  1024    11    4  36.36%  3-4 8-9
t/cmd_return.t       1   256     2    1  50.00%  1
t/cmd_string.t       3   768    57    3   5.26%  21 45-46
t/tcl_backslash.t    4  1024    35    4  11.43%  31-34

These break down into two classes of errors:

1) ``Pad index out of range'' {global, proc, return}

2) Data::Escape::String can't escape unicode {string, backslash}

I've opened a TODO ticket for #2: [perl #37321] Any takers on this appreciated.

If I can get #1 working, I'll just TODO everything that depends on #2 and get this checked in.

I've attached the generated PIR output for the sample program, which outputs "10"

set a 0
while {$a < 10} {
  incr a
}
puts $a

It's functional but ugly. (Patches welcome once I checkin)

.pragma n_operators 1
.sub blah @ANON
.include "languages/tcl/lib/returncodes.pir"
$P0 = new .String
$P0="a"
$P1 = new .String
$P1="0"
.local pmc command
$P2 = new .String
$P2="set"
$S3=$P2
$S3 = "&" . $S3
push_eh bad_command3
command = find_global "Tcl", $S3
clear_eh
if_null command, bad_command3
$P3 = command($P0,$P1)
goto resume3
bad_command3:
$S3=$P2
$S3=concat "invalid command name \"" ,$S3
$S3.="\""
.throw($S3)
resume3:
.include "languages/tcl/lib/returncodes.pir"
$P3 = new .String
$P3="$a < 10"
$P4 = new .String
$P4="\n  incr a\n"
.local pmc command
$P5 = new .String
$P5="while"
$S6=$P5
$S6 = "&" . $S6
push_eh bad_command6
command = find_global "Tcl", $S6
clear_eh
if_null command, bad_command6
$P6 = command($P3,$P4)
goto resume6
bad_command6:
$S6=$P5
$S6=concat "invalid command name \"" ,$S6
$S6.="\""
.throw($S6)
resume6:
.include "languages/tcl/lib/returncodes.pir"
.local pmc read
read=find_global "_Tcl", "__read"
$P6 = read("a")
.local pmc command
$P7 = new .String
$P7="puts"
$S8=$P7
$S8 = "&" . $S8
push_eh bad_command8
command = find_global "Tcl", $S8
clear_eh
if_null command, bad_command8
$P8 = command($P6)
goto resume8
bad_command8:
$S8=$P7
$S8=concat "invalid command name \"" ,$S8
$S8.="\""
.throw($S8)
resume8:
.return ($P8)
.end
.pragma n_operators 1
.sub blah @ANON
.include "languages/tcl/lib/returncodes.pir"
$P0 = new .String
$P0="a"
.local pmc command
$P1 = new .String
$P1="incr"
$S2=$P1
$S2 = "&" . $S2
push_eh bad_command2
command = find_global "Tcl", $S2
clear_eh
if_null command, bad_command2
$P2 = command($P0)
goto resume2
bad_command2:
$S2=$P1
$S2=concat "invalid command name \"" ,$S2
$S2.="\""
.throw($S2)
resume2:
.return ($P2)
.end
10

On Sep 30, 2005, at 1:39 PM, Amos Robinson wrote:

Eeek. Yes, I forgot just how crazy a language it was. :-D


Yes, that's the plan, but the initial implementation isn't going to
be a compiler like most people would expect:

For example, something like:

while {$a < 10} { incr a }

while isn't language syntax. it's a command. So, this code would
result in creating two PMCs for the args (first arg is {$a <10},
second is {incr a}), and then lookup the while PIR .sub, and invoke
it with the two PMC args.

Future versions of the compiler will be able to cheat (presuming the
while builtin hasn't been overriden) and generate inline-able PIR,
which should improve performance.)

Regards.






Reply via email to