core-syntax-helpers.scm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ;;; Syntax helper procedures
  2. ;;; Copyright (C) 2024 Igalia, S.L.
  3. ;;;
  4. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  5. ;;; you may not use this file except in compliance with the License.
  6. ;;; You may obtain a copy of the License at
  7. ;;;
  8. ;;; http://www.apache.org/licenses/LICENSE-2.0
  9. ;;;
  10. ;;; Unless required by applicable law or agreed to in writing, software
  11. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  12. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. ;;; See the License for the specific language governing permissions and
  14. ;;; limitations under the License.
  15. ;;; Commentary:
  16. ;;;
  17. ;;; Primitive syntax.
  18. ;;;
  19. ;;; Code:
  20. (library (hoot core-syntax-helpers)
  21. (export make-variable-transformer
  22. identifier? generate-temporaries
  23. free-identifier=? bound-identifier=?
  24. syntax-local-binding syntax-violation
  25. %initialize-syntax-helpers!)
  26. (import (hoot core-syntax)
  27. (hoot cross-compilation)
  28. (prefix (only (hoot primitives)
  29. make-variable-transformer
  30. identifier? generate-temporaries
  31. free-identifier=? bound-identifier=?
  32. syntax-local-binding syntax-violation)
  33. host:))
  34. (define-syntax-rule (define-syntax-helper name host-name)
  35. (define name (cross-compilation-case (#t host-name) (#f #f))))
  36. (define-syntax-rule (define-syntax-helpers initialize!
  37. (name host-name) ...)
  38. (begin
  39. (define-syntax-helper name host-name)
  40. ...
  41. (define (do-init host-name ...)
  42. (set! name host-name) ...)
  43. (define* (initialize! #:key name ...)
  44. (do-init name ...))))
  45. (define-syntax-helpers %initialize-syntax-helpers!
  46. (make-variable-transformer host:make-variable-transformer)
  47. (identifier? host:identifier?)
  48. (generate-temporaries host:generate-temporaries)
  49. (free-identifier=? host:free-identifier=?)
  50. (bound-identifier=? host:bound-identifier=?)
  51. (syntax-local-binding host:syntax-local-binding)
  52. (syntax-violation host:syntax-violation)))