bugfixes #66

Merged
pkulev merged 43 commits from bugfixes into main 2026-10-19 21:14:40 +02:00
Owner
No description provided.
alex-eg requested review from pkulev 2026-10-14 18:56:01 +02:00
pkulev requested changes 2026-10-14 21:40:34 +02:00
Dismissed
pkulev left a comment
Collaborator

Reviewed at f9809c1 on CHICKEN 6.0.0. make run-tests is green, including modules ok and exit code ok. I then compiled programs outside the suite with this sexc -C and cc -std=c11.

These hold.

  • The precedence cases come out 300 / (compared > 0 ? compared : 1), (*q)[i], #define SUM (1 + 2) used as 2 * SUM, and compared != 0.
  • sizeof of (* char), (* const char), (* p), (unsigned int), int and [int 4] is sizeof(char *), sizeof(const char *), sizeof(*p), sizeof(unsigned int), sizeof(int), sizeof(int [4]).
  • 0x10, #x10, 0b11 and #o10 are the integers 16, 16, 3 and 8.
  • 0.9871465422297019 and -0.0 keep every digit.
  • Two methods that call each other get static int vːb (...); above vːa.
  • A grouped header is a sex error with (var i int 0) in it and with (= s 0).
  • Two case arms that each declare bits are each a C block.
  • match inside #(shape : ...) is match is a statement, and has no value.
  • A private record behind a pointer is a bodyless declaration on the interface. The same record by value, as a parameter or a return, is importers cannot see this type, held by value at the pub form.
  • --depfile= on tests/modules/greet-app.sex names greet.sex and ledger.sex, each with an empty rule. sexc -C -o - prints the C and creates no file.

Four of the fixes still miss the program they describe.

1. A function type counts as a pointer. type-uses marks every name inside an fn or closure type as behind a pointer, and the comment says declaring is enough. C still needs the body when that function takes or returns the type by value.

(record cell ((v int)))
(pub fn take ((cb (fn ((c cell)) void))) void)

--public-interface is (record cell) plus the pub fn. An importer compiles to:

struct cell;
typedef struct cell cell;
void take (void (*cb)(cell));

A callback written to that signature, (fn visit ((c cell)) void), is parameter 1 ('c') has incomplete type. (pub fn take ((cb (fn () cell))) void) is the same forward declaration, emitted as cell (*cb)(). The same cell written directly, (pub fn take ((c cell)) void), is already rejected at the pub form.

2. The member-path warning is one field late. The comment on walk-member-path says the warning names (. font handle). It runs when the type in hand is already missing, before the next field, so the last field is consumed and the walk returns.

(struct font ((size int)))
(pub fn main () int
  (var font (struct font))
  (return (. font handle)))

sexc is silent. The C is return font.handle;, and cc says struct font has no member named handle. Adding one more field, (. font handle x), warns cannot type this; '.' reads it as a value (. font handle). An untyped base warns about the name font.

3. [int const N] loses the bound. array-bound? treats a symbol after a qualifier as part of the type. A numeric bound is kept, so [int const 4] is four ints. A name is dropped:

(define N 4)
(var a [const int N])
(var b [int const N])
(var c [unsigned int N])

emits const int a[N];, int const N b[]; and unsigned int c[N];. cc expands the macro and rejects int const 4 b[] with expected identifier or '(' before numeric constant.

