fixing a bug in previous commit
Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
parent
af19f4e30d
commit
933f9512ea
|
@ -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) {
|
||||
|
|
77
smh.hb
Normal file
77
smh.hb
Normal 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()
|
||||
}
|
Loading…
Reference in a new issue