github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/integration_test/spectest/v1/testdata/stack.wast (about)

     1  (module
     2    (func (export "fac-expr") (param $n i64) (result i64)
     3      (local $i i64)
     4      (local $res i64)
     5      (local.set $i (local.get $n))
     6      (local.set $res (i64.const 1))
     7      (block $done
     8        (loop $loop
     9          (if
    10            (i64.eq (local.get $i) (i64.const 0))
    11            (then (br $done))
    12            (else
    13              (local.set $res (i64.mul (local.get $i) (local.get $res)))
    14              (local.set $i (i64.sub (local.get $i) (i64.const 1)))
    15            )
    16          )
    17          (br $loop)
    18        )
    19      )
    20      (local.get $res)
    21    )
    22  
    23    (func (export "fac-stack") (param $n i64) (result i64)
    24      (local $i i64)
    25      (local $res i64)
    26      (local.get $n)
    27      (local.set $i)
    28      (i64.const 1)
    29      (local.set $res)
    30      (block $done
    31        (loop $loop
    32          (local.get $i)
    33          (i64.const 0)
    34          (i64.eq)
    35          (if
    36            (then (br $done))
    37            (else
    38              (local.get $i)
    39              (local.get $res)
    40              (i64.mul)
    41              (local.set $res)
    42              (local.get $i)
    43              (i64.const 1)
    44              (i64.sub)
    45              (local.set $i)
    46            )
    47          )
    48          (br $loop)
    49        )
    50      )
    51      (local.get $res)
    52    )
    53  
    54    (func (export "fac-stack-raw") (param $n i64) (result i64)
    55      (local $i i64)
    56      (local $res i64)
    57      local.get $n
    58      local.set $i
    59      i64.const 1
    60      local.set $res
    61      block $done
    62        loop $loop
    63          local.get $i
    64          i64.const 0
    65          i64.eq
    66          if $body
    67            br $done
    68          else $body
    69            local.get $i
    70            local.get $res
    71            i64.mul
    72            local.set $res
    73            local.get $i
    74            i64.const 1
    75            i64.sub
    76            local.set $i
    77          end $body
    78          br $loop
    79        end $loop
    80      end $done
    81      local.get $res
    82    )
    83  
    84    (func (export "fac-mixed") (param $n i64) (result i64)
    85      (local $i i64)
    86      (local $res i64)
    87      (local.set $i (local.get $n))
    88      (local.set $res (i64.const 1))
    89      (block $done
    90        (loop $loop
    91          (i64.eq (local.get $i) (i64.const 0))
    92          (if
    93            (then (br $done))
    94            (else
    95              (i64.mul (local.get $i) (local.get $res))
    96              (local.set $res)
    97              (i64.sub (local.get $i) (i64.const 1))
    98              (local.set $i)
    99            )
   100          )
   101          (br $loop)
   102        )
   103      )
   104      (local.get $res)
   105    )
   106  
   107    (func (export "fac-mixed-raw") (param $n i64) (result i64)
   108      (local $i i64)
   109      (local $res i64)
   110      (local.set $i (local.get $n))
   111      (local.set $res (i64.const 1))
   112      block $done
   113        loop $loop
   114          (i64.eq (local.get $i) (i64.const 0))
   115          if
   116            br $done
   117          else
   118            (i64.mul (local.get $i) (local.get $res))
   119            local.set $res
   120            (i64.sub (local.get $i) (i64.const 1))
   121            local.set $i
   122          end
   123          br $loop
   124        end
   125      end
   126      local.get $res
   127    )
   128  )
   129  
   130  (assert_return (invoke "fac-expr" (i64.const 25)) (i64.const 7034535277573963776))
   131  (assert_return (invoke "fac-stack" (i64.const 25)) (i64.const 7034535277573963776))
   132  (assert_return (invoke "fac-mixed" (i64.const 25)) (i64.const 7034535277573963776))
   133  
   134  
   135  ;; Syntax of flat call_indirect
   136  
   137  (module
   138    (type $proc (func))
   139    (table 1 funcref)
   140  
   141    (func
   142      (block i32.const 0 call_indirect)
   143      (loop i32.const 0 call_indirect)
   144      (if (i32.const 0) (then i32.const 0 call_indirect))
   145      (if (i32.const 0)
   146        (then i32.const 0 call_indirect)
   147        (else i32.const 0 call_indirect)
   148      )
   149      (block i32.const 0 call_indirect (type $proc))
   150      (loop i32.const 0 call_indirect (type $proc))
   151      (if (i32.const 0) (then i32.const 0 call_indirect (type $proc)))
   152      (if (i32.const 0)
   153        (then i32.const 0 call_indirect (type $proc))
   154        (else i32.const 0 call_indirect (type $proc))
   155      )
   156      (block i32.const 0 i32.const 0 call_indirect (param i32))
   157      (loop i32.const 0 i32.const 0 call_indirect (param i32))
   158      (if (i32.const 0) (then i32.const 0 i32.const 0 call_indirect (param i32)))
   159      (if (i32.const 0)
   160        (then i32.const 0 i32.const 0 call_indirect (param i32))
   161        (else i32.const 0 i32.const 0 call_indirect (param i32))
   162      )
   163      (block (result i32) i32.const 0 call_indirect (result i32)) (drop)
   164      (loop (result i32) i32.const 0 call_indirect (result i32)) (drop)
   165      (if (result i32) (i32.const 0)
   166        (then i32.const 0 call_indirect (result i32))
   167        (else i32.const 0 call_indirect (result i32))
   168      ) (drop)
   169      (block i32.const 0 call_indirect (type $proc) (param) (result))
   170      (loop i32.const 0 call_indirect (type $proc) (param) (result))
   171      (if (i32.const 0)
   172        (then i32.const 0 call_indirect (type $proc) (param) (result))
   173      )
   174      (if (i32.const 0)
   175        (then i32.const 0 call_indirect (type $proc) (param) (param) (result))
   176        (else i32.const 0 call_indirect (type $proc) (param) (result) (result))
   177      )
   178  
   179      block i32.const 0 call_indirect end
   180      loop i32.const 0 call_indirect end
   181      i32.const 0 if i32.const 0 call_indirect end
   182      i32.const 0 if i32.const 0 call_indirect else i32.const 0 call_indirect end
   183      block i32.const 0 call_indirect (type $proc) end
   184      loop i32.const 0 call_indirect (type $proc) end
   185      i32.const 0 if i32.const 0 call_indirect (type $proc) end
   186      i32.const 0
   187      if
   188        i32.const 0 call_indirect (type $proc)
   189      else
   190        i32.const 0 call_indirect (type $proc)
   191      end
   192      block i32.const 0 i32.const 0 call_indirect (param i32) end
   193      loop i32.const 0 i32.const 0 call_indirect (param i32) end
   194      i32.const 0 if i32.const 0 i32.const 0 call_indirect (param i32) end
   195      i32.const 0
   196      if
   197        i32.const 0 i32.const 0 call_indirect (param i32)
   198      else
   199        i32.const 0 i32.const 0 call_indirect (param i32)
   200      end
   201      block (result i32) i32.const 0 call_indirect (result i32) end drop
   202      loop (result i32) i32.const 0 call_indirect (result i32) end drop
   203      i32.const 0
   204      if (result i32)
   205        i32.const 0 call_indirect (result i32)
   206      else
   207        i32.const 0 call_indirect (result i32)
   208      end drop
   209      block i32.const 0 call_indirect (type $proc) (param) (result) end
   210      loop i32.const 0 call_indirect (type $proc) (param) (result) end
   211      i32.const 0 if i32.const 0 call_indirect (type $proc) (param) (result) end
   212      i32.const 0
   213      if
   214        i32.const 0 call_indirect (type $proc) (param) (result)
   215      else
   216        i32.const 0 call_indirect (type $proc) (param) (param) (result) (result)
   217      end
   218      i32.const 0 call_indirect
   219    )
   220  )