4. sexc file.sex -o - still writes an executable named -. -C -o - prints the C. Without -C, the output name - is passed to cc as -o -, and the working directory gets an ELF named -. The help says `-' is stdout too.

Reviewed at `f9809c1` on CHICKEN 6.0.0. `make run-tests` is green, including `modules ok` and `exit code ok`. I then compiled programs outside the suite with this `sexc -C` and `cc -std=c11`. These hold. - The precedence cases come out `300 / (compared > 0 ? compared : 1)`, `(*q)[i]`, `#define SUM (1 + 2)` used as `2 * SUM`, and `compared != 0`. - `sizeof` of `(* char)`, `(* const char)`, `(* p)`, `(unsigned int)`, `int` and `[int 4]` is `sizeof(char *)`, `sizeof(const char *)`, `sizeof(*p)`, `sizeof(unsigned int)`, `sizeof(int)`, `sizeof(int [4])`. - `0x10`, `#x10`, `0b11` and `#o10` are the integers 16, 16, 3 and 8. - `0.9871465422297019` and `-0.0` keep every digit. - Two methods that call each other get `static int vːb (...);` above `vːa`. - A grouped header is a sex error with `(var i int 0)` in it and with `(= s 0)`. - Two `case` arms that each declare `bits` are each a C block. - `match` inside `#(shape : ...)` is `match is a statement, and has no value`. - A private record behind a pointer is a bodyless declaration on the interface. The same record by value, as a parameter or a return, is `importers cannot see this type, held by value` at the pub form. - `--depfile=` on `tests/modules/greet-app.sex` names `greet.sex` and `ledger.sex`, each with an empty rule. `sexc -C -o -` prints the C and creates no file. Four of the fixes still miss the program they describe. **1. A function type counts as a pointer.** `type-uses` marks every name inside an `fn` or `closure` type as behind a pointer, and the comment says declaring is enough. C still needs the body when that function takes or returns the type by value. ```sex (record cell ((v int))) (pub fn take ((cb (fn ((c cell)) void))) void) ``` `--public-interface` is `(record cell)` plus the pub fn. An importer compiles to: ```c struct cell; typedef struct cell cell; void take (void (*cb)(cell)); ``` A callback written to that signature, `(fn visit ((c cell)) void)`, is `parameter 1 ('c') has incomplete type`. `(pub fn take ((cb (fn () cell))) void)` is the same forward declaration, emitted as `cell (*cb)()`. The same `cell` written directly, `(pub fn take ((c cell)) void)`, is already rejected at the pub form. **2. The member-path warning is one field late.** The comment on `walk-member-path` says the warning names `(. font handle)`. It runs when the type in hand is already missing, before the next field, so the last field is consumed and the walk returns. ```sex (struct font ((size int))) (pub fn main () int (var font (struct font)) (return (. font handle))) ``` sexc is silent. The C is `return font.handle;`, and cc says `struct font has no member named handle`. Adding one more field, `(. font handle x)`, warns `cannot type this; '.' reads it as a value (. font handle)`. An untyped base warns about the name `font`. **3. `[int const N]` loses the bound.** `array-bound?` treats a symbol after a qualifier as part of the type. A numeric bound is kept, so `[int const 4]` is four ints. A name is dropped: ```sex (define N 4) (var a [const int N]) (var b [int const N]) (var c [unsigned int N]) ``` emits `const int a[N];`, `int const N b[];` and `unsigned int c[N];`. cc expands the macro and rejects `int const 4 b[]` with `expected identifier or '(' before numeric constant`. **4. `sexc file.sex -o -` still writes an executable named `-`.** `-C -o -` prints the C. Without `-C`, the output name `-` is passed to cc as `-o -`, and the working directory gets an ELF named `-`. The help says `` `-' is stdout too ``.
Author
Owner

Thanks. The branch is rebased onto the updated static-dispatch (913af0b) and force-pushed. Each of the four now refuses its repro or compiles it. make run-tests is green, and vs-map-viewer and asterdemo generate byte-identical C.

1. A function type counts as a pointer

4ac386f. A function type takes and returns its types by value whatever it is held through, since C wants the body to define or call one of its functions. Both repros, (fn ((c cell)) void) and (fn () cell), are now importers cannot see this type, held by value at the pub form, as cell written directly already was. A (* cell) inside the function type is still declared and no more.

2. The member-path warning

dd1718d. The warning was right for the case its comment meant: (. font handle x) on a struct only C knows warns of (. font handle), and (. font handle) alone needs no warning, the last field deciding nothing. The hole was a struct declared here, whose fields we do know. (. font handle) on (struct font ((size int))) is now no field of this name in, naming the struct and the field, at any step of the path. An indexed step like [xs 0] is checked by its name. The comment now says which case is which.

3. [int const N]

6ced17c. A qualifier waits for a type name only when no type came before it. [int const N] and [mytype const N] are int const b[N] and mytype const b[N], while [const mytype] and [* const mytype] stay unsized.

4. -o - without -C

c317d99. Refused rather than supported: -o - is stdout only for text, that is -C, -m and --public-interface. Anything else is -o - is stdout, which takes only -C, -m or --public-interface, before any work and before cc, so no file named - appears. The help says so, and tests/exit-code checks that no file is left.

