comfy cat added by Kooda on Thu Nov 5 13:16:41 2020

(load "comfy.k")
(load "elf.k")
(load "syscalls.k")

(init-memory! 144)

($define! buf #x100)

($define! exit
  ($compile
    (seq (addi a0 zero 0)
         (addi a7 zero SYS_exit)
         (ecall))
    0 0)) ;; never uses continuations

($define! entry
  ($compile
    (loop
      (seq (addi a0 zero 0)
           (addi a1 zero buf)
           (addi a2 zero 256)
           (addi a7 zero SYS_read)
           (ecall)
           (>? a0 zero) ;; read() returns 0 on end of input
           (addi a2 a0 0)
           (addi a0 zero 1)
           (addi a7 zero SYS_write)
           (ecall)))
    0 ;; loops forever of exit when test fails
    exit
    ))

(gen-elf-header! entry)
(save-bytevector "cat" (memory-vector))
(display "entry: ") (display entry) (newline)