34 lines
400 B
Plaintext
34 lines
400 B
Plaintext
import mem
|
|
import sys
|
|
|
|
struct Point {
|
|
x Int
|
|
y Int
|
|
}
|
|
|
|
main() {
|
|
p := construct(1, 2)
|
|
print(p)
|
|
delete(p)
|
|
}
|
|
|
|
construct(x Int, y Int) -> *Point {
|
|
p := new(Point)
|
|
p.x = x
|
|
p.y = y
|
|
return p
|
|
}
|
|
|
|
print(p *Point) {
|
|
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)
|
|
mem.free(out, 8)
|
|
} |