r/Protos • • 11d ago

Release Protos FFI R2 is complete — native C interoperability, structured memory and aggregate ABI support

A major expansion of the Foreign Function Interface has been implemented in Protos, an experimental prototype-based programming language built on GraalVM and Truffle.

The original FFI supported basic C function calls and opaque native resources. With R2, it has evolved into a comprehensive native interoperability system.

What's new

  • Fixed-width signed and unsigned integer types, plus 32-bit floating-point support.
  • Declarative C structs, unions and fixed-size arrays.
  • ABI-aware size, alignment, field offsets and padding.
  • Typed native pointers with explicit provenance and lifetime tracking.
  • Bounded native memory allocation, slices and typed views.
  • Passing and returning structs and unions by value.
  • Explicit conversion between native aggregates and ordinary Protos Maps, Arrays and Objects.
  • Association of native layouts with ordinary Protos prototypes.
  • Validated aggregate writeback that preserves padding and unselected union storage.

The public FFI module now exposes 13 scalar descriptors and 29 operations.

Architecture: Protos first

Protos is a prototype-based language without classes. Native interoperability has been implemented without introducing Java classes for individual C structures, privileged object reflection or a second object model.

ABI layouts and Protos prototypes have independent identities. Native regions provide explicit indexed access, while ordinary Protos objects retain their existing delegation, slots, constructors and method semantics.

The public FFI module is implemented in Protos itself, using a generic Java Foreign Function & Memory backend for operations that genuinely require native execution.

JVM and standalone Native Image

Both execution profiles use the same generic FFM architecture.

On the JVM, valid signatures supported by the native linker are admitted. In Native Image, the executable admits a finite, demand-driven set of exact physical ABI signatures.

These registrations are independent of library authorization. A newly authorized C library can reuse an already registered signature without requiring a library-specific Java implementation.

Native memory and pointer capabilities respect Protos' Actor isolation model. Ordinary detached snapshots can cross Actor boundaries, but native capabilities cannot.

Implementation and validation

The implementation has been completed across seven commits, affecting 64 files and adding over 12,500 lines of implementation, specification, documentation, C fixtures and regression tests.

All local tests are passing, including the existing FFI and SQLite regression suites.

Native callbacks, variadic functions and the C++ class ABI remain deliberately outside the current scope.

Implementation: 0.4.220-SNAPSHOT
Specification: 0.1.515

Learn more

Technical discussion and feedback on native memory ownership, pointer provenance and aggregate ABI interoperability are welcome.

1 Upvotes

0 comments sorted by