test-lower.scm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ;;; Copyright (C) 2023, 2024 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. (func $string-to-i32 (import "app" "string-to-i32")
  36. (param (ref string)) (result i32))
  37. (func $i32-to-string (import "app" "i32-to-string")
  38. (param i32) (result (ref string)))
  39. (global $s0 (ref string) (string.const "hey"))
  40. (func $main (param $i i32) (result i32)
  41. (local.get 0) (call 1) (call 0)))
  42. (wasm->wat (lower-wasm mod #:stringref-lowering 'stringref))))
  43. (let ((mod (wat->wasm
  44. '((func $string-to-i32 (import "app" "string-to-i32")
  45. (param (ref string)) (result i32))
  46. (func $i32-to-string (import "app" "i32-to-string")
  47. (param i32) (result (ref string)))
  48. (func $main (param $i i32) (result i32)
  49. (local.get $i)
  50. (call $i32-to-string)
  51. (call $string-to-i32))
  52. (global $s0 (ref string) (string.const "hey"))))))
  53. (test-equal '(module
  54. (type $wtf8 (array (mut i8)))
  55. (type $__start (func))
  56. (func $string-to-i32-stringref-0 (import "app" "string-to-i32")
  57. (param (ref extern)) (result i32))
  58. (func $i32-to-string-stringref-1 (import "app" "i32-to-string")
  59. (param i32) (result (ref extern)))
  60. (func $wtf8->extern-string (import "rt" "wtf8_to_string")
  61. (param $wtf8 (ref null 0)) (result (ref extern)))
  62. (func $extern-string->wtf8 (import "rt" "string_to_wtf8")
  63. (param $str (ref extern)) (result (ref 0)))
  64. (global $stringref-2 (mut (ref null 0)) (ref.null 0))
  65. (global $s0 (mut (ref null 0)) (ref.null 0))
  66. (data $stringref-2 #vu8(104 101 121))
  67. (func $main (param $i i32) (result i32)
  68. (local.get 0) (call 6) (call 5))
  69. (func $string-to-i32 (param (ref 0)) (result i32)
  70. (local #f i32)
  71. (local.get 0)
  72. (call 2)
  73. (call 0)
  74. (local.set 1)
  75. (local.get 1))
  76. (func $i32-to-string (param i32) (result (ref 0))
  77. (local #f (ref extern))
  78. (local.get 0)
  79. (call 1)
  80. (local.set 1)
  81. (local.get 1)
  82. (call 3))
  83. (func $__start
  84. (i32.const 0)
  85. (i32.const 3)
  86. (array.new_data 0 0)
  87. (global.set 0)
  88. (global.get 0)
  89. (ref.as_non_null)
  90. (global.set 1))
  91. (start 7))
  92. (wasm->wat (lower-wasm mod #:stringref-lowering 'wtf8))))
  93. (test-end* "test-lower")