From 933f9512ea7f14d2ae39dd6608d853c1202db621 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 21 Dec 2024 14:34:56 +0100 Subject: [PATCH] fixing a bug in previous commit Signed-off-by: Jakub Doka --- lang/src/son.rs | 13 +++++---- smh.hb | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 smh.hb diff --git a/lang/src/son.rs b/lang/src/son.rs index 1c93374..f9242fa 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -851,12 +851,15 @@ impl<'a> Codegen<'a> { if let Some((captures, capture_tuple)) = self.tys.captures_of(piter, f) && let Some(idx) = captures.iter().position(|&cid| cid.id == id) { - let ty = if captures[idx].is_ct { - ty::Id::TYPE + if captures[idx].is_ct { + let ty = self.tys.ins.args[capture_tuple.range().start + idx]; + break Some(self.ci.nodes.new_const_lit(ty::Id::TYPE, ty)); } else { - self.tys.ins.args[capture_tuple.range().start + idx] - }; - break Some(Value::new(NEVER).ty(ty)); + break Some( + Value::new(NEVER) + .ty(self.tys.ins.args[capture_tuple.range().start + idx]), + ); + } } piter = match self.tys.parent_of(piter) { diff --git a/smh.hb b/smh.hb new file mode 100644 index 0000000..8ff9716 --- /dev/null +++ b/smh.hb @@ -0,0 +1,77 @@ +length := fn(ptr: ^u8): uint { + len := 0 + loop if *(ptr + len) == 0 return len else len += 1 +} + +split_once := fn(haystack: ^u8, needle: @Any()): ?^u8 { + T := @TypeOf(needle) + if T == ^u8 { + if *needle == 0 return null + + loop if *haystack == 0 return null else { + if *haystack == *needle { + h := haystack + n := needle + + loop { + n += 1 + h += 1 + if *n == 0 { + return haystack + } else if *h == 0 | *h != *n { + break + } + } + } + haystack += 1 + } + } else if T == u8 { + loop if *haystack == needle return haystack else if *haystack == 0 return null else haystack += 1 + } +} + +SplitIter := fn($T: type): type { + return struct { + str: ^u8, + needle: T, + done: bool + + iter := fn(self: ^Self): ?^u8 { + if self.done | *self.str == 0 { + return null + } + + next := split_once(self.str, self.needle) + + if next == null { + self.done = true + return self.str + } + s := self.str + if T == ^u8 { + self.str = next + length(self.needle) + } else if T == u8 { + self.str = next + 1 + } + + return s + } + } +} + +split := fn(iter: ^u8, needle: @Any()): SplitIter(@TypeOf(needle)) { + return .( + iter, + needle, + false + ) +} + + +main := fn(): void { + full_path := "acs:/path/to/a/file\0" + splt := split(full_path, "path\0") + a := splt.iter() + splt2 := split(full_path, '/') + b := splt2.iter() +}