Commit Graph

144 Commits

Author SHA1 Message Date
00efbc5442 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-27 01:31:37 +03:00
bc4f9246c2 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-27 01:23:51 +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
600b4801de check sexc's command line on a sexc process
The -- split, the -o - spelling and the dependency rule were exported to
be unit tested, as lists and strings sexc might never hand on; a stand-in
cc and the depfile show what it does hand on.
2026-10-20 11:51:31 +03:00
ab881e4c31 test semen through semen-process alone
Its fn accessors, walk-form and macro-expand were exported to be called
on hand-built forms, checking what every compiled function and macro
already goes through; sex-fn-public? and sex-fn-body had no other caller.
2026-10-20 11:49:29 +03:00
6198c51e88 look up a module on SEX_MODULE_PATH through an import in its test
The test read the search list off get-module-paths, exported for it
alone; importing a module from each entry checks what the list is for.
2026-10-20 11:48:55 +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
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
62b1ead3eb refuse -o - for an executable or an object
Only the text outputs knew `-' as stdout; compiling handed it to cc as
a file name, and left a binary called `-' behind.
2026-10-19 16:05:08 +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
2279c371f2 hold a function type's parameters by value on the interface
A record a pub function type took or returned by value was declared
only, so an importer could neither define a callback for it nor call
one.
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
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
541d9cd610 check the constants a module's interface hands its importers
An array bound in a pub record, or a name in a pub define's body, is
the importer's to resolve too, and a private define, or one from an
import without pub, failed there as an undeclared identifier. Found in
vs-map-viewer once its units stopped importing everything. A constant
has no declaration short of itself, so it is an error at the pub form.
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
981eb6f755 print the public interface in declaration order
read-public-interface has returned the forms in order since 2512d52,
and --public-interface still reversed them as it had to before.
2026-10-19 16:05:08 +03:00
dc15aaadab write a make rule for the modules a unit reads
An import pastes another file's forms into the output, so a Makefile
had to make every object depend on every .sex. --depfile names the
modules read, including those read only for an import's interface,
with an empty rule for each, as cc -MD -MP does.

Fixes #40.
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
9fd40da8b1 resolve a relative SEX_MODULE_PATH entry from the working directory
make-absolute-pathname with no directory of its own put `src' under
the root, so SEX_MODULE_PATH=src searched /src/.

Fixes #48.
2026-10-19 16:05:08 +03:00
7abb125932 take -o - as stdout
getopt-long reads a lone `-' as an option, so -o - died there asking
for a value, and --output=- got through only to create a file named
`-'.

Fixes #43.
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
9057cbfcc6 anchor an if's arms only where the if is a statement
Every if had its arms anchored, including one inside an argument that
the writer renders as ?:, so a #line landed between its parts and the
C did not compile. -C output, with no directives, hid it.

Fixes #54.
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
f3d9c95daf read hex and binary literals
0x80 was not a number to string->number, so it became a symbol the
printer escaped as |0x80|, and #x was rejected outright. Both spellings
now read as the integer, which the C writes in decimal.

Fixes #47.
2026-10-19 16:04:51 +03:00
cc0f7f91ec read -NAME as the negation of NAME
The reader took -INFINITY as one symbol, and the leading dash was then
mangled like any other: _INFINITY. -1 was always a number, so a name
gets the same reading.

Fixes #63.
2026-10-19 16:04:51 +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
f0a1b6712f spell ? and ! in names as letters C takes
A Lisp predicate came out as ident_start?, which no C compiler reads.
ʔ and ꜝ are letters that look the part; ǃ looks closer, but clang flags
it as a homoglyph of `!' at every use.

Fixes #49.
2026-10-19 16:04:51 +03:00
ba45069484 walk a define's body, and parenthesise it
The body was pasted as read, so `cast' stayed a call and names kept
their dashes; and fmt-c parenthesised only a function-like body, so
an object-like one regrouped with the operator it was pasted under.

Fixes #55.
2026-10-19 16:04:51 +03:00
8db9246389 convert enumerators written with a value
(wire-varint 0) is a pair, and both the writer and map-fields only
expected a name: the writer passed it out unconverted, and a macro
mapping over the enum was handed the pair.

Fixes #46.
2026-10-19 16:04:51 +03:00
6f29a9c203 write a typedef's target as a type
It fell through to the expression walk, which read (* const char) as a
dereference and an array as a subscript, and died on a fn type.

Fixes #53.
2026-10-19 16:04:51 +03:00
bc5f23881f spell an array bound as an expression
It went to fmt-c unwalked, so a bound named CHUNK-AREA kept its dash
while the same name in an expression became CHUNK_AREA.

Fixes #50.
2026-10-19 16:04:51 +03:00
dfdca46e1e tell an array's bound by the shape of its type
Whether a trailing name was the bound hinged on the word before it
being a typedef Sex had seen, which a header's pthread_t never is, and
a grouped (* T) never is either: [pthread-t N] became a two-word type.

Fixes #56, #60.
2026-10-19 16:04:51 +03:00
8bc27cba26 parenthesise casts and conditionals by precedence
Neither took part in it: a cast parenthesised its operand only from a
list of binary heads that missed `|', and never itself, so `->' took
it apart; `?:' was written bare under any operator, swallowing it into
the test. Three of the four still compiled, to wrong values.

Fixes #59, #61, #62.
2026-10-19 16:04:51 +03:00
db5507b180 give a record's docstring a line of its own
All checks were successful
Sex CI / build-linux (pull_request) Successful in 5m43s
Sex CI / build-linux (push) Successful in 5m42s
2026-10-19 15:56:05 +03:00
b5030e3824 say what the threading test checks, not how -> came free 2026-10-19 15:56:05 +03:00
8f7b26eafa name the encapsulation test after what it covers 2026-10-19 15:56:05 +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