Version 2 (modified by cotto, 13 years ago)

direct C function calls in nqp


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

nextkey   =       key_next( INTERP,  key); /* from hash.pmc:get_number_keyed */
$nextkey :=       key_next($INTERP, $key); /* proposed equivalent in nqp */
$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


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