birthday.scm 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ;;; Guile-GCC --- Guile extension to GCC. -*- coding: utf-8 -*-
  2. ;;; Copyright (C) 2012 Ludovic Courtès
  3. ;;;
  4. ;;; This file is part of Guile-GCC.
  5. ;;;
  6. ;;; Guile-GCC is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; Guile-GCC is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with Guile-GCC. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (birthday)
  19. #:use-module (gcc)
  20. #:use-module (gcc cpp))
  21. ;;;
  22. ;;; Welcome, this is the `birthday' GCC plug-in! It extends C with a
  23. ;;; `#pragma guile birthday' construct, which says happy birthday Guile!
  24. ;;;
  25. (define (register-funny-pragmas)
  26. (register-c-pragma "guile" "birthday"
  27. (lambda (cpp)
  28. (let ((fn (current-function-decl)))
  29. (inform (token-source-location (peek-token cpp 0))
  30. "Happy Birthday Guile 2.0~:[ from function ~s~;~]!"
  31. (null-tree? fn)
  32. (identifier-string (decl-name fn)))
  33. (let* ((puts (built-in-decl BUILT_IN_PUTS))
  34. (str (build-string-literal
  35. "Happy Birthday, Guile 2.0!"))
  36. (call (build-call-expr %unknown-location
  37. puts (list str))))
  38. (add-statement call))))))
  39. (format #t "Welcome! You've just loaded the incredible birthday plug-in!~%")
  40. (register-callback "guile" PLUGIN_PRAGMAS register-funny-pragmas)