Commit Graph

29 Commits

Author SHA1 Message Date
cbf77c3e19 refuse a variant named like a C keyword
One with fields is a member of the sum's union, and C takes no member
named int; one without is held to the same, as one rule.
2026-10-19 16:06:13 +03:00
2189be0a76 match a sum through a pointer to it
A pointer was refused, where . reads through one; a match now reads
through the whole chain of them to the sum.
2026-10-19 16:06:13 +03:00
52057c1cf2 take a docstring on a sum
record, struct and enum take one; sum read it where its variants go.
2026-10-19 16:06:13 +03:00
2bc07a5a5f refuse a pub realization of a spec importers cannot see
It failed in whichever importer named the module before the spec's,
pointing at the module, where a hidden type is refused in the module
already: so is this, the remedy the same.
2026-10-19 16:06:13 +03:00
669b3cdc7b refuse _ in a pub var's type
Importers declare a pub var from its type alone, with nothing to solve
a wildcard against, so (pub var n _ 42) reached them as extern _ n.
2026-10-19 16:05:23 +03:00
e243abea64 lower match to an if chain, so break in an arm leaves the loop
The switch it lowered to took a break in an arm for its own, and the
loop around the match went on. With no else the last arm is the chain's
else, which keeps C from warning that a function may return nothing.
2026-10-19 16:05:15 +03:00
dbb98f8897 read a match scrutinee before a binder can shadow it
C has a declaration in scope from its own initializer, so in
(match (* e) ((neg (e)) ...)) the binding read the new, uninitialized e.
A binder named like a part of the scrutinee now has it held in a local.
2026-10-19 16:05:15 +03:00
2279c371f2 hold a function type's parameters by value on the interface
A record a pub function type took or returned by value was declared
only, so an importer could neither define a callback for it nor call
one.
2026-10-19 16:05:08 +03:00
c97ae8583b share reading a test source and catching its error
encapsulation.scm had copies of both from codegen.scm.
2026-10-19 16:05:08 +03:00
541d9cd610 check the constants a module's interface hands its importers
An array bound in a pub record, or a name in a pub define's body, is
the importer's to resolve too, and a private define, or one from an
import without pub, failed there as an undeclared identifier. Found in
vs-map-viewer once its units stopped importing everything. A constant
has no declaration short of itself, so it is an error at the pub form.
2026-10-19 16:05:08 +03:00
b998d298dd 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.
2026-10-19 16:05:08 +03:00
19090414b7 let a method call one written below it
Each method was registered just before its own body was walked, so an
earlier one could not find it. All are registered first now, and one
called above its definition is declared ahead of the bodies, which C
needs as well.

