wasm: fix to work with wabt's wat2wasm.
authorJoel Martin <github@martintribe.org>
Sat, 8 Dec 2018 22:51:16 +0000 (16:51 -0600)
committerJoel Martin <github@martintribe.org>
Sat, 8 Dec 2018 23:02:13 +0000 (17:02 -0600)
15 files changed:
wasm/core.wam
wasm/env.wam
wasm/mem.wam
wasm/platform_libc.wam
wasm/printer.wam
wasm/printf.wam
wasm/reader.wam
wasm/step5_tco.wam
wasm/step6_file.wam
wasm/step7_quote.wam
wasm/step8_macros.wam
wasm/step9_try.wam
wasm/stepA_mal.wam
wasm/string.wam
wasm/types.wam

index ef2da7f..59e9067 100644 (file)
@@ -79,7 +79,7 @@
 
   (func $keyword (param $args i32) (result i32)
     (LET $str ($to_String ($MEM_VAL1_ptr $args)))
-    (if i32 (i32.eq (i32.load8_u $str) (CHR "\x7f"))
+    (if (result i32) (i32.eq (i32.load8_u $str) (CHR "\x7f"))
       (then ($INC_REF ($MEM_VAL1_ptr $args)))
       (else
         (drop ($sprintf_1 (get_global $printf_buf) "\x7f%s" $str))
   (func $get (param $args i32) (result i32)
     (LET $hm  ($MEM_VAL1_ptr $args)
          $key ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args)))
-    (if i32 (i32.eq $hm (get_global $NIL))
+    (if (result i32) (i32.eq $hm (get_global $NIL))
       (then ($INC_REF (get_global $NIL)))
       (else ($INC_REF (i32.wrap/i64 ($HASHMAP_GET $hm $key)))))
   )
     (LET $hm  ($MEM_VAL1_ptr $args)
          $key ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args)))
     ($TRUE_FALSE
-      (if i32 (i32.eq $hm (get_global $NIL))
+      (if (result i32) (i32.eq $hm (get_global $NIL))
         (then 0)
         (else (i32.wrap/i64
                 (i64.shr_u ($HASHMAP_GET $hm $key) (i64.const 32))))))
   )
 
   (func $meta (param $args i32) (result i32)
-    (if i32 (i32.eq ($TYPE ($MEM_VAL1_ptr $args)) (get_global $METADATA_T))
+    (if (result i32) (i32.eq ($TYPE ($MEM_VAL1_ptr $args)) (get_global $METADATA_T))
       (then ($INC_REF ($MEM_VAL1_ptr ($MEM_VAL1_ptr $args))))
       (else ($INC_REF (get_global $NIL)))))
 
   )
 
   (func $reset_BANG (param $args i32) (result i32)
-    (local $atom i32 $val i32)
     (LET $atom ($MEM_VAL1_ptr $args)
          $val  ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args)))
     ($_reset_BANG $atom $val)
