zilch-lang / specification

A complete specification on Zilch and N⋆
BSD 3-Clause "New" or "Revised" License
10 stars 0 forks source link

The Foreign Function Interface #13

Open Mesabloo opened 2 years ago

Mesabloo commented 2 years ago

The Foreign Function Interface (FFI for short) is a mecanism proposed by many programming languages which is used to link programs written in two different programming languages together through the use of a common ABI. The most common FFI in programming languages nowadays is one targetting the C ABI, but some also exist for JS (e.g. Koka or Purescript), C# (Koka), Java (we may add Scala and other JVM-targetting programming languages there), etc.

The grammar itself is very simple:

Foreign functions cannot have effects (this doesn't mean they are pure! this only means they need to be encapsulated on the Zilch-side to create side-effects, e.g. in effect hgandlers) and cannot either be exported by modules, as their use is strictly unsafe. That way, unsafe FFI-defined function cannot escape a module by accident, which would lead to unsafe codebases using this module.


Semantics are left undefined for now because an ABI will have to be defined.