pmatch.test 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #! /bin/sh
  2. # -*-scheme-*-
  3. exec ${MES-src/mes} --no-auto-compile -L ${0%/*} -L module -C module -e '(tests pmatch)' -s "$0" "$@"
  4. !#
  5. ;;; -*-scheme-*-
  6. ;;; GNU Mes --- Maxwell Equations of Software
  7. ;;; Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  8. ;;;
  9. ;;; This file is part of GNU Mes.
  10. ;;;
  11. ;;; GNU Mes is free software; you can redistribute it and/or modify it
  12. ;;; under the terms of the GNU General Public License as published by
  13. ;;; the Free Software Foundation; either version 3 of the License, or (at
  14. ;;; your option) any later version.
  15. ;;;
  16. ;;; GNU Mes is distributed in the hope that it will be useful, but
  17. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;;; GNU General Public License for more details.
  20. ;;;
  21. ;;; You should have received a copy of the GNU General Public License
  22. ;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  23. (define-module (tests pmatch)
  24. #:use-module (system base pmatch)
  25. #:use-module (mes mes-0)
  26. #:use-module (mes test))
  27. (cond-expand
  28. (mes
  29. (mes-use-module (mes test))
  30. (mes-use-module (mes pmatch)))
  31. (else))
  32. (pass-if "first dummy" #t)
  33. (pass-if-not "second dummy" #f)
  34. (pass-if-equal "pmatch" 0
  35. (let ((o 0))
  36. (pmatch o
  37. (_ o))))
  38. (pass-if-equal "pmatch nyacc minimal" "main"
  39. (let* ((ast '(("main") PARAM-LIST))
  40. (mets (pmatch ast
  41. (((,name) _) name))))
  42. ;;(format (current-error-port) "mets: ~s\n" mets)
  43. mets))
  44. (pass-if-equal "pmatch nyacc" "main"
  45. (let ((ast '(fctn-defn
  46. (decl-spec-list (type-spec (fixed-type "int")))
  47. (ftn-declr
  48. (ident "main")
  49. (param-list
  50. (param-decl
  51. (decl-spec-list (type-spec (fixed-type "int")))
  52. (param-declr (ident "argc")))
  53. (param-decl
  54. (decl-spec-list (type-spec (fixed-type "char")))
  55. (param-declr
  56. (ptr-declr (pointer) (array-of (ident "argv")))))))
  57. (compd-stmt
  58. (block-item-list
  59. (if (gt (p-expr (ident "argc")) (p-expr (fixed "1")))
  60. (return (p-expr (ident "argc"))))
  61. (return (p-expr (fixed "42"))))))))
  62. (pmatch ast
  63. ((fctn-defn _ (ftn-declr (ident ,name) _) _) name)
  64. (_ 'bla))))
  65. (result 'report)