index 37ff695..3132b4a 100644 (file)
@@ -1,8 +1,6 @@
 (module $env
 
   (func $ENV_NEW (param $outer i32) (result i32)
-    (local $data i32 $env i32)
-
     (LET $data ($HASHMAP) ;; allocate the data hashmap
          $env  ($ALLOC (get_global $ENVIRONMENT_T) $data $outer 0))
     ;; environment takes ownership
index 9524f93..7a6e634 100644 (file)
 
   (func $MalType_size (param $type i32) (result i32)
     ;;; if (type <= 5 || type == 9 || type == 12)
-    (if i32 (OR (i32.le_u $type 5)
+    (if (result i32) (OR (i32.le_u $type 5)
                 (i32.eq $type 9)
                 (i32.eq $type 12))
       (then 2)
       (else
         ;;; else if (type == 8 || type == 10 || type == 11)
-        (if i32 (OR (i32.eq $type 8)
+        (if (result i32) (OR (i32.eq $type 8)
                     (i32.eq $type 10)
                     (i32.eq $type 11))
           (then 4)
   (func $MalVal_size (param $mv i32) (result i32)
     (LET $type ($TYPE $mv))
     ;; if (type == FREE_T)
-    (if i32 (i32.eq $type (get_global $FREE_T))
+    (if (result i32) (i32.eq $type (get_global $FREE_T))
       (then
         ;;; return (mv->refcnt_type & 0xffe0)>>5
         (i32.shr_u (i32.and (i32.load $mv) 0xffe0) 5)) ;;; / 32
index 0327f52..1c769af 100644 (file)
@@ -47,7 +47,7 @@
         ($memmove $buf $line $len)
         ($lib_free $line)))
     (i32.store8 (i32.add $buf $len) (CHR "\x00"))
-    (return (if i32 $line 1 0))
+    (return (if (result i32) $line 1 0))
   )
 
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
index 7aea5b4..0bd0823 100644 (file)
       ;; 8: hashmap
       (set_local
         $res ($sprintf_1 $res "%c"
-                         (if i32 (i32.eq $type (get_global $LIST_T))
-                           (CHR "(")
-                           (else (if i32 (i32.eq $type (get_global $VECTOR_T))
-                                   (CHR "[")
+                         (if (result i32) (i32.eq $type (get_global $LIST_T))
+                           (then (CHR "("))
+                           (else (if (result i32) (i32.eq $type (get_global $VECTOR_T))
+                                   (then (CHR "["))
                                    (else (CHR "{")))))))
       ;; PR_SEQ_LOOP
       ;;; while (VAL0(mv) != 0)
 
       (set_local
         $res ($sprintf_1 $res "%c"
-                         (if i32 (i32.eq $type (get_global $LIST_T))
-                           (CHR ")")
-                           (else (if i32 (i32.eq $type (get_global $VECTOR_T))
-                                   (CHR "]")
+                         (if (result i32) (i32.eq $type (get_global $LIST_T))
+                           (then (CHR ")"))
+                           (else (if (result i32) (i32.eq $type (get_global $VECTOR_T))
+                                   (then (CHR "]"))
                                    (else (CHR "}")))))))
       (br $done))
       ;; 9: function
index d1bd8d8..b06a238 100644 (file)
@@ -68,7 +68,7 @@
     ;; Calculate smallest to most significant digit
     (loop $loop
       (set_local $digit (i32.rem_u $val $radix))
-      (i32.store8 $pbuf (if i32 (i32.lt_u $digit 10)
+      (i32.store8 $pbuf (if (result i32) (i32.lt_u $digit 10)
                             (i32.add (CHR "0") $digit)
                             (i32.sub (i32.add (CHR "A") $digit) 10)))
       (set_local $pbuf (i32.add $pbuf 1))
index 45715ca..e87c01e 100644 (file)
     (else
       (return ($STRING (get_global $SYMBOL_T) $tok))))
     ))))))))))))))))))))))))))))))))
+    0 ;; not reachable
   )
 
   (func $read_str (param $str i32) (result i32)
index 161a6c5..c7a0984 100644 (file)
@@ -40,7 +40,7 @@
           (br_if $done (i32.eq ($VAL0 $ast) 0))
 
           (if $skiplast
-            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)) 0)))
+            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)))))
 
           (if (i32.eq $type (get_global $HASHMAP_T))
             (then
index 902626c..4898f21 100644 (file)
@@ -40,7 +40,7 @@
           (br_if $done (i32.eq ($VAL0 $ast) 0))
 
           (if $skiplast
-            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)) 0)))
+            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)))))
 
           (if (i32.eq $type (get_global $HASHMAP_T))
             (then
index 5a699b0..bfbfed1 100644 (file)
@@ -90,7 +90,7 @@
           (br_if $done (i32.eq ($VAL0 $ast) 0))
 
           (if $skiplast
-            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)) 0)))
+            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)))))
 
           (if (i32.eq $type (get_global $HASHMAP_T))
             (then
index c45f2f3..445d0fe 100644 (file)
           (br_if $done (i32.eq ($VAL0 $ast) 0))
 
           (if $skiplast
-            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)) 0)))
+            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)))))
 
           (if (i32.eq $type (get_global $HASHMAP_T))
             (then
index d7636b6..61d9100 100644 (file)
           (br_if $done (i32.eq ($VAL0 $ast) 0))
 
           (if $skiplast
-            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)) 0)))
+            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)))))
 
           (if (i32.eq $type (get_global $HASHMAP_T))
             (then
index 6aa05c9..495e3e6 100644 (file)
           (br_if $done (i32.eq ($VAL0 $ast) 0))
 
           (if $skiplast
-            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)) 0)))
+            (br_if $done (i32.eqz ($VAL0 ($MEM_VAL0_ptr $ast)))))
 
           (if (i32.eq $type (get_global $HASHMAP_T))
             (then
index 28190a8..593ea1c 100644 (file)
@@ -39,8 +39,8 @@
       (loop $loop
         (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))
+        (if (AND (i32.eq (i32.load8_u $haystack)
+                         (i32.load8_u $needle))
                  (i32.eqz ($strncmp $haystack $needle $needle_len)))
           (return $haystack))
         (set_local $haystack (i32.add $haystack 1))
@@ -73,7 +73,7 @@
         (br $loop)
       )
     )
-    (if i32 $neg
+    (if (result i32) $neg
       (then (i32.sub 0 $acc))
       (else $acc))
   )
         (br $loop)
       )
     )
