Changes between Version 3 and Version 4 of HllInteroperability

Show
Ignore:
Timestamp:
06/26/09 19:00:44 (13 years ago)
Author:
tene
Comment:

Add a usage example

Legend:

Unmodified
Added
Removed
Modified
  • HllInteroperability

    v3 v4  
    11= General Issues = 
    22* Until case mangling issues in Parrot are fixed, you must use an all-lowercase HLL name (someone plz add TT#) 
     3* Due to current bugs in Parrot, the 'load_language' opcode *must* be called from the 'parrot' HLL 
    34= Library Loading = 
    45To provide other languages access to libraries written in your language, you must add a 'load_library' method to your compiler object.  This method must accept one positional parameter, a list (or ::-delimited string?) representing the name of the library to load, and an arbitrary quantity of other named parameters (:named :slurpy), which it is (currently) free to ignore.  This method should return a hash containing the following attributes: 
     
    1920 
    2021For existing implementations of this, look at runtime/parrot/languages/parrot/parrot.pir in the Parrot repository and perl6.pir in the rakudo repository. 
     22 
     23An example implementation of a 'foreign_load' function: 
     24{{{ 
     25.sub 'foreign_load' 
     26    .param string lang 
     27    .param string module 
     28    .local pmc compiler, name, library, imports, callerns, foreignlibns 
     29    $P0 = getinterp 
     30    callerns = $P0['namespace';1] 
     31    'load-language'(lang) 
     32    compiler = compreg lang 
     33    name = split '::', module 
     34    library = compiler.'load_library'(name) 
     35    imports = library['symbols'] 
     36    imports = imports['DEFAULT'] 
     37    .local pmc iter, item 
     38    iter = new 'Iterator', imports 
     39  import_loop: 
     40    unless iter goto import_loop_end 
     41    $S0 = shift iter 
     42    $P0 = imports[$S0] 
     43    callerns[$S0] = $P0 
     44    goto import_loop 
     45  import_loop_end: 
     46    foreignlibns = library['namespace'] 
     47    if null foreignlibns goto no_foreign_ns 
     48    $S0 = pop name 
     49    set_hll_global name, $S0, foreignlibns 
     50  no_foreign_ns: 
     51    .return (library) 
     52.end 
     53}}}