An import pastes another file's forms into the output, so a Makefile
had to make every object depend on every .sex. --depfile names the
modules read, including those read only for an import's interface,
with an empty rule for each, as cc -MD -MP does.
Fixes#40.
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.
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.
getopt-long reads a lone `-' as an option, so -o - died there asking
for a value, and --output=- got through only to create a file named
`-'.
Fixes#43.
Past a typed base, it is a field of a struct only C knows that has no
type, and the warning named the base anyway: `font' for what was
(. font handle), with font declared on the line before.
Fixes#41.
The body walk passed a #(...) by as an atom, so nothing inside one was
typed, dispatched or lifted: (. self p) read as self.p with self a
pointer, where the same path outside the literal was right.
Fixes#45.
C's parens carried over, ((var i int 0) (< i 4) (++ i)), left the
writer short of slots, and it died in caddr with no location; with a
long enough body it would have compiled the body into the header.
Fixes#42.
Every if had its arms anchored, including one inside an argument that
the writer renders as ?:, so a #line landed between its parts and the
C did not compile. -C output, with no directives, hid it.
Fixes#54.
A case body shared the switch's scope, so two cases could not each
declare `bits', and a label could not be followed by a declaration
before C23; inference shared the scope too, and typed a later case's
read of an outer name as the earlier case's local.
Fixes#51.
0x80 was not a number to string->number, so it became a symbol the
printer escaped as |0x80|, and #x was rejected outright. Both spellings
now read as the integer, which the C writes in decimal.
Fixes#47.
The reader took -INFINITY as one symbol, and the leading dash was then
mangled like any other: _INFINITY. -1 was always a number, so a name
gets the same reading.
Fixes#63.
(* char) is a pointer type and (* p) a dereference, and only the names
in scope tell them apart, so semen decides and marks a type for the
writer. Before, both were walked as expressions: sizeof(*char).
Fixes#52.
A Lisp predicate came out as ident_start?, which no C compiler reads.
ʔ and ꜝ are letters that look the part; ǃ looks closer, but clang flags
it as a homoglyph of `!' at every use.
Fixes#49.
The body was pasted as read, so `cast' stayed a call and names kept
their dashes; and fmt-c parenthesised only a function-like body, so
an object-like one regrouped with the operator it was pasted under.
Fixes#55.
(wire-varint 0) is a pair, and both the writer and map-fields only
expected a name: the writer passed it out unconverted, and a macro
mapping over the enum was handed the pair.
Fixes#46.
Whether a trailing name was the bound hinged on the word before it
being a typedef Sex had seen, which a header's pthread_t never is, and
a grouped (* T) never is either: [pthread-t N] became a two-word type.
Fixes#56, #60.
Neither took part in it: a cast parenthesised its operand only from a
list of binary heads that missed `|', and never itself, so `->' took
it apart; `?:' was written bare under any operator, swallowing it into
the test. Three of the four still compiled, to wrong values.
Fixes#59, #61, #62.
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.
A match binder looks like a reference to its field and is not one. And
with `.' reading an untyped receiver as a value, nothing said how to
write the arrow by hand.
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.
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.
Only a local's initializer was walked, so at file scope a path was not
dispatched, a lambda was never lifted, and a constructor written in
place would have been left a call to nothing.
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.
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.
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.
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.
(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.
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.
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.
f5eee71 spelled the closure environment in C99 for a floor nobody meant
to keep: closures were already C11 through _Static_assert. max_align_t
says the alignment in one word again, and the floor test now holds C11.
`.' now writes whichever of C's member operators the type calls for,
so nothing needs the arrow spelled out and the name is free for the
macro Clojure spells the same way: (-> 5 double-it (add 3)) reads in
the order it happens rather than inside out.
It has no business in the prelude, which every unit pays for whether
or not it threads anything, so it opens the standard library instead
and is imported like anything else. The compiler finds lib/ by asking
the binary where it is -- beside sexc in a work tree, under
../share/sex once installed -- and looks there last, so a module of
one's own by that name still wins.
The C arrow becomes `%->', and that rename is what makes the rest
possible. The closure lifter writes arrows of its own for the capture
record, those forms go back through walk-statement, and a macro named
`->' threads them: (-> ƛcaptures n) turns into a call to n, with
nothing saying so until the C compiler.
fmt-c rendered a bare `->' as the arrow, which left the one spelling
that cannot be right -- threading with no import -- looking like the
operator it stopped being. It goes through c-apply now, the way any
other head nothing knows does.
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.
Every toplevel form was followed by a blank line whether or not one
was written, so the prelude's run of typedefs arrived at twice the
height. A function had no location of its own to measure from either,
having lost it where its header and body are stitched together.
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.
A target is a filename, and the ː separator turned GL/gl.h into
GLːgl.h, so every program including a header from a subdirectory
stopped compiling the moment qualified names got their separator.
Encapsulation.org's example was written before any of it was built
and still called methods the way the first draft did. It compiles
now, so it lives here as well, and the doc's block and this file are
the same text.
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.
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.
The walker offered walk-fn every cdr as well as every form, so the
tail (t) of (fn g () t) read as a call to a macro named t: any
function whose return type or parameter type shared a name with a
macro expanded that tail and died on the macro's arity.
(. v length) made the shape of a form depend on the receiver's type:
(. a b c d e) was either the path a.b.c.d.e or a/b called on c d e,
and nothing but the ops registry could say which. Resolution had to
arbitrate, a field won, and so adding a field named length to vec2
turned every (. v length) in reach from a call into a read -- silently,
and only sometimes into a type error.
Resolution may need types; shape must not. (.length v) puts the method
where an operator belongs, so (. v x) is always the field x, a field
and a method of one name coexist, and a reader needs no symbol table
to see where the arguments start.
Which of &, * or nothing goes in front of the receiver now follows
from its own type against the method's self, rather than from whether
the caller wrote . or ->, so (.length v) and (.length p) are the same
call and -> is member access again and nothing else.
The reader already allowed it: only a standalone . becomes dot-access,
and .foo is the ordinary symbol designated initializers are made of.
A sum is the tag enum, a payload struct per variant that carries
fields, the record holding both, and a constructor each. match is a
switch over the tag whose arms open a block and bind the payload as
locals, so the shape of the generated C is the shape a C programmer
would have written by hand.
What it is for is the refusal: a match that leaves a variant out is an
error naming the ones missing, and so are an arm the sum does not
have, a wrong number of binders, and the same arm written twice. C
cannot say any of that, which is why every switch over a tag in the
wild ends in a defensive default nobody can tell from a real case.
Only the sum is typedef'd. A payload struct would put shapeːcircle in
the ordinary namespace, where the constructor of that name already
lives; as a bare tag it collides with nothing. The sum's own typedef
is emitted ahead of the payload structs, since a variant may hold a
pointer back to the sum, and constructors are static even for a pub
sum, which is pasted into the importer whole.
The scrutinee is read once per binding, so one that is not a path of
names is held in a local first -- otherwise (match (f) ...) would call
f once for the tag and again for every field it binds.