This group implement a partial support for the Nit FFI in the interpreter.

It compiles foreign code on demand into a dynamic library that is then loaded and executed.

Features

This FFI implementation is a proof of concept, it implements the light FFI and only a subset of the full FFI.

From the light FFI:

  • Nested extern methods.
  • Module level code blocks.
  • Passage of primitive types.
  • Extern classes and constructors.

From the full FFI:

  • Static Nit types in C.
  • Public code block propagation.
  • The cflags and ldflags annotations.

Missing features: (Still TODO)

  • Callback to Nit code.
  • Support C++, Java and Objective-C.
  • Reference pinning.
  • Support the pkgconfig and extra_java_files annotations.

The shared library and its API

The generated shared library hold the compiled foreign code of a single module. It is generated a the first extern method invocation within the module.

The shared library also implements a standard API to be used by the interpreter. This API is compose of 2 main elements:

  • A single data structure to pass Nit instances and primitive data types:

    typedef union nit_call_arg {
      long value_Int;
      int value_Bool;
      uint32_t value_Char;
      uint8_t value_Byte;
      int8_t value_Int8;
      int16_t value_Int16;
      uint16_t value_UInt16;
      int32_t value_Int32;
      uint32_t value_UInt32;
      double value_Float;
      void* value_Pointer;
    } nit_call_arg;
    
  • Standardized entrypoints, one per extern method in the module. Their signature is composed of the number or arguments, a preallocated array of the arguments and a preallocated structure for the return value.

    int (*nit_foreign_lib_entry)(int argc, nit_call_arg *args, nit_call_arg *ret);
    

    Each entrypoints unpack the arguments and call the FFI implementation method. The return value is stored in the preallocated structure where the interpreter can retreive it.

All subgroups and modules

module dynamic_loading_ffi

nitc :: dynamic_loading_ffi

Execute FFI code by creating and loading shared libraries
module on_demand_compiler

nitc :: on_demand_compiler

Compiles extern code within a module to a static library, as needed
package_diagram nitc\>interpreter\>dynamic_loading_ffi\> dynamic_loading_ffi nitc\>ffi\> ffi nitc\>interpreter\>dynamic_loading_ffi\>->nitc\>ffi\> nitc\>interpreter\> interpreter nitc\>interpreter\>dynamic_loading_ffi\>->nitc\>interpreter\> nitc\>platform\> platform nitc\>ffi\>->nitc\>platform\> nitc\>modelize\> modelize nitc\>ffi\>->nitc\>modelize\> nitc\>nitni\> nitni nitc\>ffi\>->nitc\>nitni\> nitc nitc nitc\>ffi\>->nitc nitc\>interpreter\>->nitc nitc\>semantize\> semantize nitc\>interpreter\>->nitc\>semantize\> nitc\>model\> model nitc\>interpreter\>->nitc\>model\> nitc\>frontend\> frontend nitc\>interpreter\>->nitc\>frontend\> ...nitc\>platform\> ... ...nitc\>platform\>->nitc\>platform\> ...nitc\>modelize\> ... ...nitc\>modelize\>->nitc\>modelize\> ...nitc\>nitni\> ... ...nitc\>nitni\>->nitc\>nitni\> ...nitc ... ...nitc->nitc ...nitc\>semantize\> ... ...nitc\>semantize\>->nitc\>semantize\> ...nitc\>model\> ... ...nitc\>model\>->nitc\>model\> ...nitc\>frontend\> ... ...nitc\>frontend\>->nitc\>frontend\> nitc\>vm\> vm nitc\>vm\>->nitc\>interpreter\> nitc... ... nitc...->nitc nitc\>vm\>... ... nitc\>vm\>...->nitc\>vm\>

Ancestors

group api

nitc > doc > api

Components required to build a web server about the nit model.
group base64

base64

Offers the base 64 encoding and decoding algorithms
group c

c

Structures and services for compatibility with the C language
group catalog

nitc > catalog

Basic catalog generator for Nit packages
group codecs

core > codecs

Group module for all codec-related manipulations
group collection

core > collection

This module define several collection classes.
group commands

nitc > doc > commands

group compiler

nitc > compiler

Compilation to C
group compiler_ffi

nitc > compiler > compiler_ffi

Full FFI support for the compiler
group config

config

Configuration options for nit tools and apps
group console

console

Defines some ANSI Terminal Control Escape Sequences.
group core

core

Nit common library of core classes and methods
group counter

