Helper for implementors of the Truffle NFI.
The Truffle NFI can be used to call native libraries from other Truffle languages. To load a
native library, the user should evaluate a source of the following syntax:
NativeSource ::= [ BackendSelector ] LibraryDescriptor [ BindBlock ]
BackendSelector ::= 'with' ident
BindBlock ::= '{' { BindDirective } '}'
BindDirective ::= ident Signature ';'
LibraryDescriptor ::= DefaultLibrary | LoadLibrary
DefaultLibrary ::= 'default'
LoadLibrary ::= 'load' [ '(' ident { '|' ident } ')' ] string
Signature ::= '(' [ Type { ',' Type } ] [ '...' Type { ',' Type } ] ')' ':' Type
Type ::= Signature | SimpleType | ArrayType | EnvType
SimpleType ::= ident
ArrayType ::= '[' SimpleType ']'
EnvType ::= 'env'
The BackendSelector ('with' ident) can be used to explicitly select an alternative backend for
the Truffle NFI. If the BackendSelector is missing, the default backend (selector 'native') is
used.
Implementors of Truffle NFI backends must parse their source string using the
Parser.parseLibraryDescriptor(java.lang.CharSequence) function, and must use
Parser.parseSignature(java.lang.CharSequence) to parse the signature argument string of the
bind method on native symbols.