-    (if i32 (i32.eq (i32.load8_u $s1) (i32.load8_u $s2))
+    (if (result i32) (i32.eq (i32.load8_u $s1) (i32.load8_u $s2))
       (then 0)
       (else
-        (if i32 (i32.lt_u (i32.load8_u $s1) (i32.load8_u $s2))
+        (if (result i32) (i32.lt_u (i32.load8_u $s1) (i32.load8_u $s2))
           (then -1)
           (else 1))))
   )
             (i32.eq (i32.load8_u (i32.add $i $s1))
                     (i32.load8_u (i32.add $i $s2))))
       (return 0))
-    (if i32 (i32.lt_u (i32.load8_u (i32.add $i $s1))
+    (if (result i32) (i32.lt_u (i32.load8_u (i32.add $i $s1))
                       (i32.load8_u (i32.add $i $s2)))
       (then -1)
       (else 1))
         (block $done
           (loop $loop
             (if (i32.ge_u $s 3) (br $done))
-            (set_local $needle (if i32 (i32.eq $s 0)   $needle0
-                                 (if i32 (i32.eq $s 1) $needle1
+            (set_local $needle (if (result i32) (i32.eq $s 0)   $needle0
+                                 (if (result i32) (i32.eq $s 1) $needle1
                                                        $needle2)))
-            (set_local $replace (if i32 (i32.eq $s 0)   $replace0
-                                  (if i32 (i32.eq $s 1) $replace1
+            (set_local $replace (if (result i32) (i32.eq $s 0)   $replace0
+                                  (if (result i32) (i32.eq $s 1) $replace1
                                                         $replace2)))
             (set_local $needle_len ($strlen $needle))
             (set_local $replace_len ($strlen $replace))
         (block $done2
           (loop $loop2
             (if (i32.ge_u $s 3) (br $done2))
-            (set_local $needle (if i32 (i32.eq $s 0)   $needle0
-                                 (if i32 (i32.eq $s 1) $needle1
+            (set_local $needle (if (result i32) (i32.eq $s 0)   $needle0
+                                 (if (result i32) (i32.eq $s 1) $needle1
                                                        $needle2)))
-            (set_local $replace (if i32 (i32.eq $s 0)   $replace0
-                                  (if i32 (i32.eq $s 1) $replace1
+            (set_local $replace (if (result i32) (i32.eq $s 0)   $replace0
+                                  (if (result i32) (i32.eq $s 1) $replace1
                                                         $replace2)))
             (set_local $s (i32.add $s 1))
             (set_local $found_tmp ($strstr $src_str $needle))
index b432efd..a2d0cd3 100644 (file)
@@ -59,7 +59,7 @@
   )
 
   (func $TRUE_FALSE (param $val i32) (result i32)
-    ($INC_REF (if i32 $val (get_global $TRUE) (get_global $FALSE)))
+    ($INC_REF (if (result i32) $val (get_global $TRUE) (get_global $FALSE)))
   )
 
   (func $THROW_STR_0 (param $fmt i32)
     (else (if (AND (i32.eq $ta (get_global $HASHMAP_T))
                    (i32.eq $tb (get_global $HASHMAP_T)))
       ;; EQUAL_Q_HM
-      (return 1))
+      (then (return 1))
     ;; TODO: remove this once strings are interned
     (else (if (OR (AND (i32.eq $ta (get_global $STRING_T))
                        (i32.eq $tb (get_global $STRING_T)))
                   (AND (i32.eq $ta (get_global $SYMBOL_T))
                        (i32.eq $tb (get_global $SYMBOL_T))))
-      (return (i32.eqz ($strcmp ($to_String $a) ($to_String $b))))
+      (then (return (i32.eqz ($strcmp ($to_String $a) ($to_String $b)))))
     (else
       (return (AND (i32.eq $ta $tb)
-                   (i32.eq ($VAL0 $a) ($VAL0 $b)))))))))
+                   (i32.eq ($VAL0 $a) ($VAL0 $b))))))))))
+    0 ;; not reachable
   )
 
   (func $DEREF_META (param $mv i32) (result i32)
   ;; sequence functions
 
   (func $MAP_LOOP_START (param $type i32) (result i32)
-    (LET $res (if i32 (i32.eq $type (get_global $LIST_T))
-                (get_global $EMPTY_LIST)
-              (else (if i32 (i32.eq $type (get_global $VECTOR_T))
-                (get_global $EMPTY_VECTOR)
-              (else (if i32 (i32.eq $type (get_global $HASHMAP_T))
-                (get_global $EMPTY_HASHMAP)
+    (LET $res (if (result i32) (i32.eq $type (get_global $LIST_T))
+                (then (get_global $EMPTY_LIST))
+              (else (if (result i32) (i32.eq $type (get_global $VECTOR_T))
+                (then (get_global $EMPTY_VECTOR))
+              (else (if (result i32) (i32.eq $type (get_global $HASHMAP_T))
+                (then (get_global $EMPTY_HASHMAP))
               (else
                 ($THROW_STR_1 "read_seq invalid type %d" $type)
                 0)))))))