test-lower.scm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ;;; Copyright (C) 2023 Igalia, S.L.
  2. ;;;
  3. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  4. ;;; you may not use this file except in compliance with the License.
  5. ;;; You may obtain a copy of the License at
  6. ;;;
  7. ;;; http://www.apache.org/licenses/LICENSE-2.0
  8. ;;;
  9. ;;; Unless required by applicable law or agreed to in writing, software
  10. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  11. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ;;; See the License for the specific language governing permissions and
  13. ;;; limitations under the License.
  14. ;;; Commentary:
  15. ;;;
  16. ;;; String tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (srfi srfi-64)
  20. (wasm wat)
  21. (wasm lower)
  22. (test utils))
  23. (test-begin "test-lower")
  24. (let ((mod (wat->wasm
  25. '((func $string-to-i32 (import "app" "string-to-i32")
  26. (param (ref string)) (result i32))
  27. (func $i32-to-string (import "app" "i32-to-string")
  28. (param i32) (result (ref string)))
  29. (func $main (param $i i32) (result i32)
  30. (local.get $i)
  31. (call $i32-to-string)
  32. (call $string-to-i32))
  33. (global $s0 (ref string) (string.const "hey"))))))
  34. (test-equal '(module
  35. (type #f (func (param (ref string)) (result i32)))
  36. (type #f (func (param i32) (result (ref string))))
  37. (type #f (func (param $i i32) (result i32)))
  38. (import "app" "string-to-i32"
  39. (func $string-to-i32 (param (ref string)) (result i32)))
  40. (import "app" "i32-to-string"
  41. (func $i32-to-string (param i32) (result (ref string))))
  42. (global $s0 (ref string) (string.const "hey"))
  43. (func $main (param $i i32) (result i32)
  44. (local.get 0) (call 1) (call 0)))
  45. (wasm->wat (lower-wasm mod #:stringref-lowering 'stringref))))
  46. (let ((mod (wat->wasm
  47. '((func $string-to-i32 (import "app" "string-to-i32")
  48. (param (ref string)) (result i32))
  49. (func $i32-to-string (import "app" "i32-to-string")
  50. (param i32) (result (ref string)))
  51. (func $main (param $i i32) (result i32)
  52. (local.get $i)
  53. (call $i32-to-string)
  54. (call $string-to-i32))
  55. (global $s0 (ref string) (string.const "hey"))))))
  56. (test-equal '(module
  57. (type $wtf8 (array (mut i8)))
  58. (type $__start (func))
  59. (type #f (func (param (ref extern)) (result i32)))
  60. (type #f (func (param i32) (result (ref extern))))
  61. (type #f (func (param $wtf8 (ref null 0)) (result (ref extern))))
  62. (type #f (func (param $str (ref null extern)) (result (ref 0))))
  63. (type #f (func (param $i i32) (result i32)))
  64. (type #f (func (param (ref 0)) (result i32)))
  65. (type #f (func (param i32) (result (ref 0))))
  66. (import "app" "string-to-i32"
  67. (func $string-to-i32-stringref-0
  68. (param (ref extern)) (result i32)))
  69. (import "app" "i32-to-string"
  70. (func $i32-to-string-stringref-1
  71. (param i32) (result (ref extern))))
  72. (import "rt" "wtf8_to_string"
  73. (func $wtf8->extern-string
  74. (param $wtf8 (ref null 0)) (result (ref extern))))
  75. (import "rt" "string_to_wtf8"
  76. (func $extern-string->wtf8
  77. (param $str (ref null extern)) (result (ref 0))))
  78. (global $stringref-2 (mut (ref null 0)) (ref.null 0))
  79. (global $s0 (mut (ref null 0)) (ref.null 0))
  80. (data $stringref-2 #vu8(104 101 121))
  81. (func $main (param $i i32) (result i32)
  82. (local.get 0) (call 6) (call 5))
  83. (func $string-to-i32 (param (ref 0)) (result i32)
  84. (local #f i32)
  85. (local.get 0)
  86. (call 2)
  87. (call 0)
  88. (local.set 1)
  89. (local.get 1))
  90. (func $i32-to-string (param i32) (result (ref 0))
  91. (local #f (ref extern))
  92. (local.get 0)
  93. (call 1)
  94. (local.set 1)
  95. (local.get 1)
  96. (call 3))
  97. (func $__start
  98. (i32.const 0)
  99. (i32.const 3)
  100. (array.new_data 0 0)
  101. (global.set 0)
  102. (global.get 0)
  103. (ref.as_non_null)
  104. (global.set 1))
  105. (start 7))
  106. (wasm->wat (lower-wasm mod #:stringref-lowering 'wtf8))))
  107. (test-end* "test-lower")