Ok. I'm looking at switching tcl over from an interpreter to a compiler.

I'll probably do this by using generating PIR, then doing using the compile opcode, ala:

.sub main
  $P1 = compreg "PIR"
  $S1 = ".sub joe\nprint \"Woof\\n\"\n.end\n"
  $P2 = compile $P1, $S1
  invokecc $P2
  end
.end

This is all good, but leads me to wonder how I can wrap my compiler into something that compreg could use itself, so that we could eventually do something like:

.sub main

  $P1 = new PerlString
  $P1 = "a value"
  store_lex -1, "a", $P1

  $P1 = compreg "TCL"
  $S1 = "puts $a"
  $P2 = compile $P1, $S1
  invokecc $P2
  end
.end

And get "a value\n" as output.

Docs say that

compreg(in STR, in PMC)
Register the sub $2 as a compiler for source type $1. $2 is either
a NCI PMC with signature "pIt" or a PASM Sub.


What should this PASM sub look like? I tried doing a simple wrapper of an existing compiler, ala:

.sub main

  newsub $P1, .Sub, foo_compiler
  compreg "PIERS", $P1

# ...

  $P2 = compreg "PIERS"
  $S1 = "print \"Eeek\\n\"\n"
  $P3 = compile $P2, $S1
  invokecc $P3
  end
.end

.sub foo_compiler
  .param string code
  $P1 = compreg "PASM"
  $P2 = compile $P1, code
  .pcc_begin_return
    .return $P2
  .pcc_end_return
.end

- This runs fine if you change the second PIERS to PASM, but if you leave it as is, parrot crashes.

Regards.


--
Will "Coke" Coleda will at coleda dot com




Reply via email to