1
0
forked from alex-eg/sex
Commit Graph

317 Commits

Author SHA1 Message Date
4463f796f8 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-27 01:31:37 +03:00
8ddeac7bab 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-27 01:31:37 +03:00
c05904c15e 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-27 01:31:37 +03:00
27ef5ac805 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-27 01:31:37 +03:00
0cb3956e02 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-27 01:31:37 +03:00
0852079827 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-27 01:31:37 +03:00
5cd931cb4e 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-27 01:31:37 +03:00
6d84553652 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-27 01:31:37 +03:00
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
635cc48aa3 drop what infer had for types nothing builds
No source makes an unknown type, a rigid variable or a variable with a
class to satisfy, so the branches unify, bind-tvar! and entails? kept for
them never ran, and the classes registered for them were never asked.
2026-10-27 01:23:51 +03:00
d2f36d35c6 delete what nothing calls
walk-generic-toplevel and non-empty-list? had no caller left, a type
variable's id was never read, and every expression's type was recorded
in a table nothing looked up.
2026-10-27 01:23:51 +03:00
eb5bf3688b export only what another module imports
set-working-directory is reached only through with-directory's expansion,
so it is exported as that macro's helper; form-location, form-type,
register-macro and get-macro had no importer.
2026-10-27 01:23:51 +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
8488a58be1 redo the scan when modules.mk is missing
The stamp, newer than every source, stood for a modules.mk deleted since,
so make went on without the rules and called sex-tests up to date after a
test source changed.
2026-10-20 11:46:13 +03:00
0628d1c212 read a file once in an include cycle
Two files that include-relative each other sent the scan between them
for good, and make sat on the stamp recipe with it.
2026-10-20 11:46:13 +03:00
49b463ac7b keep a root file named after a CHICKEN module out of the graph
Only the eggs were told apart from the modules, so a scheme.scm became
the scheme every unit imports, a dependency of every object and of
itself, and the build went on to link it.
2026-10-20 11:46:13 +03:00
67749c8db0 build the programs the way the modules are built
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
397766822d read the module graph off the import forms
Each module's prerequisite line restated its import form, so adding a
module or an import meant editing the Makefile to match, and a missed
line only showed when an object came out of order.
2026-10-19 21:48:51 +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
c65721a070 keep the local egg repository in a file of its own
The Makefile was mostly about where the eggs live; what sexc is built
from is easier to find without it.
2026-10-19 21:48:04 +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
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
64db505e6b work out what a module exports once per unit
Every module's interface check walks the pub imports below it, so a
chain reduced each module's interface once per level above it.
2026-10-19 18:21:02 +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
44101c0c06 tell what a member path walked from the fields it has left 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
f87e9faa8f parenthesise a conditional without a helper to do it for 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
70aafb70e6 read each module once per unit
A pub import chain had its interface check read every module below
again, so the deepest was parsed once per level above it.
2026-10-19 16:05:08 +03:00
dcd93c0d9e compile the name spellings once, and skip a name that has none
Read from a table, the patterns were compiled again for every symbol
written; that tripled what unkebabify cost.
2026-10-19 16:05:08 +03:00
5b3f2bd421 name the test for output going to stdout
-o - was taught to two copies of it.
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
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
449a53abf9 hand sexc every digit of a test program's doubles
sextest prints the program it read back to sexc, and printed doubles
in CHICKEN's default 15 digits: 0.16666666666666666 arrived as
0.166666666666667, another number.
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