3 MES=${MES-$(dirname $0)/mes}
5 echo '()' | cat $moduledir/mes/base-0.mes $0 /dev/stdin | $MES $MES_FLAGS -- "$@"
8 ([ -f a.out ] && chmod +x a.out)
12 ;;; Mes --- Maxwell Equations of Software
13 ;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
15 ;;; This file is part of Mes.
17 ;;; Mes is free software; you can redistribute it and/or modify it
18 ;;; under the terms of the GNU General Public License as published by
19 ;;; the Free Software Foundation; either version 3 of the License, or (at
20 ;;; your option) any later version.
22 ;;; Mes is distributed in the hope that it will be useful, but
23 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;;; GNU General Public License for more details.
27 ;;; You should have received a copy of the GNU General Public License
28 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
32 ;;; mescc.mes is a proof-of-concept simplistic C compiler and linker
37 ;;(mes-use-module (language c compiler))
40 (let* ((files (cddr (command-line)))
41 (file (if (pair? files) (car files))))
42 (cond ((equal? file "--help")
43 (format (current-error-port) "Usage: mescc.mes [--help|--version|FILE] > a.out\n")
45 ((equal? file "--version")
46 (format (current-error-port) "mescc.mes (mes) ~a\n" %version)
49 (mes-use-module (mes guile))
50 (mes-use-module (language c99 compiler))
52 (define %datadir (if (string-prefix? "@DATADIR" "@DATADIR@") "" "@DATADIR@"))
53 (define %docdir (if (string-prefix? "@DOCDIR" "@DOCDIR@") "doc/" "@DOCDIR@"))
54 (define %moduledir "module/")
55 (define %prefix (if (string-prefix? "@PREFIX" "@PREFIX@") "" "@PREFIX@"))
56 (define %version (if (string-prefix? "@VERSION" "@VERSION@") "git" "@VERSION@"))
58 (define (main arguments)
59 (let* ((mfiles (cddr arguments))
60 (mfiles (if (or (null? mfiles) (not (equal? (car mfiles) "--"))) mfiles
62 (mfile (if (null? mfiles) (string-append %docdir "examples/main.c")
64 (format (current-error-port) "compiling: ~a\n" mfile)
65 (with-input-from-file mfile