f0f94f30e1
- parser: add parserIsTypeArgListAhead() for Func<Type>(args) and Type<T> { ... }
- hir_lower: method call desugaring with typeName tracking, self keyword,
ekField typeName propagation, variable type tracking, strip '*' suffix
from pointer type names in method calls, fix externFuncs buffer overflow
(64 -> 256 elements) that corrupted structCount
- qbe_backend: QBE_FindStruct, QBE_FieldOffset, QBE_TypeSize helpers;
hStructInit field-by-field codegen; hFieldPtr with offset + auto-load;
hAssign/hStore special case for hFieldPtr (generate pointer, not value);
fix null as *HirNode -> null as *void for extraData comparisons
30 lines
574 B
Plaintext
30 lines
574 B
Plaintext
// Structs - Basic struct usage
|
|
import Std::Io::{PrintLine, PrintInt};
|
|
|
|
|
|
struct Point {
|
|
x: int;
|
|
y: int;
|
|
}
|
|
|
|
func AddPoints(a: Point, b: Point) -> Point {
|
|
let result: Point = Point { x: a.x + b.x, y: a.y + b.y };
|
|
return result;
|
|
}
|
|
|
|
func Main() -> int {
|
|
let p1: Point = Point { x: 10, y: 20 };
|
|
let p2: Point = Point { x: 5, y: 15 };
|
|
let sum: Point = AddPoints(p1, p2);
|
|
|
|
PrintLine("Point sum:");
|
|
PrintLine("x = ");
|
|
PrintInt(sum.x);
|
|
PrintLine("");
|
|
PrintLine("y = ");
|
|
PrintInt(sum.y);
|
|
PrintLine("");
|
|
|
|
return 0;
|
|
}
|