mescc: Merge mescc.mes and mescc.scm.
* scripts/mescc: New file. * scripts/mescc.mes: Remove. * guile/mescc.scm: Remove. * guile/guix/make.scm (CC.mescc): Update. * install.sh (TINYCC_SEED): Update. * make.scm (bootstrap?): Update. * test.sh (MES): Update. * check-boot.sh: Use $GUILE to allow running without Guile.
This commit is contained in:
parent
2cc6f166db
commit
c6fecdc353
|
@ -110,7 +110,7 @@ for i in $tests; do
|
||||||
echo ' [SKIP]'
|
echo ' [SKIP]'
|
||||||
continue;
|
continue;
|
||||||
fi
|
fi
|
||||||
guile -L guile -L . <(echo '(use-modules (mes guile))'; cat scaffold/boot/$i) >& /dev/null
|
$GUILE -L guile -L . <(echo '(use-modules (mes guile))'; cat scaffold/boot/$i) >& /dev/null
|
||||||
x=$(
|
x=$(
|
||||||
if [ -z "${i/5[0-9]-*/}" ]; then
|
if [ -z "${i/5[0-9]-*/}" ]; then
|
||||||
cat scaffold/boot/$i | MES_BOOT=boot-00.scm $MES 2>&1;
|
cat scaffold/boot/$i | MES_BOOT=boot-00.scm $MES 2>&1;
|
||||||
|
|
|
@ -19,14 +19,13 @@
|
||||||
# along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
# along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
export MES=${MES-src/mes}
|
export MES=${MES-src/mes}
|
||||||
export MESCC=${MESCC-scripts/mescc.mes}
|
export MESCC=${MESCC-scripts/mescc}
|
||||||
#export MES_ARENA=${MES_ARENA-200000000} > 12GB mem
|
#export MES_ARENA=${MES_ARENA-200000000} > 12GB mem
|
||||||
|
|
||||||
GUILE=${GUILE-guile}
|
GUILE=${GUILE-guile}
|
||||||
MES=${MES-src/mes}
|
MES=${MES-src/mes}
|
||||||
M1=${M1-M1}
|
M1=${M1-M1}
|
||||||
HEX2=${HEX2-hex2}
|
HEX2=${HEX2-hex2}
|
||||||
MESCC=${MESCC-guile/mescc.scm}
|
|
||||||
MES_PREFIX=${MES_PREFIX-.}
|
MES_PREFIX=${MES_PREFIX-.}
|
||||||
|
|
||||||
# $MESCC -E -o lib/crt1.E lib/crt1.c
|
# $MESCC -E -o lib/crt1.E lib/crt1.c
|
||||||
|
|
|
@ -385,16 +385,18 @@
|
||||||
"-o" ,(target-file-name t)
|
"-o" ,(target-file-name t)
|
||||||
,@input-files)))))))
|
,@input-files)))))))
|
||||||
|
|
||||||
(define %MESCC "guile/mescc.scm")
|
(define %MESCC "scripts/mescc")
|
||||||
(define* (CC.mescc #:key (cc %MESCC))
|
(define* (CC.mescc #:key (cc %MESCC))
|
||||||
(method (name "CC.mescc")
|
(method (name "CC.mescc")
|
||||||
(build (lambda (o t)
|
(build (lambda (o t)
|
||||||
(let ((input-files (map target-file-name (target-inputs t))))
|
(let ((input-files (map target-file-name (target-inputs t))))
|
||||||
(format #t " ~a\t ~a -> ~a\n" (method-name o) (string-join input-files) (target-file-name t))
|
(format #t " ~a\t ~a -> ~a\n" (method-name o) (string-join input-files) (target-file-name t))
|
||||||
|
(setenv "MES" "guile")
|
||||||
(apply system**
|
(apply system**
|
||||||
`("guile/mescc.scm" "-c"
|
`("scripts/mescc" "-c"
|
||||||
"-o" ,(target-file-name t)
|
"-o" ,(target-file-name t)
|
||||||
,@input-files)))))
|
,@input-files))
|
||||||
|
(unsetenv "MES"))))
|
||||||
(inputs (list (store #:add-file "guile/language/c99/info.go")
|
(inputs (list (store #:add-file "guile/language/c99/info.go")
|
||||||
(store #:add-file "guile/language/c99/compiler.go")
|
(store #:add-file "guile/language/c99/compiler.go")
|
||||||
(store #:add-file "guile/mes/as-i386.go")
|
(store #:add-file "guile/mes/as-i386.go")
|
||||||
|
|
158
guile/mescc.scm
158
guile/mescc.scm
|
@ -1,158 +0,0 @@
|
||||||
#! /bin/sh
|
|
||||||
# -*-scheme-*-
|
|
||||||
GODIR=${GODIR-@GODIR@}
|
|
||||||
GUILEDIR=${GUILEDIR-@GUILEDIR@}
|
|
||||||
[ "$GODIR" = @"GODIR"@ ] && GODIR=$(dirname $0)
|
|
||||||
[ "$GUILEDIR" = @"GUILEDIR"@ ] && GUILEDIR=$(dirname $0)
|
|
||||||
export GUILE_AUTO_COMPILE=${GUILE_AUTO_COMPILE-0}
|
|
||||||
GUILE_LOAD_COMPILED_PATH=$GODIR:$GUILE_LOAD_COMPILED_PATH
|
|
||||||
exec ${GUILE-guile} -L $GUILEDIR -e '(mescc)' -s "$0" "$@"
|
|
||||||
!#
|
|
||||||
|
|
||||||
;;; Mes --- The Maxwell Equations of Software
|
|
||||||
;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
|
||||||
;;;
|
|
||||||
;;; This file is part of GNU Guix.
|
|
||||||
;;;
|
|
||||||
;;; Mes is free software; you can redistribute it and/or modify it
|
|
||||||
;;; under the terms of the GNU General Public License as published by
|
|
||||||
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
||||||
;;; your option) any later version.
|
|
||||||
;;;
|
|
||||||
;;; Mes is distributed in the hope that it will be useful, but
|
|
||||||
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;; GNU General Public License for more details.
|
|
||||||
;;;
|
|
||||||
;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
;; The Maxwell Equations of Software -- John McCarthy page 13
|
|
||||||
;; http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf
|
|
||||||
|
|
||||||
#!
|
|
||||||
Run with Guile-1.8:
|
|
||||||
GUILE='~/src/guile-1.8/build/pre-inst-guile --debug -q' guile/mescc.scm
|
|
||||||
!#
|
|
||||||
|
|
||||||
(define-module (mescc)
|
|
||||||
#:use-module (language c99 info)
|
|
||||||
#:use-module (language c99 compiler)
|
|
||||||
#:use-module (mes elf)
|
|
||||||
#:use-module (mes M1)
|
|
||||||
#:use-module (ice-9 getopt-long)
|
|
||||||
#:use-module (ice-9 pretty-print)
|
|
||||||
#:use-module (srfi srfi-1)
|
|
||||||
#:use-module (srfi srfi-26)
|
|
||||||
#:export (main))
|
|
||||||
|
|
||||||
(cond-expand
|
|
||||||
(guile-2)
|
|
||||||
(guile
|
|
||||||
(use-modules (ice-9 syncase))))
|
|
||||||
|
|
||||||
(define %prefix (if (string-prefix? "@PREFIX" "@PREFIX@") (or (getenv "MES_PREFIX") "") "@PREFIX@"))
|
|
||||||
(module-define! (resolve-module '(language c99 compiler)) '%prefix %prefix)
|
|
||||||
|
|
||||||
(define (parse-opts args)
|
|
||||||
(let* ((option-spec
|
|
||||||
'((c (single-char #\c))
|
|
||||||
(define (single-char #\D) (value #t))
|
|
||||||
(E (single-char #\E))
|
|
||||||
(g (single-char #\g))
|
|
||||||
(help (single-char #\h))
|
|
||||||
(include (single-char #\I) (value #t))
|
|
||||||
(o (single-char #\o) (value #t))
|
|
||||||
(version (single-char #\V) (value #t))))
|
|
||||||
(options (getopt-long args option-spec))
|
|
||||||
(help? (option-ref options 'help #f))
|
|
||||||
(files (option-ref options '() '()))
|
|
||||||
(usage? (and (not help?) (null? files)))
|
|
||||||
(version? (option-ref options 'version #f)))
|
|
||||||
(or
|
|
||||||
(and version?
|
|
||||||
(format (current-output-port) "mescc.scm (mes) ~a\n" %version))
|
|
||||||
(and (or help? usage?)
|
|
||||||
(format (or (and usage? (current-error-port)) (current-output-port)) "\
|
|
||||||
Usage: mescc.scm [OPTION]... FILE...
|
|
||||||
-c compile and assemble, but do not link
|
|
||||||
-D DEFINE define DEFINE
|
|
||||||
-E preprocess only; do not compile, assemble or link
|
|
||||||
-g add debug info [GDB, objdump] TODO: hex2 footer
|
|
||||||
-h, --help display this help and exit
|
|
||||||
-I DIR append DIR to include path
|
|
||||||
-o FILE write output to FILE
|
|
||||||
-v, --version display version and exit
|
|
||||||
")
|
|
||||||
(exit (or (and usage? 2) 0)))
|
|
||||||
options)))
|
|
||||||
|
|
||||||
(define (read-object file)
|
|
||||||
(let ((char (with-input-from-file file read-char)))
|
|
||||||
(if (eq? char #\#) (error "hex2 format not supported:" file)))
|
|
||||||
(with-input-from-file file read))
|
|
||||||
|
|
||||||
(define (main:ast->info file)
|
|
||||||
(let ((ast (with-input-from-file file read)))
|
|
||||||
(c99-ast->info ast)))
|
|
||||||
|
|
||||||
(define (source->ast defines includes)
|
|
||||||
(lambda (file)
|
|
||||||
(with-input-from-file file
|
|
||||||
(lambda ()
|
|
||||||
(pretty-print (c99-input->ast #:defines defines #:includes includes))))))
|
|
||||||
|
|
||||||
(define (source->info defines includes)
|
|
||||||
(lambda (file)
|
|
||||||
(with-input-from-file file
|
|
||||||
(lambda ()
|
|
||||||
((c99-input->info #:defines defines #:includes includes))))))
|
|
||||||
|
|
||||||
(define (ast? o)
|
|
||||||
(or (string-suffix? ".E" o)
|
|
||||||
(string-suffix? ".guile-E" o)))
|
|
||||||
|
|
||||||
(define (object? o)
|
|
||||||
(or (string-suffix? ".o" o)
|
|
||||||
(string-suffix? ".guile-o" o)))
|
|
||||||
|
|
||||||
(define (main args)
|
|
||||||
(let* ((options (parse-opts args))
|
|
||||||
(files (option-ref options '() '()))
|
|
||||||
(file (car files))
|
|
||||||
(preprocess? (option-ref options 'E #f))
|
|
||||||
(compile? (option-ref options 'c #f))
|
|
||||||
(debug-info? (option-ref options 'g #f))
|
|
||||||
(asts (filter ast? files))
|
|
||||||
(objects (filter object? files))
|
|
||||||
(sources (filter (cut string-suffix? ".c" <>) files))
|
|
||||||
(base (substring file (1+ (or (string-rindex file #\/) -1)) (- (string-length file) 2)))
|
|
||||||
(out (option-ref options 'o (cond (compile? (string-append base ".o"))
|
|
||||||
(preprocess? (string-append base ".E"))
|
|
||||||
(else "a.out"))))
|
|
||||||
(multi-opt (lambda (option) (lambda (o) (and (eq? (car o) option) (cdr o)))))
|
|
||||||
(defines (reverse (filter-map (multi-opt 'define) options)))
|
|
||||||
(includes (reverse (filter-map (multi-opt 'include) options))))
|
|
||||||
(setenv "NYACC_TRACE" "yes")
|
|
||||||
(when (getenv "MES_DEBUG") (format (current-error-port) "options=~s\n" options)
|
|
||||||
(format (current-error-port) "output: ~a\n" out))
|
|
||||||
(if (and (pair? sources) (pair? objects)) (error "cannot mix source and object files:" files))
|
|
||||||
(with-output-to-file out
|
|
||||||
(lambda ()
|
|
||||||
(if (and (not compile?)
|
|
||||||
(not preprocess?)) (set-port-encoding! (current-output-port) "ISO-8859-1"))
|
|
||||||
(cond ((pair? objects) (let ((objects (map read-object objects)))
|
|
||||||
(if compile? (objects->M1 objects)
|
|
||||||
(objects->elf objects))))
|
|
||||||
((pair? asts) (let* ((infos (map main:ast->info asts))
|
|
||||||
(objects (map info->object infos)))
|
|
||||||
(if compile? (objects->M1 objects)
|
|
||||||
(objects->elf objects))))
|
|
||||||
((pair? sources) (if preprocess? (map (source->ast defines includes) sources)
|
|
||||||
(let* ((infos (map (source->info defines includes) sources))
|
|
||||||
(objects (map info->object infos)))
|
|
||||||
(if compile? (objects->M1 objects)
|
|
||||||
(objects->elf objects))))))))
|
|
||||||
(if (and (not compile?)
|
|
||||||
(not preprocess?))
|
|
||||||
(chmod out #o755))))
|
|
|
@ -20,11 +20,9 @@ cp crt1.hex2 $MES_PREFIX/lib/crt1.hex2
|
||||||
cp libc-mes.hex2 $MES_PREFIX/lib/libc-mes.hex2
|
cp libc-mes.hex2 $MES_PREFIX/lib/libc-mes.hex2
|
||||||
cp libc+tcc-mes.hex2 $MES_PREFIX/lib/libc+tcc-mes.hex2
|
cp libc+tcc-mes.hex2 $MES_PREFIX/lib/libc+tcc-mes.hex2
|
||||||
|
|
||||||
cp scripts/mescc.mes $PREFIX/bin/mescc.mes
|
cp scripts/mescc $PREFIX/bin/mescc
|
||||||
sed -e "s,@PREFIX@,$MES_PREFIX,g" \
|
sed -e "s,@PREFIX@,$MES_PREFIX,g" \
|
||||||
scripts/mescc.mes > $PREFIX/bin/mescc.mes
|
scripts/mescc > $PREFIX/bin/mescc
|
||||||
sed -e "s,@PREFIX@,$MES_PREFIX,g" \
|
|
||||||
guile/mescc.scm > $PREFIX/bin/mescc.scm
|
|
||||||
|
|
||||||
mkdir -p $MES_PREFIX
|
mkdir -p $MES_PREFIX
|
||||||
tar -cf- doc guile include lib module scaffold stage0 | tar -xf- -C $MES_PREFIX
|
tar -cf- doc guile include lib module scaffold stage0 | tar -xf- -C $MES_PREFIX
|
||||||
|
|
8
make.scm
8
make.scm
|
@ -507,11 +507,7 @@ exec ${GUILE-guile} --no-auto-compile -L . -L guile -C . -C guile -s "$0" ${1+"$
|
||||||
|
|
||||||
(add-target (group "check-tests" #:dependencies (filter (target-prefix? "check-tests/") %targets)))
|
(add-target (group "check-tests" #:dependencies (filter (target-prefix? "check-tests/") %targets)))
|
||||||
|
|
||||||
;; FIXME: run tests/base.test
|
(add-target (install "scripts/mescc" #:dir "bin" #:substitutes #t))
|
||||||
(setenv "MES" "src/mes.guile")
|
|
||||||
|
|
||||||
(add-target (install "guile/mescc.scm" #:dir "bin" #:substitutes #t))
|
|
||||||
(add-target (install "scripts/mescc.mes" #:dir "bin" #:substitutes #t))
|
|
||||||
(define bootstrap? #f)
|
(define bootstrap? #f)
|
||||||
(if bootstrap?
|
(if bootstrap?
|
||||||
(add-target (install "src/mes.mes" #:dir "bin" #:installed-name "mes"))
|
(add-target (install "src/mes.mes" #:dir "bin" #:installed-name "mes"))
|
||||||
|
@ -539,7 +535,7 @@ exec ${GUILE-guile} --no-auto-compile -L . -L guile -C . -C guile -s "$0" ${1+"$
|
||||||
"module/mes/as.mes"
|
"module/mes/as.mes"
|
||||||
"module/mes/as.scm"
|
"module/mes/as.scm"
|
||||||
"module/mes/base.mes"
|
"module/mes/base.mes"
|
||||||
"module/mes/boot-0.scm"
|
;;"module/mes/boot-0.scm"
|
||||||
"module/mes/boot-00.scm"
|
"module/mes/boot-00.scm"
|
||||||
"module/mes/boot-01.scm"
|
"module/mes/boot-01.scm"
|
||||||
"module/mes/boot-02.scm"
|
"module/mes/boot-02.scm"
|
||||||
|
|
1
scripts/mes
Symbolic link
1
scripts/mes
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../src/mes.gcc
|
|
@ -1,5 +1,15 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
|
mes_p=$(type -p mes)
|
||||||
|
if [ '(' -z "$mes_p" -a -z "$MES" ')' -o "$MES" = "guile" -o "$MES" = "mes.guile" ]; then
|
||||||
|
GODIR=${GODIR-@GODIR@}
|
||||||
|
GUILEDIR=${GUILEDIR-@GUILEDIR@}
|
||||||
|
[ "$GODIR" = @"GODIR"@ ] && GODIR=$(dirname $0)
|
||||||
|
[ "$GUILEDIR" = @"GUILEDIR"@ ] && GUILEDIR=$(dirname $0)/../guile
|
||||||
|
export GUILE_AUTO_COMPILE=${GUILE_AUTO_COMPILE-0}
|
||||||
|
GUILE_LOAD_COMPILED_PATH=$GODIR:$GUILE_LOAD_COMPILED_PATH
|
||||||
|
exec ${GUILE-guile} -L $GUILEDIR -e '(mescc)' -s "$0" "$@"
|
||||||
|
else
|
||||||
MES=${MES-$(dirname $0)/mes}
|
MES=${MES-$(dirname $0)/mes}
|
||||||
PREFIX=${PREFIX-@PREFIX@}
|
PREFIX=${PREFIX-@PREFIX@}
|
||||||
MES_PREFIX=${MES_PREFIX-$PREFIX}
|
MES_PREFIX=${MES_PREFIX-$PREFIX}
|
||||||
|
@ -12,6 +22,7 @@ MES_MODULEDIR=${MES_MODULEDIR-$MES_PREFIX/"module"}
|
||||||
export MES_MODULEDIR
|
export MES_MODULEDIR
|
||||||
$MES -s $0 "$@"
|
$MES -s $0 "$@"
|
||||||
exit $?
|
exit $?
|
||||||
|
fi
|
||||||
!#
|
!#
|
||||||
|
|
||||||
;;; Mes --- Maxwell Equations of Software
|
;;; Mes --- Maxwell Equations of Software
|
||||||
|
@ -32,15 +43,38 @@ exit $?
|
||||||
;;; You should have received a copy of the GNU General Public License
|
;;; You should have received a copy of the GNU General Public License
|
||||||
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
;;; Commentary:
|
#!
|
||||||
|
Run with Guile-1.8:
|
||||||
|
GUILE='~/src/guile-1.8/build/pre-inst-guile --debug -q' scripts/mescc
|
||||||
|
!#
|
||||||
|
|
||||||
;;; mescc.mes is a proof-of-concept simplistic C compiler and linker
|
(define-module (mescc)
|
||||||
|
#:use-module (language c99 info)
|
||||||
|
#:use-module (language c99 compiler)
|
||||||
|
#:use-module (mes elf)
|
||||||
|
#:use-module (mes M1)
|
||||||
|
#:use-module (ice-9 getopt-long)
|
||||||
|
#:use-module (ice-9 pretty-print)
|
||||||
|
#:use-module (srfi srfi-1)
|
||||||
|
#:use-module (srfi srfi-26)
|
||||||
|
#:export (main))
|
||||||
|
|
||||||
;;; Code:
|
(define %prefix (if (string-prefix? "@PREFIX" "@PREFIX@") (or (getenv "MES_PREFIX") "") "@PREFIX@"))
|
||||||
|
|
||||||
;;LALR
|
(cond-expand
|
||||||
;;(mes-use-module (language c compiler))
|
(mes
|
||||||
;;Nyacc
|
(define %scheme "mes"))
|
||||||
|
(guile-2
|
||||||
|
(define %scheme "guile")
|
||||||
|
(define-macro (mes-use-module . rest) #t)
|
||||||
|
(module-define! (resolve-module '(language c99 compiler)) '%prefix %prefix))
|
||||||
|
(guile
|
||||||
|
(use-modules (ice-9 syncase))
|
||||||
|
(define %scheme "guile")
|
||||||
|
(define-macro (mes-use-module . rest) #t)
|
||||||
|
(module-define! (resolve-module '(language c99 compiler)) '%prefix %prefix)))
|
||||||
|
|
||||||
|
(define guile? (equal? %scheme "guile"))
|
||||||
|
|
||||||
(mes-use-module (mes guile))
|
(mes-use-module (mes guile))
|
||||||
(mes-use-module (mes getopt-long))
|
(mes-use-module (mes getopt-long))
|
||||||
|
@ -53,9 +87,7 @@ exit $?
|
||||||
(mes-use-module (srfi srfi-1))
|
(mes-use-module (srfi srfi-1))
|
||||||
(mes-use-module (srfi srfi-26))
|
(mes-use-module (srfi srfi-26))
|
||||||
|
|
||||||
(format (current-error-port) "mescc.mes...\n")
|
(format (current-error-port) "mescc[~a]...\n" %scheme)
|
||||||
|
|
||||||
(define %prefix (if (string-prefix? "@PREFIX" "@PREFIX@") (or (getenv "MES_PREFIX") "") "@PREFIX@"))
|
|
||||||
|
|
||||||
(define (parse-opts args)
|
(define (parse-opts args)
|
||||||
(let* ((option-spec
|
(let* ((option-spec
|
||||||
|
@ -66,7 +98,8 @@ exit $?
|
||||||
(help (single-char #\h))
|
(help (single-char #\h))
|
||||||
(include (single-char #\I) (value #t))
|
(include (single-char #\I) (value #t))
|
||||||
(o (single-char #\o) (value #t))
|
(o (single-char #\o) (value #t))
|
||||||
(version (single-char #\V))))
|
(version (single-char #\V))
|
||||||
|
(write (single-char #\w) (value #t))))
|
||||||
(options (getopt-long args option-spec))
|
(options (getopt-long args option-spec))
|
||||||
(help? (option-ref options 'help #f))
|
(help? (option-ref options 'help #f))
|
||||||
(files (option-ref options '() '()))
|
(files (option-ref options '() '()))
|
||||||
|
@ -74,10 +107,10 @@ exit $?
|
||||||
(version? (option-ref options 'version #f)))
|
(version? (option-ref options 'version #f)))
|
||||||
(or
|
(or
|
||||||
(and version?
|
(and version?
|
||||||
(format (current-output-port) "mescc.scm (mes) ~a\n" %version))
|
(format (current-output-port) "mescc (mes) ~a\n" %version))
|
||||||
(and (or help? usage?)
|
(and (or help? usage?)
|
||||||
(format (or (and usage? (current-error-port)) (current-output-port)) "\
|
(format (or (and usage? (current-error-port)) (current-output-port)) "\
|
||||||
Usage: mescc.mes [OPTION]... FILE...
|
Usage: mescc [OPTION]... FILE...
|
||||||
-c compile and assemble, but do not link
|
-c compile and assemble, but do not link
|
||||||
-D DEFINE define DEFINE
|
-D DEFINE define DEFINE
|
||||||
-E preprocess only; do not compile, assemble or link
|
-E preprocess only; do not compile, assemble or link
|
||||||
|
@ -86,6 +119,13 @@ Usage: mescc.mes [OPTION]... FILE...
|
||||||
-I DIR append DIR to include path
|
-I DIR append DIR to include path
|
||||||
-o FILE write output to FILE
|
-o FILE write output to FILE
|
||||||
-v, --version display version and exit
|
-v, --version display version and exit
|
||||||
|
-w,--write=TYPE dump Nyacc AST using TYPE {pretty-print,write}
|
||||||
|
|
||||||
|
Environment variables:
|
||||||
|
|
||||||
|
MES=BINARY run on mes-executable BINARY {mes,guile}
|
||||||
|
MES_DEBUG=LEVEL show debug output with verbosity LEVEL {0..5}
|
||||||
|
NYACC_TRACE=1 show Nyacc progress
|
||||||
")
|
")
|
||||||
(exit (or (and usage? 2) 0)))
|
(exit (or (and usage? 2) 0)))
|
||||||
options)))
|
options)))
|
||||||
|
@ -99,7 +139,7 @@ Usage: mescc.mes [OPTION]... FILE...
|
||||||
(let ((ast (with-input-from-file file read)))
|
(let ((ast (with-input-from-file file read)))
|
||||||
(c99-ast->info ast)))
|
(c99-ast->info ast)))
|
||||||
|
|
||||||
(define (source->ast defines includes)
|
(define (source->ast write defines includes)
|
||||||
(lambda (file)
|
(lambda (file)
|
||||||
(with-input-from-file file
|
(with-input-from-file file
|
||||||
(lambda ()
|
(lambda ()
|
||||||
|
@ -113,11 +153,11 @@ Usage: mescc.mes [OPTION]... FILE...
|
||||||
|
|
||||||
(define (ast? o)
|
(define (ast? o)
|
||||||
(or (string-suffix? ".E" o)
|
(or (string-suffix? ".E" o)
|
||||||
(string-suffix? ".mes-E" o)))
|
(string-suffix? (string-append "." %scheme "-E") o)))
|
||||||
|
|
||||||
(define (object? o)
|
(define (object? o)
|
||||||
(or (string-suffix? ".o" o)
|
(or (string-suffix? ".o" o)
|
||||||
(string-suffix? ".mes-o" o)))
|
(string-suffix? (string-append "." %scheme "-o") o)))
|
||||||
|
|
||||||
(define (main args)
|
(define (main args)
|
||||||
(let* ((options (parse-opts args))
|
(let* ((options (parse-opts args))
|
||||||
|
@ -135,14 +175,18 @@ Usage: mescc.mes [OPTION]... FILE...
|
||||||
(else "a.out"))))
|
(else "a.out"))))
|
||||||
(multi-opt (lambda (option) (lambda (o) (and (eq? (car o) option) (cdr o)))))
|
(multi-opt (lambda (option) (lambda (o) (and (eq? (car o) option) (cdr o)))))
|
||||||
(defines (reverse (filter-map (multi-opt 'define) options)))
|
(defines (reverse (filter-map (multi-opt 'define) options)))
|
||||||
(includes (reverse (filter-map (multi-opt 'include) options))))
|
(includes (reverse (filter-map (multi-opt 'include) options)))
|
||||||
|
(pretty-print/write (string->symbol (option-ref options 'write (if guile? "pretty-print" "write"))))
|
||||||
|
(pretty-print/write (if (eq? pretty-print/write 'pretty-print) pretty-print write)))
|
||||||
|
(when (getenv "MES_DEBUG")
|
||||||
(setenv "NYACC_TRACE" "yes")
|
(setenv "NYACC_TRACE" "yes")
|
||||||
(when (getenv "MES_DEBUG") (format (current-error-port) "options=~s\n" options)
|
(format (current-error-port) "options=~s\n" options)
|
||||||
(format (current-error-port) "output: ~a\n" out))
|
(format (current-error-port) "output: ~a\n" out))
|
||||||
(if (and (pair? sources) (pair? objects)) (error "cannot mix source and object files:" files))
|
(if (and (pair? sources) (pair? objects)) (error "cannot mix source and object files:" files))
|
||||||
(with-output-to-port (open-output-file out (if (and (not compile?)
|
(with-output-to-file out
|
||||||
(not preprocess?)) S_IRWXU))
|
|
||||||
(lambda ()
|
(lambda ()
|
||||||
|
(if (and (not compile?)
|
||||||
|
(not preprocess?)) (set-port-encoding! (current-output-port) "ISO-8859-1"))
|
||||||
(cond ((pair? objects) (let ((objects (map read-object objects)))
|
(cond ((pair? objects) (let ((objects (map read-object objects)))
|
||||||
(if compile? (objects->M1 objects)
|
(if compile? (objects->M1 objects)
|
||||||
(objects->elf objects))))
|
(objects->elf objects))))
|
||||||
|
@ -150,7 +194,7 @@ Usage: mescc.mes [OPTION]... FILE...
|
||||||
(objects (map info->object infos)))
|
(objects (map info->object infos)))
|
||||||
(if compile? (objects->M1 objects)
|
(if compile? (objects->M1 objects)
|
||||||
(objects->elf objects))))
|
(objects->elf objects))))
|
||||||
((pair? sources) (if preprocess? (map (source->ast defines includes) sources)
|
((pair? sources) (if preprocess? (map (source->ast pretty-print/write defines includes) sources)
|
||||||
(let* ((infos (map (source->info defines includes) sources))
|
(let* ((infos (map (source->info defines includes) sources))
|
||||||
(objects (map info->object infos)))
|
(objects (map info->object infos)))
|
||||||
(if compile? (objects->M1 objects)
|
(if compile? (objects->M1 objects)
|
3
test.sh
3
test.sh
|
@ -26,7 +26,8 @@ rm -f "$t".mes-out
|
||||||
|
|
||||||
M1=${M1-M1}
|
M1=${M1-M1}
|
||||||
HEX2=${HEX2-hex2}
|
HEX2=${HEX2-hex2}
|
||||||
MESCC=${MESCC-guile/mescc.scm}
|
MES=${MES-guile}
|
||||||
|
MESCC=${MESCC-scripts/mescc}
|
||||||
|
|
||||||
sh $MESCC -E -o scaffold/tests/$t.E scaffold/tests/$t.c
|
sh $MESCC -E -o scaffold/tests/$t.E scaffold/tests/$t.c
|
||||||
sh $MESCC -c -o scaffold/tests/$t.M1 scaffold/tests/$t.E
|
sh $MESCC -c -o scaffold/tests/$t.M1 scaffold/tests/$t.E
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
!#
|
!#
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
export MES_BOOT=boot-02.scm
|
export MES_BOOT=boot-02.scm
|
||||||
$MES < $0
|
$MES < $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
!#
|
!#
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-166000000}
|
#export MES_ARENA=${MES_ARENA-166000000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-200000}
|
#export MES_ARENA=${MES_ARENA-200000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
#paredit:||
|
#paredit:||
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
# ***REMOVE THIS BLOCK COMMENT INITIALLY***
|
# ***REMOVE THIS BLOCK COMMENT INITIALLY***
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
!#
|
!#
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# -*-scheme-*-
|
# -*-scheme-*-
|
||||||
MES=${MES-$(dirname $0)/../src/mes}
|
MES=${MES-$(dirname $0)/../src/mes.gcc}
|
||||||
#export MES_ARENA=${MES_ARENA-40000}
|
#export MES_ARENA=${MES_ARENA-40000}
|
||||||
$MES -s $0
|
$MES -s $0
|
||||||
exit $?
|
exit $?
|
||||||
|
|
Loading…
Reference in a new issue