making the generic function names distinct
Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
parent
786e3e6bfd
commit
2c53f9ece9
|
@ -116,7 +116,31 @@ impl hblang::backend::Backend for Backend {
|
||||||
} else {
|
} else {
|
||||||
self.asm.name.push_str(hblang::strip_cwd(&file.path));
|
self.asm.name.push_str(hblang::strip_cwd(&file.path));
|
||||||
self.asm.name.push('.');
|
self.asm.name.push('.');
|
||||||
|
if fd.parent != hbty::Id::from(fd.file) {
|
||||||
|
write!(
|
||||||
|
self.asm.name,
|
||||||
|
"{}",
|
||||||
|
hbty::Display::new(types, files, fd.parent)
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
self.asm.name.push_str(file.ident_str(fd.name));
|
self.asm.name.push_str(file.ident_str(fd.name));
|
||||||
|
if fd.is_generic {
|
||||||
|
let mut args = fd.sig.args.args();
|
||||||
|
self.asm.name.push('(');
|
||||||
|
while let Some(arg) = args.next(types) {
|
||||||
|
if let hbty::Arg::Type(ty) = arg {
|
||||||
|
write!(
|
||||||
|
self.asm.name,
|
||||||
|
"{},",
|
||||||
|
hbty::Display::new(types, files, ty)
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.asm.name.pop().unwrap();
|
||||||
|
self.asm.name.push(')');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let linkage = if func == from {
|
let linkage = if func == from {
|
||||||
cm::Linkage::Export
|
cm::Linkage::Export
|
||||||
|
|
31
smh.hb
31
smh.hb
|
@ -1,31 +0,0 @@
|
||||||
ResultInner := fn($T: type, $E: type): type return union {ok: T, err: E}
|
|
||||||
|
|
||||||
Result := fn($T: type, $E: type): type return struct {
|
|
||||||
inner: ResultInner(T, E),
|
|
||||||
is_ok: bool,
|
|
||||||
|
|
||||||
$ok := fn(k: T): Self return .(.{ok: k}, true)
|
|
||||||
$err := fn(k: E): Self return .(.{err: k}, false)
|
|
||||||
$unwrap := fn(self: Self): T return self.expect("Panic: Unwrap on Error Variant.\0".ptr)
|
|
||||||
$unwrap_unchecked := fn(self: Self): T return self.inner.ok
|
|
||||||
unwrap_or := fn(self: Self, v: T): T if self.is_ok return self.inner.ok else return v
|
|
||||||
unwrap_or_else := fn(self: Self, $F: type): T if self.is_ok return self.inner.ok else return F(self.inner.err)
|
|
||||||
expect := fn(self: Self, msg: ^u8): T if self.is_ok return self.inner.ok else {
|
|
||||||
@eca(0, msg)
|
|
||||||
die
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SomeError := enum {
|
|
||||||
SkillIssue,
|
|
||||||
}
|
|
||||||
|
|
||||||
div := fn(a: uint, b: uint): Result(uint, SomeError) {
|
|
||||||
if b != 0 return Result(uint, SomeError).ok(a / b)
|
|
||||||
return Result(uint, SomeError).err(.SkillIssue)
|
|
||||||
}
|
|
||||||
|
|
||||||
main := fn(): uint {
|
|
||||||
a := div(100, 0)
|
|
||||||
return a.expect("goof\0".ptr)
|
|
||||||
}
|
|
Loading…
Reference in a new issue