Commit Graph

79 Commits

Author SHA1 Message Date
c5dec9383a type a value if as the join of its branches
It had no rule, so _ could not be set from one.
2026-10-19 18:26:12 +03:00
671f1a3207 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 18:26:12 +03:00
2af65e18e1 take a docstring on a sum
record, struct and enum take one; sum read it where its variants go.
2026-10-19 18:26:12 +03:00
2d7f58e15e 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 18:26:12 +03:00
91246940e5 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 18:26:12 +03:00
212bac8e10 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 18:26:12 +03:00
f06cbbb197 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-19 18:26:12 +03:00
6e9b70e7f1 refuse a malformed closure capture
((+ a 1)) was a capture named `+' holding a.
2026-10-19 18:26:12 +03:00
784250d061 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 18:26:12 +03:00
25cdb613a4 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-19 18:26:12 +03:00
ed1a3a218c refuse _ in a function's signature
Nothing solves it there, and it reached the C as _.
2026-10-19 18:26:12 +03:00
622621c563 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 18:26:12 +03:00
1ec9427424 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-19 18:26:12 +03:00
8dd7a975a0 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 18:26:12 +03:00
5059f811e0 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 18:26:12 +03:00
c08014306b 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 18:26:12 +03:00
edddb98178 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-19 18:26:12 +03:00
2345f7854e 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-19 18:26:12 +03:00
207c239de6 leave an empty for slot empty
() went to C as NULL, so (for () () ()) tested false and never ran; it
is for (;;).
2026-10-19 18:26:12 +03:00
d133c397c8 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-19 18:26:12 +03:00
36b37f34c1 write #() as {0}
{} is C23's. #() is all zeros, which C11 spells {0}, whatever it
initializes.
2026-10-19 18:26:12 +03:00
87676b24fb 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-19 18:26:12 +03:00
62ca848de8 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-19 18:26:12 +03:00
d9b9316eb0 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 18:26:12 +03:00
bf0cf33261 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 18:26:12 +03:00
4e97f52bb8 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 18:26:12 +03:00
2f305a4df9 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 18:26:12 +03:00
f304d92b8d 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 18:26:12 +03:00
52c53c851b 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 18:26:12 +03:00
b60f58a694 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 18:26:12 +03:00
04122768b4 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-19 18:26:12 +03:00
b52b2ffa07 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-19 18:26:12 +03:00
4f3de6b11b 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-19 18:26:12 +03:00
cf3363263e 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-19 18:26:12 +03:00
2c92a2fd7d 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 18:26:12 +03:00
f9350c0474 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 18:23:43 +03:00
ba26e4e828 write every star of a pointer chain to a struct
c-struct/aux wrote the tag and the first * after it and dropped the
rest, so (* * struct pt) declared a struct pt *.
2026-10-19 18:23:43 +03:00
f42cff460f 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 18:23:43 +03:00
136b6bca23 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-19 18:23:43 +03:00
5880e6904d 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 18:23:43 +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