Allison Randal wrote:

I had a much longer reply, but I'm going to let it steep overnight and see what percolates.

I ran through a number of possibilities, but so far my favorite is: find_global and store_global are truly 'global', that is, they always require a fully specified namespace, including the HLL namespace.

    $P0 = find_global 'bar'                   # the top-level namespace
    $P1 = find_global 'parrot', 'bar'         # 'bar' in ['parrot']
    $P2 = find_global ['parrot';'Foo'], 'bar' # 'bar' in ['parrot';'Foo']
    $P3 = find_global 'tcl', 'bar'            # 'bar' in ['tcl']

Then a set of opcodes using the add_*, del_*, get_* naming scheme handle the "magically assume the HLL root/current namespace" behavior. (PDD 21 uses both get_* and find_* for retrieval. It's better to standardize on one, but it doesn't really matter which one.)

    .HLL "Perl5", "perl5_group"
    $P0 = get_symbol 'bar'        # 'bar' in ['perl5']
    $P1 = get_symbol 'Foo', 'bar' # 'bar in ['perl5';'Foo']

    .namespace [ 'Foo' ]
    $P2 = get_symbol 'bar'        # 'bar' in ['perl5';'Foo']

(I thought about prefixing all the opcodes that assume the HLL namespace with hll_, but since those are the common case, I'd rather mark the rarer global case.)


The .namespace directive has more flexibility, since it's a directive not an opcode. We can keep the basic syntax as the magical HLL behavior:

    .namespace [ 'Foo' ]        # namespace is ['parrot';'Foo']

    .HLL "Perl5", "perl5_group" # namespace is ['perl5']
    .namespace [ 'Foo' ]        # namespace is ['perl5';'Foo']

If you only use .HLL and no .namespace, then it assumes the root HLL namespace.

And add a couple of special forms for the rarer cases when you want to set the current namespace to the HLL or global root:

    .namespace hll_root
    .namespace global_root


------

Here are some of the "also-ran"s, in abbreviated form:
--
We could take the Perl 5 strategy of reserving a name ('main' or 'root' or something similar) to always act as an alias to the top-level of the current HLL namespace.

Conclusion: Perl 5 on Parrot will use this strategy, and so might other languages, but we shouldn't force it on all languages.

--
We could break out the root prefix from the rest of the name:


  $P2 = find_global 'parrot', ['Foo'], 'bar' # bar in ['parrot';'Foo']

Conclusion: reaching the global root would require an empty prefix key and an empty namespace name key. Not really an improvement, more of an unprovement.

--
We could have separate opcodes for "direct access" and "hll indirect access".

Conclusion: this led to a combinatorial explosion (bad), but then to the simplified solution above.

--
We could assume the current HLL namespace, and call methods on the namespace object to retrieve "meta" information like the root HLL namespace or global namespace.

Conclusion: more complex than is necessary to solve the problem.

------

Allison

Reply via email to