Playing with Lean initialization code
This commit is contained in:
1 parent
0fe346c73f
commit
ba8bdf146a
3 files changed
+45
-6
No files matched your search
@@ -6,6 +6,9 @@ def myCustomString := "KJLKJLKJLKJLKJLJLKLKJ"
|
||||
@[export mycustomint]
|
||||
def myCustomInt : UInt32 := 42069
|
||||
|
||||
@[export mycustomnat]
|
||||
def myCustomNat : Nat := 69420
|
||||
|
||||
@[export mycustomintfunction]
|
||||
def myCustomIntFunction (input: UInt32): UInt32 := input + 42069
|
||||
|
||||
|
||||
@@ -48,10 +48,9 @@ fn main() {
|
||||
println!("cargo::rustc-link-search=native={}", lean_lib_dir.display());
|
||||
println!("cargo::rustc-link-arg=-Wl,-rpath,{}", lean_lib_dir.display());
|
||||
|
||||
// You may need these depending on what your exported Lean code references.
|
||||
// They are commonly needed when initializing/calling Lean from a non-Lean host.
|
||||
// println!("cargo::rustc-link-lib=dylib=Init_shared");
|
||||
// println!("cargo::rustc-link-lib=dylib=leanshared_2");
|
||||
// println!("cargo::rustc-link-lib=dylib=leanshared_1");
|
||||
// println!("cargo::rustc-link-lib=dylib=leanshared");
|
||||
// Lean runtime/core shared libraries
|
||||
println!("cargo::rustc-link-lib=dylib=Init_shared");
|
||||
println!("cargo::rustc-link-lib=dylib=leanshared_2");
|
||||
println!("cargo::rustc-link-lib=dylib=leanshared_1");
|
||||
println!("cargo::rustc-link-lib=dylib=leanshared");
|
||||
}
|
||||
@@ -1,14 +1,51 @@
|
||||
use std::ffi::c_void;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct LeanObject {
|
||||
_private: [u8; 0],
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
unsafe extern "C" {
|
||||
fn mycustomintfunction(x: u32) -> u32;
|
||||
//fn mycustomint() -> u32;
|
||||
//static mycustomint : u32;
|
||||
|
||||
// Initializers - names from objdump
|
||||
#[link_name = "initialize_lean_x2dffi_x2dexperiment_LeanFfiExperiment"]
|
||||
fn initialize_LeanFfiExperiment(builtin: u8) -> *mut LeanObject;
|
||||
|
||||
#[link_name = "initialize_lean_x2dffi_x2dexperiment_LeanFfiExperiment_Basic"]
|
||||
fn initialize_LeanFfiExperiment_Basic(builtin: u8) -> *mut LeanObject;
|
||||
|
||||
// See https://lean-lang.org/doc/reference/latest/Run-Time-Code/Foreign-Function-Interface/
|
||||
fn lean_initialize_thread();
|
||||
fn lean_finalize_thread();
|
||||
|
||||
// fn lean_io_result_is_ok(obj: *mut LeanObject) -> bool;
|
||||
fn lean_io_result_show_error(obj: *mut LeanObject);
|
||||
// fn lean_dec_ref(obj: *mut LeanObject);
|
||||
// fn lean_dec(obj: *mut LeanObject);
|
||||
|
||||
fn lean_initialize_runtime_module();
|
||||
fn lean_io_mark_end_initialization();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Going to invoke Lean FFI");
|
||||
|
||||
unsafe {
|
||||
lean_initialize_runtime_module();
|
||||
let _res = initialize_LeanFfiExperiment(1);
|
||||
// if lean_io_result_is_ok(res) {
|
||||
// // lean_dec_ref(res);
|
||||
// } else {
|
||||
// lean_io_result_show_error(res);
|
||||
// // lean_dec(res);
|
||||
// std::process::exit(1);
|
||||
// }
|
||||
}
|
||||
|
||||
let input = 20;
|
||||
let output = unsafe { mycustomintfunction(input) };
|
||||
|
||||
|
||||
Reference in new issue
Block a user