c3d / xl

A minimalist, general-purpose programming language based on meta-programming and parse tree rewrites
GNU General Public License v3.0
270 stars 15 forks source link

Foreign function interface (FFI) with easy to use macro #29

Closed c3d closed 4 years ago

c3d commented 4 years ago

Provide an easy-to-use way to generate the foreign function interface (FFI) to call into C code.

The objective is make it very quick to "export" a C function in such a way that it can be called by XL code. Ideally, the whole process would be automated by the C++ compiler using meta-programming techniques.

c3d commented 4 years ago

Implemented in the native.h header file.

Typical usage found in the runtime.

Tree *  xl_evaluate(Scope *scope, Tree *tree)
// ----------------------------------------------------------------------------
//   Dispatch evaluation to the main entry point
// ----------------------------------------------------------------------------
{
    return MAIN->Evaluate(scope, tree);
}
XL_NATIVE(evaluate);