Adding modifiers to NCI
Allison Randal
allison at parrot.org
Sat Dec 27 00:54:05 UTC 2008
chromatic wrote:
>
> Having written or maintained more than one thunking layer between different
> calling conventions (Perl 5 to C, Parrot to C, Perl 5 to Parrot, Parrot to
> Perl 5), let me assure you that calling conventions between languages differ
> more than they are similar.
>
> Forcing all creators of NCI bindings to map well-understood C concepts to
> completely different semantics in an attempt to unify parsing -- especially
> when there already exists a usable, forty-year old mechanism for specifying
> the signatures of C functions -- is a foolish consistency.
We're not using a "forty-year old mechanism for specifying the
signatures of C functions", we're using our own custom syntax that
includes things like the Parrot interpreter, Parrot register types,
slurpy arrays, etc.
Oh, wait... do you think I mean that we should eliminate NCI entirely in
favor of PCC? No, not at all. I'm only talking about the strings
representing the signatures.
>> Shifting this syntax over to PCC-style is a trivial conversion.
>
> If that is the case, you may convince me.
Okay, quick pass conversion:
# INT register stuff
# I (same) - INTVAL
# c (C) - char
# s (H) - short
# i (T) - int
# l (L) - long
# NUM register stuff
# N (same) - FLOATVAL
# f (F) - float
# d (D) - double
# STR register stuff
# S (same) - pointer to a STRING-register
# t (C*) - character string (0-terminated)
# Buffers are not valid return parameters,
# use 'p' when the native function returns a pointer value
# b (V*) - void *
# B (V**) - void **
# PMC register stuff
# P (same) - pointer to a PMC-register
# O ('Pi' for *P*MC *i*nvocant) - pointer to PMC-register (object)
# p (A) - data pointer from PMC (on store into a new UnManagedStruct
PMC) [Note: generic pointer type, i.e. "pointer to *A*nything" ]
# 2 (H*) - pointer to short
# 3 (T*) - pointer to int
# 4 (L*) - pointer to long
# void stuff
# v (V) - void
# special stuff
# 0 (Z) - insert a NULL (pointer) - doesn't consume a register
# J (same) - Parrot_Interp param
# @ ('Ps' for *P*MC *s*lurpy) - slurpy array
# callback stuff
# U ('Pc' for *P*MC *c*allback) - Single PMC parameter to pass into
callback - user data
And, converting a few samples:
d JOd # Parrot builtins
becomes:
JPiD->D
v JOPSP # Namespace.set_global
becomes:
JPiPSP->V
(or:)
JPiPSP->
Allison
More information about the parrot-dev
mailing list