Implement new features #6

Merged
n3tael merged 9 commits from bedohswe/labast:master into master 2024-06-20 20:39:40 +00:00
2 changed files with 2 additions and 2 deletions
Showing only changes of commit 751971576e - Show all commits

View File

@ -42,7 +42,7 @@ pub fn native(stack: &mut Stack, arg: String) {
let module = Library::new([libpref, arg, libsuf].join("")).unwrap(); let module = Library::new([libpref, arg, libsuf].join("")).unwrap();
// C libraries should use // C libraries should use
// void (*labashka)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size); // void (*labashka)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size);

из-за того что stack_pop_callback, stack_push_callback и stack_len_callback станут unsafe, нужно изменить тип:

let func: Symbol<extern "C" fn(unsafe extern fn() -> u16, unsafe extern fn(u16), unsafe extern fn() -> usize, usize)> = module.get(b"labashka").unwrap();
из-за того что `stack_pop_callback`, `stack_push_callback` и `stack_len_callback` станут `unsafe`, нужно изменить тип: ```rust let func: Symbol<extern "C" fn(unsafe extern fn() -> u16, unsafe extern fn(u16), unsafe extern fn() -> usize, usize)> = module.get(b"labashka").unwrap(); ```
let func: Symbol<unsafe extern "C" fn(extern fn() -> u16, extern fn(u16) -> i32, extern fn () -> usize, usize)> = module.get(b"labashka").unwrap(); let func: Symbol<unsafe extern "C" fn(extern fn() -> u16, extern fn(u16), extern fn() -> usize, usize)> = module.get(b"labashka").unwrap();
func(stack_pop_callback,stack_push_callback,stack_len_callback, stack.memory.size()); func(stack_pop_callback,stack_push_callback,stack_len_callback, stack.memory.size());
} }
} }

View File

@ -4,7 +4,7 @@
// rustc --crate-type cdylib native_test.rs -o native_test.dll // rustc --crate-type cdylib native_test.rs -o native_test.dll
#[no_mangle] #[no_mangle]
unsafe extern "C" fn labashka(pop: extern fn() -> u16, push: extern fn(u16) -> i32, len: extern fn () -> usize, max: usize) { unsafe extern "C" fn labashka(pop: extern fn() -> u16, push: extern fn(u16), len: extern fn () -> usize, max: usize) {
println!("At {}, there's {}.", len(), pop()); println!("At {}, there's {}.", len(), pop());
push(12); push(12);
println!("Maximum size is {}.", max); println!("Maximum size is {}.", max);