boot: sized numbers (i8..u64, f32), conversions, unsigned arithmetic

The self-hosted compiler now has the numeric types the C++ one has: int and
float stay the i64 and f64 defaults, the others lower to their LLVM sizes;
literals adapt to the other operand if they fit, smaller types widen into
bigger ones, signed and unsigned mixing is refused, division and shifts and
comparisons pick their signedness, and u8(x), f32(x), bool(x) convert.

boot.sh: 11 passed, 0 failed, 10 skipped (was 9 / 12).
This commit is contained in:
Nexoniarz 2026-10-25 18:42:04 +01:00
commit 873b52565d
3 changed files with 301 additions and 96 deletions

View file

@ -85,7 +85,8 @@ fn node(ptr[Parser] p, str kind) -> ast.Node {
}
fn isTypeName(str n) -> bool {
return n == "int" || n == "float" || n == "bool" || n == "char" || n == "str" || n == "ptr"
names := ["int", "float", "bool", "char", "str", "ptr", "i8", "i16", "i32", "i64", "u8", "u16", "u32", "u64", "f32", "f64"]
return names.contains(n)
}
// int, str, ptr[T], []T, Name, module.Name
@ -104,6 +105,12 @@ fn parseType(ptr[Parser] p) -> ast.Type {
expect(p, "]", "']'")
return t
}
if name == "i64" {
return ast.simple("int")
}
if name == "f64" {
return ast.simple("float")
}
return ast.simple(name)
}
t := ast.Type(kind: "named", name: name)