Interop with Other Languages

! This section is a draft. Many important details have yet to be ironed out.

A major goal of Puck is minimal-overhead language interoperability while maintaining type safety.

There are three issues that complicate language interop:

  1. Conflicting memory management systems, i.e. Boehm GC vs. reference counting
  2. Conflicting type systems, i.e. Python vs. Rust
  3. The language of communication, i.e. the C ABI.

For the first, Puck uses what amounts to a combination of ownership and reference counting: and thus it is exchangeable in this regard with Nim (same system), Rust (ownership), Swift (reference counting), and many others. (It should be noted that ownership systems are broadly compatible with reference counting systems).

For the second, Puck has a type system of similar capability to that of Rust, Nim, and Swift: and thus interop with those languages should be straightforward for the user. Its type system is strictly more powerful than that of Python or C, and so interop requires additional help. Its type system is equally as powerful as but somewhat orthogonal to Java's, and so interop is a little more difficult.

For the third, Puck is being written at the same time as the crABI ABI spec is in development. crABI promises a C-ABI-compatible, cross-language ABI spec, which would dramatically simplify the task of linking to object files produced by other languages. It is being led by the Rust language team, and both the Nim and Swift teams have expressed interest in it, which bodes quite well for its future.

Languages often focus on interop from purely technical details. This is very important: but typically no thought is given to usability (and often none can be, for necessity of compiler support), and so using foreign function interfaces very much feel like using foreign interfaces. Puck attempts to change that.

...todo...

Existing systems to learn from:

  • The Rust ABI
  • https://www.hobofan.com/rust-interop/
  • CBindGen
  • https://github.com/chinedufn/swift-bridge
  • https://kotlinlang.org/docs/native-c-interop.html
  • https://github.com/crackcomm/rust-lang-interop
  • https://doc.rust-lang.org/reference/abi.html
  • https://doc.rust-lang.org/reference/items/functions.html#extern-function-qualifier
  • NimPy
  • JNim
  • Futhark
  • Haxe's callfunc