Commit Graph

31 Commits

Author SHA1 Message Date
1084b7d266 add static-assert to sex
Expands to C11 _Static_assert keyword
2026-09-29 21:05:52 +03:00
ca88d9b386 implement compound and designated literals support
All checks were successful
Sex CI / build-linux (pull_request) Successful in 4m46s
Sex CI / build-linux (push) Successful in 4m50s
2026-09-27 19:35:37 +03:00
a9b00f2135 use true bool, since we target c99 onwards 2026-09-27 18:06:59 +03:00
26e8e6c374 fix lambdas and add a test to prevent rotting
Lambdas rotted because there wasn't any test for them, and after
return type moved to the end, lambdas stayed assumning it in the
front. We fix this and add test program
2026-09-27 16:11:05 +03:00
534e9ef56b say what is wrong with a pointer type, and stop mangling fn ones
The guard against nested pointer chains searched every sublist for a
`*', including the ones that hold a type of their own.

A function type with a pointer parameter, while the same type with an int
parameter passed. (* [char 4]) was let through as well and came out
as `vector-ref char 4 * p'.

A `*' inside an array or a function type belongs to that type, so the
search stops there. What the flat conversion cannot express is now
named: a fn type is a function pointer already, and a pointer to an
array is not supported.

Parameters of a function type are walked without their names. C writes
a parameter name into a declarator and a type has none, so fmt-c prints
whatever it is handed there as a type: `(s (* char))' came out as
`char(*) s'.

fmt-c printed a nameless array declarator's #f into the C, which showed
up in these parameters.
2026-09-23 14:31:41 +03:00
e0a228c66e make feature guard produce nothing on eof/closing bracket/paren
A dropped datum is replaced by whatever follows it, but what follows
may be the end of the file or the paren closing the list we are
in. Hand the token back to the caller instead: read-list closes its
list with it and the toplevel loop stops.

A `;' comment between a guard and the form it guards was also taken for
the guarded datum, so the form stayed unconditional and the guard did
nothing. Skip comments when reading the guard.

comment-form? was defined three times over; it moves to utils.
2026-09-23 14:31:38 +03:00
847bb14340 accept pub enum, and enums used as types
Implement pub support for enums, and also anonymous enums declared
in-place.

Also give the cdr of a `pub' form the form's own location, so a
error about what follows `pub' can say where it was written
2026-09-16 17:02:45 +03:00
522c5a2c01 reject nested pointer types with proper error message 2026-09-15 21:28:41 +03:00
28ad33ca38 add sex-error reporting 2026-09-15 21:28:41 +03:00
5f9f90ef37 support || | |= operators, since we now have our own parser
Some checks failed
Sex CI / build-linux (pull_request) Failing after 3m1s
Sex CI / build-linux (push) Failing after 3m1s
Sex CI / build-macos (push) Has been cancelled
Sex CI / build-macos (pull_request) Has been cancelled
2026-09-15 20:18:20 +03:00
7e6e32488b fix stray commas and add comment packing
Some checks failed
Sex CI / build-linux (pull_request) Failing after 3m1s
Sex CI / build-macos (pull_request) Has been cancelled
2026-09-15 16:32:55 +03:00
fa4ad5acee fix comments inside statements shifting their meaning 2026-09-15 16:32:55 +03:00
d609a0c591 begin -> do
Shorter and doesn't imply existence of `end'
2026-09-15 16:32:55 +03:00
d83ee32f12 add source line number preservation
Some checks failed
Sex CI / build-macos (pull_request) Has been cancelled
Sex CI / build-linux (pull_request) Failing after 3m34s
For source-level debug. Add --line-directives option, defaulted to
statement. Disabled when used with -C. Explicit non-none value
overrides disabling when -C is present
2026-09-09 14:16:32 +03:00
528f26b7ef migrate to Chicken 6 2026-09-09 12:45:12 +03:00
1ca77aaf59 replace Scheme read with our tokenizer and parser
Also implement . as field access operator and preserve ;-comments in
generated C
2026-09-09 12:44:52 +03:00
196694f18e modularize sex
Also rename macros to sex-macros, module-system to sex-modules for
clarity, uniformity, and to avoid name clashes with Chicken's
units/modules named "macros" and "modules"
2026-04-29 22:48:55 +03:00
f5b3fcb399 add #line directive to generated C code to support source debugging 2025-12-01 15:42:06 +03:00
c483b81f1c replace fold-right append with flatten in type-convert-to-c
They are not equivalent, but it'll be allright in this
case. Probably. Passes tests at least.
2025-10-30 18:05:44 +03:00
9e50df5c44 add malformed fn form match case in fmt-c-writer
Spent like 10 minutes trying to understand why my fn pointer is being
fucked up in test case. Turned out I was missing return type, and
whole fn pointer type fall through down to defaut case.
2025-10-30 18:05:44 +03:00
e4c79bda75 rewrite Todo -> TODO
for better searchig I guess?
2025-10-30 18:05:44 +03:00
e9de3409ec optimize fmt-c-writer type unwrapping 2025-10-30 18:05:44 +03:00
Ekaterina Vaartis
fc332311d3 fix nested types producing wrong C code 2025-10-30 18:05:44 +03:00
951f96f340 add define support 2025-10-30 18:05:44 +03:00
a6348b7b5a add enum support 2025-10-30 18:05:44 +03:00
2f75e80bc9 add c-or/c-bit-or/c-bit-or= support 2025-10-30 18:05:44 +03:00
c517b522ad fix structure attributes 2025-10-30 18:05:44 +03:00
0d314388f0 fix arrays of structs, multiple struct fields with same type 2025-10-30 18:05:44 +03:00
f9c58b21b4 overhaul fmt-c-writer completely
It now looks very nice.
2025-10-30 18:05:44 +03:00
48a3d06925 move Sex to better types
Types, fns and vars are now written in another, better, more intuitive
and readable way.

Types:
"pointer to const char" is "* const char"
"array of pointers to volatile int" is "[* volatile int]"
Read left to right

Vars (as well as fn args, struct fields):
(var name type)
(struct vec3 ((x float) (y float) (z float))
(fn vec3-add ((v1 vec3) (v2 vec3)) vec3 ...)

Also fns are now have return types after arg list.

* is now must not be attached to any type name (or variable for that
matter)
2025-10-30 18:05:44 +03:00
b1744bb6af split semantic processing and fmt-c code generation
Introducing Sex SEMantic ENgine: the semen.
Also split reader to other file (it can be replaced in the future).
Macro expansion inside Sex code doesn't work yet, and it must be done
in semen, not during fmt-c generation as before.
2025-09-29 15:50:01 +03:00