Added Rust support to the Fun core. (0.38.0)
This commit is contained in:
parent
8aa150f8f7
commit
149e135318
12 changed files with 299 additions and 1 deletions
16
src/rust/Cargo.toml
Normal file
16
src/rust/Cargo.toml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "hello-c-world"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
# Optimize for minimal size
|
||||
opt-level = "z"
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
# If Cargo is new enough, this strips symbols from Rust objects
|
||||
strip = "symbols"
|
||||
44
src/rust/src/lib.rs
Normal file
44
src/rust/src/lib.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2026-01-27
|
||||
*/
|
||||
|
||||
#![no_std]
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Vm;
|
||||
|
||||
extern "C" {
|
||||
fn vm_pop_i64(vm: *mut Vm) -> i64;
|
||||
fn vm_push_i64(vm: *mut Vm, v: i64);
|
||||
}
|
||||
|
||||
// Submodule with additional Rust VM math ops (exported via C ABI)
|
||||
pub mod vm;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fun_op_radd(vm: *mut Vm) -> i32 {
|
||||
unsafe {
|
||||
let b = vm_pop_i64(vm);
|
||||
let a = vm_pop_i64(vm);
|
||||
vm_push_i64(vm, a + b);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fun_rust_get_string() -> *const core::ffi::c_char {
|
||||
b"Hello from Rust ops!\0".as_ptr() as *const _
|
||||
}
|
||||
|
||||
// Minimal panic handler for no_std; abort behavior requested via Cargo profile
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue