Version 3 (modified by cotto, 13 years ago)

add some example L1 code, although any relation to the implemented L1 is probably coincidental


One of the main goals of the pmc_pct branch is the ability to use a prescription-strength compiler to compile PMCs into L1 and C, rather than the Perl5-based pmc2c. Once pmcc is a viable replacement for pmc2c, we can start modifying it to support functions written in other languages such as nqp. However, nqp as it stands it not adequate for doing everything that we currently do in C-based PMCs. The purpose of this page is to document the known shortcomings of nqp in this area and to suggest possible ways to extend its syntax to handle these cases. To accomplish this, we are attempting to rewrite three representative PMCs (Hash, ResizablePMCArray and String) in nqp by translating the C into nqp as directly as possible.

List of Shortcomings

Direct C Function Calls

nqp syntax

/* original C code */
nextkey   =       key_next( INTERP,  key); /* from hash.pmc:get_number_keyed */

/* possible equivalent nqp-like code */
$nextkey :=       key_next($INTERP, $key);
$nextkey := cfunc:key_next($INTERP, $key); /* possible alternative syntax */

Much of Parrot will continue to be written in C well after our PMCs and ops are implemented in L1, and that L1 code (and any HLLs that compile down to L1) will need an efficient way to call those C functions directly.

equivalent L1 code

# NOTE: This code may be plausible and it may be terrible.
#       It's late and I wanted to try writing some L1.
c_arg      INTERP
c_arg      key
c_return   nextkey
find_cfunc $P0, 'next_key'
call_cfunc $P0

The equivalent L1 code will need to deal with C calling conventions and efficiently looking up (and caching) the appropriate symbol.