From d1ff7361b5f93313dac0049d3035d3fc13b8f99b Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Tue, 29 Sep 2026 18:07:49 -0400 Subject: Update pit --- crates/teleia/build.rs | 2 ++ crates/teleia/src/script.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'crates') diff --git a/crates/teleia/build.rs b/crates/teleia/build.rs index aeb074e..857e2ea 100644 --- a/crates/teleia/build.rs +++ b/crates/teleia/build.rs @@ -1,5 +1,7 @@ fn main() { println!("cargo::rerun-if-changed=../../flake.lock"); + println!("cargo::rerun-if-env-changed=LIBCOLONQ_PIT_NATIVE"); + println!("cargo::rerun-if-env-changed=LIBCOLONQ_PIT_WASM"); match &*std::env::var("CARGO_CFG_TARGET_ARCH").unwrap() { "x86_64" => if let Ok(p) = std::env::var("LIBCOLONQ_PIT_NATIVE") { println!("cargo::rustc-link-search={}", p); diff --git a/crates/teleia/src/script.rs b/crates/teleia/src/script.rs index 300ed72..88fe759 100644 --- a/crates/teleia/src/script.rs +++ b/crates/teleia/src/script.rs @@ -34,6 +34,21 @@ extern "C" fn unwrap_nativefunc(rt: *mut PitRuntime, args: PitValue, data: *mut } } +#[repr(C)] +#[derive(Debug, Clone, Copy)] +enum PitSort { + Double, + Integer, + Symbol, + Cell, + Cons, + Array, + Bytes, + Func, + NativeFunc, + NativeData, +} + #[repr(C)] #[derive(Debug, Clone, Copy)] struct PitValue { data: u64 } @@ -68,6 +83,7 @@ struct PitParser { unsafe extern "C" { pub fn pit_runtime_test(out: *mut u8, out_len: i64, buf: *mut u8, len: i64) -> c_int; fn pit_runtime_new(buf: *mut MaybeUninit, len: i64) -> *mut PitRuntime; + fn pit_runtime_set_fuel(rt: *mut PitRuntime, fuel: i64); fn pit_error_get(buf: *mut PitRuntime) -> PitValue; fn pit_install_library_essential(buf: *mut PitRuntime); fn pit_install_library_plist(buf: *mut PitRuntime); @@ -90,6 +106,7 @@ unsafe extern "C" { fn pit_value_eq(x: PitValue, y: PitValue) -> bool; + fn pit_value_as_integer(rt: *mut PitRuntime, v: PitValue) -> i64; fn pit_value_as_double(rt: *mut PitRuntime, v: PitValue) -> f64; fn pit_value_array_new(rt: *mut PitRuntime, len: i64) -> PitValue; @@ -146,6 +163,11 @@ impl Runtime { if self.eq(ve, NIL) { return Ok(()) }; Err(Error { msg: self.dump(ve).unwrap_or("".to_owned()) }.into()) } + pub fn set_fuel(&mut self, fuel: i64) { + unsafe { + pit_runtime_set_fuel(self.rt, fuel); + } + } pub fn parse(&mut self, s: &str) -> utils::Erm { let lexer = Lexer::from_bytes(s.as_bytes()); let mut parser = Parser::from_lexer(lexer); @@ -189,6 +211,13 @@ impl Runtime { pub fn eq(&self, x: Value, y: Value) -> bool { unsafe { pit_value_eq(x.val, y.val) } } + pub fn as_integer(&mut self, x: Value) -> utils::Erm { + unsafe { + let v = pit_value_as_integer(self.rt, x.val); + self.error()?; + Ok(v) + } + } pub fn as_double(&mut self, x: Value) -> utils::Erm { unsafe { let v = pit_value_as_double(self.rt, x.val); -- cgit v1.3.1