macro.test 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #! /bin/sh
  2. # -*-scheme-*-
  3. if [ "$MES" != guile ]; then
  4. export MES_BOOT=boot-02.scm
  5. MES=${MES-$(dirname $0)/../src/mes}
  6. $MES < $0
  7. exit $?
  8. else
  9. exit 0
  10. fi
  11. exec ${MES-mes} --no-auto-compile -L ${0%/*} -L module -C module -e '(tests macro)' -s "$0" "$@"
  12. !#
  13. ;;; -*-scheme-*-
  14. ;;; GNU Mes --- Maxwell Equations of Software
  15. ;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  16. ;;;
  17. ;;; This file is part of GNU Mes.
  18. ;;;
  19. ;;; GNU Mes is free software; you can redistribute it and/or modify it
  20. ;;; under the terms of the GNU General Public License as published by
  21. ;;; the Free Software Foundation; either version 3 of the License, or (at
  22. ;;; your option) any later version.
  23. ;;;
  24. ;;; GNU Mes is distributed in the hope that it will be useful, but
  25. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  26. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. ;;; GNU General Public License for more details.
  28. ;;;
  29. ;;; You should have received a copy of the GNU General Public License
  30. ;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  31. (define-module (tests boot)
  32. #:use-module (mes mes-0)
  33. #:use-module (mes test))
  34. (cond-expand
  35. (mes
  36. (primitive-load "module/mes/test.scm"))
  37. (guile-2)
  38. (guile
  39. (use-modules (ice-9 syncase))))
  40. (pass-if "first dummy" #t)
  41. (pass-if-not "second dummy" #f)
  42. (define gensym
  43. ((lambda (symbols)
  44. (lambda (. rest)
  45. ((lambda (head tail)
  46. (set! symbols tail)
  47. head)
  48. (car symbols)
  49. (cdr symbols))))
  50. '(g0 g1 g2 g3 g4)))
  51. ;; type-0.mes
  52. (define (string . lst)
  53. (list->string lst))
  54. ;; scm.mes
  55. (define (symbol-append . rest)
  56. (string->symbol (apply string-append (map symbol->string rest))))
  57. (define-macro (make-fluid . default)
  58. ((lambda (fluid)
  59. (list
  60. 'begin
  61. (list
  62. 'module-define!
  63. (list 'boot-module)
  64. (list 'quote fluid)
  65. (list
  66. (lambda (v)
  67. (lambda ( . rest)
  68. (if (null? rest) v
  69. (set! v (car rest)))))
  70. (and (pair? default) (car default))))
  71. (list 'quote fluid)))
  72. (symbol-append 'fluid: (gensym))))
  73. (define fluid (make-fluid 42))
  74. (pass-if-eq "fluid" 42 (fluid))
  75. (fluid 0)
  76. (pass-if-eq "fluid 0" 0 (fluid))
  77. (fluid '())
  78. (pass-if-eq "fluid null" '() (fluid))
  79. (define (fluid-ref fluid)
  80. (fluid))
  81. (define (fluid-set! fluid value)
  82. (fluid value))
  83. (fluid-set! fluid 0)
  84. (pass-if-eq "fluid 0" 0 (fluid-ref fluid))
  85. (fluid-set! fluid '())
  86. (pass-if-eq "fluid null" '() (fluid-ref fluid))
  87. (result 'report)