From 1c7d50579fbfa3f4d5796f192ffbf7b3fecbfe7f Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Tue, 29 Sep 2026 19:03:14 -0400 Subject: Update pit --- crates/teleia/src/script.rs | 34 +++++++++++++++++++++++++++++++++- flake.lock | 8 ++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/crates/teleia/src/script.rs b/crates/teleia/src/script.rs index 88fe759..2e7ea3c 100644 --- a/crates/teleia/src/script.rs +++ b/crates/teleia/src/script.rs @@ -36,7 +36,7 @@ extern "C" fn unwrap_nativefunc(rt: *mut PitRuntime, args: PitValue, data: *mut #[repr(C)] #[derive(Debug, Clone, Copy)] -enum PitSort { +pub enum Sort { Double, Integer, Symbol, @@ -81,6 +81,17 @@ struct PitParser { #[allow(dead_code)] unsafe extern "C" { + static PIT__SORT_DOUBLE: i64; + static PIT__SORT_INTEGER: i64; + static PIT__SORT_SYMBOL: i64; + static PIT__SORT_CELL: i64; + static PIT__SORT_CONS: i64; + static PIT__SORT_ARRAY: i64; + static PIT__SORT_BYTES: i64; + static PIT__SORT_FUNC: i64; + static PIT__SORT_NATIVEFUNC: i64; + static PIT__SORT_NATIVEDATA: i64; + 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); @@ -104,6 +115,8 @@ unsafe extern "C" { fn pit_symtab_get(rt: *mut PitRuntime, sym: PitValue) -> PitValue; fn pit_symtab_fget(rt: *mut PitRuntime, sym: PitValue) -> PitValue; + fn pit_value_sort(x: PitValue) -> i64; + fn pit_value_sort_or_heavy_sort(x: PitValue) -> i64; fn pit_value_eq(x: PitValue, y: PitValue) -> bool; fn pit_value_as_integer(rt: *mut PitRuntime, v: PitValue) -> i64; @@ -168,6 +181,25 @@ impl Runtime { pit_runtime_set_fuel(self.rt, fuel); } } + pub fn sort_of(&mut self, v: Value) -> utils::Erm { + unsafe { + let vt = pit_value_sort_or_heavy_sort(v.val); + self.error()?; + if vt == PIT__SORT_DOUBLE { Ok(Sort::Double) } + else if vt == PIT__SORT_INTEGER { Ok(Sort::Integer) } + else if vt == PIT__SORT_SYMBOL { Ok(Sort::Symbol) } + else if vt == PIT__SORT_CELL { Ok(Sort::Cell) } + else if vt == PIT__SORT_CONS { Ok(Sort::Cons) } + else if vt == PIT__SORT_ARRAY { Ok(Sort::Array) } + else if vt == PIT__SORT_BYTES { Ok(Sort::Bytes) } + else if vt == PIT__SORT_FUNC { Ok(Sort::Func) } + else if vt == PIT__SORT_NATIVEFUNC { Ok(Sort::NativeFunc) } + else if vt == PIT__SORT_NATIVEDATA { Ok(Sort::NativeData) } + else { + utils::erm(Error { msg: format!("unknown pit sort index: {}", vt) }) + } + } + } pub fn parse(&mut self, s: &str) -> utils::Erm { let lexer = Lexer::from_bytes(s.as_bytes()); let mut parser = Parser::from_lexer(lexer); diff --git a/flake.lock b/flake.lock index aff32d5..24c210a 100644 --- a/flake.lock +++ b/flake.lock @@ -59,11 +59,11 @@ ] }, "locked": { - "lastModified": 1790718702, - "narHash": "sha256-VKvO91LtC8f+yW6nokidG2dUpW89nsoK8qYyWb6PlLY=", + "lastModified": 1790722782, + "narHash": "sha256-/QJdpk2P/23c6kAL7rd8INfms0DuFV6owL2iS3HkVCc=", "ref": "refs/heads/master", - "rev": "30bd399aed4c91e4d43cd5a911e7f3eafbcb4649", - "revCount": 29, + "rev": "fe4c9bd487cb9ae59d86dc7680855c5797ae04e3", + "revCount": 30, "type": "git", "url": "ssh://git@git.colonq.computer/~/libcolonq" }, -- cgit v1.3.1