more-tests-and-corner-cases #72

Merged
pkulev merged 74 commits from more-tests-and-corner-cases into main 2026-10-27 22:21:02 +01:00
Owner

Just a bunch of tests covering corner cases and bugfixes for them.

Just a bunch of tests covering corner cases and bugfixes for them.
alex-eg added 70 commits 2026-10-26 23:32:18 +01:00
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.
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.
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.
A negative literal is one token in Sex and two in C, so (- -1) came out
--1, which C reads as decrementing a constant.
It came after, so a record pointing at itself, (next (* node)), named a
type C had not been told of yet.
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.
Under -std=c11 C reads trigraphs, which Sex has none of: "??=" came out
"#", and "??/" before the closing quote left the string open.
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.
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.
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.
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.
[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.
(< a b c) reached C as C's own chain, which compares a boolean with c.
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.
(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.
(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.
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.
The join took the first pointer, so (- p q) declared the distance
between two pointers as a third.
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.
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.
Only pub macros crossed, so one built on a private macro expanded in
the importer into a call of a C function nothing defines.
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.
A char is C's, and #\λ came out a multi-character constant whose value
is the C compiler's to choose.
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.
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.
sex-fmt-c exports a c-literal? of its own, and the writer imports both;
which one it got depended on the order of its imports.
(. 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 ->.
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.
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.
A type was flattened word by word, a struct's body included, so
(* (struct ((c int)))) came out struct c{ int; } *.
Anything in the list but a name or (name value) was taken apart as if
it were the pair: (! 1 2) came out ! = 1.
{} is C23's. #() is all zeros, which C11 spells {0}, whatever it
initializes.
(do), and a for with no body, gave c-begin nothing to begin with, and
the writer died on its arity.
() went to C as NULL, so (for () () ()) tested false and never ran; it
is for (;;).
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).
[3] in braces reached the writer as a subscript of one operand, and
sexc died taking the second.
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.
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.
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.
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.
A lifted function with no body was a declaration of one, and nothing
defined it, so the program did not link.
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.
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 *.
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.
Nothing solves it there, and it reached the C as _.
Every later stage's error says file:line, and the reader's said only
what; an unclosed list, met at the end of the file, now names the line
it opened on as well.
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.
(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.
((+ a 1)) was a capture named `+' holding a.
getopt-long read it as an option it did not know, and died.
A failed -C -o left the file truncated, which make would take for done.
It was never read, and nothing said so.
-o naming the input wrote over it, whatever was asked for.
Every error ended in CHICKEN's call history, which is for working on
sexc itself, and is now asked for by SEXC_DEBUG; a missing input file
says so, rather than as an open-input-file error of CHICKEN's.
They were its own wherever they stood, so a name spelled like one --
(var array int), a parameter `define' -- came out %array, %define.
A definition names every parameter before C23, as a closure's code
already does.
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.
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.
Two modules importing each other with pub hand the unit its own
interface back, and its types were defined twice.
It failed in whichever importer named the module before the spec's,
pointing at the module, where a hidden type is refused in the module
already: so is this, the remedy the same.
Its interface was read as written, so pub forms a macro wrote never
reached them, which list-macros' is-public? flag exists for. The
module's macros, and those its imports give it, are lent for the
reading and taken back after. One reading a type the module keeps to
itself cannot expand there, and gives importers nothing, as before.
record, struct and enum take one; sum read it where its variants go.
A pointer was refused, where . reads through one; a match now reads
through the whole chain of them to the sum.
One with fields is a member of the sum's union, and C takes no member
named int; one without is held to the same, as one rule.
017 is 17 to Scheme and 15 to C, so whoever reads the Sex and whoever
reads the C would each take it for something else.
The call was compiled as a function's, and the macro went unused there
without a word.
'-fields read as (- fields), so (cat name '-fields) built name(- fields).
A quoted list keeps the rule: it is code a macro returns as often as not.
It had no rule, so _ could not be set from one.
SEX_CC="ccache cc" went looking for an executable of that whole name;
it is read as make reads CC now.
read a member path and a receiver through a pointer chain
All checks were successful
Sex CI / build-linux (pull_request) Successful in 5m34s
acbd4928f5
A pointer to a pointer has no fields, so (. pp x) has one meaning, and
it came out pp->x; it is (*pp)->x, and a method receiver alike.
alex-eg requested review from pkulev 2026-10-26 23:32:18 +01:00
pkulev requested changes 2026-10-27 00:03:05 +01:00
Dismissed
pkulev left a comment
Collaborator

Request changes at acbd492. Built with CHICKEN 6.0.0. The second ./sex-tests passed. sextest passed all 26 programs in tests/sex-programs. check-modules, check-exit-code, and check-command-line passed.

Two of the new checks let a program through and hand cc -std=c11 -pedantic-errors something it rejects.

  1. Two captures of one name. check-capture-names compares each capture with the parameters, and with a var at the top of the body. The comment says no two are alike. Two captures are not in that comparison. Inside a function,
(var f (closure ((int)) int)
  (closure ((x int)) int (n n) (return (+ x n))))

comes out as a capture struct with two members n, a local int n twice, and ƛ0_outer_make (int n, int n). gcc reports a duplicate member and a redefinition of the parameter. sexc exits with gcc's status.

  1. -9223372036854775808 is the minimum long long, and the decimal is not a C literal. The signed ranks keep a value when abs is below 2^63. This one's absolute value is 2^63, so it has no type: (var x _ -9223372036854775808) is cannot infer the type of. Written out as (long long), the C is long long x = -9223372036854775808;. Under -std=c11 -pedantic-errors that constant is unsigned, and the negation is not the minimum. A positive past 2^63-1 is given a u and compiles. This one sits in the signed range.

The first ./sex-tests failed holds no directive in tests/line-directives.scm. The marker 123 also occurs in the path from create-temporary-directory, and that path is in every #line. A second run passed. The assertion and the temporary directory are older than this branch.

A toplevel macro that raises is dropped while a module's interface is read. An importer of a file whose (boom) calls (error "nope") still compiles, and still sees the other pub forms. Compiling that file itself reports expanding boom: nope. The comment says a call that cannot expand gives importers nothing; an error takes the same path.

Request changes at `acbd492`. Built with CHICKEN 6.0.0. The second `./sex-tests` passed. `sextest` passed all 26 programs in `tests/sex-programs`. `check-modules`, `check-exit-code`, and `check-command-line` passed. Two of the new checks let a program through and hand `cc -std=c11 -pedantic-errors` something it rejects. 1. **Two captures of one name.** `check-capture-names` compares each capture with the parameters, and with a `var` at the top of the body. The comment says no two are alike. Two captures are not in that comparison. Inside a function, ``` (var f (closure ((int)) int) (closure ((x int)) int (n n) (return (+ x n)))) ``` comes out as a capture struct with two members `n`, a local `int n` twice, and `ƛ0_outer_make (int n, int n)`. gcc reports a duplicate member and a redefinition of the parameter. sexc exits with gcc's status. 2. **`-9223372036854775808` is the minimum `long long`, and the decimal is not a C literal.** The signed ranks keep a value when `abs` is below `2^63`. This one's absolute value is `2^63`, so it has no type: `(var x _ -9223372036854775808)` is `cannot infer the type of`. Written out as `(long long)`, the C is `long long x = -9223372036854775808;`. Under `-std=c11 -pedantic-errors` that constant is unsigned, and the negation is not the minimum. A positive past `2^63-1` is given a `u` and compiles. This one sits in the signed range. The first `./sex-tests` failed `holds no directive` in `tests/line-directives.scm`. The marker `123` also occurs in the path from `create-temporary-directory`, and that path is in every `#line`. A second run passed. The assertion and the temporary directory are older than this branch. A toplevel macro that raises is dropped while a module's interface is read. An importer of a file whose `(boom)` calls `(error "nope")` still compiles, and still sees the other `pub` forms. Compiling that file itself reports `expanding boom: nope`. The comment says a call that cannot expand gives importers nothing; an error takes the same path.
alex-eg added 4 commits 2026-10-27 21:38:39 +01:00
check-capture-names held captures against the parameters and the body,
not against each other: (n n) gave C two members and two parameters n.
-9223372036854775808 reached C as written, where it negates an unsigned
constant, and had no type for inference: it is read as
-9223372036854775807 - 1, which is long long on both sides.
"holds no directive" searched for 123, a digit run the temporary
directory in every #line could hold too.
report a module's macro call failing for other than its own names
All checks were successful
Sex CI / build-linux (pull_request) Successful in 5m38s
Sex CI / build-linux (push) Successful in 5m33s
724f4dd3e9
Reading a module's interface dropped any toplevel call that raised, not
only one asking after a declaration of the module's, which no importer
has yet. Lookups now tell which names they missed, and only those failures
give importers nothing.
Author
Owner

Fixed at 724f4dd:

  1. 28aaaf6 refuses two captures of one name.
  2. a2bbb73 reads -9223372036854775808 as -9223372036854775807 - 1, typed long long; c11.sex now holds it under -pedantic-errors.
  3. d890080 finds the conditional by mvar < 123 … : 125, which no path holds.
  4. 724f4dd: lookups report the names they miss; an interface-time macro call that fails is dropped only when it asked after a name its own module declares. (boom) now fails for importers too (tests/modules/gen/broken.sex).
Fixed at `724f4dd`: 1. `28aaaf6` refuses two captures of one name. 2. `a2bbb73` reads `-9223372036854775808` as `-9223372036854775807 - 1`, typed `long long`; `c11.sex` now holds it under `-pedantic-errors`. 3. `d890080` finds the conditional by `mvar < 123` … `: 125`, which no path holds. 4. `724f4dd`: lookups report the names they miss; an interface-time macro call that fails is dropped only when it asked after a name its own module declares. `(boom)` now fails for importers too (`tests/modules/gen/broken.sex`).
pkulev approved these changes 2026-10-27 22:17:07 +01:00
pkulev left a comment
Collaborator

Approved at 724f4dd. make check passed on CHICKEN 6.0.0: the unit tests, all 26 programs in tests/sex-programs, check-modules, check-exit-code, and check-command-line.

The holes from last time are closed. Two captures of one name, including (a (a 1)), are refused before any C is written. -9223372036854775808 and -0x8000000000000000 are both long long n = -9223372036854775807 - 1, which -std=c11 -pedantic-errors accepts, and the value is the minimum. holds no directive looks for mvar < 123 and : 125, and passed. An importer of a module whose (boom) raises is told expanding boom: nope. A call that fails after asking for a name the module itself declares still gives the interface nothing, and the module's own compile is where that one is checked.

Approved at `724f4dd`. `make check` passed on CHICKEN 6.0.0: the unit tests, all 26 programs in `tests/sex-programs`, `check-modules`, `check-exit-code`, and `check-command-line`. The holes from last time are closed. Two captures of one name, including `(a (a 1))`, are refused before any C is written. `-9223372036854775808` and `-0x8000000000000000` are both `long long n = -9223372036854775807 - 1`, which `-std=c11 -pedantic-errors` accepts, and the value is the minimum. `holds no directive` looks for `mvar < 123` and `: 125`, and passed. An importer of a module whose `(boom)` raises is told `expanding boom: nope`. A call that fails after asking for a name the module itself declares still gives the interface nothing, and the module's own compile is where that one is checked.
pkulev merged commit 724f4dd3e9 into main 2026-10-27 22:21:02 +01:00
alex-eg reviewed 2026-10-27 23:45:48 +01:00
@@ -53,3 +56,3 @@
;;; A type variable is a mutable cell. `ref' is #f while unsolved and
;;; the type it stands for once bound -- union-find, with the path
;;; compression done in `resolve'.
;;; compression done in `resolve'. `quals' are the ones written on it --
Author
Owner

Uh... Rebase artifact?

Uh... Rebase artifact?
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alex-eg/sex#72