compile-psyntax.scm 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ;;; -*- mode: scheme; coding: utf-8; -*-
  2. ;;;
  3. ;;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
  4. ;;;
  5. ;;; This library is free software; you can redistribute it and/or
  6. ;;; modify it under the terms of the GNU Lesser General Public
  7. ;;; License as published by the Free Software Foundation; either
  8. ;;; version 3 of the License, or (at your option) any later version.
  9. ;;;
  10. ;;; This library is distributed in the hope that it will be useful,
  11. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ;;; Lesser General Public License for more details.
  14. ;;;
  15. ;;; You should have received a copy of the GNU Lesser General Public
  16. ;;; License along with this library; if not, write to the Free Software
  17. ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. (use-modules (language tree-il)
  19. (language tree-il optimize)
  20. (language tree-il canonicalize)
  21. (ice-9 pretty-print))
  22. (let ((source (list-ref (command-line) 1))
  23. (target (list-ref (command-line) 2)))
  24. (let ((in (open-input-file source))
  25. (out (open-output-file (string-append target ".tmp"))))
  26. (write '(eval-when (compile) (set-current-module (resolve-module '(guile))))
  27. out)
  28. (newline out)
  29. (let loop ((x (read in)))
  30. (if (eof-object? x)
  31. (begin
  32. (close-port out)
  33. (close-port in))
  34. (begin
  35. (pretty-print (tree-il->scheme
  36. (canonicalize!
  37. (optimize!
  38. (macroexpand x 'c '(compile load eval))
  39. (current-module)
  40. '())))
  41. out)
  42. (newline out)
  43. (loop (read in))))))
  44. (system (format #f "mv -f ~s.tmp ~s" target target)))