On Jul 27, 2005, at 9:46 PM, Thilo Planz wrote:
Hi,
I have a few beginner's question about ParTcl.
I am trying to embed ParTcl into a PIR application, which seems to
work quite nicely, except that I have not yet figured out how to do
certain things.
This is almost certainly no fault of your own. =-)
=====
1) Is there a way to reset the Tcl interpreter between invocations?
.sub _main @MAIN
load_bytecode "languages/tcl/lib/tcllib.pbc"
$P1 = compreg 'TCL'
$P0 = compile $P1, 'set a 1; puts $a'
$P0()
# now reset the TCL interpreter somehow
$P0 = compile $P1, 'incr a; puts $a'
$P0()
.end
Well, the interpreter is running inside parrot - all the sub and
variable definitions are stored in parrot namespaces... so for your
particular example, removing the global variable '$a' from the
namespace "Tcl" should be sufficient. The interpreter should have its
own state which you can reset, but a lot of that is hidden in globals
in the "_Tcl" namespace.
I think when we add support for [interp] and [safe], you'll be able
to do manage this process more cleanly.
====
2) I can access TCL variables from PIR using
find_global "_Tcl", "__read"
Is there any way to access Parrot globals from TCL ( other than
doing inline PIR to assign them to a TCL variable) ?
At this point, no. We need the [namespace] command to be able to poke
around outside the "Tcl" namespace. At which point you'll be able to
do something like:
set a ::_parrot::Perl6::\$b
Interoperability between HLLs isn't finalized yet, though, so I'm not
sure if we'll each end up in our own top level namespace.
====
3) Is there a way to pass parameters to the subroutine produced by
the TCL compiler ?
.sub _main @MAIN
load_bytecode "languages/tcl/lib/tcllib.pbc"
$P1 = compreg 'TCL'
$P0 = compile $P1, 'puts $first_parameter'
$P0('hello')
# now reset the TCL interpreter somehow
.end
Nope. I would expect this to work:
.sub main @MAIN
load_bytecode "languages/tcl/lib/tcllib.pbc"
$P0 = compreg "TCL"
$P1 = compile $P0, "proc _tmp {a} {puts $a}"
$P1()
$P2 = find_global "Tcl", "&_tmp"
$P3 = new String
$P3 = "hello"
$P2($P3)
.end
That is, define a sub in Tcl that does what you want, then invoke
that sub. This fails on the last line, however, with "_scratch_pad:
too deep". Adding this as a TODO item in the partcl test suite...
====
4) Is there a way to pass parameters from TCL to inline PIR code ?
My current work-around is to put them into variables and access
those using "__Tcl"::"__read".
At the moment, no. However, since [inline] is a partcl creation (not
part of pure tcl), we can define whatever semantics we like: We could
pre-process the string and expand variable/backslash/command
substitution...
But, as I noted above: every variable and proc in the script is
really a parrot variable at some level: so you can use find_global,
find_lex, find_name, etc. Variables have a $ sigil, procedures have a
& sigil. Variables in tcl's level 0 are parrot globals, everything
used in a proc is a lexical. {{ check out t/tcl_pir_compiler.t test #
2 for an example going in the other direction. }}
The sigils are to avoid problems with code like: "set a 2; a", which
until a week or so ago, failed because it was trying to execute a
String PMC with a value of 2, instead of correctly complaining about
an invalid command.
====
Thanks,
Thilo
Thank you! Sorry the answer to most of your questions was "no"... If
there's anything I can do to help improve partcl for your use, let me
know. Since I was able to get a concrete TODO test out of #3, that'll
probably get fixed first.
Regards.