counter

Simple numerical statistical analysis and presentation
group csv

csv

CSV document handling.
group curl

curl

Data transfer powered by the native curl library
group doc

nitc > doc

group dot

dot

Dot rendering library
group frontend

nitc > frontend

Collect and orchestration of main frontend phases
group gen_nit

gen_nit

Support to generate and otherwise manipulate Nit code
group github

github

Nit wrapper for Github API
group graph

graph

group html

html

HTML output facilities
group ini

ini

ini - Read and write INI configuration files
group json

json

read and write JSON formatted text
group libevent

libevent

Low-level wrapper around the libevent library to manage events on file descriptors
group logger

logger

A simple logger for Nit
group markdown

markdown

A markdown parser for Nit.
group md5

md5

Native MD5 digest implementation as Text::md5
group meta

meta

Simple user-defined meta-level to manipulate types of instances as object.
group metrics

nitc > metrics

Various statistics about Nit models and programs
group model

nitc > model

The meta model of Nit programs
group modelize

nitc > modelize

Create a model from nit source files
group mongodb

mongodb

MongoDB Nit Driver.
group more_collections

more_collections

Highly specific, but useful, collections-related classes.
group neo4j

neo4j

Neo4j connector through its JSON REST API using curl.
group nitc

nitc

Nit compiler and tools
group nitcorn

nitcorn

Lightweight framework for Web applications development
group nitni

nitc > nitni

Native interface related services (used underneath the FFI)
group opts

opts

Management of options on the command line
group ordered_tree

ordered_tree

Manipulation and presentation of ordered trees.
group parser

nitc > parser

Parser and AST for the Nit language
group parser_base

parser_base

Simple base for hand-made parsers of all kinds
group perfect_hashing

perfect_hashing

Perfect hashing and perfect numbering
group performance_analysis

performance_analysis

Services to gather information on the performance of events by categories
group pipeline

pipeline

Pipelined filters and operations on iterators.
group platform

nitc > platform

Platform system, used to customize the behavior of the compiler.
group popcorn

popcorn

Popcorn
group poset

poset

Pre order sets and partial order set (ie hierarchies)
group prompt

prompt

Basic services to display a prompt
group pthreads

pthreads

POSIX Threads support
group realtime

realtime

Services to keep time of the wall clock time
group saf

nitc > saf

Nit Static Analysis Framework.
group semantize

nitc > semantize

Process bodies of methods in regard with the model.
group serialization

serialization

Abstract serialization services
group static

nitc > doc > static

Nitdoc generation framework
group template

template

Basic template system
group term

nitc > doc > term

group testing

nitc > testing

Test unit generation and execution for Nit.
group text

core > text

All the classes and methods related to the manipulation of text entities
group trees

trees

General module for tree data structures
group uml

nitc > uml

Group head module for UML generation services
group vm

nitc > vm

Entry point of all vm components

Parents

group ffi

nitc > ffi

Full FFI support, independent of the compiler
group interpreter

nitc > interpreter

Interpretation of Nit programs

Children

group interpreter

nitc > interpreter

Interpretation of Nit programs

Descendants

group api

nitc > doc > api

Components required to build a web server about the nit model.
group catalog

nitc > catalog

Basic catalog generator for Nit packages
group commands

nitc > doc > commands

group compiler

nitc > compiler

Compilation to C
group compiler_ffi

nitc > compiler > compiler_ffi

Full FFI support for the compiler
group doc

nitc > doc

group ffi

nitc > ffi

Full FFI support, independent of the compiler
group frontend

nitc > frontend

Collect and orchestration of main frontend phases
group metrics

nitc > metrics

Various statistics about Nit models and programs
group model

nitc > model

The meta model of Nit programs
group modelize

nitc > modelize

Create a model from nit source files
group nitc

nitc

Nit compiler and tools
group nitni

nitc > nitni

Native interface related services (used underneath the FFI)
group parser

nitc > parser

Parser and AST for the Nit language
group platform

nitc > platform

Platform system, used to customize the behavior of the compiler.
group saf

nitc > saf

Nit Static Analysis Framework.
group semantize

nitc > semantize

Process bodies of methods in regard with the model.
group static

nitc > doc > static

Nitdoc generation framework
group term

nitc > doc > term

group testing

nitc > testing

Test unit generation and execution for Nit.
group uml

nitc > uml

Group head module for UML generation services
group vm

nitc > vm

Entry point of all vm components