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.
A method is reachable two ways, spelled out as vec2/length or through
its receiver as (. v length), and both land on the same function. The
registry behind the second one is why this is a form and not a
defmacro: a macro expands and vanishes, while resolution, module
export and the spec bounds still to come all want a declaration site
they can read.
The receiver is adjusted to whatever the method asks for -- & where a
value meets a pointer self, * where a pointer meets a value one -- so
the call reads the same whichever is in hand. A field wins over a
method of the same name, so adding one cannot shadow a field in
silence, and needing & on something that is not an lvalue is refused
here rather than by cc: &(f()) is not C, and an expression has nowhere
to put a temporary.
Qualified names are spelled vec2ːlength. The compiler composes them
and the user does not, so __ would collide with a hand-written
vec2__length, and is reserved in C++ besides. The separator has to be
a letter, C admitting letters in an identifier and not symbols, which
is what ruled out § -- hence U+02D0, on the same grounds as the ƛ a
lifted closure carries.
A block crosses a module boundary as a block, its pub methods cut down
to prototypes. Prototypes alone would say that vec2ːlength exists
without saying that vec2 has a length, and the receiver needs the
second thing; which is also why sex-modules now links against types.
(record point ...) emits the struct and a typedef of the same name, so
point stands alone wherever (struct point) had to -- in a var, a
pointer, an arglist, a sizeof. struct, union and enum keep C's
meaning, for a type that came from a header or is laid out to match one.
read-public-interface folded with cons and never reversed, so an
imported pub fn whose prototype named a type declared above it in the
same module was pasted before that type, and the unit did not compile.
`walk-parts' walked the whole `var' form, and a `fn' type's parameter
list is shaped like a call: `(fn ((c int)) int)' came out as
`int (*fp)(c int)'. A closure literal had no type, so calling one in
place missed the rewrite; sextest fed sexc symbols Sex cannot read.
`&&', the bitwise operators, the shifts and `++' each stopped with
`cannot infer'; an array operand came back as the array; a rank tie
went to whichever operand came first; and a toplevel `_' reached the
writer unsolved.
`max_align_t' is C11 and the union goes into every unit, so a program
with no closure in it stopped building under -std=c99. `unify' also
bound a rigid variable one way round only.
The argument list was flattened with one separator throughout, so
`((long long))' and `((long) (long))' named one struct. A capture
borrowing a name looked only at the local scope chain.
A `while' or `switch' body is a block with no `do' around it, and its
declarations landed in the enclosing frame. Two operands of one narrow
type skipped the conversions, so `(+ c c)' answered `char'.
fmt-c takes a parameter's name with `cadr', so an unnamed one handed
over bare lost its second word to it: `(* const char)' dropped its
star, and `(int)' had no second word at all.
An arglist entry, an array's bound and its element type ask one
question, and disagreed: `(unsigned int)' was a name plus a type, a
trailing typedef a bound, a subscript the type's second word.
Two things out of one mechanism. `_' as a type means "work it out from
the initializer", so (var n _ (strlen s)) stops needing size-t spelled
out; `type-of' hands a macro the type of an expression, so a macro can
dispatch on what it was handed rather than on what was declared. Both
read the same answers from two sides.
Algorithm W's core, intra-procedural, with the extensions C forces:
- an unknown type, since (include stdio.h) brings in names we never
parsed. Unification is consistency rather than equality, so
anything touching an unparsed declaration stops constraining
instead of rejecting a program that compiled yesterday;
- the usual arithmetic conversions, since `+' is not a function of
one type;
- checking mode for initializers, since #(0 0) has no type of its own
and takes one from its context. #(T : ...) is the way out of that.
What it wanted on the way:
- what type a *name* has, which neither the typedef nor the tag
database recorded. One table serves functions and variables, since
a function type already has a surface spelling;
- a scope chain, so a (var c int 9) inside a do ends with the block;
- form-type, keyed by cons cell, so one form has one type;
- macros expanded during the walk rather than before it, so type-of
is answered in the scope the macro was written in.
Closures take the same machinery: a receiver whose type comes from a
call, captures written (name expr) and typed from the expression, and
conversion from a bare function wherever a closure is expected.
type-match grew `_' on the pattern side, since (closure ((int)) int)
and (closure ((float)) int) were separate clauses for one case.
A bare list was read as several forms, so a macro returning
`((make-adder 10) 5)' -- a call of what make-adder returns -- was
spliced into two. Add a new $ char to denote splicing, so ($ form ...)
splices.