Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

coke (5373)

  (email not shown publicly)

Journal of coke (5373)

Wednesday October 13, 2004
06:49 PM

ParTcl: Dynamic Tcl PMCs

[ #21331 ]
A few months ago, I put together a cargo cult version of basic PMC types for Tcl based on their Perl counterparts. I ripped out all reference to PerlUndef, and made sure the shimmering (automatic conversion of datatypes) was working between the various types.

After posting this to the list, I was told that this was good, but these PMCs needed to be dynamic. That is, rather than being types that are shipped with the basic parrot core, they should be available as a dynamically loadable library. Makes sense. (Note: This also means that Perl's PMCs should also be moved to a dynamic library, especially now that parrot has its own, non-Perl base types.).

Things sat for a bit after that. Thanks to Mattia Barbon who provided a way to group related pmcs together into a single library to load (Before this, interrelated pmcs were uncompilable, as each depended on another that hadn't been compiled yet.). Also thanks to Steve Fink, who got that working under OS X, which is my primary development environment.

Now, if you

cd dynclasses && make

you get runtime/parrot/dynext/ (or something like it.) (If you don't, there's a bug, and please report it to the perl6 internals list. )

Now, at the top level parrot directory, you can create foo.imc containing:

.sub main
  loadlib $P0, "tclgroup"    # Load combined tcl lib
  $I0 = find_type "TclInt"   # Find ID for a TclInt *
  $P0 = new $I0              # Instantiate
  $P0 = "asdf"               # Assign
  print $P0
  print "\n"
  $S0 = typeof $P0           # Get the type description.
  print $S0
  print "\n"

This snippet prints out


Note that the type of the PMC has shimmered (morphed, if you prefer) to the appropriate data type. I need to do more work to nail down the appropriate reactions for each kind of shimmer for Tcl.

Next steps:

  1. Remove any dependence in Tcl's PIR on the Perl* PMCs.
  2. Provide the ability to generate Tcl Lists from within Tcl
    (that is, write [list]), and insure that the right thing happens when shimmering between a list and a string. For example, insure that:

    puts '[string range [list 1 2 3] 0 2]'

    Actually generates

    '1 2'

    which will have been shimmered from a TclList (returned by [list]) to a TclString

[*] - these steps are, of course, unnecessary with built in types. They're necessary here because when parrot started, we didn't know anything about Tcl. We have to load the pmcs, and then, because the pmc types were created at runtime, we have to use a runtime check to get our class ID. (As opposed to the builtin type String, which you can, thanks to runtime/parrot/include/pmctypes.pasm, just create with $P0 = new String)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.