Commit Graph

19 Commits

Author SHA1 Message Date
b51cda0af3 highlight ops and match 2026-10-14 17:27:52 +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
3a10ee099b implement sum and match
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.
2026-10-03 22:59:15 +03:00
622db8eadc add record, a struct that names itself
(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.
2026-10-03 22:46:39 +03:00
d609a0c591 begin -> do
Shorter and doesn't imply existence of `end'
2026-09-15 16:32:55 +03:00
24b3e71969 update sex-mode.el
- add switch and case indents
- add begin and default highlighting as keywords
2026-04-29 22:48:55 +03:00
97d44a0050 add union to emacs.el keyword list 2025-08-22 15:47:36 +03:00
6c6e00e6dc implement new macro system 2025-08-06 15:38:04 +03:00
44a352849a implement modules 2025-08-02 10:49:38 +03:00
0cc324e11d fix pub wrong indent 2025-07-17 11:50:04 +03:00
e932afab0a prefix define and define-syntax with chicken-
as we have define in cpp
2025-06-14 18:09:50 +03:00
ef19ff4e56 add define and define-syntax syntax coloring in sex-mode.el 2025-06-14 14:10:19 +03:00
5f919c387d change load to chicken-load in sex sources
to explicitly denote that it is chiken
2025-06-14 14:09:39 +03:00
bd71dcc8a7 add chicken-import support to sex
also fix unquoting to single atom processing wrongly in walk-sex-tree
2025-06-14 14:07:00 +03:00
84550be2bd add union support to sex-mode.el 2025-06-13 18:20:58 +03:00
16dec0728f add extern support 2025-06-13 18:20:51 +03:00
f247a65bf0 sex-mode inherits scheme mode 2025-06-11 20:24:12 +03:00
39e1e4a664 rewrite tree walk with tree module
also add pub support
2025-06-05 17:11:30 +03:00
06d8dd331e add sex-mode.el 2025-05-30 12:38:18 +03:00