Skip to content

Commit 46039ef

Browse files
ffi: basic example
1 parent cdaec0b commit 46039ef

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
members = [
33
"trunk_lexer",
44
"trunk_parser",
5-
"trunk_interpreter"
5+
"trunk_interpreter",
6+
"trunk_ffi"
67
]

trunk_ffi/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "trunk_ffi"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
9+
[dependencies]
10+
trunk_parser = { path = "../trunk_parser" }

trunk_ffi/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[no_mangle]
2+
pub extern "C" fn fib(n: i32) -> i32 {
3+
if n < 2 {
4+
return n;
5+
}
6+
7+
return fib(n - 1) + fib(n - 2);
8+
}

0 commit comments

Comments
 (0)