Compare commits
7 Commits
6f7b28cfa5
...
67749c8db0
| Author | SHA1 | Date | |
|---|---|---|---|
| 67749c8db0 | |||
| faa9036dcc | |||
| c33bfd704d | |||
| 397766822d | |||
| a504fc1410 | |||
| c65721a070 | |||
| dcb65c5504 |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -5,10 +5,11 @@
|
|||||||
*.o
|
*.o
|
||||||
*.import.scm
|
*.import.scm
|
||||||
*.link
|
*.link
|
||||||
modules.mk
|
/modules.mk
|
||||||
sexc
|
/modules.stamp
|
||||||
sex-tests
|
/sexc
|
||||||
sextest
|
/sex-tests
|
||||||
|
/sextest
|
||||||
|
|
||||||
# Scrapped design docs, kept for reference
|
# Scrapped design docs, kept for reference
|
||||||
/attic
|
/attic
|
||||||
|
|||||||
54
Makefile
54
Makefile
@@ -1,5 +1,6 @@
|
|||||||
CHICKEN_C ?= csc
|
CHICKEN_C ?= csc
|
||||||
CSI ?= csi
|
# beside csc, whatever it is called: chicken-csc comes with chicken-csi
|
||||||
|
CSI ?= $(patsubst %csc,%csi,$(CHICKEN_C))
|
||||||
CSC_FLAGS += -K prefix -static
|
CSC_FLAGS += -K prefix -static
|
||||||
# What and why:
|
# What and why:
|
||||||
# -emit-all-import-libraries: Emit import-libraries for all defined modules.
|
# -emit-all-import-libraries: Emit import-libraries for all defined modules.
|
||||||
@@ -38,28 +39,37 @@ include eggs.mk
|
|||||||
|
|
||||||
# Each program, and the source it is built from
|
# Each program, and the source it is built from
|
||||||
PROGRAMS = sexc=main.scm sextest=tools/sextest/sextest.scm sex-tests=tests/run.scm
|
PROGRAMS = sexc=main.scm sextest=tools/sextest/sextest.scm sex-tests=tests/run.scm
|
||||||
|
PROGRAM_NAMES = $(foreach p,$(PROGRAMS),$(firstword $(subst =, ,$(p))))
|
||||||
|
PROGRAM_OBJ = $(foreach p,$(PROGRAMS),$(patsubst %.scm,%.o,$(lastword $(subst =, ,$(p)))))
|
||||||
|
|
||||||
# MODULES, the programs' names and objects, and a line for each naming
|
# MODULES, and a line for each module and program naming what it
|
||||||
# what it imports, read off the import forms
|
# imports, read off the import forms. Not for clean, which has to work
|
||||||
|
# when they cannot be read
|
||||||
|
ifneq ($(MAKECMDGOALS),clean)
|
||||||
include modules.mk
|
include modules.mk
|
||||||
OBJ = $(MODULES:%=%.o)
|
endif
|
||||||
|
|
||||||
modules.mk: $(SOURCES) tools/module-deps.scm dependencies.txt
|
# The scan is redone whenever a source may have changed what it
|
||||||
$(CSI) -s tools/module-deps.scm $(PROGRAMS) > $@.tmp
|
# imports, or a NAME.scm may have come to be the module an import
|
||||||
mv $@.tmp $@
|
# names; but modules.mk is rewritten only when that changed, since make
|
||||||
|
# starts over each time it is, and a source dated in the future would
|
||||||
|
# have it start over for good
|
||||||
|
modules.mk: modules.stamp ;
|
||||||
|
|
||||||
|
modules.stamp: $(SOURCES) $(filter-out %.import.scm,$(wildcard *.scm)) \
|
||||||
|
tools/module-deps.scm dependencies.txt Makefile
|
||||||
|
$(CSI) -s tools/module-deps.scm $(PROGRAMS) > modules.mk.tmp \
|
||||||
|
|| { rm -f modules.mk.tmp; exit 1; }
|
||||||
|
if cmp -s modules.mk.tmp modules.mk; then rm modules.mk.tmp; \
|
||||||
|
else mv modules.mk.tmp modules.mk; fi
|
||||||
|
touch $@
|
||||||
|
|
||||||
#------------------------------------------------------------------
|
#------------------------------------------------------------------
|
||||||
|
|
||||||
# Everything is linked with the modules among its prerequisites
|
|
||||||
LINKS = $(addprefix -link ,$(basename $(filter-out $<,$(filter %.o,$^))))
|
|
||||||
|
|
||||||
# A module is one file that declares its own exports, made a module by
|
# A module is one file that declares its own exports, made a module by
|
||||||
# -module, except the vendored sex-fmt-c, a (module ...) form of its own
|
# -module, except the vendored sex-fmt-c, a (module ...) form of its own
|
||||||
MODULE = -module $*
|
|
||||||
sex-fmt-c.o: MODULE =
|
|
||||||
|
|
||||||
%.o: %.scm
|
%.o: %.scm
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) $< $(MODULE) -o $@ -unit $* $(LINKS)
|
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) $< $(if $(filter sex-fmt-c,$*),,-module $*) -o $@ -unit $*
|
||||||
|
|
||||||
# A program's object is named after its source: csc names its own after
|
# A program's object is named after its source: csc names its own after
|
||||||
# -o, and sexc.o is the module's
|
# -o, and sexc.o is the module's
|
||||||
@@ -67,7 +77,7 @@ $(PROGRAM_OBJ): %.o: %.scm
|
|||||||
$(CHICKEN_C) $(CSC_FLAGS) -c $< -o $@
|
$(CHICKEN_C) $(CSC_FLAGS) -c $< -o $@
|
||||||
|
|
||||||
$(PROGRAM_NAMES):
|
$(PROGRAM_NAMES):
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $< -o $@ $(LINKS)
|
$(CHICKEN_C) $(CSC_FLAGS) $< -o $@
|
||||||
|
|
||||||
# A program directly in tests/sex-programs is a test; lib/ holds what
|
# A program directly in tests/sex-programs is a test; lib/ holds what
|
||||||
# they import
|
# they import
|
||||||
@@ -76,8 +86,12 @@ SEX_TEST_PROGRAMS = $(wildcard tests/sex-programs/*.sex)
|
|||||||
check run-tests: sexc sex-tests sextest
|
check run-tests: sexc sex-tests sextest
|
||||||
./sex-tests
|
./sex-tests
|
||||||
./sextest --sexc=./sexc $(SEX_TEST_PROGRAMS)
|
./sextest --sexc=./sexc $(SEX_TEST_PROGRAMS)
|
||||||
cd tests/modules && SEXC=$(CURDIR)/sexc $(CSI) -s check.scm
|
@$(MAKE) --no-print-directory check-modules
|
||||||
cd tests/exit-code && SEXC=$(CURDIR)/sexc $(CSI) -s check.scm
|
@$(MAKE) --no-print-directory check-exit-code
|
||||||
|
|
||||||
|
# The end-to-end checks, each on its own: run with the eggs on the path
|
||||||
|
check-modules check-exit-code: check-%: sexc
|
||||||
|
cd tests/$* && SEXC='$(CURDIR)/sexc' $(CSI) -s check.scm
|
||||||
|
|
||||||
install: all installdirs
|
install: all installdirs
|
||||||
$(INSTALL_PROGRAM) sexc $(DESTDIR)$(bindir)/sexc
|
$(INSTALL_PROGRAM) sexc $(DESTDIR)$(bindir)/sexc
|
||||||
@@ -95,9 +109,9 @@ uninstall:
|
|||||||
-rmdir $(DESTDIR)$(sexlibdir)
|
-rmdir $(DESTDIR)$(sexlibdir)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJ) $(PROGRAM_OBJ) modules.mk
|
rm -f *.o $(PROGRAM_OBJ) modules.mk modules.stamp
|
||||||
rm -f *.import.scm
|
rm -f *.import.scm
|
||||||
rm -f *.link $(PROGRAM_OBJ:.o=.link)
|
rm -f *.link $(PROGRAM_OBJ:.o=.link)
|
||||||
rm -f sexc sex-tests sextest
|
rm -f $(PROGRAM_NAMES)
|
||||||
|
|
||||||
.PHONY: all check run-tests install install-strip installdirs uninstall clean
|
.PHONY: all check run-tests check-modules check-exit-code install install-strip installdirs uninstall clean
|
||||||
|
|||||||
@@ -10,20 +10,22 @@
|
|||||||
;;; Everything is built inside a scratch directory, so nothing is left
|
;;; Everything is built inside a scratch directory, so nothing is left
|
||||||
;;; here to clean up.
|
;;; here to clean up.
|
||||||
;;;
|
;;;
|
||||||
;;; csi -s check.scm
|
;;; make check-exit-code
|
||||||
|
|
||||||
(import scheme
|
(import scheme
|
||||||
(chicken base)
|
(chicken base)
|
||||||
(chicken file)
|
(chicken file)
|
||||||
(chicken io)
|
|
||||||
(chicken pathname)
|
(chicken pathname)
|
||||||
(chicken process)
|
(chicken process)
|
||||||
(chicken process-context)
|
(chicken process-context)
|
||||||
|
(chicken string)
|
||||||
test)
|
test)
|
||||||
|
|
||||||
|
;;; A path stays good past the change of directory below; a bare name
|
||||||
|
;;; is looked up on PATH
|
||||||
(define sexc
|
(define sexc
|
||||||
(let ((path (or (get-environment-variable "SEXC") "../../sexc")))
|
(let ((path (or (get-environment-variable "SEXC") "../../sexc")))
|
||||||
(if (absolute-pathname? path)
|
(if (or (absolute-pathname? path) (not (substring-index "/" path)))
|
||||||
path
|
path
|
||||||
(make-pathname (current-directory) path))))
|
(make-pathname (current-directory) path))))
|
||||||
|
|
||||||
@@ -33,12 +35,13 @@
|
|||||||
|
|
||||||
;;; Whether sexc exits 0 when run with ARGS, saying nothing of it
|
;;; Whether sexc exits 0 when run with ARGS, saying nothing of it
|
||||||
(define (sexc-succeeds? . args)
|
(define (sexc-succeeds? . args)
|
||||||
(let ((proc (process* sexc args)))
|
(zero? (system (string-append (string-intersperse (map qs (cons sexc args)))
|
||||||
(read-string #f (process-output-port proc))
|
" >/dev/null 2>&1"))))
|
||||||
(read-string #f (process-error-port proc))
|
|
||||||
(process-wait proc)
|
;;; Every check below expects a failure, which a sexc that cannot run
|
||||||
(and (process-returned-normally? proc)
|
;;; gives too
|
||||||
(zero? (process-exit-status proc)))))
|
(test "sexc compiles a program" #t
|
||||||
|
(sexc-succeeds? "hello.sex" "-o" out))
|
||||||
|
|
||||||
(test "a failed emission leaves no temporary .c" '()
|
(test "a failed emission leaves no temporary .c" '()
|
||||||
(begin
|
(begin
|
||||||
|
|||||||
@@ -28,13 +28,14 @@
|
|||||||
;;; and ledger, which only greet does but which decides what the app is
|
;;; and ledger, which only greet does but which decides what the app is
|
||||||
;;; told of it.
|
;;; told of it.
|
||||||
;;;
|
;;;
|
||||||
;;; csi -s check.scm
|
;;; make check-modules
|
||||||
|
|
||||||
(import scheme
|
(import scheme
|
||||||
(chicken base)
|
(chicken base)
|
||||||
(chicken file)
|
(chicken file)
|
||||||
(chicken io)
|
(chicken io)
|
||||||
(chicken irregex)
|
(chicken irregex)
|
||||||
|
(chicken pathname)
|
||||||
(chicken process)
|
(chicken process)
|
||||||
(chicken process-context)
|
(chicken process-context)
|
||||||
srfi-1
|
srfi-1
|
||||||
@@ -42,6 +43,11 @@
|
|||||||
|
|
||||||
(define sexc (or (get-environment-variable "SEXC") "../../sexc"))
|
(define sexc (or (get-environment-variable "SEXC") "../../sexc"))
|
||||||
|
|
||||||
|
;;; Where the objects and the app go: not beside the sources, where what
|
||||||
|
;;; an earlier run left would pass for what this one did not build
|
||||||
|
(define scratch (create-temporary-directory))
|
||||||
|
(define (built name) (make-pathname scratch name))
|
||||||
|
|
||||||
;;; The lines PROGRAM prints when run with ARGS, or #f when it fails
|
;;; The lines PROGRAM prints when run with ARGS, or #f when it fails
|
||||||
(define (output-of program . args)
|
(define (output-of program . args)
|
||||||
(let* ((proc (process program args))
|
(let* ((proc (process program args))
|
||||||
@@ -56,14 +62,15 @@
|
|||||||
(take (or (output-of sexc "--public-interface" "greet.sex") '()) 3))
|
(take (or (output-of sexc "--public-interface" "greet.sex") '()) 3))
|
||||||
|
|
||||||
(test-assert "the app links with both modules"
|
(test-assert "the app links with both modules"
|
||||||
(and (output-of sexc "ledger.sex" "-c" "-o" "ledger.o")
|
(and (output-of sexc "ledger.sex" "-c" "-o" (built "ledger.o"))
|
||||||
(output-of sexc "greet.sex" "-c" "-o" "greet.o")
|
(output-of sexc "greet.sex" "-c" "-o" (built "greet.o"))
|
||||||
(output-of sexc "greet-app.sex" "-o" "greet-app" "--depfile=greet-app.d"
|
(output-of sexc "greet-app.sex" "-o" (built "greet-app")
|
||||||
"--" "greet.o" "ledger.o")))
|
(string-append "--depfile=" (built "greet-app.d"))
|
||||||
|
"--" (built "greet.o") (built "ledger.o"))))
|
||||||
|
|
||||||
(test-assert "the dependency rule names both modules"
|
(test-assert "the dependency rule names both modules"
|
||||||
(irregex-match "greet-app: greet-app\\.sex .*/greet\\.sex .*/ledger\\.sex"
|
(irregex-match ".*/greet-app: greet-app\\.sex .*/greet\\.sex .*/ledger\\.sex"
|
||||||
(call-with-input-file "greet-app.d" read-line)))
|
(call-with-input-file (built "greet-app.d") read-line)))
|
||||||
|
|
||||||
(test "the app runs through both"
|
(test "the app runs through both"
|
||||||
'("hello, world"
|
'("hello, world"
|
||||||
@@ -79,8 +86,8 @@
|
|||||||
"board 42"
|
"board 42"
|
||||||
"ledger 2"
|
"ledger 2"
|
||||||
"colour 123")
|
"colour 123")
|
||||||
(output-of "./greet-app"))
|
(output-of (built "greet-app")))
|
||||||
|
|
||||||
(for-each delete-file* '("greet.o" "ledger.o" "greet-app" "greet-app.d"))
|
(delete-directory scratch #t)
|
||||||
|
|
||||||
(test-exit)
|
(test-exit)
|
||||||
|
|||||||
@@ -1,23 +1,28 @@
|
|||||||
;;; The compiler's modules and the programs built from them, as make
|
;;; The compiler's modules and the programs built from them, as make
|
||||||
;;; reads them: what each one imports, read off its import forms. A
|
;;; reads them: what each one imports, read off its import forms. A
|
||||||
;;; module is a NAME.scm in the current directory; a program is named
|
;;; module is a NAME.scm in the current directory; a program is named
|
||||||
;;; with its source, whose include-relative files count as its own.
|
;;; with its source. The files either includes with include-relative
|
||||||
|
;;; count as its own.
|
||||||
;;;
|
;;;
|
||||||
;;; csi -s tools/module-deps.scm sexc=main.scm > modules.mk
|
;;; csi -s tools/module-deps.scm sexc=main.scm > modules.mk
|
||||||
;;;
|
;;;
|
||||||
;;; prints
|
;;; prints
|
||||||
;;;
|
;;;
|
||||||
;;; MODULES = fmt-c-writer infer reader ...
|
;;; MODULES = fmt-c-writer infer reader ...
|
||||||
;;; PROGRAM_NAMES = sexc
|
|
||||||
;;; PROGRAM_OBJ = main.o
|
|
||||||
;;; SOURCES = fmt-c-writer.scm infer.scm ... main.scm
|
;;; SOURCES = fmt-c-writer.scm infer.scm ... main.scm
|
||||||
;;; infer.o: types.o utils.o
|
;;; infer.o: types.o utils.o
|
||||||
;;; ...
|
;;; ...
|
||||||
;;; main.o: sexc.o
|
;;; main.o: sexc.o
|
||||||
;;; sexc: main.o sexc.o
|
;;; sexc: main.o sexc.o
|
||||||
|
;;; fmt-c-writer.scm:
|
||||||
|
;;; ...
|
||||||
|
;;;
|
||||||
|
;;; and a source deleted since is then one make has nothing to do for,
|
||||||
|
;;; rather than one it has no rule to make
|
||||||
|
|
||||||
(import scheme
|
(import scheme
|
||||||
(chicken base)
|
(chicken base)
|
||||||
|
(chicken condition)
|
||||||
(chicken file)
|
(chicken file)
|
||||||
(chicken io)
|
(chicken io)
|
||||||
(chicken pathname)
|
(chicken pathname)
|
||||||
@@ -44,14 +49,28 @@
|
|||||||
(let ((file (string-append (symbol->string name) ".scm")))
|
(let ((file (string-append (symbol->string name) ".scm")))
|
||||||
(and (file-exists? file) file))))
|
(and (file-exists? file) file))))
|
||||||
|
|
||||||
;;; The names FILE imports, and the files it includes
|
;;; FILE's forms, or the end of the scan, naming the file that has none
|
||||||
|
(define (forms-of file)
|
||||||
|
(handle-exceptions exn
|
||||||
|
(begin
|
||||||
|
(display (string-append "module-deps: " file ": "
|
||||||
|
((condition-property-accessor 'exn 'message "") exn)
|
||||||
|
"\n")
|
||||||
|
(current-error-port))
|
||||||
|
(exit 1))
|
||||||
|
(call-with-input-file file read-list)))
|
||||||
|
|
||||||
|
;;; The names FILE imports, and the files it includes; the vendored
|
||||||
|
;;; sex-fmt-c imports inside its (module name exports ...) form
|
||||||
(define (scan file)
|
(define (scan file)
|
||||||
(let loop ((forms (call-with-input-file file read-list)) (names '()) (files '()))
|
(let loop ((forms (forms-of file)) (names '()) (files '()))
|
||||||
(if (null? forms)
|
(if (null? forms)
|
||||||
(values names files)
|
(values names files)
|
||||||
(let ((form (car forms)))
|
(let ((form (car forms)))
|
||||||
(cond
|
(cond
|
||||||
((not (pair? form)) (loop (cdr forms) names files))
|
((not (pair? form)) (loop (cdr forms) names files))
|
||||||
|
((and (eq? (car form) 'module) (list? form) (>= (length form) 3))
|
||||||
|
(loop (append (cdddr form) (cdr forms)) names files))
|
||||||
((eq? (car form) 'import)
|
((eq? (car form) 'import)
|
||||||
(loop (cdr forms) (append (map spec-name (cdr form)) names) files))
|
(loop (cdr forms) (append (map spec-name (cdr form)) names) files))
|
||||||
((eq? (car form) 'include-relative)
|
((eq? (car form) 'include-relative)
|
||||||
@@ -73,19 +92,16 @@
|
|||||||
(loop (cdr names) acc))
|
(loop (cdr names) acc))
|
||||||
(else (loop (cdr names) (cons (car names) acc))))))
|
(else (loop (cdr names) (cons (car names) acc))))))
|
||||||
|
|
||||||
(define (imported-modules file)
|
;;; Each module reached from ROOTS, as (name imported-modules . included-files)
|
||||||
(let-values (((names files) (scan file)))
|
|
||||||
(local-modules names)))
|
|
||||||
|
|
||||||
;;; Each module reached from ROOTS, with the modules it imports
|
|
||||||
(define (module-graph roots)
|
(define (module-graph roots)
|
||||||
(let loop ((pending roots) (graph '()))
|
(let loop ((pending roots) (graph '()))
|
||||||
(cond ((null? pending) (sort graph (lambda (a b) (symbol<? (car a) (car b)))))
|
(cond ((null? pending) (sort graph (lambda (a b) (symbol<? (car a) (car b)))))
|
||||||
((assq (car pending) graph) (loop (cdr pending) graph))
|
((assq (car pending) graph) (loop (cdr pending) graph))
|
||||||
(else
|
(else
|
||||||
(let ((deps (imported-modules (module-file (car pending)))))
|
(let-values (((names files) (scan (module-file (car pending)))))
|
||||||
(loop (append (cdr pending) deps)
|
(let ((deps (local-modules names)))
|
||||||
(cons (cons (car pending) deps) graph)))))))
|
(loop (append (cdr pending) deps)
|
||||||
|
(cons (cons (car pending) (cons deps files)) graph))))))))
|
||||||
|
|
||||||
(define (objects names)
|
(define (objects names)
|
||||||
(map (lambda (name) (string-append (symbol->string name) ".o")) names))
|
(map (lambda (name) (string-append (symbol->string name) ".o")) names))
|
||||||
@@ -96,9 +112,9 @@
|
|||||||
|
|
||||||
;;; sexc=main.scm, read off main.scm and the files it includes
|
;;; sexc=main.scm, read off main.scm and the files it includes
|
||||||
(define-record-type program
|
(define-record-type program
|
||||||
(make-program name object modules sources)
|
(make-program binary object modules sources)
|
||||||
program?
|
program?
|
||||||
(name program-name)
|
(binary program-binary)
|
||||||
(object program-object)
|
(object program-object)
|
||||||
(modules program-modules)
|
(modules program-modules)
|
||||||
(sources program-sources))
|
(sources program-sources))
|
||||||
@@ -114,17 +130,19 @@
|
|||||||
(let* ((programs (map read-program (command-line-arguments)))
|
(let* ((programs (map read-program (command-line-arguments)))
|
||||||
(graph (module-graph
|
(graph (module-graph
|
||||||
(local-modules (apply append (map program-modules programs))))))
|
(local-modules (apply append (map program-modules programs))))))
|
||||||
|
(define sources
|
||||||
|
(append (apply append (map (lambda (node) (cons (module-file (car node)) (cddr node)))
|
||||||
|
graph))
|
||||||
|
(apply append (map program-sources programs))))
|
||||||
(print "MODULES = " (string-intersperse (map (o symbol->string car) graph) " "))
|
(print "MODULES = " (string-intersperse (map (o symbol->string car) graph) " "))
|
||||||
(print "PROGRAM_NAMES = " (string-intersperse (map program-name programs) " "))
|
(print "SOURCES = " (string-intersperse sources " "))
|
||||||
(print "PROGRAM_OBJ = " (string-intersperse (map program-object programs) " "))
|
(for-each (lambda (node)
|
||||||
(print "SOURCES = "
|
(rule (car (objects (list (car node))))
|
||||||
(string-intersperse (append (map (o module-file car) graph)
|
(append (cddr node) (objects (cadr node)))))
|
||||||
(apply append (map program-sources programs)))
|
|
||||||
" "))
|
|
||||||
(for-each (lambda (node) (rule (car (objects (list (car node)))) (objects (cdr node))))
|
|
||||||
graph)
|
graph)
|
||||||
(for-each (lambda (p)
|
(for-each (lambda (p)
|
||||||
(let ((modules (objects (program-modules p))))
|
(let ((modules (objects (program-modules p))))
|
||||||
(rule (program-object p) (append (cdr (program-sources p)) modules))
|
(rule (program-object p) (append (cdr (program-sources p)) modules))
|
||||||
(rule (program-name p) (cons (program-object p) modules))))
|
(rule (program-binary p) (cons (program-object p) modules))))
|
||||||
programs))
|
programs)
|
||||||
|
(for-each (lambda (source) (print source ":")) sources))
|
||||||
|
|||||||
Reference in New Issue
Block a user