While reading pdd23 and thinking of implementation strategies for .begin_eh / .end_eh the following ideas jumped onto my branes:

- .begin_eh / .end_eh is by far not the only metainfo we want / need in PBC files
- we already have debug info (line numbers / file info => PC relation)
- we need more like HLL debug info / src code info
- there's also perl6 =pod stuff coming somewhen
- and last but not least some P6 COMPILING stuff comes to my mind (whatever that does) - we also want to convert current PackFile structures to some PMCs, which are more accessible to runtime

The needed meta info can of course all be hardcoded somehow into imcc files but that's all not reusable and general. Therefore I was thinking about utilizing existing stuff namely PIR to accomplish the same task. Here's a first draft of the exception handler range setup code:

.begin_eh LABEL =>
.meta {
        $I0 = exists $META['EH_range']
        if $I0 goto init_ok
        $P0 = new .ResizablePMCArray
        $META['EH_range'] = $P0
last_eh_range = new .ResizablePMCArray # decl / '_parrot' global access omitted
     init_ok:
        $P0 = $META['EH_range']
        $P1 = new .FixedIntegerArray
        $P1 = 3
        $P1[0] = $PC
        $P1[1] = $LABEL
        push $P0, $P1
        push last_eh_range, $P1
    }

.end_eh =>
.meta {
        $P1 = pop last_eh_range
        $P1[2] = $PC
    }

So the idea is:
- we enable running code during compilation and even per line (triggered by meta directives)
  (:immediate is only per subroutine and a bit different)
- above snippets are actually subroutines, called with needed/used arguments like the $META hash, $PC (program counter), line number, whatever
- these subs are autoloaded from some compiler library
- the code isn't ment to run arbitrary actions, but just to create needed meta information ... - which is basically one frozen PMC aggregate: the %META hash, with named sections, which are some other structures like the array of exception handler ranges - this metainfo is then of course available at runtime via e.g. the interpinfo opcode

There are of course some implementation obstacles (we want to create constant/persistent PMCs, access the constant table...) but it might be worth the effort to attack the general solution.

What do you think?
leo

Reply via email to