check what a module's importers can see of its types

An importer is given the pub forms and nothing else, so a pub form
naming a private type, or one from an import without pub, compiled in
its module and failed in every importer with `unknown type name'.

The pub forms are checked as the module itself is compiled. A record,
struct, union or sum behind a pointer needs only declaring, so its
bodyless declaration goes out ahead of them -- the opaque handle that
(pub record T) already gave by hand. Held by value it needs its body,
and a typedef or an enum has no declaration short of its definition:
those are errors at the pub form, saying what would do instead. A name
Sex has no declaration for is left to C.

An importer may now be handed a declaration after the definition it
declares, so a bodyless aggregate no longer replaces known fields.

Fixes #57, #58.
This commit is contained in:
2026-10-09 17:43:09 +03:00
parent 24f11cdcba
commit d94daa9066
9 changed files with 323 additions and 17 deletions

View File

@@ -17,15 +17,18 @@
# 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.
# 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.
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\ncolour 123
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:
@$(SEXC) ledger.sex -c -o ledger.o
@$(SEXC) greet.sex -c -o greet.o
@$(SEXC) greet-app.sex -o greet-app -- greet.o
@$(SEXC) greet-app.sex -o greet-app -- greet.o ledger.o
@if [ "`./greet-app`" = "`printf '$(EXPECTED)\n'`" ]; then \
echo "modules ok"; \
else \
@@ -34,6 +37,6 @@ check:
@$(MAKE) --no-print-directory clean
clean:
@rm -f greet.o greet-app
@rm -f greet.o ledger.o greet-app
.PHONY: check clean