vextoly/cryn

[# first-class handles: two files open at once, stream routing, append #]
define main
  make string "cryn_test_28a.txt" pa
  make string "cryn_test_28b.txt" pb
  make string "one\n" s1
  make string "two\n" s2
  make string "\n" nl
  make int64 ha
  make int64 hb

  address pa
  open write
  home
  compare 0
  jump fail when less
  move ha
  write

  address pb
  open write
  home
  compare 0
  jump fail when less
  move hb
  write

  move ha
  read
  use
  home
  address s1
  output text
  flush

  move hb
  read
  use
  home
  address s2
  output text
  flush

  move ha
  read
  close
  home
  compare 0
  jump fail when different

  move hb
  read
  close
  home
  compare 0
  jump fail when different

  address pa
  open append
  home
  compare 0
  jump fail when less
  push
  use
  home
  address s2
  output text
  flush
  pop
  close
  home
  compare 0
  jump fail when different

  use 0
  address pa
  open read
  home
  compare 0
  jump fail when less
  push
  use
  home
  set 0
  mark rd
  input
  compare -1
  jump fin when equal
  convert uint8
  output
  jump rd
  mark fin
  pop
  close

  address nl
  output text
  set 0
  stop

  mark fail
  set 1
  stop
end