forked from alex-eg/sex
A spec is a contract that emits nothing; a realization is that contract's methods for one type, mangled typeːspecːmethod. A default is copied into every realizing type with the parameter substituted, so the `show' a default calls is that type's own and the whole thing stays static dispatch with nothing left at runtime. The methods land in the ops registry beside inherent ones, which is what lets (.show v) find them with no second lookup -- and makes the duplicate check already there catch a spec method colliding with an ops method or with another spec's. Coherence came free. A realization's signatures are checked against the spec, arguments and return type both, after substituting the parameter; a missing required method is named, and so is one the spec has not got. That is what makes a spec a contract rather than a naming convention. The bound is asked rather than declared: realizes? goes into the macro API beside type-of, and a generic calls it and raises its own error. That is the return this document was written for -- `plain does not realize ord' where the line is, instead of a wall of C errors from a monomorphization two stages downstream. A default is static even when the realization is pub, and does not travel on export: every importing unit synthesizes its own copy, so sending one too would be a second definition of one symbol. The cost is that a module whose defaults call printf has to pub include stdio.h -- which is also why pub include and pub import now work, both having been accepted by read-public-interface and refused by semen.
39 lines
1.5 KiB
Makefile
39 lines
1.5 KiB
Makefile
# 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.
|
|
#
|
|
# The public forms carry comments in their headers, which the reduction
|
|
# to a prototype and to an extern both have to look past.
|
|
|
|
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)\ncolour 123
|
|
|
|
check:
|
|
@$(SEXC) greet.sex -c -o greet.o
|
|
@$(SEXC) greet-app.sex -o greet-app -- greet.o
|
|
@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 greet-app
|
|
|
|
.PHONY: check clean
|