[# seek edges: offset in the working value and as a literal, seeking
before the start fails without moving the position, seeking past the
end reads end of file and writes extend the file #]
define main
make string "cryn_test_35.txt" path
make int64 h
make int64 r1
make int64 r2
make int64 r3
address path
open both
home
compare 0
jump bad when less
move h
write
push
use
home
make string "abcdef" data
address data
output text
flush
[# literal form: land on byte 3 and read it #]
seek 3
home
compare 0
jump ok1 when equal
set 1
stop
mark ok1
input
move r1
write
[# working value form: land on byte 0 and read it #]
set 0
seek
home
compare 0
jump ok2 when equal
set 1
stop
mark ok2
input
move r2
write
[# negative offset fails, reports -1, position stays put at byte 1 #]
set -1
seek
home
compare -1
jump ok3 when equal
set 1
stop
mark ok3
input
move r3
write
[# past the end reads end of file #]
seek 100
home
compare 0
jump ok4 when equal
set 1
stop
mark ok4
input
compare -1
jump past when equal
set 1
stop
mark past
[# writing there extends the file: byte 100 becomes G over a gap #]
set 71
convert uint8
output
flush
pop
close
use 0
move r1
read
convert uint8
output
move r2
read
convert uint8
output
move r3
read
convert uint8
output
[# read the whole file back: six letters, one gap byte, one G #]
address path
open read
move h
write
push
use
home
set 0
mark rd
input
compare -1
jump fin when equal
convert uint8
output
jump rd
mark fin
pop
close
set 0
stop
mark bad
set 1
stop
end