use tishlang_bytecode::deserialize;
use tishlang_vm::Vm;
pub fn tish_run_chunk(ptr: *const u8, len: usize) -> i32 {
tish_run_chunk_impl(ptr, len)
}
#[no_mangle]
extern "C" fn tish_run_chunk_impl(ptr: *const u8, len: usize) -> i32 {
if ptr.is_null() || len < 8 {
return 1;
}
let slice = unsafe { std::slice::from_raw_parts(ptr, len) };
match deserialize(slice) {
Ok(chunk) => {
let mut vm = Vm::new();
match vm.run(&chunk) {
Ok(_) => 0,
Err(e) => {
eprintln!("Runtime error: {}", e);
1
}
}
}
Err(e) => {
eprintln!("Deserialization error: {}", e);
1
}
}
}