mirror of
https://github.com/kanaka/mal.git
synced 2024-07-07 10:26:18 +03:00
wasm: fix odd WASI readline behavior.
Most of the time, the WASI fd_read call returns the whole line including the newline. Other times, it returns everything except the newline. So before stompiing the newline, check for that condition. This fixes the WASI based wasm implementations (wasmtime, wasmer, lucet).
This commit is contained in:
parent
58a6054e51
commit
1e8a122ddd
|
@ -49,7 +49,12 @@
|
|||
(if (i32.le_s (i32.load $nread_ptr) 0)
|
||||
(return 0))
|
||||
;; Replace ending newline with NULL
|
||||
(i32.store8 (i32.add $buf (i32.sub (i32.load $nread_ptr) 1)) 0)
|
||||
;; NOTE: oddly, there isn't always a newline so check first
|
||||
;; Specifically, this input chops too much:
|
||||
;; (abcd abcdefg (abc (n) (if (> n 0) (+ n (abcdefg (- n 1))) 0)))
|
||||
(if (i32.eq (CHR "\n")
|
||||
(i32.load8_u (i32.add $buf (i32.sub (i32.load $nread_ptr) 1)) 0))
|
||||
(i32.store8 (i32.add $buf (i32.sub (i32.load $nread_ptr) 1)) 0))
|
||||
1
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user