2026-01-08 13:15:27 +01:00
|
|
|
import ../stdlib/stdlib.sl
|
|
|
|
|
import ../stdlib/io.sl
|
|
|
|
|
import ../stdlib/mem.sl
|
2025-12-28 11:46:01 +01:00
|
|
|
|
|
|
|
|
: test-mem-alloc
|
|
|
|
|
4096 alloc dup 1337 swap ! # allocate 4096 bytes, store 1337 at start
|
|
|
|
|
dup @ puti cr # print value at start
|
|
|
|
|
4096 free # free the memory
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
struct: Point
|
|
|
|
|
field x 8
|
|
|
|
|
field y 8
|
|
|
|
|
;struct
|
|
|
|
|
|
2026-01-08 13:15:27 +01:00
|
|
|
: main
|
2025-12-28 11:46:01 +01:00
|
|
|
32 alloc # allocate 32 bytes (enough for a Point struct)
|
|
|
|
|
dup 111 swap Point.x!
|
|
|
|
|
dup 222 swap Point.y!
|
|
|
|
|
dup Point.x@ puti cr
|
|
|
|
|
Point.y@ puti cr
|
|
|
|
|
32 free # free the memory
|
|
|
|
|
;
|