26 lines
663 B
Plaintext
26 lines
663 B
Plaintext
; status: design/speculative
|
|
; Follow-up mutable struct example. Top-level i32 structs, immediate field
|
|
; access, immutable struct locals, struct parameters, struct returns, and field
|
|
; access through stored struct values are promoted through
|
|
; `examples/supported/struct.slo` and
|
|
; `examples/supported/struct-value-flow.slo`.
|
|
; Field mutation remains speculative.
|
|
|
|
(module point)
|
|
|
|
(struct Point
|
|
(x i32)
|
|
(y i32))
|
|
|
|
(fn point_x_followup () -> i32
|
|
(let p Point (Point (x 3) (y 4)))
|
|
; Future design target, not current Slovo:
|
|
; (set-field p x 7)
|
|
(. p x))
|
|
|
|
(test "field access reads x"
|
|
(= (point_x_followup) 3))
|
|
|
|
(fn main () -> i32
|
|
(point_x_followup))
|