|
324 | 324 | (assert_return (invoke "is-odd" (i32.const 7)) (i32.const 1)) |
325 | 325 | (assert_return (invoke "is-odd" (i32.const 8)) (i32.const 0)) |
326 | 326 | (assert_return (invoke "is-odd" (i32.const 9)) (i32.const 1)) |
| 327 | + |
| 328 | +;; The exported functions call the imported identity host functions `n` times. |
| 329 | +;; The host functions are supposed to be identity functions with fixed arity. |
| 330 | +;; |
| 331 | +;; After successful execution the exported functions returns 0. |
| 332 | +(module |
| 333 | + (import "wasmitest" "identity-0" (func $identity-0)) |
| 334 | + (import "wasmitest" "identity-1" (func $identity-1 (param i64) (result i64))) |
| 335 | + (import "wasmitest" "identity-2" (func $identity-2 (param i64 i64) (result i64 i64))) |
| 336 | + |
| 337 | + (func $forward-identity-0 |
| 338 | + (return_call $identity-0) |
| 339 | + ) |
| 340 | + (func $forward-identity-1 (param i64) (result i64) |
| 341 | + (return_call $identity-1 (local.get 0)) |
| 342 | + ) |
| 343 | + (func $forward-identity-2 (param i64 i64) (result i64 i64) |
| 344 | + (return_call $identity-2 (local.get 0) (local.get 1)) |
| 345 | + ) |
| 346 | + |
| 347 | + (func (export "n-times-identity-0") (param $n i64) (result i64) |
| 348 | + (loop $continue |
| 349 | + (if |
| 350 | + (i64.eqz (local.get $n)) |
| 351 | + (then |
| 352 | + (return (i64.const 0)) |
| 353 | + ) |
| 354 | + ) |
| 355 | + (call $forward-identity-0) |
| 356 | + (local.set $n (i64.sub (local.get $n) (i64.const 1))) |
| 357 | + (br $continue) |
| 358 | + ) |
| 359 | + (unreachable) |
| 360 | + ) |
| 361 | + |
| 362 | + (func (export "n-times-identity-1") (param $n i64) (result i64) |
| 363 | + (loop $continue |
| 364 | + (if |
| 365 | + (i64.eqz (local.get $n)) |
| 366 | + (then |
| 367 | + (return (i64.const 0)) |
| 368 | + ) |
| 369 | + ) |
| 370 | + (drop (call $forward-identity-1 (local.get $n))) |
| 371 | + (local.set $n (i64.sub (local.get $n) (i64.const 1))) |
| 372 | + (br $continue) |
| 373 | + ) |
| 374 | + (unreachable) |
| 375 | + ) |
| 376 | + |
| 377 | + (func (export "n-times-identity-2") (param $n i64) (result i64) |
| 378 | + (loop $continue |
| 379 | + (if |
| 380 | + (i64.eqz (local.get $n)) |
| 381 | + (then |
| 382 | + (return (i64.const 0)) |
| 383 | + ) |
| 384 | + ) |
| 385 | + (call $forward-identity-2 |
| 386 | + (local.get $n) (local.get $n) |
| 387 | + ) |
| 388 | + ;; drop all return values from the host function call |
| 389 | + (drop) (drop) |
| 390 | + (local.set $n (i64.sub (local.get $n) (i64.const 1))) |
| 391 | + (br $continue) |
| 392 | + ) |
| 393 | + (unreachable) |
| 394 | + ) |
| 395 | +) |
| 396 | +(assert_return (invoke "n-times-identity-0" (i64.const 0)) (i64.const 0)) |
| 397 | +(assert_return (invoke "n-times-identity-0" (i64.const 1)) (i64.const 0)) |
| 398 | +(assert_return (invoke "n-times-identity-0" (i64.const 10)) (i64.const 0)) |
| 399 | +(assert_return (invoke "n-times-identity-1" (i64.const 0)) (i64.const 0)) |
| 400 | +(assert_return (invoke "n-times-identity-1" (i64.const 1)) (i64.const 0)) |
| 401 | +(assert_return (invoke "n-times-identity-1" (i64.const 10)) (i64.const 0)) |
| 402 | +(assert_return (invoke "n-times-identity-2" (i64.const 0)) (i64.const 0)) |
| 403 | +(assert_return (invoke "n-times-identity-2" (i64.const 1)) (i64.const 0)) |
| 404 | +(assert_return (invoke "n-times-identity-2" (i64.const 10)) (i64.const 0)) |
0 commit comments