Early preview: syntax, standard library APIs, and tooling may change.

Numerics and SystemsFFI Preview

FFI Preview

foreign: blocks are the native trust boundary for calling C-compatible symbols.

Foreign Blocks

foreign: blocks declare C-compatible symbols. Use include: when the generated C needs a header.

foreign(include: "stdlib.h"):
	pure func c_abs(n: Int) -> Int = "labs"

C ABI

Blorp can bind functions exported with a C-compatible ABI.

long labs(long n);

Purity/Safety Modes

A pure func inside a foreign: block is for side-effect-free native code; @no_copy skips defensive copies only when you can prove the C side will not mutate or retain data.

foreign(include: "stdlib.h"):
	pure func c_abs(n: Int) -> Int = "labs"

Package Boundary

Keep FFI declarations in explicit user or package modules so unsafe edges stay easy to audit.

import:
	pkg/math/native as Native

Example

ffi-add.brp
foreign(include: "stdlib.h"):
	pure func c_abs(n: Int) -> Int = "labs"


pure func magnitude(n: Int) -> Int:
	c_abs(n)


func main(args: List[String]) -> Void:
	print(magnitude(-42))

Try it

terminal
blorp run ffi-add.brp