Compare commits
8 Commits
c317d9950c
...
d8903c38f1
| Author | SHA1 | Date | |
|---|---|---|---|
| d8903c38f1 | |||
| ebe7969553 | |||
| 2b840eb8c0 | |||
| 3b717f9634 | |||
| 2cd980bdf1 | |||
| 434ac778bf | |||
| 1a899d9f3c | |||
| 69b38e7c9f |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,10 +5,10 @@
|
|||||||
*.o
|
*.o
|
||||||
*.import.scm
|
*.import.scm
|
||||||
*.link
|
*.link
|
||||||
|
modules.mk
|
||||||
sexc
|
sexc
|
||||||
sex-tests
|
sex-tests
|
||||||
sextest
|
sextest
|
||||||
tools/sextest/sextest
|
|
||||||
|
|
||||||
# Scrapped design docs, kept for reference
|
# Scrapped design docs, kept for reference
|
||||||
/attic
|
/attic
|
||||||
|
|||||||
166
Makefile
166
Makefile
@@ -1,6 +1,5 @@
|
|||||||
CHICKEN_C ?= csc
|
CHICKEN_C ?= csc
|
||||||
CHICKEN_INSTALL ?= chicken-install
|
CSI ?= csi
|
||||||
CHICKEN_STATUS ?= chicken-status
|
|
||||||
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.
|
||||||
@@ -33,113 +32,52 @@ SEX_LIB = $(wildcard lib/*.sex)
|
|||||||
|
|
||||||
MODULE_FLAGS = -emit-all-import-libraries -module-registration -c
|
MODULE_FLAGS = -emit-all-import-libraries -module-registration -c
|
||||||
|
|
||||||
# Order matters, since module check correctness on compilation
|
|
||||||
MODULES = utils types infer sex-macros reader sex-modules semen sex-fmt-c fmt-c-writer sexc
|
|
||||||
OBJ = $(MODULES:%=%.o)
|
|
||||||
|
|
||||||
DEPSFILE = dependencies.txt
|
|
||||||
DEPSLOCK = eggs.lock
|
|
||||||
EGGS_DIR := $(abspath .eggs)
|
|
||||||
|
|
||||||
# Compiler's own repository (types.db, chicken.*), ignoring ambient venv vars.
|
|
||||||
SYSTEM_CHICKEN_REPO := $(shell env \
|
|
||||||
-u CHICKEN_INSTALL_REPOSITORY -u CHICKEN_REPOSITORY_PATH \
|
|
||||||
-u CHICKEN_EGG_CACHE -u CHICKEN_INSTALL_PREFIX \
|
|
||||||
$(CHICKEN_INSTALL) -repository 2>/dev/null)
|
|
||||||
CHICKEN_ABI := $(notdir $(SYSTEM_CHICKEN_REPO))
|
|
||||||
EGGS_STAMP := $(EGGS_DIR)/.installed-$(CHICKEN_ABI)
|
|
||||||
|
|
||||||
# Try project-local chicken repository first. In case it doesn't exist (packaging for distros),
|
|
||||||
# system-wide repository will be used.
|
|
||||||
unexport CHICKEN_INSTALL_REPOSITORY
|
|
||||||
unexport CHICKEN_EGG_CACHE
|
|
||||||
unexport CHICKEN_INSTALL_PREFIX
|
|
||||||
export CHICKEN_REPOSITORY_PATH := $(EGGS_DIR):$(SYSTEM_CHICKEN_REPO)
|
|
||||||
|
|
||||||
all: sexc
|
all: sexc
|
||||||
|
|
||||||
sexc: $(OBJ) main.scm
|
include eggs.mk
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) main.scm -o sexc-tmp -link sexc
|
|
||||||
# otherwise csc hangs, probably because it tries to compile to sexc.o first
|
# Each program, and the source it is built from
|
||||||
mv sexc-tmp sexc
|
PROGRAMS = sexc=main.scm sextest=tools/sextest/sextest.scm sex-tests=tests/run.scm
|
||||||
|
|
||||||
|
# MODULES, the programs' names and objects, and a line for each naming
|
||||||
|
# what it imports, read off the import forms
|
||||||
|
include modules.mk
|
||||||
|
OBJ = $(MODULES:%=%.o)
|
||||||
|
|
||||||
|
modules.mk: $(SOURCES) tools/module-deps.scm dependencies.txt
|
||||||
|
$(CSI) -s tools/module-deps.scm $(PROGRAMS) > $@.tmp
|
||||||
|
mv $@.tmp $@
|
||||||
|
|
||||||
#------------------------------------------------------------------
|
#------------------------------------------------------------------
|
||||||
|
|
||||||
utils.o: utils.module.scm utils.scm
|
# Everything is linked with the modules among its prerequisites
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) utils.module.scm -o utils.o -unit utils
|
LINKS = $(addprefix -link ,$(basename $(filter-out $<,$(filter %.o,$^))))
|
||||||
|
|
||||||
types.o: types.module.scm types.scm
|
# A module is one file that declares its own exports, made a module by
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) types.module.scm -o types.o -unit types
|
# -module, except the vendored sex-fmt-c, a (module ...) form of its own
|
||||||
|
MODULE = -module $*
|
||||||
|
sex-fmt-c.o: MODULE =
|
||||||
|
|
||||||
infer.o: infer.module.scm infer.scm types.o utils.o
|
%.o: %.scm
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) infer.module.scm -o infer.o -unit infer -link types,utils
|
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) $< $(MODULE) -o $@ -unit $* $(LINKS)
|
||||||
|
|
||||||
sex-macros.o: sex-macros.module.scm sex-macros.scm
|
# A program's object is named after its source: csc names its own after
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sex-macros.module.scm -o sex-macros.o -unit sex-macros
|
# -o, and sexc.o is the module's
|
||||||
|
$(PROGRAM_OBJ): %.o: %.scm
|
||||||
|
$(CHICKEN_C) $(CSC_FLAGS) -c $< -o $@
|
||||||
|
|
||||||
reader.o: reader.module.scm reader.scm utils.o
|
$(PROGRAM_NAMES):
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) reader.module.scm -o reader.o -unit reader -link utils
|
$(CHICKEN_C) $(CSC_FLAGS) $< -o $@ $(LINKS)
|
||||||
|
|
||||||
sex-modules.o: sex-modules.module.scm sex-modules.scm reader.o types.o utils.o
|
# A program directly in tests/sex-programs is a test; lib/ holds what
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sex-modules.module.scm -o sex-modules.o -unit sex-modules -link reader,types,utils
|
# they import
|
||||||
|
SEX_TEST_PROGRAMS = $(wildcard tests/sex-programs/*.sex)
|
||||||
semen.o: semen.module.scm semen.scm infer.o sex-macros.o sex-modules.o types.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) semen.module.scm -o semen.o -unit semen -link sex-macros,sex-modules,infer,types,utils
|
|
||||||
|
|
||||||
sex-fmt-c.o: sex-fmt-c.scm
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sex-fmt-c.scm -o sex-fmt-c.o -unit sex-fmt-c
|
|
||||||
|
|
||||||
fmt-c-writer.o: fmt-c-writer.module.scm fmt-c-writer.scm sex-fmt-c.o types.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) fmt-c-writer.module.scm -o fmt-c-writer.o -unit fmt-c-writer -link sex-fmt-c,types,utils
|
|
||||||
|
|
||||||
sexc.o: sexc.module.scm infer.o types.o sexc.scm fmt-c-writer.o sex-macros.o sex-modules.o reader.o semen.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sexc.module.scm -o sexc.o -unit sexc -link fmt-c-writer,sex-macros,sex-modules,reader,semen,infer,types,utils
|
|
||||||
|
|
||||||
# Unit testing
|
|
||||||
sex-tests:
|
|
||||||
$(MAKE) -C ./tests sex-tests
|
|
||||||
cp ./tests/sex-tests ./
|
|
||||||
|
|
||||||
sextest:
|
|
||||||
$(MAKE) -C ./tools/sextest sextest
|
|
||||||
cp ./tools/sextest/sextest .
|
|
||||||
|
|
||||||
SEX_TEST_PROGRAMS = c11 \
|
|
||||||
closure-signatures \
|
|
||||||
closures \
|
|
||||||
comments \
|
|
||||||
compound-literals \
|
|
||||||
feature-flags \
|
|
||||||
features \
|
|
||||||
fixpoint \
|
|
||||||
hello-world \
|
|
||||||
inference \
|
|
||||||
lambdas \
|
|
||||||
lists \
|
|
||||||
operators \
|
|
||||||
ops \
|
|
||||||
precedence \
|
|
||||||
records \
|
|
||||||
serialize \
|
|
||||||
specs \
|
|
||||||
sums \
|
|
||||||
threading \
|
|
||||||
type-shapes \
|
|
||||||
unicode \
|
|
||||||
unnamed-params \
|
|
||||||
wildcards \
|
|
||||||
worked-example
|
|
||||||
|
|
||||||
# Multi-module linking is checked end to end; see tests/modules/Makefile.
|
|
||||||
check-modules: sexc
|
|
||||||
@$(MAKE) --no-print-directory -C ./tests/modules check SEXC=../../sexc
|
|
||||||
|
|
||||||
# The failure paths are checked end to end; see tests/exit-code/Makefile.
|
|
||||||
check-exit-code: sexc
|
|
||||||
@$(MAKE) --no-print-directory -C ./tests/exit-code check SEXC=../../sexc
|
|
||||||
|
|
||||||
check run-tests: sexc sex-tests sextest
|
check run-tests: sexc sex-tests sextest
|
||||||
./sex-tests && ./sextest --sexc=./sexc $(SEX_TEST_PROGRAMS:%=./tests/sex-programs/%.sex) && $(MAKE) check-modules && $(MAKE) check-exit-code
|
./sex-tests
|
||||||
|
./sextest --sexc=./sexc $(SEX_TEST_PROGRAMS)
|
||||||
|
cd tests/modules && SEXC=$(CURDIR)/sexc $(CSI) -s check.scm
|
||||||
|
cd tests/exit-code && 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
|
||||||
@@ -156,38 +94,10 @@ uninstall:
|
|||||||
rm -f $(SEX_LIB:lib/%=$(DESTDIR)$(sexlibdir)/%)
|
rm -f $(SEX_LIB:lib/%=$(DESTDIR)$(sexlibdir)/%)
|
||||||
-rmdir $(DESTDIR)$(sexlibdir)
|
-rmdir $(DESTDIR)$(sexlibdir)
|
||||||
|
|
||||||
$(EGGS_STAMP) deps-update: export CHICKEN_EGG_CACHE := $(EGGS_DIR)/cache
|
|
||||||
$(EGGS_STAMP) deps-update: export CHICKEN_INSTALL_REPOSITORY := $(EGGS_DIR)
|
|
||||||
$(EGGS_STAMP) deps-update: export CHICKEN_INSTALL_PREFIX := $(EGGS_DIR)
|
|
||||||
$(EGGS_STAMP) deps-update: export CHICKEN_REPOSITORY_PATH := $(EGGS_DIR):$(SYSTEM_CHICKEN_REPO)
|
|
||||||
|
|
||||||
$(EGGS_STAMP): $(DEPSLOCK)
|
|
||||||
mkdir -p $(CHICKEN_EGG_CACHE)
|
|
||||||
$(CHICKEN_INSTALL) -force -from-list $(DEPSLOCK)
|
|
||||||
touch $@
|
|
||||||
|
|
||||||
deps: $(EGGS_STAMP)
|
|
||||||
|
|
||||||
deps-update: $(DEPSFILE) deps-clean
|
|
||||||
mkdir -p $(CHICKEN_EGG_CACHE)
|
|
||||||
$(CHICKEN_INSTALL) -force $$(cat $(DEPSFILE))
|
|
||||||
# Local repo only: a system path here would leak distro eggs into the lock.
|
|
||||||
CHICKEN_REPOSITORY_PATH=$(EGGS_DIR) $(CHICKEN_STATUS) -list | sort > $(DEPSLOCK).tmp
|
|
||||||
mv $(DEPSLOCK).tmp $(DEPSLOCK)
|
|
||||||
touch $(EGGS_STAMP)
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJ) main.o
|
rm -f $(OBJ) $(PROGRAM_OBJ) modules.mk
|
||||||
rm -f *.import.scm
|
rm -f *.import.scm
|
||||||
rm -f *.link
|
rm -f *.link $(PROGRAM_OBJ:.o=.link)
|
||||||
rm -f sexc sex-tests sextest
|
rm -f sexc sex-tests sextest
|
||||||
$(MAKE) -C ./tests clean
|
|
||||||
$(MAKE) -C ./tests/modules clean
|
|
||||||
$(MAKE) -C ./tools/sextest clean
|
|
||||||
|
|
||||||
deps-clean:
|
.PHONY: all check run-tests install install-strip installdirs uninstall clean
|
||||||
rm -rf $(EGGS_DIR)
|
|
||||||
|
|
||||||
.PHONY: all check run-tests check-modules check-exit-code \
|
|
||||||
install install-strip installdirs uninstall \
|
|
||||||
deps deps-update deps-clean clean sex-tests sextest
|
|
||||||
|
|||||||
52
eggs.mk
Normal file
52
eggs.mk
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
# The eggs sexc needs, in a project-local repository when there is one.
|
||||||
|
#
|
||||||
|
# make deps install the versions pinned in eggs.lock into .eggs
|
||||||
|
# make deps-update install the newest of dependencies.txt, and pin them
|
||||||
|
#
|
||||||
|
# Without .eggs (packaging for distros) the system repository is used.
|
||||||
|
|
||||||
|
CHICKEN_INSTALL ?= chicken-install
|
||||||
|
CHICKEN_STATUS ?= chicken-status
|
||||||
|
|
||||||
|
DEPSFILE = dependencies.txt
|
||||||
|
DEPSLOCK = eggs.lock
|
||||||
|
EGGS_DIR := $(abspath .eggs)
|
||||||
|
|
||||||
|
# Compiler's own repository (types.db, chicken.*), ignoring ambient venv vars.
|
||||||
|
SYSTEM_CHICKEN_REPO := $(shell env \
|
||||||
|
-u CHICKEN_INSTALL_REPOSITORY -u CHICKEN_REPOSITORY_PATH \
|
||||||
|
-u CHICKEN_EGG_CACHE -u CHICKEN_INSTALL_PREFIX \
|
||||||
|
$(CHICKEN_INSTALL) -repository 2>/dev/null)
|
||||||
|
CHICKEN_ABI := $(notdir $(SYSTEM_CHICKEN_REPO))
|
||||||
|
EGGS_STAMP := $(EGGS_DIR)/.installed-$(CHICKEN_ABI)
|
||||||
|
|
||||||
|
# The path replaces CHICKEN's own rather than extending it, so the
|
||||||
|
# system repository has to be on it too
|
||||||
|
unexport CHICKEN_INSTALL_REPOSITORY
|
||||||
|
unexport CHICKEN_EGG_CACHE
|
||||||
|
unexport CHICKEN_INSTALL_PREFIX
|
||||||
|
export CHICKEN_REPOSITORY_PATH := $(EGGS_DIR):$(SYSTEM_CHICKEN_REPO)
|
||||||
|
|
||||||
|
$(EGGS_STAMP) deps-update: export CHICKEN_EGG_CACHE := $(EGGS_DIR)/cache
|
||||||
|
$(EGGS_STAMP) deps-update: export CHICKEN_INSTALL_REPOSITORY := $(EGGS_DIR)
|
||||||
|
$(EGGS_STAMP) deps-update: export CHICKEN_INSTALL_PREFIX := $(EGGS_DIR)
|
||||||
|
|
||||||
|
$(EGGS_STAMP): $(DEPSLOCK)
|
||||||
|
mkdir -p $(CHICKEN_EGG_CACHE)
|
||||||
|
$(CHICKEN_INSTALL) -force -from-list $(DEPSLOCK)
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
deps: $(EGGS_STAMP)
|
||||||
|
|
||||||
|
deps-update: $(DEPSFILE) deps-clean
|
||||||
|
mkdir -p $(CHICKEN_EGG_CACHE)
|
||||||
|
$(CHICKEN_INSTALL) -force $$(cat $(DEPSFILE))
|
||||||
|
# Local repo only: a system path here would leak distro eggs into the lock.
|
||||||
|
CHICKEN_REPOSITORY_PATH=$(EGGS_DIR) $(CHICKEN_STATUS) -list | sort > $(DEPSLOCK).tmp
|
||||||
|
mv $(DEPSLOCK).tmp $(DEPSLOCK)
|
||||||
|
touch $(EGGS_STAMP)
|
||||||
|
|
||||||
|
deps-clean:
|
||||||
|
rm -rf $(EGGS_DIR)
|
||||||
|
|
||||||
|
.PHONY: deps deps-update deps-clean
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(module fmt-c-writer (emit-c
|
|
||||||
sex-line-directives)
|
|
||||||
"fmt-c-writer.scm")
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
scheme
|
scheme
|
||||||
(scheme base) ; make-parameter
|
(scheme base) ; make-parameter
|
||||||
(chicken base)
|
(chicken base)
|
||||||
|
(chicken module)
|
||||||
(chicken string)
|
(chicken string)
|
||||||
(chicken syntax)
|
(chicken syntax)
|
||||||
brev-separate ; fn, flatten
|
brev-separate ; fn, flatten
|
||||||
@@ -16,6 +17,14 @@
|
|||||||
types ; array-bound?, named-arg?
|
types ; array-bound?, named-arg?
|
||||||
utils)
|
utils)
|
||||||
|
|
||||||
|
(export
|
||||||
|
emit-c
|
||||||
|
sex-line-directives
|
||||||
|
|
||||||
|
;; for the tests
|
||||||
|
atom-to-fmt-c unkebabify type-convert-to-c
|
||||||
|
process-toplevel-form walk-expr walk-type walk-var walk-fn-def walk-struct)
|
||||||
|
|
||||||
;;; egg `tree' not ported to CHICKEN 6 yet
|
;;; egg `tree' not ported to CHICKEN 6 yet
|
||||||
(define (tree-map f tree)
|
(define (tree-map f tree)
|
||||||
(cond ((null? tree) (list))
|
(cond ((null? tree) (list))
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
(module infer
|
|
||||||
(;; The IR
|
|
||||||
tvar?
|
|
||||||
tvar-id
|
|
||||||
tvar-classes
|
|
||||||
tvar-rigid?
|
|
||||||
fresh-tvar
|
|
||||||
fresh-rigid-tvar
|
|
||||||
|
|
||||||
prim-type? prim-name prim-quals make-prim
|
|
||||||
ptr-type? ptr-target ptr-quals make-ptr
|
|
||||||
array-type? array-elt array-size make-array-type
|
|
||||||
fn-type? fn-ret fn-args fn-variadic? make-fn-type
|
|
||||||
agg-type? agg-kind agg-name agg-spelling agg-quals make-agg
|
|
||||||
alias-type? alias-name alias-expansion alias-quals make-alias
|
|
||||||
unknown-type? the-unknown-type
|
|
||||||
|
|
||||||
resolve
|
|
||||||
underlying
|
|
||||||
c-primitive?
|
|
||||||
type-quals
|
|
||||||
free-tvars
|
|
||||||
decay
|
|
||||||
|
|
||||||
;; The boundary
|
|
||||||
parse-type
|
|
||||||
unparse-type
|
|
||||||
|
|
||||||
;; Constraints
|
|
||||||
register-class!
|
|
||||||
add-instance!
|
|
||||||
entails?
|
|
||||||
default-tvar!
|
|
||||||
default-type-variables!
|
|
||||||
|
|
||||||
;; Unification
|
|
||||||
unify
|
|
||||||
|
|
||||||
;; Type schemes
|
|
||||||
scheme? scheme-vars scheme-constraints scheme-type
|
|
||||||
make-scheme
|
|
||||||
generalize
|
|
||||||
instantiate
|
|
||||||
substitute)
|
|
||||||
"infer.scm")
|
|
||||||
46
infer.scm
46
infer.scm
@@ -25,12 +25,58 @@
|
|||||||
scheme
|
scheme
|
||||||
(scheme base)
|
(scheme base)
|
||||||
(chicken base)
|
(chicken base)
|
||||||
|
(chicken module)
|
||||||
matchable
|
matchable
|
||||||
srfi-1
|
srfi-1
|
||||||
srfi-69
|
srfi-69
|
||||||
types
|
types
|
||||||
utils)
|
utils)
|
||||||
|
|
||||||
|
(export
|
||||||
|
;; The IR
|
||||||
|
tvar?
|
||||||
|
tvar-id
|
||||||
|
tvar-classes
|
||||||
|
tvar-rigid?
|
||||||
|
fresh-tvar
|
||||||
|
fresh-rigid-tvar
|
||||||
|
|
||||||
|
prim-type? prim-name prim-quals make-prim
|
||||||
|
ptr-type? ptr-target ptr-quals make-ptr
|
||||||
|
array-type? array-elt array-size make-array-type
|
||||||
|
fn-type? fn-ret fn-args fn-variadic? make-fn-type
|
||||||
|
agg-type? agg-kind agg-name agg-spelling agg-quals make-agg
|
||||||
|
alias-type? alias-name alias-expansion alias-quals make-alias
|
||||||
|
unknown-type? the-unknown-type
|
||||||
|
|
||||||
|
resolve
|
||||||
|
underlying
|
||||||
|
c-primitive?
|
||||||
|
type-quals
|
||||||
|
free-tvars
|
||||||
|
decay
|
||||||
|
|
||||||
|
;; The boundary
|
||||||
|
parse-type
|
||||||
|
unparse-type
|
||||||
|
|
||||||
|
;; Constraints
|
||||||
|
register-class!
|
||||||
|
add-instance!
|
||||||
|
entails?
|
||||||
|
default-tvar!
|
||||||
|
default-type-variables!
|
||||||
|
|
||||||
|
;; Unification
|
||||||
|
unify
|
||||||
|
|
||||||
|
;; Type schemes
|
||||||
|
scheme? scheme-vars scheme-constraints scheme-type
|
||||||
|
make-scheme
|
||||||
|
generalize
|
||||||
|
instantiate
|
||||||
|
substitute)
|
||||||
|
|
||||||
;;; ---------------------------------------------------------------
|
;;; ---------------------------------------------------------------
|
||||||
;;; The IR
|
;;; The IR
|
||||||
;;; ---------------------------------------------------------------
|
;;; ---------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
(module reader (read-from-file
|
|
||||||
read-raw-forms
|
|
||||||
|
|
||||||
current-features
|
|
||||||
platform-features)
|
|
||||||
"reader.scm")
|
|
||||||
11
reader.scm
11
reader.scm
@@ -16,11 +16,22 @@
|
|||||||
scheme
|
scheme
|
||||||
(scheme base) ; make-parameter
|
(scheme base) ; make-parameter
|
||||||
(chicken base)
|
(chicken base)
|
||||||
|
(chicken module)
|
||||||
(chicken pathname)
|
(chicken pathname)
|
||||||
(chicken platform) ; software-version, machine-type
|
(chicken platform) ; software-version, machine-type
|
||||||
(only srfi-1 every any) ; srfi-1 also has an append-reverse
|
(only srfi-1 every any) ; srfi-1 also has an append-reverse
|
||||||
utils)
|
utils)
|
||||||
|
|
||||||
|
(export
|
||||||
|
read-from-file
|
||||||
|
read-raw-forms
|
||||||
|
|
||||||
|
current-features
|
||||||
|
platform-features
|
||||||
|
|
||||||
|
;; for the tests
|
||||||
|
parse-all)
|
||||||
|
|
||||||
;;; Sentinels for structural tokens
|
;;; Sentinels for structural tokens
|
||||||
(define close-paren (list '%close-paren))
|
(define close-paren (list '%close-paren))
|
||||||
(define close-bracket (list '%close-bracket))
|
(define close-bracket (list '%close-bracket))
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
(module semen ()
|
|
||||||
"semen.scm")
|
|
||||||
@@ -19,7 +19,11 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
(export/rename (process semen-process))
|
(export/rename (process semen-process))
|
||||||
(export closure-env-declaration)
|
(export closure-env-declaration
|
||||||
|
;; for the tests
|
||||||
|
sex-fn? sex-fn-public? sex-fn-name sex-fn-arglist
|
||||||
|
sex-fn-return-type sex-fn-prototype sex-fn-body
|
||||||
|
walk-form macro-expand)
|
||||||
|
|
||||||
;;; for lambda extraction, docstring processing, macro expansion,
|
;;; for lambda extraction, docstring processing, macro expansion,
|
||||||
;;; injection of module headers, i.e. all things that rearrange code
|
;;; injection of module headers, i.e. all things that rearrange code
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
(module sex-macros
|
|
||||||
(register-macro
|
|
||||||
cat
|
|
||||||
comment
|
|
||||||
get-macro
|
|
||||||
macro?
|
|
||||||
apply-macro
|
|
||||||
defmacro)
|
|
||||||
"sex-macros.scm")
|
|
||||||
@@ -2,9 +2,19 @@
|
|||||||
scheme
|
scheme
|
||||||
(only fmt fmt)
|
(only fmt fmt)
|
||||||
(chicken base)
|
(chicken base)
|
||||||
|
(chicken module)
|
||||||
(chicken plist)
|
(chicken plist)
|
||||||
(chicken string))
|
(chicken string))
|
||||||
|
|
||||||
|
(export
|
||||||
|
register-macro
|
||||||
|
cat
|
||||||
|
comment
|
||||||
|
get-macro
|
||||||
|
macro?
|
||||||
|
apply-macro
|
||||||
|
defmacro)
|
||||||
|
|
||||||
(define (cat-syms s-1 s-2)
|
(define (cat-syms s-1 s-2)
|
||||||
(fmt #f s-1 s-2))
|
(fmt #f s-1 s-2))
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
(module sex-modules
|
|
||||||
(get-modules-public-forms
|
|
||||||
load-persistent-module-paths
|
|
||||||
check-public-interface
|
|
||||||
module-dependencies
|
|
||||||
read-public-interface)
|
|
||||||
"sex-modules.scm")
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
(chicken base)
|
(chicken base)
|
||||||
(chicken file)
|
(chicken file)
|
||||||
(chicken load)
|
(chicken load)
|
||||||
|
(chicken module)
|
||||||
(chicken pathname)
|
(chicken pathname)
|
||||||
(chicken process-context)
|
(chicken process-context)
|
||||||
(chicken string)
|
(chicken string)
|
||||||
@@ -14,6 +15,16 @@
|
|||||||
types
|
types
|
||||||
utils)
|
utils)
|
||||||
|
|
||||||
|
(export
|
||||||
|
get-modules-public-forms
|
||||||
|
load-persistent-module-paths
|
||||||
|
check-public-interface
|
||||||
|
module-dependencies
|
||||||
|
read-public-interface
|
||||||
|
|
||||||
|
;; for the tests
|
||||||
|
get-module-paths)
|
||||||
|
|
||||||
(define +persistent-module-paths+ (list))
|
(define +persistent-module-paths+ (list))
|
||||||
|
|
||||||
;;; for guarding against multiple imports (sort of mandatory #pragma
|
;;; for guarding against multiple imports (sort of mandatory #pragma
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
(module sexc (main) "sexc.scm")
|
|
||||||
8
sexc.scm
8
sexc.scm
@@ -4,6 +4,7 @@
|
|||||||
(chicken base)
|
(chicken base)
|
||||||
(chicken condition) ; handle-exceptions
|
(chicken condition) ; handle-exceptions
|
||||||
(chicken file)
|
(chicken file)
|
||||||
|
(chicken module)
|
||||||
(chicken plist)
|
(chicken plist)
|
||||||
(chicken pretty-print)
|
(chicken pretty-print)
|
||||||
(chicken process)
|
(chicken process)
|
||||||
@@ -20,6 +21,13 @@
|
|||||||
srfi-1 ; list routines
|
srfi-1 ; list routines
|
||||||
utils)
|
utils)
|
||||||
|
|
||||||
|
(export
|
||||||
|
main
|
||||||
|
|
||||||
|
;; for the tests
|
||||||
|
args-before-separator args-after-separator
|
||||||
|
dependency-rule spell-stdout-output)
|
||||||
|
|
||||||
;;; Main function facilities
|
;;; Main function facilities
|
||||||
|
|
||||||
(define opts-grammar
|
(define opts-grammar
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
CHICKEN_C = csc
|
|
||||||
|
|
||||||
CSC_FLAGS += -K prefix -static
|
|
||||||
MODULE_FLAGS = -emit-all-import-libraries -module-registration -c
|
|
||||||
|
|
||||||
MODULES = utils types infer sex-macros reader sex-modules semen sex-fmt-c fmt-c-writer sexc
|
|
||||||
SEX_OBJ = $(MODULES:%=%.o)
|
|
||||||
|
|
||||||
TESTS = basic semen reader fmt-c-writer utils line-directives codegen encapsulation args module-path types infer
|
|
||||||
TEST_SRCS = $(TESTS:%=%.scm)
|
|
||||||
|
|
||||||
sex-tests: run.scm $(TEST_SRCS) $(SEX_OBJ)
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) run.scm -o sex-tests -link sexc
|
|
||||||
|
|
||||||
#------------------------------------------------------------------
|
|
||||||
|
|
||||||
utils.o: utils.module.scm ../utils.scm
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) utils.module.scm -o utils.o -unit utils
|
|
||||||
|
|
||||||
types.o: types.module.scm ../types.scm
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) types.module.scm -o types.o -unit types
|
|
||||||
|
|
||||||
infer.o: infer.module.scm ../infer.scm types.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) infer.module.scm -o infer.o -unit infer -link types,utils
|
|
||||||
|
|
||||||
sex-macros.o: sex-macros.module.scm ../sex-macros.scm
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sex-macros.module.scm -o sex-macros.o -unit sex-macros
|
|
||||||
|
|
||||||
reader.o: reader.module.scm ../reader.scm utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) reader.module.scm -o reader.o -unit reader -link utils
|
|
||||||
|
|
||||||
sex-modules.o: sex-modules.module.scm ../sex-modules.scm reader.o types.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sex-modules.module.scm -o sex-modules.o -unit sex-modules -link reader,types,utils
|
|
||||||
|
|
||||||
semen.o: semen.module.scm ../semen.scm infer.o sex-macros.o sex-modules.o types.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) semen.module.scm -o semen.o -unit semen -link sex-macros,sex-modules,infer,types,utils
|
|
||||||
|
|
||||||
sex-fmt-c.o: ../sex-fmt-c.scm
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) ../sex-fmt-c.scm -o sex-fmt-c.o -unit sex-fmt-c
|
|
||||||
|
|
||||||
fmt-c-writer.o: fmt-c-writer.module.scm ../fmt-c-writer.scm sex-fmt-c.o types.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) fmt-c-writer.module.scm -o fmt-c-writer.o -unit fmt-c-writer -link sex-fmt-c,types,utils
|
|
||||||
|
|
||||||
sexc.o: sexc.module.scm infer.o types.o ../sexc.scm fmt-c-writer.o sex-macros.o sex-modules.o reader.o semen.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sexc.module.scm -o sexc.o -unit sexc -link fmt-c-writer,sex-macros,sex-modules,reader,semen,infer,types,utils
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f $(SEX_OBJ)
|
|
||||||
rm -f *.import.scm
|
|
||||||
rm -f *.link
|
|
||||||
rm -f sex-tests
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
# The failure paths.
|
|
||||||
#
|
|
||||||
# Each needs a process to show itself, so none fits the unit suite:
|
|
||||||
# sexc has to fail when cc fails -- exiting 0 after a failed compile
|
|
||||||
# makes every driver, sextest included, read it as success -- it has to
|
|
||||||
# clean up its temporary .c when its own emission throws, and it has to
|
|
||||||
# refuse `-o -' for an executable, which cc would write to a file named
|
|
||||||
# `-'.
|
|
||||||
#
|
|
||||||
# Everything is built inside a scratch directory, so nothing is left
|
|
||||||
# here to clean up.
|
|
||||||
|
|
||||||
SEXC ?= ../../sexc
|
|
||||||
|
|
||||||
check:
|
|
||||||
@d=`mktemp -d`; \
|
|
||||||
TMPDIR=$$d $(SEXC) nested-pointer.sex -o $$d/out >/dev/null 2>&1; \
|
|
||||||
if [ -n "`find $$d -name '*.c'`" ]; then \
|
|
||||||
echo "exit code FAILED: the temporary .c survived a failed emission"; \
|
|
||||||
rm -rf $$d; exit 1; \
|
|
||||||
fi; \
|
|
||||||
if $(SEXC) hello.sex -o $$d/out -- -no-such-cc-flag >/dev/null 2>&1; then \
|
|
||||||
echo "exit code FAILED: sexc reported success after cc failed"; \
|
|
||||||
rm -rf $$d; exit 1; \
|
|
||||||
fi; \
|
|
||||||
if (cd $$d && $(abspath $(SEXC)) $(CURDIR)/hello.sex -o - >/dev/null 2>&1) || [ -e $$d/- ]; then \
|
|
||||||
echo "exit code FAILED: -o - built an executable"; \
|
|
||||||
rm -rf $$d; exit 1; \
|
|
||||||
fi; \
|
|
||||||
rm -rf $$d; echo "exit code ok"
|
|
||||||
|
|
||||||
.PHONY: check
|
|
||||||
62
tests/exit-code/check.scm
Normal file
62
tests/exit-code/check.scm
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
;;; The failure paths.
|
||||||
|
;;;
|
||||||
|
;;; Each needs a process to show itself, so none fits the unit suite:
|
||||||
|
;;; sexc has to fail when cc fails -- exiting 0 after a failed compile
|
||||||
|
;;; makes every driver, sextest included, read it as success -- it has to
|
||||||
|
;;; clean up its temporary .c when its own emission throws, and it has to
|
||||||
|
;;; refuse `-o -' for an executable, which cc would write to a file named
|
||||||
|
;;; `-'.
|
||||||
|
;;;
|
||||||
|
;;; Everything is built inside a scratch directory, so nothing is left
|
||||||
|
;;; here to clean up.
|
||||||
|
;;;
|
||||||
|
;;; csi -s check.scm
|
||||||
|
|
||||||
|
(import scheme
|
||||||
|
(chicken base)
|
||||||
|
(chicken file)
|
||||||
|
(chicken io)
|
||||||
|
(chicken pathname)
|
||||||
|
(chicken process)
|
||||||
|
(chicken process-context)
|
||||||
|
test)
|
||||||
|
|
||||||
|
(define sexc
|
||||||
|
(let ((path (or (get-environment-variable "SEXC") "../../sexc")))
|
||||||
|
(if (absolute-pathname? path)
|
||||||
|
path
|
||||||
|
(make-pathname (current-directory) path))))
|
||||||
|
|
||||||
|
(define scratch (create-temporary-directory))
|
||||||
|
(define out (make-pathname scratch "out"))
|
||||||
|
(set-environment-variable! "TMPDIR" scratch)
|
||||||
|
|
||||||
|
;;; Whether sexc exits 0 when run with ARGS, saying nothing of it
|
||||||
|
(define (sexc-succeeds? . args)
|
||||||
|
(let ((proc (process* sexc args)))
|
||||||
|
(read-string #f (process-output-port proc))
|
||||||
|
(read-string #f (process-error-port proc))
|
||||||
|
(process-wait proc)
|
||||||
|
(and (process-returned-normally? proc)
|
||||||
|
(zero? (process-exit-status proc)))))
|
||||||
|
|
||||||
|
(test "a failed emission leaves no temporary .c" '()
|
||||||
|
(begin
|
||||||
|
(sexc-succeeds? "nested-pointer.sex" "-o" out)
|
||||||
|
(glob (make-pathname scratch "*.c"))))
|
||||||
|
|
||||||
|
(test "a failed cc fails sexc" #f
|
||||||
|
(sexc-succeeds? "hello.sex" "-o" out "--" "-no-such-cc-flag"))
|
||||||
|
|
||||||
|
(define hello (make-pathname (current-directory) "hello.sex"))
|
||||||
|
(change-directory scratch)
|
||||||
|
|
||||||
|
(test "-o - is refused for an executable" #f
|
||||||
|
(sexc-succeeds? hello "-o" "-"))
|
||||||
|
|
||||||
|
(test "and leaves no file named -" #f
|
||||||
|
(file-exists? "-"))
|
||||||
|
|
||||||
|
(delete-directory scratch #t)
|
||||||
|
|
||||||
|
(test-exit)
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(module fmt-c-writer
|
|
||||||
*
|
|
||||||
"../fmt-c-writer.scm")
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
(module infer
|
|
||||||
(;; The IR
|
|
||||||
tvar?
|
|
||||||
tvar-id
|
|
||||||
tvar-classes
|
|
||||||
tvar-rigid?
|
|
||||||
fresh-tvar
|
|
||||||
fresh-rigid-tvar
|
|
||||||
|
|
||||||
prim-type? prim-name prim-quals make-prim
|
|
||||||
ptr-type? ptr-target ptr-quals make-ptr
|
|
||||||
array-type? array-elt array-size make-array-type
|
|
||||||
fn-type? fn-ret fn-args fn-variadic? make-fn-type
|
|
||||||
agg-type? agg-kind agg-name agg-spelling agg-quals make-agg
|
|
||||||
alias-type? alias-name alias-expansion alias-quals make-alias
|
|
||||||
unknown-type? the-unknown-type
|
|
||||||
|
|
||||||
resolve
|
|
||||||
underlying
|
|
||||||
c-primitive?
|
|
||||||
type-quals
|
|
||||||
free-tvars
|
|
||||||
decay
|
|
||||||
|
|
||||||
;; The boundary
|
|
||||||
parse-type
|
|
||||||
unparse-type
|
|
||||||
|
|
||||||
;; Constraints
|
|
||||||
register-class!
|
|
||||||
add-instance!
|
|
||||||
entails?
|
|
||||||
default-tvar!
|
|
||||||
default-type-variables!
|
|
||||||
|
|
||||||
;; Unification
|
|
||||||
unify
|
|
||||||
|
|
||||||
;; Type schemes
|
|
||||||
scheme? scheme-vars scheme-constraints scheme-type
|
|
||||||
make-scheme
|
|
||||||
generalize
|
|
||||||
instantiate
|
|
||||||
substitute)
|
|
||||||
"../infer.scm")
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
# Multi-module linking.
|
|
||||||
#
|
|
||||||
# Modules are only testable end to end, and nothing else in the suite
|
|
||||||
# links more than one translation unit. Three things have to hold at
|
|
||||||
# once: an imported `pub fn' comes out as a prototype with external
|
|
||||||
# linkage, an imported `pub var' as an extern declaration, and the
|
|
||||||
# module's object survives being passed after `--'. Get any of them
|
|
||||||
# wrong and this fails to link -- or, in the `pub var' case, links and
|
|
||||||
# quietly counts into a private copy.
|
|
||||||
#
|
|
||||||
# It also checks what only a second translation unit can check: that an
|
|
||||||
# imported type reaches the type database, by expanding a macro that
|
|
||||||
# reads the imported struct's fields; and that a closure type crossing
|
|
||||||
# the boundary works both ways -- one built in the module and called
|
|
||||||
# here, one built here and called there, through a code pointer that is
|
|
||||||
# static in the other object. And that a record can cross as a handle
|
|
||||||
# alone, its fields left behind and its methods still found.
|
|
||||||
#
|
|
||||||
# The public forms carry comments in their headers, which the reduction
|
|
||||||
# to a prototype and to an extern both have to look past. And a type the
|
|
||||||
# app cannot see -- private to greet, or from a module greet imports
|
|
||||||
# without `pub' -- crosses behind a pointer, declared and no more.
|
|
||||||
#
|
|
||||||
# The interface prints as importers get it: the declarations first, then
|
|
||||||
# the pub forms in the order they were written.
|
|
||||||
#
|
|
||||||
# The app's dependency rule names both modules: greet, which it imports,
|
|
||||||
# and ledger, which only greet does but which decides what the app is
|
|
||||||
# told of it.
|
|
||||||
|
|
||||||
SEXC ?= ../../sexc
|
|
||||||
|
|
||||||
EXPECTED = hello, world\nhello, sex\n2 greetings\ntext times \ntext times \nmood 1\nclosure 15 21 201\nvec2 7 7\nvec2(3 4)\ntally 2\nboard 42\nledger 2\ncolour 123
|
|
||||||
|
|
||||||
check:
|
|
||||||
@if [ "`$(SEXC) --public-interface greet.sex | head -3`" != "`printf '(record cell)\n(record ledger)\n(include stdio.h)'`" ]; then \
|
|
||||||
echo "modules FAILED, the interface begins:"; $(SEXC) --public-interface greet.sex | head -3; exit 1; \
|
|
||||||
fi
|
|
||||||
@$(SEXC) ledger.sex -c -o ledger.o
|
|
||||||
@$(SEXC) greet.sex -c -o greet.o
|
|
||||||
@$(SEXC) greet-app.sex -o greet-app --depfile=greet-app.d -- greet.o ledger.o
|
|
||||||
@if ! head -1 greet-app.d | grep -q '^greet-app: greet-app.sex .*/greet.sex .*/ledger.sex$$'; then \
|
|
||||||
echo "modules FAILED, the dependency rule is:"; cat greet-app.d; $(MAKE) clean; exit 1; \
|
|
||||||
fi
|
|
||||||
@if [ "`./greet-app`" = "`printf '$(EXPECTED)\n'`" ]; then \
|
|
||||||
echo "modules ok"; \
|
|
||||||
else \
|
|
||||||
echo "modules FAILED, got:"; ./greet-app; $(MAKE) clean; exit 1; \
|
|
||||||
fi
|
|
||||||
@$(MAKE) --no-print-directory clean
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@rm -f greet.o ledger.o greet-app greet-app.d
|
|
||||||
|
|
||||||
.PHONY: check clean
|
|
||||||
86
tests/modules/check.scm
Normal file
86
tests/modules/check.scm
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
;;; Multi-module linking.
|
||||||
|
;;;
|
||||||
|
;;; Modules are only testable end to end, and nothing else in the suite
|
||||||
|
;;; links more than one translation unit. Three things have to hold at
|
||||||
|
;;; once: an imported `pub fn' comes out as a prototype with external
|
||||||
|
;;; linkage, an imported `pub var' as an extern declaration, and the
|
||||||
|
;;; module's object survives being passed after `--'. Get any of them
|
||||||
|
;;; wrong and this fails to link -- or, in the `pub var' case, links and
|
||||||
|
;;; quietly counts into a private copy.
|
||||||
|
;;;
|
||||||
|
;;; It also checks what only a second translation unit can check: that an
|
||||||
|
;;; imported type reaches the type database, by expanding a macro that
|
||||||
|
;;; reads the imported struct's fields; and that a closure type crossing
|
||||||
|
;;; the boundary works both ways -- one built in the module and called
|
||||||
|
;;; here, one built here and called there, through a code pointer that is
|
||||||
|
;;; static in the other object. And that a record can cross as a handle
|
||||||
|
;;; alone, its fields left behind and its methods still found.
|
||||||
|
;;;
|
||||||
|
;;; The public forms carry comments in their headers, which the reduction
|
||||||
|
;;; to a prototype and to an extern both have to look past. And a type the
|
||||||
|
;;; app cannot see -- private to greet, or from a module greet imports
|
||||||
|
;;; without `pub' -- crosses behind a pointer, declared and no more.
|
||||||
|
;;;
|
||||||
|
;;; The interface prints as importers get it: the declarations first, then
|
||||||
|
;;; the pub forms in the order they were written.
|
||||||
|
;;;
|
||||||
|
;;; The app's dependency rule names both modules: greet, which it imports,
|
||||||
|
;;; and ledger, which only greet does but which decides what the app is
|
||||||
|
;;; told of it.
|
||||||
|
;;;
|
||||||
|
;;; csi -s check.scm
|
||||||
|
|
||||||
|
(import scheme
|
||||||
|
(chicken base)
|
||||||
|
(chicken file)
|
||||||
|
(chicken io)
|
||||||
|
(chicken irregex)
|
||||||
|
(chicken process)
|
||||||
|
(chicken process-context)
|
||||||
|
srfi-1
|
||||||
|
test)
|
||||||
|
|
||||||
|
(define sexc (or (get-environment-variable "SEXC") "../../sexc"))
|
||||||
|
|
||||||
|
;;; The lines PROGRAM prints when run with ARGS, or #f when it fails
|
||||||
|
(define (output-of program . args)
|
||||||
|
(let* ((proc (process program args))
|
||||||
|
(lines (read-lines (process-output-port proc))))
|
||||||
|
(process-wait proc)
|
||||||
|
(and (process-returned-normally? proc)
|
||||||
|
(zero? (process-exit-status proc))
|
||||||
|
lines)))
|
||||||
|
|
||||||
|
(test "the interface begins with the declarations"
|
||||||
|
'("(record cell)" "(record ledger)" "(include stdio.h)")
|
||||||
|
(take (or (output-of sexc "--public-interface" "greet.sex") '()) 3))
|
||||||
|
|
||||||
|
(test-assert "the app links with both modules"
|
||||||
|
(and (output-of sexc "ledger.sex" "-c" "-o" "ledger.o")
|
||||||
|
(output-of sexc "greet.sex" "-c" "-o" "greet.o")
|
||||||
|
(output-of sexc "greet-app.sex" "-o" "greet-app" "--depfile=greet-app.d"
|
||||||
|
"--" "greet.o" "ledger.o")))
|
||||||
|
|
||||||
|
(test-assert "the dependency rule names both modules"
|
||||||
|
(irregex-match "greet-app: greet-app\\.sex .*/greet\\.sex .*/ledger\\.sex"
|
||||||
|
(call-with-input-file "greet-app.d" read-line)))
|
||||||
|
|
||||||
|
(test "the app runs through both"
|
||||||
|
'("hello, world"
|
||||||
|
"hello, sex"
|
||||||
|
"2 greetings"
|
||||||
|
"text times "
|
||||||
|
"text times "
|
||||||
|
"mood 1"
|
||||||
|
"closure 15 21 201"
|
||||||
|
"vec2 7 7"
|
||||||
|
"vec2(3 4)"
|
||||||
|
"tally 2"
|
||||||
|
"board 42"
|
||||||
|
"ledger 2"
|
||||||
|
"colour 123")
|
||||||
|
(output-of "./greet-app"))
|
||||||
|
|
||||||
|
(for-each delete-file* '("greet.o" "ledger.o" "greet-app" "greet-app.d"))
|
||||||
|
|
||||||
|
(test-exit)
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(module reader
|
|
||||||
*
|
|
||||||
"../reader.scm")
|
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
(import
|
(import
|
||||||
test)
|
test)
|
||||||
|
|
||||||
(include "basic.scm")
|
(include-relative "basic.scm")
|
||||||
(include "semen.scm")
|
(include-relative "semen.scm")
|
||||||
(include "reader.scm")
|
(include-relative "reader.scm")
|
||||||
(include "fmt-c-writer.scm")
|
(include-relative "fmt-c-writer.scm")
|
||||||
(include "utils.scm")
|
(include-relative "utils.scm")
|
||||||
(include "line-directives.scm")
|
(include-relative "line-directives.scm")
|
||||||
(include "codegen.scm")
|
(include-relative "codegen.scm")
|
||||||
(include "encapsulation.scm")
|
(include-relative "encapsulation.scm")
|
||||||
(include "args.scm")
|
(include-relative "args.scm")
|
||||||
(include "module-path.scm")
|
(include-relative "module-path.scm")
|
||||||
(include "types.scm")
|
(include-relative "types.scm")
|
||||||
(include "infer.scm")
|
(include-relative "infer.scm")
|
||||||
|
|
||||||
;;; Should be the last in the test suite
|
;;; Should be the last in the test suite
|
||||||
(test-exit)
|
(test-exit)
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
(module semen *
|
|
||||||
"../semen.scm")
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(module sex-macros
|
|
||||||
*
|
|
||||||
"../sex-macros.scm")
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(module sex-modules
|
|
||||||
*
|
|
||||||
"../sex-modules.scm")
|
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
(include stddef.h)
|
(include stddef.h)
|
||||||
(include stdio.h)
|
(include stdio.h)
|
||||||
|
|
||||||
(import list-macros)
|
(import lib/list-macros)
|
||||||
|
|
||||||
(struct foo
|
(struct foo
|
||||||
((a-field float)
|
((a-field float)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
(module sexc
|
|
||||||
*
|
|
||||||
"../sexc.scm")
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
(module types
|
|
||||||
(add-struct
|
|
||||||
add-union
|
|
||||||
add-enum
|
|
||||||
add-typedef
|
|
||||||
add-define
|
|
||||||
|
|
||||||
type-match
|
|
||||||
type-pattern-matches?
|
|
||||||
map-fields
|
|
||||||
|
|
||||||
add-sum!
|
|
||||||
get-sum
|
|
||||||
add-constructor!
|
|
||||||
get-constructor
|
|
||||||
variant-fields
|
|
||||||
reset-declarations!
|
|
||||||
|
|
||||||
add-spec!
|
|
||||||
get-spec
|
|
||||||
spec-parameter
|
|
||||||
spec-methods
|
|
||||||
add-realization!
|
|
||||||
realizes?
|
|
||||||
normalize-fields
|
|
||||||
|
|
||||||
add-method!
|
|
||||||
get-method
|
|
||||||
qualify-op
|
|
||||||
ops-key
|
|
||||||
|
|
||||||
add-name-type!
|
|
||||||
get-name-type
|
|
||||||
type-of
|
|
||||||
current-type-of
|
|
||||||
get-return-type
|
|
||||||
|
|
||||||
get-type-info
|
|
||||||
get-tag-info
|
|
||||||
get-fields
|
|
||||||
get-underlying-type
|
|
||||||
|
|
||||||
type-head?
|
|
||||||
named-arg?
|
|
||||||
named-arg-type
|
|
||||||
arglist-types
|
|
||||||
strip-pub
|
|
||||||
array-bound?
|
|
||||||
array-element-type)
|
|
||||||
"../types.scm")
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(module utils
|
|
||||||
*
|
|
||||||
"../utils.scm")
|
|
||||||
130
tools/module-deps.scm
Normal file
130
tools/module-deps.scm
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
;;; The compiler's modules and the programs built from them, as make
|
||||||
|
;;; 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
|
||||||
|
;;; with its source, whose include-relative files count as its own.
|
||||||
|
;;;
|
||||||
|
;;; csi -s tools/module-deps.scm sexc=main.scm > modules.mk
|
||||||
|
;;;
|
||||||
|
;;; prints
|
||||||
|
;;;
|
||||||
|
;;; MODULES = fmt-c-writer infer reader ...
|
||||||
|
;;; PROGRAM_NAMES = sexc
|
||||||
|
;;; PROGRAM_OBJ = main.o
|
||||||
|
;;; SOURCES = fmt-c-writer.scm infer.scm ... main.scm
|
||||||
|
;;; infer.o: types.o utils.o
|
||||||
|
;;; ...
|
||||||
|
;;; main.o: sexc.o
|
||||||
|
;;; sexc: main.o sexc.o
|
||||||
|
|
||||||
|
(import scheme
|
||||||
|
(chicken base)
|
||||||
|
(chicken file)
|
||||||
|
(chicken io)
|
||||||
|
(chicken pathname)
|
||||||
|
(chicken process-context)
|
||||||
|
(chicken sort)
|
||||||
|
(chicken string))
|
||||||
|
|
||||||
|
;;; As csc reads them, given -K prefix
|
||||||
|
(keyword-style #:prefix)
|
||||||
|
|
||||||
|
;;; (only sex-macros cat) -> sex-macros
|
||||||
|
(define (spec-name spec)
|
||||||
|
(if (and (pair? spec) (memq (car spec) '(only except prefix rename)))
|
||||||
|
(spec-name (cadr spec))
|
||||||
|
spec))
|
||||||
|
|
||||||
|
;;; dependencies.txt names the eggs, so a stray test.scm is not the
|
||||||
|
;;; module the tests import
|
||||||
|
(define eggs (call-with-input-file "dependencies.txt" read-list))
|
||||||
|
|
||||||
|
(define (module-file name)
|
||||||
|
(and (symbol? name)
|
||||||
|
(not (memq name eggs))
|
||||||
|
(let ((file (string-append (symbol->string name) ".scm")))
|
||||||
|
(and (file-exists? file) file))))
|
||||||
|
|
||||||
|
;;; The names FILE imports, and the files it includes
|
||||||
|
(define (scan file)
|
||||||
|
(let loop ((forms (call-with-input-file file read-list)) (names '()) (files '()))
|
||||||
|
(if (null? forms)
|
||||||
|
(values names files)
|
||||||
|
(let ((form (car forms)))
|
||||||
|
(cond
|
||||||
|
((not (pair? form)) (loop (cdr forms) names files))
|
||||||
|
((eq? (car form) 'import)
|
||||||
|
(loop (cdr forms) (append (map spec-name (cdr form)) names) files))
|
||||||
|
((eq? (car form) 'include-relative)
|
||||||
|
(let ((included (make-pathname (pathname-directory file) (cadr form))))
|
||||||
|
(let-values (((more-names more-files) (scan included)))
|
||||||
|
(loop (cdr forms)
|
||||||
|
(append more-names names)
|
||||||
|
(append (cons included more-files) files)))))
|
||||||
|
(else (loop (cdr forms) names files)))))))
|
||||||
|
|
||||||
|
(define (symbol<? a b)
|
||||||
|
(string<? (symbol->string a) (symbol->string b)))
|
||||||
|
|
||||||
|
;;; The modules among NAMES, once each
|
||||||
|
(define (local-modules names)
|
||||||
|
(let loop ((names names) (acc '()))
|
||||||
|
(cond ((null? names) (sort acc symbol<?))
|
||||||
|
((or (memq (car names) acc) (not (module-file (car names))))
|
||||||
|
(loop (cdr names) acc))
|
||||||
|
(else (loop (cdr names) (cons (car names) acc))))))
|
||||||
|
|
||||||
|
(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)
|
||||||
|
(let loop ((pending roots) (graph '()))
|
||||||
|
(cond ((null? pending) (sort graph (lambda (a b) (symbol<? (car a) (car b)))))
|
||||||
|
((assq (car pending) graph) (loop (cdr pending) graph))
|
||||||
|
(else
|
||||||
|
(let ((deps (imported-modules (module-file (car pending)))))
|
||||||
|
(loop (append (cdr pending) deps)
|
||||||
|
(cons (cons (car pending) deps) graph)))))))
|
||||||
|
|
||||||
|
(define (objects names)
|
||||||
|
(map (lambda (name) (string-append (symbol->string name) ".o")) names))
|
||||||
|
|
||||||
|
(define (rule target prerequisites)
|
||||||
|
(unless (null? prerequisites)
|
||||||
|
(print target ": " (string-intersperse prerequisites " "))))
|
||||||
|
|
||||||
|
;;; sexc=main.scm, read off main.scm and the files it includes
|
||||||
|
(define-record-type program
|
||||||
|
(make-program name object modules sources)
|
||||||
|
program?
|
||||||
|
(name program-name)
|
||||||
|
(object program-object)
|
||||||
|
(modules program-modules)
|
||||||
|
(sources program-sources))
|
||||||
|
|
||||||
|
(define (read-program spec)
|
||||||
|
(let* ((parts (string-split spec "="))
|
||||||
|
(source (cadr parts)))
|
||||||
|
(let-values (((names files) (scan source)))
|
||||||
|
(make-program (car parts) (pathname-replace-extension source "o")
|
||||||
|
(local-modules names) (cons source files)))))
|
||||||
|
|
||||||
|
;;; Only core here: modules.mk is made before `make deps' installs eggs
|
||||||
|
(let* ((programs (map read-program (command-line-arguments)))
|
||||||
|
(graph (module-graph
|
||||||
|
(local-modules (apply append (map program-modules programs))))))
|
||||||
|
(print "MODULES = " (string-intersperse (map (o symbol->string car) graph) " "))
|
||||||
|
(print "PROGRAM_NAMES = " (string-intersperse (map program-name programs) " "))
|
||||||
|
(print "PROGRAM_OBJ = " (string-intersperse (map program-object programs) " "))
|
||||||
|
(print "SOURCES = "
|
||||||
|
(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)
|
||||||
|
(for-each (lambda (p)
|
||||||
|
(let ((modules (objects (program-modules p))))
|
||||||
|
(rule (program-object p) (append (cdr (program-sources p)) modules))
|
||||||
|
(rule (program-name p) (cons (program-object p) modules))))
|
||||||
|
programs))
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
CHICKEN_C = csc
|
|
||||||
CSC_FLAGS += -K prefix -static
|
|
||||||
MODULE_FLAGS = -emit-all-import-libraries -module-registration -c
|
|
||||||
|
|
||||||
ROOT = ../..
|
|
||||||
|
|
||||||
# sextest reuses sexc's reader (and its utils dependency) instead of
|
|
||||||
# duplicating the S-expression reader. The module wrappers here include
|
|
||||||
# the shared sources from the project root.
|
|
||||||
|
|
||||||
sextest: sextest.scm reader.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) sextest.scm -o sextest -link reader,utils
|
|
||||||
|
|
||||||
utils.o: utils.module.scm $(ROOT)/utils.scm
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) utils.module.scm -o utils.o -unit utils
|
|
||||||
|
|
||||||
reader.o: reader.module.scm $(ROOT)/reader.scm utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) reader.module.scm -o reader.o -unit reader -link utils
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.o *.import.scm *.link sextest
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
(module reader (read-from-file
|
|
||||||
read-raw-forms
|
|
||||||
|
|
||||||
current-features
|
|
||||||
platform-features)
|
|
||||||
"../../reader.scm")
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
(module utils
|
|
||||||
(get-env-var
|
|
||||||
set-working-directory
|
|
||||||
to-absolute-pathname
|
|
||||||
comment-form?
|
|
||||||
strip-header-comments
|
|
||||||
list-split
|
|
||||||
list-join
|
|
||||||
recons
|
|
||||||
current-source-file
|
|
||||||
set-form-source!
|
|
||||||
form-source
|
|
||||||
form-file
|
|
||||||
form-line
|
|
||||||
copy-form-source!
|
|
||||||
stamp-form-source!
|
|
||||||
form-location
|
|
||||||
sex-error
|
|
||||||
with-directory
|
|
||||||
)
|
|
||||||
"../../utils.scm")
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
(module types
|
|
||||||
(add-struct
|
|
||||||
add-union
|
|
||||||
add-enum
|
|
||||||
add-typedef
|
|
||||||
add-define
|
|
||||||
|
|
||||||
type-match
|
|
||||||
type-pattern-matches?
|
|
||||||
map-fields
|
|
||||||
|
|
||||||
add-sum!
|
|
||||||
get-sum
|
|
||||||
add-constructor!
|
|
||||||
get-constructor
|
|
||||||
variant-fields
|
|
||||||
reset-declarations!
|
|
||||||
|
|
||||||
add-spec!
|
|
||||||
get-spec
|
|
||||||
spec-parameter
|
|
||||||
spec-methods
|
|
||||||
add-realization!
|
|
||||||
realizes?
|
|
||||||
normalize-fields
|
|
||||||
|
|
||||||
add-method!
|
|
||||||
get-method
|
|
||||||
qualify-op
|
|
||||||
ops-key
|
|
||||||
|
|
||||||
add-name-type!
|
|
||||||
get-name-type
|
|
||||||
type-of
|
|
||||||
current-type-of
|
|
||||||
get-return-type
|
|
||||||
|
|
||||||
get-type-info
|
|
||||||
get-tag-info
|
|
||||||
get-fields
|
|
||||||
get-underlying-type
|
|
||||||
|
|
||||||
type-head?
|
|
||||||
named-arg?
|
|
||||||
named-arg-type
|
|
||||||
arglist-types
|
|
||||||
strip-pub
|
|
||||||
array-bound?
|
|
||||||
array-element-type)
|
|
||||||
"types.scm")
|
|
||||||
51
types.scm
51
types.scm
@@ -12,9 +12,60 @@
|
|||||||
scheme
|
scheme
|
||||||
(scheme base)
|
(scheme base)
|
||||||
(chicken base)
|
(chicken base)
|
||||||
|
(chicken module)
|
||||||
srfi-1
|
srfi-1
|
||||||
srfi-69)
|
srfi-69)
|
||||||
|
|
||||||
|
(export
|
||||||
|
add-struct
|
||||||
|
add-union
|
||||||
|
add-enum
|
||||||
|
add-typedef
|
||||||
|
add-define
|
||||||
|
|
||||||
|
type-match
|
||||||
|
type-pattern-matches?
|
||||||
|
map-fields
|
||||||
|
|
||||||
|
add-sum!
|
||||||
|
get-sum
|
||||||
|
add-constructor!
|
||||||
|
get-constructor
|
||||||
|
variant-fields
|
||||||
|
reset-declarations!
|
||||||
|
|
||||||
|
add-spec!
|
||||||
|
get-spec
|
||||||
|
spec-parameter
|
||||||
|
spec-methods
|
||||||
|
add-realization!
|
||||||
|
realizes?
|
||||||
|
normalize-fields
|
||||||
|
|
||||||
|
add-method!
|
||||||
|
get-method
|
||||||
|
qualify-op
|
||||||
|
ops-key
|
||||||
|
|
||||||
|
add-name-type!
|
||||||
|
get-name-type
|
||||||
|
type-of
|
||||||
|
current-type-of
|
||||||
|
get-return-type
|
||||||
|
|
||||||
|
get-type-info
|
||||||
|
get-tag-info
|
||||||
|
get-fields
|
||||||
|
get-underlying-type
|
||||||
|
|
||||||
|
type-head?
|
||||||
|
named-arg?
|
||||||
|
named-arg-type
|
||||||
|
arglist-types
|
||||||
|
strip-pub
|
||||||
|
array-bound?
|
||||||
|
array-element-type)
|
||||||
|
|
||||||
;;; Two namespaces: `struct point' and a `point' typedef are separate
|
;;; Two namespaces: `struct point' and a `point' typedef are separate
|
||||||
;;; declarations. Tags -- struct, union and enum alike -- share the
|
;;; declarations. Tags -- struct, union and enum alike -- share the
|
||||||
;;; second table between them
|
;;; second table between them
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
(module utils
|
|
||||||
(get-env-var
|
|
||||||
set-working-directory
|
|
||||||
to-absolute-pathname
|
|
||||||
comment-form?
|
|
||||||
strip-header-comments
|
|
||||||
list-split
|
|
||||||
list-join
|
|
||||||
recons
|
|
||||||
current-source-file
|
|
||||||
set-form-source!
|
|
||||||
form-source
|
|
||||||
form-file
|
|
||||||
form-line
|
|
||||||
form-end-line
|
|
||||||
copy-form-source!
|
|
||||||
stamp-form-source!
|
|
||||||
form-location
|
|
||||||
set-form-type!
|
|
||||||
form-type
|
|
||||||
sex-error
|
|
||||||
sex-warning
|
|
||||||
with-directory
|
|
||||||
)
|
|
||||||
"utils.scm")
|
|
||||||
25
utils.scm
25
utils.scm
@@ -2,11 +2,36 @@
|
|||||||
scheme
|
scheme
|
||||||
(scheme base) ; make-parameter
|
(scheme base) ; make-parameter
|
||||||
(chicken base)
|
(chicken base)
|
||||||
|
(chicken module)
|
||||||
(chicken pathname)
|
(chicken pathname)
|
||||||
(chicken process-context)
|
(chicken process-context)
|
||||||
srfi-1
|
srfi-1
|
||||||
srfi-69)
|
srfi-69)
|
||||||
|
|
||||||
|
(export
|
||||||
|
get-env-var
|
||||||
|
set-working-directory
|
||||||
|
to-absolute-pathname
|
||||||
|
comment-form?
|
||||||
|
strip-header-comments
|
||||||
|
list-split
|
||||||
|
list-join
|
||||||
|
recons
|
||||||
|
current-source-file
|
||||||
|
set-form-source!
|
||||||
|
form-source
|
||||||
|
form-file
|
||||||
|
form-line
|
||||||
|
form-end-line
|
||||||
|
copy-form-source!
|
||||||
|
stamp-form-source!
|
||||||
|
form-location
|
||||||
|
set-form-type!
|
||||||
|
form-type
|
||||||
|
sex-error
|
||||||
|
sex-warning
|
||||||
|
with-directory)
|
||||||
|
|
||||||
(define-syntax prog1
|
(define-syntax prog1
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
((prog1 form . forms)
|
((prog1 form . forms)
|
||||||
|
|||||||
Reference in New Issue
Block a user