Commit Graph

180 Commits

Author SHA1 Message Date
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
755a733252 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 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
28e967ef25 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 21:52:55 +03:00
e83a3b4a96 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 21:52:55 +03:00
17d1467d1e leave an empty for slot empty
() went to C as NULL, so (for () () ()) tested false and never ran; it
is for (;;).
2026-10-19 21:52:55 +03:00
0313b04a70 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 21:52:55 +03:00
d6ad58f9c0 write #() as {0}
{} is C23's. #() is all zeros, which C11 spells {0}, whatever it
initializes.
2026-10-19 21:52:55 +03:00
817cddd2c8 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 21:52:55 +03:00
0e4c2353e7 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 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
3ce76c81f5 write a #line file name as a C string literal
It was pasted between quotes as it came, so a quote in the path ended
it, a backslash began an escape, and ?? read as a trigraph.
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
8bd991a934 refuse a char literal that is not one byte
A char is C's, and #\λ came out a multi-character constant whose value
is the C compiler's to choose.
2026-10-19 21:52:55 +03:00
8b5a94dbe0 read a string's escapes the way C spells them
An escape the reader did not know lost its backslash, so "\x41" read
as "x41" and "\012" as NUL and "12". A string is text, so \x and octal
reach only as far as ASCII; past it, \u and \U name the character.
2026-10-19 21:52:55 +03:00
faa7c5fb93 give importers the private macros a pub one expands into
Only pub macros crossed, so one built on a private macro expanded in
the importer into a call of a C function nothing defines.
2026-10-19 21:52:55 +03:00
f9647df009 refuse _ in a pub var's type
Importers declare a pub var from its type alone, with nothing to solve
a wildcard against, so (pub var n _ 42) reached them as extern _ n.
2026-10-19 21:52:43 +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
20fc8cf7ad 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 21:52:43 +03:00
9fdfbe26b8 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 21:52:43 +03:00
bc1b5b69d4 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 21:52:43 +03:00
829acf3192 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 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
47c421b381 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 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
c1c6a3dd15 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 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
753406462d escape a ? that follows a ? in string literals
Under -std=c11 C reads trigraphs, which Sex has none of: "??=" came out
"#", and "??/" before the closing quote left the string open.
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
8d09d8f68b parenthesize a negative literal under a unary operator
A negative literal is one token in Sex and two in C, so (- -1) came out
--1, which C reads as decrementing a constant.
2026-10-19 21:52:11 +03:00
de93c53cd8 promote the prelude's integer types like C's own
u8 and i32 are typedefs of <stdint.h> names nothing parses, so they had
no rank: (+ a a) over two u8 200s was a u8 holding 144, and (+ n 1) over
an i32 could not be typed at all.
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
67749c8db0 build the programs the way the modules are built
All checks were successful
Sex CI / build-linux (pull_request) Successful in 5m17s
Each program had its own recipe: a hand-written link list, a cd into
tests/ to keep its includes off the modules' namesakes, and an output
renamed so as not to overwrite sexc.o. Read off their imports and built
from an object named after their source, they share one rule.
2026-10-19 21:49:43 +03:00
faa9036dcc take every program in tests/sex-programs as a test
A program left out of the hand-kept list was never run, and nothing said
so; the one module the tests import moves to lib/ instead.
2026-10-19 21:49:32 +03:00
c33bfd704d check modules and exit codes with the test egg
Written as shell inside make, a check said only that it failed and left
the reason to rerunning it by hand; now each says what it expected.
2026-10-19 21:49:24 +03:00
a504fc1410 build the unit tests and sextest from the root
Each subdirectory's Makefile repeated the compiler's module list just to
link one program, and its result was copied back to the root anyway.
2026-10-19 21:48:16 +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