Commit Graph

77 Commits

Author SHA1 Message Date
289f26a5b9 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-20 13:58:13 +03:00
0781ad7a4b keep the writer's own words to the head of a form
They were its own wherever they stood, so a name spelled like one --
(var array int), a parameter `define' -- came out %array, %define.
2026-10-20 13:57:56 +03:00
893e9b2848 refuse a malformed closure capture
((+ a 1)) was a capture named `+' holding a.
2026-10-20 13:56:52 +03:00
77a53da276 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-20 13:56:34 +03:00
c707a9db41 say which macro call an error came from
A wrong argument count was CHICKEN's to report, about a procedure with
no name, and an error raised in a macro's body said nothing of the call.
2026-10-20 13:56:16 +03:00
411abc8ecb refuse _ in a function's signature
Nothing solves it there, and it reached the C as _.
2026-10-20 13:55:39 +03:00
97b99ab842 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-20 13:55:38 +03:00
60680bbb0a read an array's length as types does
Inference took only an integer for a length, and read a name there as
part of the element type: [_ N] did not solve, and an array of [int N]
decayed to int N *.
2026-10-20 13:41:58 +03:00
2e2c2373df 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-20 13:41:50 +03:00
1393976bfc 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-20 13:41:50 +03:00
315611ced0 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-20 13:41:50 +03:00
72adb5284b designate an initializer's element by its index
[3] in braces reached the writer as a subscript of one operand, and
sexc died taking the second.
2026-10-20 13:41:50 +03:00
18962f43ad nest a function type's declarator round the name
A function type's return was written ahead of its declarator, so one
returning a function pointer came out int (*)(int) get (void), and a
variable of such a type as void (*)() (*g)(int).
2026-10-20 13:41:50 +03:00
4e71d327f5 leave an empty for slot empty
() went to C as NULL, so (for () () ()) tested false and never ran; it
is for (;;).
2026-10-20 13:41:43 +03:00
b7a3e08fda write an empty block as {}
(do), and a for with no body, gave c-begin nothing to begin with, and
the writer died on its arity.
2026-10-20 13:41:43 +03:00
26f5df1898 write #() as {0}
{} is C23's. #() is all zeros, which C11 spells {0}, whatever it
initializes.
2026-10-20 13:41:43 +03:00
83a1355b6f refuse a malformed enumerator
Anything in the list but a name or (name value) was taken apart as if
it were the pair: (! 1 2) came out ! = 1.
2026-10-20 13:41:43 +03:00
b83009408c keep an aggregate written in place behind a pointer
A type was flattened word by word, a struct's body included, so
(* (struct ((c int)))) came out struct c{ int; } *.
2026-10-20 13:41:43 +03:00
a8694c04fc 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-20 13:41:29 +03:00
6c28b946fc 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-20 13:41:29 +03:00
32680e2aed 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-20 13:41:29 +03:00
b4598c5442 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-20 13:41:02 +03:00
0036a02766 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-20 13:41:02 +03:00
8cf237041d 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-20 13:41:02 +03:00
7b2a6e0078 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-20 13:41:02 +03:00
e646ddd0ed keep the qualifiers written on a wildcard
(const _) parsed to a type variable, which had nowhere to keep the
const, so the type it was solved to came out without one -- for
(const _) and for the target of (* const _) alike.
2026-10-20 13:40:56 +03:00
4639c8ee90 require case labels to be values written once
(case (1 2) ...) is a list of labels, so (case (+ 1 1) ...) came out
case +: case 1: case 1:, and a value repeated in a switch was left to C
to report, without saying where.
2026-10-20 13:40:34 +03:00
3d126d60af hold operators to the operands they take
Past them an operator was written as it came: (/ a) as /a, (! a b) as
a ! b. (++ a b) steps each in turn, through a comma operator the writer
lacked: bare in a for header, and in parens wherever else, since bare
it would begin another declarator or argument.
2026-10-20 13:40:34 +03:00
9639eb3b80 refuse a comparison of other than two operands
(< a b c) reached C as C's own chain, which compares a boolean with c.
2026-10-20 13:40:34 +03:00
c123120d22 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-20 13:40:26 +03:00
5b0ca21c35 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-20 13:40:26 +03:00
2c9fde897f 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-20 13:40:03 +03:00
7159eeb5d2 group a number's digits with _
C23 groups them with ', which in Sex is quote, so 1'000 read as 1 and
(quote 0); _ between two digits is dropped instead, and anywhere else
stays part of a name.
2026-10-20 13:40:03 +03:00
92f676d4b5 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-20 13:40:03 +03:00
673787837c drop the generics scaffolding from infer, and test what semen uses
Schemes, instances, rigid variables and defaulting were built ahead of
generics and called by the tests alone, which reached into the IR for
them. The suite now goes through what infer exports, the eleven names
semen imports; what a wildcard solves is checked from source as well.
2026-10-20 12:00:17 +03:00
bf8ba2f9fd test the writer on the C it writes
The walk-* tests pinned the forms handed to fmt-c, which were right
while the C they became lost a const; spelled as C, they check what fmt-c
makes of them too. The cases no source can reach, an atom no form holds
and a name the reader takes for a negation, go.
2026-10-20 11:56:02 +03:00
13d20a102d keep what follows the star of a pointer to a tagged type
fmt-c wrote (const * struct what) as struct what*, and (* * struct what)
as struct what*, a pointer short; a pointer to an enum crashed it, the star
taken for the enum's values.
2026-10-20 11:54:37 +03:00
4758802810 read the unit tests' sources from a file, the way sexc does
The reader exported parse-all only so the tests could give a source the
file name its locations carry; read-from-file gives it one, through the
reader's own interface. The pipeline helpers move out of codegen.scm for
every suite to use.
2026-10-20 11:48:02 +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
6e150aaaf1 take a name after a qualified type as the bound
[int const N] read N as the type a trailing const was waiting for, and
wrote int const N b[]; a qualifier waits for a name only when no type
came before it.
2026-10-19 16:05:08 +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
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
8f152c2593 tell a grouped for header by its shape, not by a var in it
(for ((= s 0) (< s n) (++ s)) ...) passed the check and reached cc as
a call of (= s 0).
2026-10-19 16:05:08 +03:00
5ccbb5d7e0 write a double in the digits that read back as it
CHICKEN prints 15 significant digits unless told otherwise, too few to
name every double: 0.9871465422297019 reached the C as
0.987146542229702, a different constant. Found in vs-map-viewer, where
380 literals in a port that has to match .NET bit for bit changed this
way. The shortest spelling that reads back is written, up to 17 digits.
2026-10-19 16:05:08 +03:00
e29c6ee5c9 parenthesise what a subscript subscripts
The array was written at whatever level surrounded it, so [(* q) i]
came out *q[i] -- *(q[i]) to C, compiling with q an int ** and reading
the wrong int. The index now starts afresh too: inside a cast it had
taken the cast's level and gained parens, and so had a chain in the
else arm of ?:, which groups to the right and needs none.
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
b8098f1508 reject a for whose header is grouped
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.
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
7532c72dec write arrays with brackets in tests
The tests spelled out (¤ ...), what [...] reads into, which nobody
writes. The reader's own tests keep it: there it is the point.
2026-10-19 16:04:51 +03:00