Thanks. The branch is rebased onto the updated `static-dispatch` (913af0b) and force-pushed. Each of the four now refuses its repro or compiles it. `make run-tests` is green, and vs-map-viewer and asterdemo generate byte-identical C. ## 1. A function type counts as a pointer 4ac386f. A function type takes and returns its types by value whatever it is held through, since C wants the body to define or call one of its functions. Both repros, `(fn ((c cell)) void)` and `(fn () cell)`, are now `importers cannot see this type, held by value` at the pub form, as `cell` written directly already was. A `(* cell)` inside the function type is still declared and no more. ## 2. The member-path warning dd1718d. The warning was right for the case its comment meant: `(. font handle x)` on a struct only C knows warns of `(. font handle)`, and `(. font handle)` alone needs no warning, the last field deciding nothing. The hole was a struct declared here, whose fields we do know. `(. font handle)` on `(struct font ((size int)))` is now `no field of this name in`, naming the struct and the field, at any step of the path. An indexed step like `[xs 0]` is checked by its name. The comment now says which case is which. ## 3. `[int const N]` 6ced17c. A qualifier waits for a type name only when no type came before it. `[int const N]` and `[mytype const N]` are `int const b[N]` and `mytype const b[N]`, while `[const mytype]` and `[* const mytype]` stay unsized. ## 4. `-o -` without `-C` c317d99. Refused rather than supported: `-o -` is stdout only for text, that is `-C`, `-m` and `--public-interface`. Anything else is `-o - is stdout, which takes only -C, -m or --public-interface`, before any work and before cc, so no file named `-` appears. The help says so, and `tests/exit-code` checks that no file is left.
alex-eg requested review from pkulev 2026-10-15 20:06:04 +02:00
pkulev changed target branch from static-dispatch to main 2026-10-19 17:07:47 +02:00
pkulev added 40 commits 2026-10-19 17:07:47 +02:00
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.
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.
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.
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.
(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.
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.
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.
(* 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.
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.
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.
The tests spelled out (¤ ...), what [...] reads into, which nobody
writes. The reader's own tests keep it: there it is the point.
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.
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.
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.
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.
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.
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.
make-absolute-pathname with no directory of its own put `src' under
the root, so SEX_MODULE_PATH=src searched /src/.

Fixes #48.
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.
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.
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.
read-public-interface has returned the forms in order since 2512d52,
and --public-interface still reversed them as it had to before.
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.
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.
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.
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.
walk-initializer took its place, but walked the values as statements;
a match among them is refused again wherever the literal stands.
fn-prototype repeated sex-fn-prototype, and names? repeated mentions?;
each pair kept the better half.
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.
-o - was taught to two copies of it.
Read from a table, the patterns were compiled again for every symbol
written; that tripled what unkebabify cost.
A pub import chain had its interface check read every module below
again, so the deepest was parsed once per level above it.
(for ((= s 0) (< s n) (++ s)) ...) passed the check and reached cc as
a call of (= s 0).
encapsulation.scm had copies of both from codegen.scm.
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.
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.
[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.
Only the text outputs knew `-' as stdout; compiling handed it to cc as
a file name, and left a binary called `-' behind.
alex-eg added 3 commits 2026-10-19 17:21:22 +02:00
Every module's interface check walks the pub imports below it, so a
chain reduced each module's interface once per level above it.
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.
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
540f5c75cd
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.
pkulev approved these changes 2026-10-19 21:13:45 +02:00
pkulev left a comment
Collaborator

Approved at 540f5c7 on CHICKEN 6.0.0. make run-tests is green, including modules ok and exit code ok.

The four programs from the last review are fixed.

A function type is held by value on the interface, including through a pointer. (pub fn take ((cb (fn ((c cell)) void))) void) and (pub fn take ((cb (fn () cell))) void) and (pub fn take ((cb (* (fn ((c cell)) void)))) void) are importers cannot see this type, held by value at the pub form. A pointer inside the function type is still a declaration:

struct cell;
typedef struct cell cell;
void take (void (*cb)(cell *));

sexc -c accepts an importer that passes (fn visit ((c (* cell))) void).

A field a struct declared here does not have is no field of this name in (struct font) handle, on (. font handle) and on (. font handle x). (. font size) is font.size. A struct only C knows still warns one step in: (. t a b) says cannot type this; '.' reads it as a value (. t a), and (. t a) says nothing. An indexed field that is there is w.xs[0].

[int const N] is int const b[N], [const int N] is const int a[N], [unsigned int N] is unsigned int d[N], [mytype const N] is mytype const c[N], and [const mytype] stays const mytype e[].

sexc file.sex -o - and sexc -c -o - are -o - is stdout, which takes only -C, -m or --public-interface, and no file named - is left. sexc -C -o - and sexc --public-interface -o - print the text.

Two methods that call each other still get the later one's prototype above the first body.

Approved at `540f5c7` on CHICKEN 6.0.0. `make run-tests` is green, including `modules ok` and `exit code ok`. The four programs from the last review are fixed. A function type is held by value on the interface, including through a pointer. `(pub fn take ((cb (fn ((c cell)) void))) void)` and `(pub fn take ((cb (fn () cell))) void)` and `(pub fn take ((cb (* (fn ((c cell)) void)))) void)` are `importers cannot see this type, held by value` at the pub form. A pointer inside the function type is still a declaration: ```c struct cell; typedef struct cell cell; void take (void (*cb)(cell *)); ``` `sexc -c` accepts an importer that passes `(fn visit ((c (* cell))) void)`. A field a struct declared here does not have is `no field of this name in (struct font) handle`, on `(. font handle)` and on `(. font handle x)`. `(. font size)` is `font.size`. A struct only C knows still warns one step in: `(. t a b)` says `cannot type this; '.' reads it as a value (. t a)`, and `(. t a)` says nothing. An indexed field that is there is `w.xs[0]`. `[int const N]` is `int const b[N]`, `[const int N]` is `const int a[N]`, `[unsigned int N]` is `unsigned int d[N]`, `[mytype const N]` is `mytype const c[N]`, and `[const mytype]` stays `const mytype e[]`. `sexc file.sex -o -` and `sexc -c -o -` are `-o - is stdout, which takes only -C, -m or --public-interface`, and no file named `-` is left. `sexc -C -o -` and `sexc --public-interface -o -` print the text. Two methods that call each other still get the later one's prototype above the first body.
pkulev merged commit 540f5c75cd into main 2026-10-19 21:14:40 +02:00
pkulev deleted branch bugfixes 2026-10-19 21:14:45 +02:00
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#66