add define-once
[bpt/guile.git] / module / ice-9 / compile-psyntax.scm
CommitLineData
adb8f306
LC
1;;; -*- mode: scheme; coding: utf-8; -*-
2;;;
3;;; Copyright (C) 2009, 2010 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
19(use-modules (language tree-il)
417ee098 20 (language tree-il optimize)
adb8f306
LC
21 (ice-9 pretty-print))
22
9c35c579
AW
23(let ((source (list-ref (command-line) 1))
24 (target (list-ref (command-line) 2)))
25 (let ((in (open-input-file source))
26 (out (open-output-file (string-append target ".tmp"))))
27 (write '(eval-when (compile) (set-current-module (resolve-module '(guile))))
28 out)
29 (newline out)
30 (let loop ((x (read in)))
31 (if (eof-object? x)
32 (begin
33 (close-port out)
34 (close-port in))
35 (begin
65dd9e38 36 (pretty-print (tree-il->scheme
417ee098
AW
37 (optimize!
38 (macroexpand x 'c '(compile load eval))
39 (current-module)
40 '()))
65dd9e38 41 out)
9c35c579
AW
42 (newline out)
43 (loop (read in))))))
44 (system (format #f "mv -f ~s.tmp ~s" target target)))