fixing a bug in previous commit

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-21 14:34:56 +01:00
parent af19f4e30d
commit 933f9512ea
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
2 changed files with 85 additions and 5 deletions

View file

@ -851,12 +851,15 @@ impl<'a> Codegen<'a> {
if let Some((captures, capture_tuple)) = self.tys.captures_of(piter, f) if let Some((captures, capture_tuple)) = self.tys.captures_of(piter, f)
&& let Some(idx) = captures.iter().position(|&cid| cid.id == id) && let Some(idx) = captures.iter().position(|&cid| cid.id == id)
{ {
let ty = if captures[idx].is_ct { if captures[idx].is_ct {
ty::Id::TYPE let ty = self.tys.ins.args[capture_tuple.range().start + idx];
break Some(self.ci.nodes.new_const_lit(ty::Id::TYPE, ty));
} else { } else {
self.tys.ins.args[capture_tuple.range().start + idx] break Some(
}; Value::new(NEVER)
break Some(Value::new(NEVER).ty(ty)); .ty(self.tys.ins.args[capture_tuple.range().start + idx]),
);
}
} }
piter = match self.tys.parent_of(piter) { piter = match self.tys.parent_of(piter) {

77
smh.hb Normal file
View file

@ -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()
}