Fixes #44.
2026-10-19 16:05:08 +03:00
a0b323980f refuse a match in a case label
case and case/fallthrough walked their label as a statement, so a match
there was taken and wrote `case switch:'.
2026-10-19 15:32:47 +03:00
913af0b463 start a global from braces, not a compound literal
All checks were successful
Sex CI / build-linux (pull_request) Successful in 5m42s
A compound literal is no constant in C11, so a global built by a
constructor or a typed literal failed under -pedantic-errors; gcc says
so, clang lets it pass.
2026-10-15 11:20:53 +03:00
6cda0873c6 hold a literal for an array field to the field's length
A longer one reached cc as excess elements, and a shorter one filled
the rest with zeros where a named array of that length was refused.
2026-10-15 11:15:57 +03:00
0a5eb1e0ce refuse a match in a control form's test
An if, while or for walked every slot as a statement, so a match in
its test came out as a switch inside the condition, which cc refuses.
2026-10-15 11:15:19 +03:00
9c5f678830 hand an array field its elements
An array field compiled to C that cc refused: an array is neither an
initializer of another nor something a payload literal can be built
from. Both the constructor and the binder now spell it out element by
element, which needs a length sexc can count. A sum holding itself by
value is refused at the declaration rather than as cc's incomplete type.
2026-10-14 17:14:36 +03:00
427177d50f write a sum's constructors in place
A constructor was a static function per variant. One taking an array
field cannot exist, its parameter being a pointer, and building some
variants in place and others by call would make two kinds of
constructor. In place, every one is a constant where one is wanted, an
lvalue a method can take the address of, and nothing a pub sum has to
paste into its importer.

What the function did for free is done here instead: arity is checked,
since a short compound literal zero-fills quietly, and an argument is
converted against its field's closure type. The price is that a
constructor is no longer a function value; a lambda makes one.
2026-10-14 17:11:38 +03:00
9af9113bf5 walk the values of a brace literal
The walk stopped at a vector, so whatever a literal held reached the
writer as written: #(v : (.get a)) was (v){.get(a)}, and a path through
a pointer inside one read it as a value.
2026-10-14 17:07:20 +03:00
224ef8fb6b file methods, realizations and sums under what a typedef names
A typedef had the fields of its record but none of its methods, and a
typedef of a sum was not a sum to match. A typedef that ends in a
scalar still keeps its own, so (typedef meters float) does not lend
its methods to every float.
2026-10-14 16:54:16 +03:00
bb2f05fa36 type a macro call by what it expands to
A receiver, a scrutinee or the start of a path was typed before the
walk had expanded it, so (.len (the a)) had no type to dispatch on and
(. (the p) x) read a pointer as a value.
2026-10-14 16:40:37 +03:00
3baaafafc3 refuse the matches and sums cc would refuse
Two else arms, a variant declared twice, and a match standing where a
value is wanted all reached cc as broken C; an arm that is not a list
crashed sexc. A variant called tag collided with the tag enum, now
spelled shapeǂ so no variant name can reach it.
2026-10-14 16:37:51 +03:00
5ba55f05a5 read a spread self as the pointer it is
(self * const v) typed the method's self as `self', so a call passed a
value where the method took a pointer, and a spec written one way
refused a realization written the other. A const receiver handed to a
method taking (* v) is now refused rather than left to cc's warning.
2026-10-14 16:24:00 +03:00
f5c53cdd41 tell a spec default by its body, not its length
A required method with a docstring or a comment counted as a default:
the realization could leave it out, and got a prototype with no
definition or a function with no return.
2026-10-14 15:54:07 +03:00
e9960488fb test an opaque record across a module boundary
A bodyless pub record ahead of a private definition exports the handle
and keeps the fields, the way flecs keeps ecs_world_t. It worked with
nothing added, and nothing said so.
2026-10-08 11:09:42 +03:00
fb4b8aa1f9 dispatch . on the type it reads from
Which of C's two member operators applies is a question the compiler
can already answer -- (.length v) and (.length p) have picked & or *
off the receiver's type since methods moved into the head -- so making
the programmer answer it again asks them to restate what semen knows,
and to revisit every reader of a field the day it becomes a pointer.

A path resolves a step at a time, since only the type in hand answers
for the next field. A receiver nothing can type is read as a value and
warned about rather than refused: refusing leaves no spelling at all
for a struct out of a header nobody has parsed.

Two things had to come along. A parameter written (p * struct point)
was recorded with nothing but the `*' for a type, which left half the
paths in list-macros unanswerable. And fmt-c parenthesised a member
access written inside another, which went unnoticed while only match
nested them -- its bindings have been reading ((s.u).circle).r since
sums went in.
2026-10-05 02:08:15 +03:00
7f3f22e853 type a method call, so one can be another's receiver
expression-type knew nothing about a .method head, so the receiver of
(.length-sq (.sub a b)) had no type and the outer call could not
resolve. Vector arithmetic is nothing but nested calls like that one.
2026-10-04 14:04:01 +03:00
6181a6c8d4 implement spec and realize
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.
2026-10-04 12:56:24 +03:00
07cf85910a test what record, ops, sum and match refuse
The diagnostics are what these forms are for -- a match that leaves a
variant out is the thing C cannot say -- and until now every one of
them was checked by hand and none by the suite.

The two registries refuse a second declaration of one name, which is
per translation unit and not per process, so semen-process clears
them on the way in. sexc compiles one file per process and never
noticed; a suite that compiles forty in one did.
2026-10-03 23:33:38 +03:00