mirror of
https://github.com/kanaka/mal.git
synced 2024-11-13 01:43:50 +03:00
wasm: drop unnecessary signed suffixes.
Apparently some of the assemblers ignored these sign indicators and so this worked in the past.
This commit is contained in:
parent
f2858819cc
commit
0c62f14e6a
@ -170,11 +170,11 @@
|
||||
($VAL0 ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args))))))
|
||||
(func $subtract (param $args i32) (result i32)
|
||||
($INTEGER
|
||||
(i32.sub_s ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
(i32.sub ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
($VAL0 ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args))))))
|
||||
(func $multiply (param $args i32) (result i32)
|
||||
($INTEGER
|
||||
(i32.mul_s ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
(i32.mul ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
($VAL0 ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args))))))
|
||||
(func $divide (param $args i32) (result i32)
|
||||
($INTEGER
|
||||
@ -443,7 +443,7 @@
|
||||
(set_local $f_args ($INC_REF ($MEM_VAL1_ptr $rest_args))))))
|
||||
(else
|
||||
;; 1 or more intermediate args
|
||||
(set_local $last_sl ($SLICE $rest_args 0 (i32.sub_s $rest_count 1)))
|
||||
(set_local $last_sl ($SLICE $rest_args 0 (i32.sub $rest_count 1)))
|
||||
(set_local $f_args (i32.wrap/i64 $last_sl))
|
||||
(set_local $last (i32.wrap/i64 (i64.shr_u $last_sl (i64.const 32))))
|
||||
;; release the terminator of the new list (we skip over it)
|
||||
|
@ -8,7 +8,7 @@
|
||||
(func $CHECK_FREE_LIST (result i32)
|
||||
(LET $first (i32.add
|
||||
(get_global $mem)
|
||||
(i32.mul_u (get_global $mem_free_list) 4))
|
||||
(i32.mul (get_global $mem_free_list) 4))
|
||||
$count 0)
|
||||
|
||||
(block $done
|
||||
@ -16,10 +16,10 @@
|
||||
(br_if $done
|
||||
(i32.ge_s $first
|
||||
(i32.add (get_global $mem)
|
||||
(i32.mul_u (get_global $mem_unused_start)
|
||||
(i32.mul (get_global $mem_unused_start)
|
||||
4))))
|
||||
(set_local $count (i32.add $count ($MalVal_size $first)))
|
||||
(set_local $first (i32.add (get_global $mem) (i32.mul_u 4 ($VAL0 $first))))
|
||||
(set_local $first (i32.add (get_global $mem) (i32.mul 4 ($VAL0 $first))))
|
||||
(br $loop)
|
||||
)
|
||||
)
|
||||
@ -27,8 +27,8 @@
|
||||
)
|
||||
|
||||
(func $PR_MEMORY_SUMMARY_SMALL
|
||||
(LET $free (i32.sub_s (get_global $MEM_SIZE)
|
||||
(i32.mul_u (get_global $mem_unused_start) 4))
|
||||
(LET $free (i32.sub (get_global $MEM_SIZE)
|
||||
(i32.mul (get_global $mem_unused_start) 4))
|
||||
$free_list_count ($CHECK_FREE_LIST)
|
||||
$mv (get_global $NIL)
|
||||
$mem_ref_count 0)
|
||||
@ -37,22 +37,22 @@
|
||||
(loop $loop
|
||||
(br_if $done (i32.ge_s $mv (i32.add
|
||||
(get_global $mem)
|
||||
(i32.mul_u (get_global $mem_unused_start)
|
||||
(i32.mul (get_global $mem_unused_start)
|
||||
4))))
|
||||
(if (i32.ne ($TYPE $mv) (get_global $FREE_T))
|
||||
(set_local $mem_ref_count (i32.add $mem_ref_count
|
||||
(i32.shr_u
|
||||
(i32.load $mv)
|
||||
5))))
|
||||
(set_local $mv (i32.add $mv (i32.mul_u 4 ($MalVal_size $mv))))
|
||||
(set_local $mv (i32.add $mv (i32.mul 4 ($MalVal_size $mv))))
|
||||
(br $loop)
|
||||
)
|
||||
)
|
||||
|
||||
($printf_3 "Free: %d, Values: %d (refs: %d), Emptys: "
|
||||
$free
|
||||
(i32.sub_s
|
||||
(i32.sub_s (get_global $mem_unused_start) 1)
|
||||
(i32.sub
|
||||
(i32.sub (get_global $mem_unused_start) 1)
|
||||
$free_list_count)
|
||||
$mem_ref_count)
|
||||
(set_local $mv (get_global $NIL))
|
||||
@ -210,9 +210,9 @@
|
||||
(LET $ms 0
|
||||
$idx 0)
|
||||
($printf_2 "String - showing %d -> %d:\n"
|
||||
$start (i32.sub_s (get_global $string_mem_next)
|
||||
$start (i32.sub (get_global $string_mem_next)
|
||||
(get_global $string_mem)))
|
||||
(if (i32.le_s (i32.sub_s (get_global $string_mem_next)
|
||||
(if (i32.le_s (i32.sub (get_global $string_mem_next)
|
||||
(get_global $string_mem))
|
||||
$start)
|
||||
(then ($print " ---\n"))
|
||||
@ -221,7 +221,7 @@
|
||||
(block $done
|
||||
(loop $loop
|
||||
(br_if $done (i32.ge_u $ms (get_global $string_mem_next)))
|
||||
(set_local $idx (i32.sub_u $ms (get_global $string_mem)))
|
||||
(set_local $idx (i32.sub $ms (get_global $string_mem)))
|
||||
(if (i32.ge_s $idx $start)
|
||||
($printf_4 "%4d: refs %2d, size %2d >> '%s'\n"
|
||||
$idx
|
||||
@ -241,7 +241,7 @@
|
||||
(if (i32.lt_s $start 0)
|
||||
(then
|
||||
(set_local $start (get_global $mem_user_start))
|
||||
(set_local $string_start (i32.sub_s (get_global $string_mem_user_start)
|
||||
(set_local $string_start (i32.sub (get_global $string_mem_user_start)
|
||||
(get_global $string_mem)))))
|
||||
(if (i32.lt_s $end 0)
|
||||
(set_local $end (get_global $mem_unused_start)))
|
||||
|
@ -85,7 +85,7 @@
|
||||
|
||||
;; combine res/env as hi 32/low 32 of i64
|
||||
(i64.or
|
||||
(i64.shl_u (i64.extend_u/i32 $res) (i64.const 32))
|
||||
(i64.shl (i64.extend_u/i32 $res) (i64.const 32))
|
||||
(i64.extend_u/i32 $env))
|
||||
)
|
||||
|
||||
|
34
wasm/mem.wam
34
wasm/mem.wam
@ -30,19 +30,19 @@
|
||||
|
||||
(func $MEM_VAL0_ptr (param $mv i32) (result i32)
|
||||
(i32.add (get_global $mem)
|
||||
(i32.mul_u (i32.load (i32.add $mv 4)) 4)))
|
||||
(i32.mul (i32.load (i32.add $mv 4)) 4)))
|
||||
(func $MEM_VAL1_ptr (param $mv i32) (result i32)
|
||||
(i32.add (get_global $mem)
|
||||
(i32.mul_u (i32.load (i32.add $mv 8)) 4)))
|
||||
(i32.mul (i32.load (i32.add $mv 8)) 4)))
|
||||
(func $MEM_VAL2_ptr (param $mv i32) (result i32)
|
||||
(i32.add (get_global $mem)
|
||||
(i32.mul_u (i32.load (i32.add $mv 12)) 4)))
|
||||
(i32.mul (i32.load (i32.add $mv 12)) 4)))
|
||||
|
||||
;; Returns the memory index mem of mv
|
||||
;; Will usually be used with a load or store by the caller
|
||||
(func $IDX (param $mv i32) (result i32)
|
||||
;; MalVal memory 64 bit (2 * i32) aligned
|
||||
(i32.div_u (i32.sub_u $mv (get_global $mem)) 4))
|
||||
(i32.div_u (i32.sub $mv (get_global $mem)) 4))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
@ -50,7 +50,7 @@
|
||||
(func $MalVal_ptr (param $mv_idx i32) (result i32)
|
||||
;; MalVal memory 64 bit (2 * i32) aligned
|
||||
;;; mem[mv_idx].refcnt_type
|
||||
(i32.add (get_global $mem) (i32.mul_u $mv_idx 4)))
|
||||
(i32.add (get_global $mem) (i32.mul $mv_idx 4)))
|
||||
|
||||
;; Returns the address of 'mem[mv_idx].refcnt_type'
|
||||
(func $MalVal_refcnt_type (param $mv_idx i32) (result i32)
|
||||
@ -77,7 +77,7 @@
|
||||
;; Will usually be used with a load or store by the caller
|
||||
(func $MalVal_val_ptr (param $mv_idx i32 $val i32) (result i32)
|
||||
(i32.add (i32.add ($MalVal_ptr $mv_idx) 4)
|
||||
(i32.mul_u $val 4)))
|
||||
(i32.mul $val 4)))
|
||||
|
||||
;; Returns the value of 'mem[mv_idx].val[val]'
|
||||
(func $MalVal_val (param $mv_idx i32 $val i32) (result i32)
|
||||
@ -294,7 +294,7 @@
|
||||
|
||||
;; decrease reference count by one
|
||||
(i32.store ($MalVal_ptr $idx)
|
||||
(i32.sub_u ($MalVal_refcnt_type $idx) 32))
|
||||
(i32.sub ($MalVal_refcnt_type $idx) 32))
|
||||
|
||||
;; nil, false, true, empty sequences
|
||||
(if (i32.le_u $mv (get_global $EMPTY_HASHMAP))
|
||||
@ -362,7 +362,7 @@
|
||||
|
||||
;; set type(FREE/15) and size
|
||||
;;; mv->refcnt_type = size*32 + FREE_T
|
||||
(i32.store $mv (i32.add (i32.mul_u $size 32) (get_global $FREE_T)))
|
||||
(i32.store $mv (i32.add (i32.mul $size 32) (get_global $FREE_T)))
|
||||
(i32.store ($MalVal_val_ptr $idx 0) (get_global $mem_free_list))
|
||||
(set_global $mem_free_list $idx)
|
||||
(if (i32.ge_u $size 3) (i32.store ($MalVal_val_ptr $idx 1) 0))
|
||||
@ -398,14 +398,14 @@
|
||||
(if $ms
|
||||
(then
|
||||
;;; ms->refcnt += 1
|
||||
(i32.store16_u $ms (i32.add (i32.load16_u $ms) 1))
|
||||
(i32.store16 $ms (i32.add (i32.load16_u $ms) 1))
|
||||
(return $ms)))))
|
||||
|
||||
;; no existing matching string so create a new one
|
||||
(set_local $ms (get_global $string_mem_next))
|
||||
(i32.store16_u $ms 1)
|
||||
(i32.store16 $ms 1)
|
||||
;;; ms->size = sizeof(MalString)+size+1
|
||||
(i32.store16_u offset=2 $ms (i32.add (i32.add 4 $size) 1))
|
||||
(i32.store16 offset=2 $ms (i32.add (i32.add 4 $size) 1))
|
||||
($memmove (i32.add $ms 4) $str (i32.add $size 1))
|
||||
;;; string_mem_next = (void *)ms + ms->size
|
||||
(set_global $string_mem_next
|
||||
@ -422,7 +422,7 @@
|
||||
(if (i32.le_s (i32.load16_u $ms) 0)
|
||||
(then
|
||||
($printf_2 "Release of already free string: %d (0x%x)\n"
|
||||
(i32.sub_s $ms (get_global $string_mem)) $ms)
|
||||
(i32.sub $ms (get_global $string_mem)) $ms)
|
||||
($fatal 1 "")))
|
||||
|
||||
;;; size = ms->size
|
||||
@ -431,7 +431,7 @@
|
||||
(set_local $next (i32.add $ms $size))
|
||||
|
||||
;;; ms->refcnt -= 1
|
||||
(i32.store16_u $ms (i32.sub_u (i32.load16_u $ms) 1))
|
||||
(i32.store16 $ms (i32.sub (i32.load16_u $ms) 1))
|
||||
|
||||
(if (i32.eqz (i32.load16_u $ms))
|
||||
(then
|
||||
@ -440,12 +440,12 @@
|
||||
;; If no more references to this string then free it up by
|
||||
;; shifting up every string afterwards to fill the gap
|
||||
;; (splice).
|
||||
($memmove $ms $next (i32.sub_s (get_global $string_mem_next)
|
||||
($memmove $ms $next (i32.sub (get_global $string_mem_next)
|
||||
$next))
|
||||
|
||||
;; Scan the mem values for string types after the freed
|
||||
;; string and shift their indexes by size
|
||||
(set_local $ms_idx (i32.sub_s $ms (get_global $string_mem)))
|
||||
(set_local $ms_idx (i32.sub $ms (get_global $string_mem)))
|
||||
(set_local $idx ($IDX (get_global $EMPTY_HASHMAP)))
|
||||
(loop $loop
|
||||
(set_local $mv ($MalVal_ptr $idx))
|
||||
@ -453,13 +453,13 @@
|
||||
(if (AND (i32.gt_s ($VAL0 $mv) $ms_idx)
|
||||
(OR (i32.eq $type (get_global $STRING_T))
|
||||
(i32.eq $type (get_global $SYMBOL_T))))
|
||||
(i32.store ($VAL0_ptr $mv) (i32.sub_s ($VAL0 $mv) $size)))
|
||||
(i32.store ($VAL0_ptr $mv) (i32.sub ($VAL0 $mv) $size)))
|
||||
(set_local $idx (i32.add $idx ($MalVal_size $mv)))
|
||||
|
||||
(br_if $loop (i32.lt_s $idx (get_global $mem_unused_start)))
|
||||
)))
|
||||
|
||||
(set_global $string_mem_next
|
||||
(i32.sub_s (get_global $string_mem_next) $size))))
|
||||
(i32.sub (get_global $string_mem_next) $size))))
|
||||
)
|
||||
)
|
||||
|
@ -46,7 +46,7 @@
|
||||
(set_local $len ($strlen $line))
|
||||
($memmove $buf $line $len)
|
||||
($lib_free $line)))
|
||||
(i32.store8_u (i32.add $buf $len) (CHR "\x00"))
|
||||
(i32.store8 (i32.add $buf $len) (CHR "\x00"))
|
||||
(return (if i32 $line 1 0))
|
||||
)
|
||||
|
||||
@ -75,7 +75,7 @@
|
||||
($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)
|
||||
)
|
||||
|
||||
@ -91,9 +91,9 @@
|
||||
(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
|
||||
)
|
||||
|
@ -37,7 +37,7 @@
|
||||
(func $read_file (param $path i32 $buf i32) (result i32)
|
||||
(LET $size ($lib_read_file $path $buf))
|
||||
;; Add null to string
|
||||
(i32.store8_u (i32.add $buf $size) 0)
|
||||
(i32.store8 (i32.add $buf $size) 0)
|
||||
(i32.add $size 1)
|
||||
)
|
||||
|
||||
|
@ -164,7 +164,7 @@
|
||||
(else
|
||||
(set_local $res_str ($pr_str_val $res_str $mv $print_readably))))
|
||||
|
||||
(set_local $res ($STRING_FINALIZE $res (i32.sub_s $res_str ($to_String $res))))
|
||||
(set_local $res ($STRING_FINALIZE $res (i32.sub $res_str ($to_String $res))))
|
||||
|
||||
$res
|
||||
)
|
||||
|
@ -51,7 +51,7 @@
|
||||
(func $_sprintdigit (param $str i32) (param $num i32) (param $base i32)
|
||||
(LET $n (i32.rem_u $num $base)
|
||||
$ch (if (result i32) (i32.lt_u $n 10) 48 55))
|
||||
(i32.store8_u $str (i32.add $n $ch))
|
||||
(i32.store8 $str (i32.add $n $ch))
|
||||
)
|
||||
|
||||
;; TODO: add max buf length (i.e. snprintnum)
|
||||
@ -63,24 +63,24 @@
|
||||
(if (AND (i32.lt_s $val 0) (i32.eq $radix 10))
|
||||
(then
|
||||
(set_local $neg 1)
|
||||
(set_local $val (i32.sub_s 0 $val))))
|
||||
(set_local $val (i32.sub 0 $val))))
|
||||
|
||||
;; Calculate smallest to most significant digit
|
||||
(loop $loop
|
||||
(set_local $digit (i32.rem_u $val $radix))
|
||||
(i32.store8_u $pbuf (if i32 (i32.lt_u $digit 10)
|
||||
(i32.store8 $pbuf (if i32 (i32.lt_u $digit 10)
|
||||
(i32.add (CHR "0") $digit)
|
||||
(i32.sub_u (i32.add (CHR "A") $digit) 10)))
|
||||
(i32.sub (i32.add (CHR "A") $digit) 10)))
|
||||
(set_local $pbuf (i32.add $pbuf 1))
|
||||
(set_local $val (i32.div_u $val $radix))
|
||||
(br_if $loop (i32.gt_u $val 0))
|
||||
)
|
||||
|
||||
(set_local $i (i32.sub_u $pbuf $buf))
|
||||
(set_local $i (i32.sub $pbuf $buf))
|
||||
(block $done
|
||||
(loop $loop
|
||||
(br_if $done (i32.ge_u $i $pad_cnt))
|
||||
(i32.store8_u $pbuf $pad_char)
|
||||
(i32.store8 $pbuf $pad_char)
|
||||
(set_local $pbuf (i32.add $pbuf 1))
|
||||
(set_local $i (i32.add $i 1))
|
||||
(br $loop)
|
||||
@ -89,22 +89,22 @@
|
||||
|
||||
(if $neg
|
||||
(then
|
||||
(i32.store8_u $pbuf (CHR "-"))
|
||||
(i32.store8 $pbuf (CHR "-"))
|
||||
(set_local $pbuf (i32.add $pbuf 1))))
|
||||
|
||||
(i32.store8_u $pbuf (CHR "\x00"))
|
||||
(i32.store8 $pbuf (CHR "\x00"))
|
||||
|
||||
;; now reverse it
|
||||
(set_local $len (i32.sub_u $pbuf $buf))
|
||||
(set_local $len (i32.sub $pbuf $buf))
|
||||
(set_local $i 0)
|
||||
(block $done
|
||||
(loop $loop
|
||||
(br_if $done (i32.ge_u $i (i32.div_u $len 2)))
|
||||
|
||||
(set_local $j (i32.load8_u (i32.add $buf $i)))
|
||||
(set_local $k (i32.add $buf (i32.sub_u (i32.sub_u $len $i) 1)))
|
||||
(i32.store8_u (i32.add $buf $i) (i32.load8_u $k))
|
||||
(i32.store8_u $k $j)
|
||||
(set_local $k (i32.add $buf (i32.sub (i32.sub $len $i) 1)))
|
||||
(i32.store8 (i32.add $buf $i) (i32.load8_u $k))
|
||||
(i32.store8 $k $j)
|
||||
(set_local $i (i32.add $i 1))
|
||||
(br $loop)
|
||||
)
|
||||
@ -149,7 +149,7 @@
|
||||
(if (i32.ne $ch (CHR "%"))
|
||||
(then
|
||||
;; TODO: check buffer length
|
||||
(i32.store8_u $pstr $ch)
|
||||
(i32.store8 $pstr $ch)
|
||||
(set_local $pstr (i32.add 1 $pstr))
|
||||
(br $loop)))
|
||||
|
||||
@ -172,9 +172,9 @@
|
||||
(set_local $fmt (i32.add 1 $fmt))
|
||||
(br_if $done (i32.eqz $ch))))
|
||||
(loop $loop
|
||||
(set_local $pad_cnt (i32.mul_s $pad_cnt 10))
|
||||
(set_local $pad_cnt (i32.mul $pad_cnt 10))
|
||||
(set_local $pad_cnt (i32.add $pad_cnt
|
||||
(i32.sub_s $ch (CHR "0"))))
|
||||
(i32.sub $ch (CHR "0"))))
|
||||
(set_local $ch (i32.load8_u $fmt))
|
||||
(set_local $fmt (i32.add 1 $fmt))
|
||||
(br_if $loop (AND (i32.ge_s $ch (CHR "0"))
|
||||
@ -193,9 +193,9 @@
|
||||
(block $done
|
||||
(loop $loop
|
||||
(br_if $done (i32.le_s $pad_cnt $len))
|
||||
(i32.store8_u $pstr (CHR " "))
|
||||
(i32.store8 $pstr (CHR " "))
|
||||
(set_local $pstr (i32.add $pstr 1))
|
||||
(set_local $pad_cnt (i32.sub_s $pad_cnt 1))
|
||||
(set_local $pad_cnt (i32.sub $pad_cnt 1))
|
||||
(br $loop)
|
||||
)
|
||||
)
|
||||
@ -203,11 +203,11 @@
|
||||
(set_local $pstr (i32.add $pstr $len)))
|
||||
(else (if (i32.eq (CHR "c") $ch)
|
||||
(then
|
||||
(i32.store8_u $pstr $v)
|
||||
(i32.store8 $pstr $v)
|
||||
(set_local $pstr (i32.add $pstr 1)))
|
||||
(else (if (i32.eq (CHR "%") $ch)
|
||||
(then
|
||||
(i32.store8_u $pstr (CHR "%"))
|
||||
(i32.store8 $pstr (CHR "%"))
|
||||
(set_local $pstr (i32.add $pstr 1))
|
||||
(br $loop)) ;; don't increase vidx
|
||||
(else
|
||||
@ -219,7 +219,7 @@
|
||||
)
|
||||
)
|
||||
|
||||
(i32.store8_u $pstr (CHR "\x00"))
|
||||
(i32.store8 $pstr (CHR "\x00"))
|
||||
$pstr
|
||||
)
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
(func $skip_to_eol (param $str i32) (result i32)
|
||||
(LET $found 0
|
||||
$c (i32.load8_c (i32.add $str (get_global $read_index))))
|
||||
$c (i32.load8_u (i32.add $str (get_global $read_index))))
|
||||
(if (i32.eq $c (CHR ";"))
|
||||
(then
|
||||
(set_local $found 1)
|
||||
@ -68,7 +68,7 @@
|
||||
(set_global $read_index (i32.add (get_global $read_index) 1))
|
||||
;; read first character
|
||||
;;; token[token_index++] = c
|
||||
(i32.store8_u (i32.add (get_global $token_buf) $token_index) $c)
|
||||
(i32.store8 (i32.add (get_global $token_buf) $token_index) $c)
|
||||
(set_local $token_index (i32.add $token_index 1))
|
||||
;; single/double character token
|
||||
(if (OR (i32.eq $c (CHR "("))
|
||||
@ -113,7 +113,7 @@
|
||||
(i32.eq $c (CHR "\n"))))))
|
||||
;; read next character
|
||||
;;; token[token_index++] = str[(*index)++]
|
||||
(i32.store8_u (i32.add (get_global $token_buf) $token_index)
|
||||
(i32.store8 (i32.add (get_global $token_buf) $token_index)
|
||||
(i32.load8_u
|
||||
(i32.add $str (get_global $read_index))))
|
||||
(set_local $token_index (i32.add $token_index 1))
|
||||
@ -139,7 +139,7 @@
|
||||
)))
|
||||
|
||||
;;; token[token_index] = '\0'
|
||||
(i32.store8_u (i32.add (get_global $token_buf) $token_index) 0)
|
||||
(i32.store8 (i32.add (get_global $token_buf) $token_index) 0)
|
||||
(get_global $token_buf)
|
||||
)
|
||||
|
||||
@ -246,7 +246,7 @@
|
||||
(return ($INTEGER ($atoi $tok))))
|
||||
(else (if (i32.eq $c0 (CHR ":"))
|
||||
(then
|
||||
(i32.store8_u $tok (CHR "\x7f"))
|
||||
(i32.store8 $tok (CHR "\x7f"))
|
||||
(return ($STRING (get_global $STRING_T) $tok)))
|
||||
(else (if (i32.eq $c0 (CHR "\""))
|
||||
(then
|
||||
@ -258,7 +258,7 @@
|
||||
(else
|
||||
;; unescape backslashes, quotes, and newlines
|
||||
;; remove the trailing quote
|
||||
(i32.store8_u (i32.add $tok $slen) (CHR "\x00"))
|
||||
(i32.store8 (i32.add $tok $slen) (CHR "\x00"))
|
||||
(set_local $tok (i32.add $tok 1))
|
||||
(drop ($REPLACE3 0 $tok
|
||||
"\\\"" "\""
|
||||
|
@ -48,7 +48,7 @@
|
||||
|
||||
;; ($PR_MEMORY_RAW
|
||||
;; (get_global $mem) (i32.add (get_global $mem)
|
||||
;; (i32.mul_u (get_global $mem_unused_start) 4)))
|
||||
;; (i32.mul (get_global $mem_unused_start) 4)))
|
||||
|
||||
(drop ($STRING (get_global $STRING_T) "uvw"))
|
||||
(drop ($STRING (get_global $STRING_T) "xyz"))
|
||||
|
@ -174,11 +174,11 @@
|
||||
($VAL0 ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args))))))
|
||||
(func $subtract (param $args i32) (result i32)
|
||||
($INTEGER
|
||||
(i32.sub_s ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
(i32.sub ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
($VAL0 ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args))))))
|
||||
(func $multiply (param $args i32) (result i32)
|
||||
($INTEGER
|
||||
(i32.mul_s ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
(i32.mul ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
($VAL0 ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args))))))
|
||||
(func $divide (param $args i32) (result i32)
|
||||
($INTEGER
|
||||
|
@ -219,11 +219,11 @@
|
||||
($VAL0 ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args))))))
|
||||
(func $subtract (param $args i32) (result i32)
|
||||
($INTEGER
|
||||
(i32.sub_s ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
(i32.sub ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
($VAL0 ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args))))))
|
||||
(func $multiply (param $args i32) (result i32)
|
||||
($INTEGER
|
||||
(i32.mul_s ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
(i32.mul ($VAL0 ($MEM_VAL1_ptr $args))
|
||||
($VAL0 ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args))))))
|
||||
(func $divide (param $args i32) (result i32)
|
||||
($INTEGER
|
||||
|
@ -363,7 +363,7 @@
|
||||
(br_if $done (i32.ge_u $i $argc))
|
||||
|
||||
(set_local $val2 ($STRING (get_global $STRING_T)
|
||||
(i32.load (i32.add $argv (i32.mul_u $i 4)))))
|
||||
(i32.load (i32.add $argv (i32.mul $i 4)))))
|
||||
|
||||
;; MAP_LOOP_UPDATE
|
||||
(set_local $res ($MAP_LOOP_UPDATE
|
||||
|
@ -425,7 +425,7 @@
|
||||
(br_if $done (i32.ge_u $i $argc))
|
||||
|
||||
(set_local $val2 ($STRING (get_global $STRING_T)
|
||||
(i32.load (i32.add $argv (i32.mul_u $i 4)))))
|
||||
(i32.load (i32.add $argv (i32.mul $i 4)))))
|
||||
|
||||
;; MAP_LOOP_UPDATE
|
||||
(set_local $res ($MAP_LOOP_UPDATE
|
||||
|
@ -87,11 +87,11 @@
|
||||
(then
|
||||
(set_global $mac_stack_top
|
||||
(i32.add (get_global $mac_stack_top) 1))
|
||||
(if (i32.ge_s (i32.mul_s (get_global $mac_stack_top) 4) 1024) ;; 256 * 4
|
||||
(if (i32.ge_s (i32.mul (get_global $mac_stack_top) 4) 1024) ;; 256 * 4
|
||||
($fatal 7 "Exhausted mac_stack!\n"))
|
||||
(i32.store (i32.add
|
||||
(get_global $mac_stack)
|
||||
(i32.mul_s (get_global $mac_stack_top) 4))
|
||||
(i32.mul (get_global $mac_stack_top) 4))
|
||||
$ast)))
|
||||
(br_if $done (get_global $error_type))
|
||||
|
||||
@ -421,9 +421,9 @@
|
||||
(br_if $done (i32.le_s (get_global $mac_stack_top) $orig_mac_stack_top))
|
||||
($RELEASE (i32.load (i32.add
|
||||
(get_global $mac_stack)
|
||||
(i32.mul_s (get_global $mac_stack_top) 4))))
|
||||
(i32.mul (get_global $mac_stack_top) 4))))
|
||||
(set_global $mac_stack_top
|
||||
(i32.sub_s (get_global $mac_stack_top) 1))
|
||||
(i32.sub (get_global $mac_stack_top) 1))
|
||||
(br $loop)
|
||||
)
|
||||
)
|
||||
@ -510,7 +510,7 @@
|
||||
(br_if $done (i32.ge_u $i $argc))
|
||||
|
||||
(set_local $val2 ($STRING (get_global $STRING_T)
|
||||
(i32.load (i32.add $argv (i32.mul_u $i 4)))))
|
||||
(i32.load (i32.add $argv (i32.mul $i 4)))))
|
||||
|
||||
;; MAP_LOOP_UPDATE
|
||||
(set_local $res ($MAP_LOOP_UPDATE
|
||||
|
@ -87,11 +87,11 @@
|
||||
(then
|
||||
(set_global $mac_stack_top
|
||||
(i32.add (get_global $mac_stack_top) 1))
|
||||
(if (i32.ge_s (i32.mul_s (get_global $mac_stack_top) 4) 1024) ;; 256 * 4
|
||||
(if (i32.ge_s (i32.mul (get_global $mac_stack_top) 4) 1024) ;; 256 * 4
|
||||
($fatal 7 "Exhausted mac_stack!\n"))
|
||||
(i32.store (i32.add
|
||||
(get_global $mac_stack)
|
||||
(i32.mul_s (get_global $mac_stack_top) 4))
|
||||
(i32.mul (get_global $mac_stack_top) 4))
|
||||
$ast)))
|
||||
(br_if $done (get_global $error_type))
|
||||
|
||||
@ -468,9 +468,9 @@
|
||||
(br_if $done (i32.le_s (get_global $mac_stack_top) $orig_mac_stack_top))
|
||||
($RELEASE (i32.load (i32.add
|
||||
(get_global $mac_stack)
|
||||
(i32.mul_s (get_global $mac_stack_top) 4))))
|
||||
(i32.mul (get_global $mac_stack_top) 4))))
|
||||
(set_global $mac_stack_top
|
||||
(i32.sub_s (get_global $mac_stack_top) 1))
|
||||
(i32.sub (get_global $mac_stack_top) 1))
|
||||
(br $loop)
|
||||
)
|
||||
)
|
||||
@ -557,7 +557,7 @@
|
||||
(br_if $done (i32.ge_u $i $argc))
|
||||
|
||||
(set_local $val2 ($STRING (get_global $STRING_T)
|
||||
(i32.load (i32.add $argv (i32.mul_u $i 4)))))
|
||||
(i32.load (i32.add $argv (i32.mul $i 4)))))
|
||||
|
||||
;; MAP_LOOP_UPDATE
|
||||
(set_local $res ($MAP_LOOP_UPDATE
|
||||
|
@ -87,11 +87,11 @@
|
||||
(then
|
||||
(set_global $mac_stack_top
|
||||
(i32.add (get_global $mac_stack_top) 1))
|
||||
(if (i32.ge_s (i32.mul_s (get_global $mac_stack_top) 4) 1024) ;; 256 * 4
|
||||
(if (i32.ge_s (i32.mul (get_global $mac_stack_top) 4) 1024) ;; 256 * 4
|
||||
($fatal 7 "Exhausted mac_stack!\n"))
|
||||
(i32.store (i32.add
|
||||
(get_global $mac_stack)
|
||||
(i32.mul_s (get_global $mac_stack_top) 4))
|
||||
(i32.mul (get_global $mac_stack_top) 4))
|
||||
$ast)))
|
||||
(br_if $done (get_global $error_type))
|
||||
|
||||
@ -468,9 +468,9 @@
|
||||
(br_if $done (i32.le_s (get_global $mac_stack_top) $orig_mac_stack_top))
|
||||
($RELEASE (i32.load (i32.add
|
||||
(get_global $mac_stack)
|
||||
(i32.mul_s (get_global $mac_stack_top) 4))))
|
||||
(i32.mul (get_global $mac_stack_top) 4))))
|
||||
(set_global $mac_stack_top
|
||||
(i32.sub_s (get_global $mac_stack_top) 1))
|
||||
(i32.sub (get_global $mac_stack_top) 1))
|
||||
(br $loop)
|
||||
)
|
||||
)
|
||||
@ -559,7 +559,7 @@
|
||||
(br_if $done (i32.ge_u $i $argc))
|
||||
|
||||
(set_local $val2 ($STRING (get_global $STRING_T)
|
||||
(i32.load (i32.add $argv (i32.mul_u $i 4)))))
|
||||
(i32.load (i32.add $argv (i32.mul $i 4)))))
|
||||
|
||||
;; MAP_LOOP_UPDATE
|
||||
(set_local $res ($MAP_LOOP_UPDATE
|
||||
|
@ -7,7 +7,7 @@
|
||||
(func $memmove (param $dst i32 $src i32 $len i32)
|
||||
(LET $idx 0)
|
||||
(loop $copy
|
||||
(i32.store8_u (i32.add $idx $dst)
|
||||
(i32.store8 (i32.add $idx $dst)
|
||||
(i32.load8_u (i32.add $idx $src)))
|
||||
(set_local $idx (i32.add 1 $idx))
|
||||
(br_if $copy (i32.lt_u $idx $len))
|
||||
@ -22,7 +22,7 @@
|
||||
(set_local $cur (i32.add $cur 1))
|
||||
(br $count)))
|
||||
)
|
||||
(i32.sub_u $cur $str)
|
||||
(i32.sub $cur $str)
|
||||
)
|
||||
|
||||
;; Based on https://stackoverflow.com/a/25705264/471795
|
||||
@ -37,7 +37,7 @@
|
||||
(set_local $i 0)
|
||||
(block $done
|
||||
(loop $loop
|
||||
(if (i32.gt_s $i (i32.sub_s $len $needle_len)) (br $done))
|
||||
(if (i32.gt_s $i (i32.sub $len $needle_len)) (br $done))
|
||||
|
||||
(if (AND (i32.eq (i32.load8_u $haystack 0)
|
||||
(i32.load8_u $needle 0))
|
||||
@ -68,13 +68,13 @@
|
||||
(then
|
||||
(set_local $neg 1))
|
||||
(else
|
||||
(set_local $acc (i32.add (i32.mul_u $acc 10)
|
||||
(i32.sub_u $ch (CHR "0"))))))
|
||||
(set_local $acc (i32.add (i32.mul $acc 10)
|
||||
(i32.sub $ch (CHR "0"))))))
|
||||
(br $loop)
|
||||
)
|
||||
)
|
||||
(if i32 $neg
|
||||
(then (i32.sub_s 0 $acc))
|
||||
(then (i32.sub 0 $acc))
|
||||
(else $acc))
|
||||
)
|
||||
|
||||
@ -163,7 +163,7 @@
|
||||
|
||||
(block $done1
|
||||
(loop $loop1
|
||||
(if (i32.ge_s (i32.sub_s $src_str $haystack) $haystack_len)
|
||||
(if (i32.ge_s (i32.sub $src_str $haystack) $haystack_len)
|
||||
(br $done1))
|
||||
|
||||
;; Find the earliest match
|
||||
@ -192,8 +192,8 @@
|
||||
)
|
||||
(if (i32.eqz $found) (br $done1))
|
||||
;; copy before the match
|
||||
($memmove $dst_str $src_str (i32.add (i32.sub_s $found $src_str) 1))
|
||||
(set_local $dst_str (i32.add $dst_str (i32.sub_s $found $src_str)))
|
||||
($memmove $dst_str $src_str (i32.add (i32.sub $found $src_str) 1))
|
||||
(set_local $dst_str (i32.add $dst_str (i32.sub $found $src_str)))
|
||||
;; add the replace string
|
||||
($memmove $dst_str $replace_s (i32.add $replace_len_s 1))
|
||||
(set_local $dst_str (i32.add $dst_str $replace_len_s))
|
||||
@ -206,9 +206,9 @@
|
||||
;; Copy the left-over
|
||||
($memmove $dst_str $src_str ($strlen $src_str))
|
||||
(set_local $dst_str (i32.add $dst_str ($strlen $src_str)))
|
||||
(i32.store8_u $dst_str (CHR "\x00"))
|
||||
(i32.store8 $dst_str (CHR "\x00"))
|
||||
|
||||
(i32.sub_s $dst_str $grass)
|
||||
(i32.sub $dst_str $grass)
|
||||
)
|
||||
|
||||
)
|
||||
|
@ -138,7 +138,7 @@
|
||||
;; return the MalVal pointer
|
||||
(func $STRING (param $type i32 $str i32) (result i32)
|
||||
(LET $ms ($ALLOC_STRING $str ($strlen $str) 1))
|
||||
($ALLOC_SCALAR $type (i32.sub_u $ms (get_global $string_mem)))
|
||||
($ALLOC_SCALAR $type (i32.sub $ms (get_global $string_mem)))
|
||||
)
|
||||
|
||||
;; Find first duplicate (internet) of mv. If one is found, free up
|
||||
@ -153,16 +153,16 @@
|
||||
(then
|
||||
(set_local $tmp $mv)
|
||||
(set_local $res ($ALLOC_SCALAR (get_global $STRING_T)
|
||||
(i32.sub_s $existing_ms
|
||||
(i32.sub $existing_ms
|
||||
(get_global $string_mem))))
|
||||
(i32.store16_u $existing_ms (i32.add (i32.load16_u $existing_ms) 1))
|
||||
(i32.store16 $existing_ms (i32.add (i32.load16_u $existing_ms) 1))
|
||||
($RELEASE $tmp)))
|
||||
$res
|
||||
)
|
||||
|
||||
(func $STRING_INIT (param $type i32) (result i32)
|
||||
(LET $ms ($ALLOC_STRING "" 0 0))
|
||||
($ALLOC_SCALAR $type (i32.sub_s $ms (get_global $string_mem)))
|
||||
($ALLOC_SCALAR $type (i32.sub $ms (get_global $string_mem)))
|
||||
)
|
||||
|
||||
(func $STRING_FINALIZE (param $mv i32 $size i32) (result i32)
|
||||
@ -174,7 +174,7 @@
|
||||
(set_local $mv $tmp))
|
||||
(else
|
||||
;;; ms->size = sizeof(MalString) + size + 1
|
||||
(i32.store16_u (i32.add $ms 2)
|
||||
(i32.store16 (i32.add $ms 2)
|
||||
(i32.add (i32.add 4 $size) 1))
|
||||
;;; string_mem_next = (void *)ms + ms->size
|
||||
(set_global $string_mem_next
|
||||
@ -346,7 +346,7 @@
|
||||
|
||||
;; combine last/res as hi 32/low 32 of i64
|
||||
(i64.or
|
||||
(i64.shl_u (i64.extend_u/i32 $last) (i64.const 32))
|
||||
(i64.shl (i64.extend_u/i32 $last) (i64.const 32))
|
||||
(i64.extend_u/i32 $res))
|
||||
)
|
||||
|
||||
@ -398,7 +398,7 @@
|
||||
)
|
||||
|
||||
;; combine found/res as hi 32/low 32 of i64
|
||||
(i64.or (i64.shl_u (i64.extend_u/i32 $found) (i64.const 32))
|
||||
(i64.or (i64.shl (i64.extend_u/i32 $found) (i64.const 32))
|
||||
(i64.extend_u/i32 $res))
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user