Compare commits
8 Commits
67749c8db0
...
6f7b28cfa5
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f7b28cfa5 | |||
| 76a521b4b9 | |||
| 20151ece1b | |||
| 7547deb8dd | |||
| 4b5f3ffd6b | |||
| a6e9b3c948 | |||
| b49f72e387 | |||
| ed369a8ff7 |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -5,11 +5,10 @@
|
|||||||
*.o
|
*.o
|
||||||
*.import.scm
|
*.import.scm
|
||||||
*.link
|
*.link
|
||||||
/modules.mk
|
modules.mk
|
||||||
/modules.stamp
|
sexc
|
||||||
/sexc
|
sex-tests
|
||||||
/sex-tests
|
sextest
|
||||||
/sextest
|
|
||||||
|
|
||||||
# Scrapped design docs, kept for reference
|
# Scrapped design docs, kept for reference
|
||||||
/attic
|
/attic
|
||||||
|
|||||||
54
Makefile
54
Makefile
@@ -1,6 +1,5 @@
|
|||||||
CHICKEN_C ?= csc
|
CHICKEN_C ?= csc
|
||||||
# beside csc, whatever it is called: chicken-csc comes with chicken-csi
|
CSI ?= 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.
|
||||||
@@ -39,37 +38,28 @@ 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, and a line for each module and program naming what it
|
# MODULES, the programs' names and objects, and a line for each naming
|
||||||
# imports, read off the import forms. Not for clean, which has to work
|
# what it imports, read off the import forms
|
||||||
# when they cannot be read
|
|
||||||
ifneq ($(MAKECMDGOALS),clean)
|
|
||||||
include modules.mk
|
include modules.mk
|
||||||
endif
|
OBJ = $(MODULES:%=%.o)
|
||||||
|
|
||||||
# The scan is redone whenever a source may have changed what it
|
modules.mk: $(SOURCES) tools/module-deps.scm dependencies.txt
|
||||||
# imports, or a NAME.scm may have come to be the module an import
|
$(CSI) -s tools/module-deps.scm $(PROGRAMS) > $@.tmp
|
||||||
# names; but modules.mk is rewritten only when that changed, since make
|
mv $@.tmp $@
|
||||||
# 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) $< $(if $(filter sex-fmt-c,$*),,-module $*) -o $@ -unit $*
|
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) $< $(MODULE) -o $@ -unit $* $(LINKS)
|
||||||
|
|
||||||
# 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
|
||||||
@@ -77,7 +67,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 $@
|
$(CHICKEN_C) $(CSC_FLAGS) $< -o $@ $(LINKS)
|
||||||
|
|
||||||
# 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
|
||||||
@@ -86,12 +76,8 @@ 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)
|
||||||
@$(MAKE) --no-print-directory check-modules
|
cd tests/modules && SEXC=$(CURDIR)/sexc $(CSI) -s check.scm
|
||||||
@$(MAKE) --no-print-directory check-exit-code
|
cd tests/exit-code && SEXC=$(CURDIR)/sexc $(CSI) -s check.scm
|
||||||
|
|
||||||
# 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
|
||||||
@@ -109,9 +95,9 @@ uninstall:
|
|||||||
-rmdir $(DESTDIR)$(sexlibdir)
|
-rmdir $(DESTDIR)$(sexlibdir)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o $(PROGRAM_OBJ) modules.mk modules.stamp
|
rm -f $(OBJ) $(PROGRAM_OBJ) modules.mk
|
||||||
rm -f *.import.scm
|
rm -f *.import.scm
|
||||||
rm -f *.link $(PROGRAM_OBJ:.o=.link)
|
rm -f *.link $(PROGRAM_OBJ:.o=.link)
|
||||||
rm -f $(PROGRAM_NAMES)
|
rm -f sexc sex-tests sextest
|
||||||
|
|
||||||
.PHONY: all check run-tests check-modules check-exit-code install install-strip installdirs uninstall clean
|
.PHONY: all check run-tests install install-strip installdirs uninstall clean
|
||||||
|
|||||||
@@ -10,22 +10,20 @@
|
|||||||
;;; 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.
|
||||||
;;;
|
;;;
|
||||||
;;; make check-exit-code
|
;;; csi -s check.scm
|
||||||
|
|
||||||
(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 (or (absolute-pathname? path) (not (substring-index "/" path)))
|
(if (absolute-pathname? path)
|
||||||
path
|
path
|
||||||
(make-pathname (current-directory) path))))
|
(make-pathname (current-directory) path))))
|
||||||
|
|
||||||
@@ -35,13 +33,12 @@
|
|||||||
|
|
||||||
;;; 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)
|
||||||
(zero? (system (string-append (string-intersperse (map qs (cons sexc args)))
|
(let ((proc (process* sexc args)))
|
||||||
" >/dev/null 2>&1"))))
|
(read-string #f (process-output-port proc))
|
||||||
|
(read-string #f (process-error-port proc))
|
||||||
;;; Every check below expects a failure, which a sexc that cannot run
|
(process-wait proc)
|
||||||
;;; gives too
|
(and (process-returned-normally? proc)
|
||||||
(test "sexc compiles a program" #t
|
(zero? (process-exit-status proc)))))
|
||||||
(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,14 +28,13 @@
|
|||||||
;;; 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.
|
||||||
;;;
|
;;;
|
||||||
;;; make check-modules
|
;;; csi -s check.scm
|
||||||
|
|
||||||
(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
|
||||||
@@ -43,11 +42,6 @@
|
|||||||
|
|
||||||
(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))
|
||||||
@@ -62,15 +56,14 @@
|
|||||||
(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" (built "ledger.o"))
|
(and (output-of sexc "ledger.sex" "-c" "-o" "ledger.o")
|
||||||
(output-of sexc "greet.sex" "-c" "-o" (built "greet.o"))
|
(output-of sexc "greet.sex" "-c" "-o" "greet.o")
|
||||||
(output-of sexc "greet-app.sex" "-o" (built "greet-app")
|
(output-of sexc "greet-app.sex" "-o" "greet-app" "--depfile=greet-app.d"
|
||||||
(string-append "--depfile=" (built "greet-app.d"))
|
"--" "greet.o" "ledger.o")))
|
||||||
"--" (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 (built "greet-app.d") read-line)))
|
(call-with-input-file "greet-app.d" read-line)))
|
||||||
|
|
||||||
(test "the app runs through both"
|
(test "the app runs through both"
|
||||||
'("hello, world"
|
'("hello, world"
|
||||||
@@ -86,8 +79,8 @@
|
|||||||
"board 42"
|
"board 42"
|
||||||
"ledger 2"
|
"ledger 2"
|
||||||
"colour 123")
|
"colour 123")
|
||||||
(output-of (built "greet-app")))
|
(output-of "./greet-app"))
|
||||||
|
|
||||||
(delete-directory scratch #t)
|
(for-each delete-file* '("greet.o" "ledger.o" "greet-app" "greet-app.d"))
|
||||||
|
|
||||||
(test-exit)
|
(test-exit)
|
||||||
|
|||||||
@@ -1,28 +1,23 @@
|
|||||||
;;; 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. The files either includes with include-relative
|
;;; with its source, whose include-relative files count as its own.
|
||||||
;;; 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)
|
||||||
@@ -49,28 +44,14 @@
|
|||||||
(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))))
|
||||||
|
|
||||||
;;; FILE's forms, or the end of the scan, naming the file that has none
|
;;; The names FILE imports, and the files it includes
|
||||||
(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 (forms-of file)) (names '()) (files '()))
|
(let loop ((forms (call-with-input-file file read-list)) (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)
|
||||||
@@ -92,16 +73,19 @@
|
|||||||
(loop (cdr names) acc))
|
(loop (cdr names) acc))
|
||||||
(else (loop (cdr names) (cons (car names) acc))))))
|
(else (loop (cdr names) (cons (car names) acc))))))
|
||||||
|
|
||||||
;;; Each module reached from ROOTS, as (name imported-modules . included-files)
|
(define (imported-modules file)
|
||||||
|
(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-values (((names files) (scan (module-file (car pending)))))
|
(let ((deps (imported-modules (module-file (car pending)))))
|
||||||
(let ((deps (local-modules names)))
|
|
||||||
(loop (append (cdr pending) deps)
|
(loop (append (cdr pending) deps)
|
||||||
(cons (cons (car pending) (cons deps files)) graph))))))))
|
(cons (cons (car pending) deps) 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))
|
||||||
@@ -112,9 +96,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 binary object modules sources)
|
(make-program name object modules sources)
|
||||||
program?
|
program?
|
||||||
(binary program-binary)
|
(name program-name)
|
||||||
(object program-object)
|
(object program-object)
|
||||||
(modules program-modules)
|
(modules program-modules)
|
||||||
(sources program-sources))
|
(sources program-sources))
|
||||||
@@ -130,19 +114,17 @@
|
|||||||
(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 "SOURCES = " (string-intersperse sources " "))
|
(print "PROGRAM_NAMES = " (string-intersperse (map program-name programs) " "))
|
||||||
(for-each (lambda (node)
|
(print "PROGRAM_OBJ = " (string-intersperse (map program-object programs) " "))
|
||||||
(rule (car (objects (list (car node))))
|
(print "SOURCES = "
|
||||||
(append (cddr node) (objects (cadr node)))))
|
(string-intersperse (append (map (o module-file car) graph)
|
||||||
|
(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-binary p) (cons (program-object p) modules))))
|
(rule (program-name p) (cons (program-object p) modules))))
|
||||||
programs)
|
programs))
|
||||||
(for-each (lambda (source) (print source ":")) sources))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user