;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(func $readline (param $prompt i32 $buf i32) (result i32)
- (local $line i32 $len i32)
- (set_local $len 0)
+ (LET $line ($lib_readline $prompt)
+ $len 0)
- (set_local $line ($lib_readline $prompt))
(if $line
(then
($lib_add_history $line)
(set_local $len ($strlen $line))
($memmove $buf $line $len)
($lib_free $line)))
- (i32.store8_u (i32.add $buf $len) (CHR "\x00"))
- (return (if i32 $line 1 0))
+ (i32.store8 (i32.add $buf $len) (CHR "\x00"))
+ (return (if (result i32) $line 1 0))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Returns malloc'd string. Must be free by caller
(func $read_file (param $path i32 $buf i32) (result i32)
- (local $fst i32 $fd i32 $st_size i32 $sz i32)
- (set_local $fst (STATIC_ARRAY 100)) ;; at least STAT_SIZE
+ (LET $fst (STATIC_ARRAY 100) ;; at least STAT_SIZE
+ $fd ($lib_open $path (get_global $O_RDONLY) 0)
+ $st_size 0
+ $sz 0)
- (set_local $fd ($lib_open $path (get_global $O_RDONLY) 0))
(if (i32.lt_s $fd 0)
(then
($printf_1 "ERROR: slurp failed to open '%s'\n" $path)
($printf_1 "ERROR: slurp failed to stat '%s'\n" $path)
(return 0)))
;; Add null to string
- (i32.store8_u (i32.add $buf $st_size) 0)
+ (i32.store8 (i32.add $buf $st_size) 0)
(i32.add 1 $st_size)
)
(func $get_time_ms (result i32)
- (local $tv i32 $secs i32 $usecs i32 $msecs i32)
- (set_local $tv (STATIC_ARRAY 10)) ;; at least TIMEVAL_SIZE
+ (LET $tv (STATIC_ARRAY 10) ;; at least TIMEVAL_SIZE
+ $secs 0
+ $usecs 0
+ $msecs 0)
(drop ($lib_gettimeofday $tv 0))
(set_local $secs (i32.load (i32.add $tv (get_global $TV_SEC_OFFSET))))
;; subtract 30 years to make sure secs is positive and can be
;; multiplied by 1000
- (set_local $secs (i32.sub_s $secs 0x38640900))
+ (set_local $secs (i32.sub $secs 0x38640900))
(set_local $usecs (i32.load (i32.add $tv (get_global $TV_USEC_OFFSET))))
- (set_local $msecs (i32.add (i32.mul_u $secs 1000)
+ (set_local $msecs (i32.add (i32.mul $secs 1000)
(i32.div_u $usecs 1000)))
$msecs
)