test-round-trip.scm 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ;;; Copyright (C) 2024 David Thompson <dave@spritely.institute>
  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. ;;; Toolchain round trip tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (hoot compile)
  20. (hoot reflect)
  21. (ice-9 binary-ports)
  22. (wasm assemble)
  23. (wasm parse)
  24. (wasm resolve)
  25. (wasm wat)
  26. (srfi srfi-64)
  27. (test utils))
  28. (test-begin "test-round-trip")
  29. ;; Test that we can compile Scheme code, build a binary, disassemble
  30. ;; it all the way back to WAT form, rebuild it, and have a working
  31. ;; equivalent program.
  32. (test-equal "round trip"
  33. 42
  34. (hoot-load ; call start function
  35. (hoot-instantiate ; load wasm in vm
  36. (resolve-wasm ; lower again
  37. (wat->wasm ; convert back to wasm
  38. (wasm->wat ; convert to wat
  39. (unresolve-wasm ; lift int ids to names, etc.
  40. (call-with-input-bytevector ; parse binary
  41. (assemble-wasm ; build binary
  42. (compile 42 #:debug? #t)) ; compile Scheme
  43. parse-wasm))))))))
  44. (test-end* "test-round-trip")