34 lines
400 B
Plaintext
Raw Normal View History

2025-02-04 20:43:15 +01:00
import mem
import sys
2025-02-04 18:16:31 +01:00
struct Point {
x Int
y Int
}
main() {
p := construct(1, 2)
2025-02-05 15:16:00 +01:00
print(p)
delete(p)
}
construct(x Int, y Int) -> *Point {
2025-02-04 18:16:31 +01:00
p := new(Point)
p.x = x
p.y = y
2025-02-05 15:16:00 +01:00
return p
}
2025-02-04 20:43:15 +01:00
2025-02-05 15:16:00 +01:00
print(p *Point) {
2025-02-04 20:43:15 +01:00
out := mem.alloc(8)
out[0] = 'x'
out[1] = ' '
out[2] = '0' + p.x
out[3] = '\n'
out[4] = 'y'
out[5] = ' '
out[6] = '0' + p.y
out[7] = '\n'
sys.write(1, out, 8)
2025-02-05 15:16:00 +01:00
mem.free(out, 8)
2025-02-04 18:16:31 +01:00
}