vextoly/cryn

[# seek: positioning an 'open both' stream so read and write interleave
   on one file — the one thing the sequential byte-stream model plus
   flush cannot express #]
define main
  make string "cryn_test_31.txt" path
  make string "ABCDE" data
  make array 8 of uint8 buf
  make int64 h
  make int64 r
  make int64 c1
  make int64 c2
  make int64 n
  make int64 i

  address path
  open both
  home
  compare 0
  jump fail when less
  move h
  write
  push
  use
  home

  address data
  output text
  flush

  set 0
  seek
  move r
  write

  input
  move c1
  write
  input
  move c2
  write

  seek 3
  set 88
  convert uint8
  output
  flush

  set 0
  seek
  set 0
  move n
  write
  mark rd
  input
  compare -1
  jump fin when equal
  convert uint8
  push
  move n
  read
  move buf
  move index
  pop
  write
  move n
  read
  add 1
  move n
  write
  jump rd
  mark fin

  pop
  close
  use 0

  move r
  read
  output
  move c1
  read
  convert uint8
  output
  move c2
  read
  convert uint8
  output

  set 0
  home
  mark pr
  move n
  read
  push
  move i
  read
  compare
  jump donePr when greater-or-equal
  set 0
  home
  move i
  read
  move buf
  move index
  read
  output
  move i
  read
  add 1
  move i
  write
  set 0
  home
  jump pr
  mark donePr
  set 0
  home
  stop

  mark fail
  set 1
  stop
end