Commit Graph

106 Commits

Author SHA1 Message Date
bfb4c116b0 refuse a macro defined after a call to it
The call was compiled as a function's, and the macro went unused there
without a word.
2026-10-19 21:56:28 +03:00
6109242cb0 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 21:56:28 +03:00
ba06256c74 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 21:56:28 +03:00
6af837834a take a docstring on a sum
record, struct and enum take one; sum read it where its variants go.
2026-10-19 21:56:28 +03:00
28f815303a type #t, an enum's constants and the bitwise names
None had a rule. A constant is typed as its enum, where C says int, so
that the enum's ops are found through it. And bit-and, bit-not and the
rest were respelled bit_and before fmt-c could see them, and called.
2026-10-19 21:56:28 +03:00
075da9191f type a call by the type of what it calls
Only a function's name was asked what it returns, so a call through a
local or a field holding a pointer had no type, a local named like a
function took the function's, and a closure's call helper, which
nothing registered, left _ nothing to read.
2026-10-19 21:56:28 +03:00
25bd4484ba name a lambda's unnamed parameters in its definition
A definition names every parameter before C23, as a closure's code
already does.
2026-10-19 21:56:28 +03:00
150bcfa037 refuse a malformed closure capture
((+ a 1)) was a capture named `+' holding a.
2026-10-19 21:52:55 +03:00
fcb7524ba1 refuse a statement of the wrong shape
(goto), (var q), (cast i), (while) and the like died in the writer, in
CHICKEN's words about a procedure of its own and with no location;
(return 1 2), (break 1) and (sizeof a b) dropped what was extra.
2026-10-19 21:52:55 +03:00
aba8a411cc refuse _ in a function's signature
Nothing solves it there, and it reached the C as _.
2026-10-19 21:52:55 +03:00
fd76937fca decay an array into a wildcard standing alone
An array as a value is a pointer to its first element; _ took the array
type, and declared a copy that C cannot initialize from it.
2026-10-19 21:52:55 +03:00
b744fb2e31 let a realization's methods call one another
Each was registered as its body was walked, so a method could not call
one coming after it -- a default included, defaults coming after the
written ones. All are registered first now, as an ops block's are.
2026-10-19 21:52:55 +03:00
d14ca86e70 define an empty lambda as an empty function
A lifted function with no body was a declaration of one, and nothing
defined it, so the program did not link.
2026-10-19 21:52:55 +03:00
5a3ead0fa2 take an unnamed closure parameter, and refuse a variadic one
The closure's type was built from each parameter's second element, so
a type alone, or the ..., crashed sexc. A variadic closure cannot work:
its call helper would have to forward what C cannot.
2026-10-19 21:52:55 +03:00
fa8324348c refuse a capture a parameter or the body names too
Captures are a closure's other parameters, and C's redefinition error
was the first anyone heard of one sharing a name with a parameter, or
being redeclared at the top of the body.
2026-10-19 21:52:55 +03:00
6519f532f4 capture an array and a const local
C copies an array neither by = nor from another array's initializer,
and a const field cannot be assigned: both failed in the C. An array is
copied in element by element; a const one is held as its value.
2026-10-19 21:52:55 +03:00
647f7f9eca resolve the closure types in a closure's signature
The struct, call helper and conversion thunk of a closure type went out
with any closure type in its signature as written, which C has no name
for; so a closure could neither return nor take one, and no currying.
2026-10-19 21:52:55 +03:00
e6863d1b43 keep an array literal a global pointer is set to
At file scope every compound literal was cut down to its braces, right
for a value and not for an array a pointer points at: the address of a
static object is a constant, and its braces alone the pointer's own.
2026-10-19 21:52:55 +03:00
59391de9d3 see a pointer through a typedef of one
Only a written (* T) was a pointer, so with (typedef pt-ref (* pt)) a
path read q as a value and a method found no type to dispatch on.
2026-10-19 21:52:55 +03:00
a7f7c86ac9 type an indexed step of a member path
(. q [pts 2] y) looked the step up as a field whole, so its type was
lost: the next step guessed a value, and through an array of pointers
wrote . for ->.
2026-10-19 21:52:55 +03:00
3ca36ff633 rename the reader's number record to number-literal
sex-fmt-c exports a c-literal? of its own, and the writer imports both;
which one it got depended on the order of its imports.
2026-10-19 21:52:55 +03:00
974657bc6b splice a $ nested in a macro's $
Only the outermost was taken apart, so ($ a ($ b c)) left the inner
one an unknown toplevel form, and in a body a call of $ in the C.
2026-10-19 21:52:55 +03:00
3a42340305 promote a lone arithmetic operand
One operand was joined with nothing and came back as it was, so (- c)
over a char was a char where C makes it an int.
2026-10-19 21:52:43 +03:00
9a9df6a430 type a pointer difference as ptrdiff-t
The join took the first pointer, so (- p q) declared the distance
between two pointers as a third.
2026-10-19 21:52:43 +03:00
d208ca2371 type an operator's result without qualifiers
The spelling was the first operand's, so (+ k 1) with k const was a
const int and (+ 1 k) was not; a value has no qualifiers either way.
2026-10-19 21:52:43 +03:00
30cabc009a read every trailing array bound as a dimension
[m 1 2] lost its second index, and [int 2 3] came out int 2 x[3]. Each
index now subscripts what the one before it gave, and [int 2 3] declares
what it indexes, int[2][3]. An inline struct's fields, once more than
one bound was looked for, were taken for one; their shape tells them apart.
2026-10-19 21:52:43 +03:00
f607db010f refuse an if used as a value with no else
With nothing for the false case the writer made (if c 1) c || 1, a
boolean; and a value if's branches were walked as statements, so one
nested there got through as well.
2026-10-19 21:52:43 +03:00
1cfa80595e read hex floats
0x1.8p3 was no number to the reader, so it became a symbol C got inside
|pipes|, and _ could not type it. It reads now as a literal written as
it was: the digits of a double's own bits, which no decimal rounds to.
2026-10-19 21:52:43 +03:00
2568f289fe write number literals the way C reads them
A C suffix was no number to string->number, so 1u and 1.5f became
symbols, and C got them inside the |pipes| CHICKEN writes those with.
They read now into a literal that prints its C spelling and is typed by
its suffix: an integer in decimal, so 0b101u needs no C23, and a float
in the digits it was written with, since through a double 0.1f could
round to another float and 0.1L would lose what it has over one.

Scheme also reads numbers C has none of. 1/2 reached C as integer
division and +inf.0 as no C at all; those, and integers past 64 bits,
are read errors now. An integer is typed by size as well, so 4000000000
is no longer an int, and one past long long gets the u C would
otherwise only warn about.
2026-10-19 21:52:43 +03:00
e835d39f58 look for an import beside the file it is written in
Imports were looked for from the unit's directory, so a module in a
subdirectory could not import its neighbours: a pub import failed, a
private one lost its handle declarations, and --public-interface changed
with where sexc ran.
2026-10-19 21:52:43 +03:00
edfae88e4d declare a record's typedef ahead of its struct
It came after, so a record pointing at itself, (next (* node)), named a
type C had not been told of yet.
2026-10-19 21:52:11 +03:00
910db917a0 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 21:52:11 +03:00
7964a08b7a 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 21:52:11 +03:00
dcb65c5504 make each compiler module one file, built once
A module was a body plus a (module ...) wrapper naming its exports, and
the wrapper came in up to three copies: the root's, a test one that
exported everything, and sextest's, each recompiling the same body.

csc -module makes a file a module by itself, with export forms in its
body, so the wrappers are gone. tests/ and tools/sextest/ link what the
root built, finding it on the repository path; the tests see what a
module exports, and the names only they need are exported as such.
2026-10-19 21:48:04 +03:00
540f5c75cd tidy what the fixes wrote around existing helpers
All checks were successful
Sex CI / build-linux (pull_request) Successful in 5m55s
Sex CI / build-linux (push) Successful in 5m57s
written-type? matches the shapes instead of measuring them, array-form?
and pub-form? replace their spelled-out copies, both test files share
one fails-with?, and moved test comments are back above their groups.
2026-10-19 18:21:19 +03:00
a4880f1b96 process an ops method's prototype once
Registering a method processed its prototype only for the signature it
records, and a method called from above was processed again to be
declared ahead.
2026-10-19 18:21:10 +03:00
f84010eda8 refuse a field a struct declared here does not have
The path was walked on and handed to cc, which named the missing field
only in C; a test leaned on a struct s an earlier test had declared.
2026-10-19 16:05:08 +03:00
44101c0c06 tell what a member path walked from the fields it has left 2026-10-19 16:05:08 +03:00
1158768446 keep the parameter-type rule in types, where both readers find it
sex-modules spelled out its own copy of named-arg-type, and its own
strip-pub; a parameter shape taught to one would not reach the other.
2026-10-19 16:05:08 +03:00
049d97b5e1 declare an ops method ahead through the one prototype accessor
fn-prototype repeated sex-fn-prototype, and names? repeated mentions?;
each pair kept the better half.
2026-10-19 16:05:08 +03:00
70228366ee drop walk-literal, which the rebase left without callers
walk-initializer took its place, but walked the values as statements;
a match among them is refused again wherever the literal stands.
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
b019da3fb3 name what a member path could not type
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.
2026-10-19 16:05:08 +03:00
a5520bf4b9 walk what an initializer holds
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.
2026-10-19 16:05:08 +03:00
7f0b194d2b make a declaring case body a block
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.
2026-10-19 16:05:08 +03:00
ab4fdc54f3 let sizeof take a type that looks like an expression
(* 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.
2026-10-19 16:04:51 +03:00
a885c21b9b infer a global's type before its braces lose theirs
A global's initializer was stripped to plain braces before `_' was
solved, so #(point : 2 3) left nothing to infer point from.
2026-10-19 15:33:37 +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