# io.ludic — reading the input file and writing the output, plus tiny stdio. # The compiler reads one .ludic file whole and emits LLVM IR text to stdout. fn read_file(path: str) -> ptr { let f = file_open(path, "rb") if ptr_is_null(f) { return ptr_null() } file_seek(f, 0, 2) let n = file_tell(f) file_seek(f, 0, 0) let buf = mem_alloc(n + 1) file_read(f, buf, n) poke8(buf, n, 0) file_close(f) return buf } # length of a NUL-terminated buffer fn cstr_len(s: ptr) -> int { var n = 0 while peek8(s, n) != 0 { n = n + 1 } return n }