Compare commits

..

43 Commits

Author SHA1 Message Date
c317d9950c 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-15 14:49:46 +03:00
6ced17c20e 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-15 14:48:25 +03:00
dd1718dffb 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-15 14:47:12 +03:00
4ac386f373 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-15 14:44:34 +03:00
1599832ece tell what a member path walked from the fields it has left 2026-10-15 13:58:22 +03:00
99a41b9d04 share reading a test source and catching its error
encapsulation.scm had copies of both from codegen.scm.
2026-10-15 13:58:22 +03:00
4d31e2ed9b parenthesise a conditional without a helper to do it for 2026-10-15 13:58:22 +03:00
d0e806bf84 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-15 13:58:22 +03:00
d92b5fc696 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-15 13:58:22 +03:00
fd6520dbe8 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-15 13:58:22 +03:00
4ad4133d92 name the test for output going to stdout
-o - was taught to two copies of it.
2026-10-15 13:58:22 +03:00
6a8c68fe3d 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-15 13:58:22 +03:00
ed7bf0879a 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-15 13:58:22 +03:00
a95e55fddc 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-15 13:58:22 +03:00
9b503c1017 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-15 13:58:22 +03:00
8db435f994 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-15 13:58:22 +03:00
286936488b 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-15 13:58:22 +03:00
86830ee4c9 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-15 13:58:22 +03:00
17badcb966 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-15 13:58:22 +03:00
31d876e30e 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-15 13:58:22 +03:00
d94daa9066 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-15 13:58:21 +03:00
24f11cdcba 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-15 13:58:21 +03:00
acd7010e6b 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-15 13:58:21 +03:00
f8c03d17c0 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-15 13:58:21 +03:00
250713e01d 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-15 13:58:21 +03:00
314bdc4e2d 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-15 13:58:21 +03:00
b9b3f9da5f 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-15 13:58:21 +03:00
2673b25f1d 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-15 13:58:21 +03:00
c162005241 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-15 13:58:21 +03:00
12d0d13a7c 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-15 13:58:09 +03:00
36ff456d24 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-15 13:58:09 +03:00
566e8326a3 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-15 13:58:09 +03:00
d41960e407 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-15 13:58:09 +03:00
85511ae037 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-15 13:58:09 +03:00
1acdd0e708 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-15 13:58:09 +03:00
c06845a80a 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-15 13:58:09 +03:00
816c1db9ed 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-15 13:58:09 +03:00
e465f6892a 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-15 13:58:09 +03:00
3701aeab3f 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-15 13:58:09 +03:00
8d1c12d03b 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-15 13:58:09 +03:00
913af0b463 start a global from braces, not a compound literal
All checks were successful
Sex CI / build-linux (pull_request) Successful in 5m42s
A compound literal is no constant in C11, so a global built by a
constructor or a typed literal failed under -pedantic-errors; gcc says
so, clang lets it pass.
2026-10-15 11:20:53 +03:00
6cda0873c6 hold a literal for an array field to the field's length
A longer one reached cc as excess elements, and a shorter one filled
the rest with zeros where a named array of that length was refused.
2026-10-15 11:15:57 +03:00
0a5eb1e0ce refuse a match in a control form's test
An if, while or for walked every slot as a statement, so a match in
its test came out as a switch inside the condition, which cc refuses.
2026-10-15 11:15:19 +03:00
8 changed files with 160 additions and 30 deletions

View File

@@ -553,8 +553,9 @@
;;;
;;; (var n int (match s ...)) -> int n = switch (s.tag) { ...
;;;
;;; A condition is not tracked: `walk-parts' takes every slot of an `if'
;;; alike.
;;; and in a control form's test, which C reads as an expression too:
;;;
;;; (if (match s ...) ...) -> if (switch (s.tag) { ...
(define operand-position? (make-parameter #f))
(define (walk-operand form env)
@@ -590,10 +591,13 @@
(cons walk-embed-result (walk-body expansion env)))))
(else
(case (car form)
((do for while if switch case case/fallthrough default)
((do case case/fallthrough default)
(parameterize ((operand-position? #f))
(with-scope env (lambda () (walk-parts form env)))))
((for while if switch)
(with-scope env (lambda () (walk-control form env))))
((lambda)
(let ((name (aux-name! env make-lambda-name)))
(add-aux-code! env (lift-lambda name form))
@@ -722,7 +726,12 @@
(convert-to-closure type arg env form)
(let ((given (expression-type arg env)))
(cond
((brace-initializer? arg) arg)
((brace-initializer? arg)
(let ((held (array-length type)))
(when (and held (not (= held (length (remove comment-form?
(vector->list arg))))))
(sex-error form "array is not as long as its field" (first field))))
arg)
((not (array-form? given))
(sex-error form "an array field takes an array" (first field)))
((not (eqv? (array-length given) (array-length type)))
@@ -906,6 +915,29 @@
(define (walk-parts form env)
(copy-form-source! form (walk-body form env)))
;;; A control form, its tests walked as values and the rest as
;;; statements
(define (walk-control form env)
(let ((slots (count (lambda (part) (not (comment-form? part))) (cdr form))))
(let loop ((parts (cdr form)) (i 0) (acc (list (car form))))
(cond
((null? parts) (copy-form-source! form (reverse acc)))
((comment-form? (car parts)) (loop (cdr parts) i (cons (car parts) acc)))
(else
(let ((walked (parameterize ((operand-position?
(test-slot? (car form) i slots)))
(walk-body (list (car parts)) env))))
(loop (cdr parts) (+ i 1) (append-reverse walked acc))))))))
;;; Whether the Ith of a control form's SLOTS is read as a value: an
;;; `if''s tests but not its trailing else, a `for''s header, the
;;; scrutinee of a `while' or a `switch'
(define (test-slot? head i slots)
(case head
((if) (and (even? i) (< (+ i 1) slots)))
((for) (< i 3))
(else (= i 0))))
;;; (match s ((circle (r)) ...) ((empty ()) ...)) is a switch over the
;;; tag, each arm a block binding that variant's fields as locals. `_'
;;; drops one. An arm the sum does not have, a wrong number of
@@ -1084,7 +1116,8 @@
;;; A type we cannot work out is read as a value, which is what the
;;; path would have meant before any of this. The warning names what
;;; could not be typed: the base, or the path up to a field of a struct
;;; only C knows -- (. font handle), not font.
;;; only C knows -- (. font handle x) warns of (. font handle), not
;;; font. A field a struct declared here lacks is an error.
(define (walk-member-path form env)
(let ((base (second form)))
(let step ((expr (walk-operand base env))
@@ -1093,7 +1126,10 @@
(told? #f))
(if (null? fields)
(copy-form-source! form expr)
(let ((target (pointer-target type)))
(let* ((target (pointer-target type))
(known (type-fields (or target type))))
(when (and (pair? known) (not (assq (field-name (car fields)) known)))
(sex-error form "no field of this name in" (or target type) (car fields)))
(unless (or type told?)
(let ((walked (drop-right (cddr form) (length fields))))
(sex-warning form "cannot type this; `.' reads it as a value"
@@ -1103,6 +1139,12 @@
(cdr fields)
(or told? (not type))))))))
;;; A field of a path, indexed or not: xs, [xs 0] -> xs
(define (field-name field)
(if (and (pair? field) (eq? '¤ (car field)) (pair? (cdr field)))
(second field)
field))
(define (lvalue? expr)
(cond ((symbol? expr) #t)
((vector? expr) #t) ; a compound literal is one
@@ -1883,7 +1925,8 @@
core
(if (> (length core) 3)
(append (take core 3)
(walk-operands core (drop core 3) env))
(map bare-braces
(walk-operands core (drop core 3) env)))
core))
env)))
(form (if qualifier
@@ -1893,6 +1936,17 @@
(add-name-type! (second core) (third core)))
(cons form (append (hash-table-ref env :lambda-aux-code) acc))))
;;; A compound literal is not a constant, though cc lets one pass at file
;;; scope unless asked to be pedantic; where it initializes, its braces
;;; alone say the same:
;;;
;;; (var g t (t/a 1)) -> static t g = {.tag = tǂa, .u = {.a = {1}}}
(define (bare-braces form)
(if (vector? form)
(let ((parts (list-split (vector->list form) ':)))
(list->vector (map bare-braces (last parts))))
form))
;;; Utils
(define (non-empty-list? form)
(and (list? form)

View File

@@ -202,7 +202,10 @@
;;;
;;; (* const cell) -> ((const . #t) (cell . #t))
;;; [cell 4] -> ((cell . #f))
;;; (fn ((cell)) int) -> ((cell . #t) (int . #t)) ; declaring is enough
;;; (fn ((cell)) int) -> ((cell . #f) (int . #f))
;;;
;;; A function type takes and returns by value whatever it is held
;;; through: C wants the body to define or call one of its functions.
(define (type-uses type behind?)
(cond
((symbol? type) (list (cons type behind?)))
@@ -215,7 +218,7 @@
(if (array-bound? type) (bound-uses (last type)) (list)))))
((fn closure)
(if (and (pair? (cdr type)) (list? (second type)))
(append-map (lambda (t) (type-uses t #t))
(append-map (lambda (t) (type-uses t #f))
(signature-types (second type) (last type)))
(list)))
((struct union enum)

View File

@@ -59,8 +59,8 @@
(value #f)
(single-char #\m))
(output ,(fmt #f "Write output to file. Default file name is a.out." nl
(pad padding) "If -C or -m options are provided, defaults to stdout;" nl
(pad padding) "`-' is stdout too")
(pad padding) "With -C, -m or --public-interface, defaults to stdout," nl
(pad padding) "which `-' names too")
(required #f)
(value #t)
(single-char #\o))
@@ -145,6 +145,12 @@
(define (stdout-output? output)
(or (eq? output 'default) (equal? output "-")))
;;; Whether ARGS ask for text, which `-o -' can send to stdout. An
;;; executable or an object goes to cc's -o, where `-' is a file name
(define (text-output? args)
(any (lambda (option) (get-arg args option #f))
'(emit-c macro-expand public-interface)))
(define (write-to-file-or-stdout output what)
(if (stdout-output? output)
(what)
@@ -254,6 +260,8 @@ status, which is ours to pass on."
(when help
(print-help)
(return #f))
(when (and (equal? output "-") (not (text-output? args)))
(error "-o - is stdout, which takes only -C, -m or --public-interface"))
;; Read time comes before everything, so the features have to be
;; in place before the first form is read
(current-features

View File

@@ -742,7 +742,8 @@ whitespace aside, THEN?"
(not (emits? "(struct pt ((x int))) (fn f ((p (* (struct pt)))) int (return (. (* p) x)))"
"*(p).x")))
(test-assert "member access through a cast"
(emits? (in-fn "(var n int (. (* (cast a (* (struct s)))) f))")
(emits? (string-append "(struct s ((f int)))"
(in-fn "(var n int (. (* (cast a (* (struct s)))) f))"))
"(*(struct s*)a).f"))
;; ...without gaining parens where none are due
(test-assert "a bare dereference is left alone"
@@ -774,7 +775,14 @@ whitespace aside, THEN?"
(test-assert "nor is an aggregate tag"
(emits? "(struct t ((z int))) (struct s ((a [struct t])))" "struct t a[]"))
(test-assert "nor one behind a pointer"
(emits? "(struct t ((z int))) (struct s ((a [* struct t])))" "struct t* a[]")))
(emits? "(struct t ((z int))) (struct s ((a [* struct t])))" "struct t* a[]"))
;; a qualifier waits for a type name only when none came before it
(test-assert "a name after a qualified type is a bound"
(emits? (in-fn "(var b [int const N])") "int const b[N]"))
(test-assert "after a qualified name too"
(emits? (in-fn "(var b [mytype const N])") "mytype const b[N]"))
(test-assert "but a qualifier alone still waits for the type"
(emits? "(typedef mytype int) (struct s ((a [const mytype])))" "const mytype a[]")))
;; `sizeof' takes a type or an expression, and `(* x)' is either.
;; What is in scope says which: a name C alone knows is a type
@@ -884,6 +892,14 @@ whitespace aside, THEN?"
(test-assert "which one step through it does not need"
(not (warns? (in-fn "(var t (* struct tm) 0) (= (. t a) 1)")
"cannot type")))
(test-assert "but a struct declared here has only the fields it names"
(reports? (in-line "(= (. p z) 1)") "no field of this name"))
(test-assert "the last step included"
(reports? (in-line "(= (. lp a z) 1)") "no field of this name"))
(test-assert "an indexed one by its name"
(reports? (string-append "(struct v ((xs [int 2])))"
(in-fn "(var w (struct v)) (= (. w [ys 0]) 1)"))
"no field of this name"))
;; the arrow is `%->' and nothing else writes one, so a bare `->'
;; is an ordinary head -- a threading macro that nobody imported,
;; and a call like any other unknown

View File

@@ -229,7 +229,11 @@ ahead of its pub forms."
(not (emits? "(pub sum t ((a ((x int)))))(fn f () t (return (t/a 1)))"
"t tːa (")))
(test-assert "so it is a constant at file scope"
(emits? "(sum t ((a ((x int)))))(var g t (t/a 1))" "static t g = (t){"))
(emits? "(sum t ((a ((x int)))))(var g t (t/a 1))"
"static t g = {.tag = tǂa, .u = {.a = {1}}};"))
(test-assert "as is any literal a global starts from"
(emits? "(record point ((x int) (y int)))(var g point #(point : 1 2))"
"static point g = {1, 2};"))
(test-assert "and an lvalue a method can take the address of"
(emits? (string-append
"(sum t ((a ((x int)))))"
@@ -254,6 +258,12 @@ ahead of its pub forms."
(test-assert "and as many as the field holds"
(reports? "(sum t ((a ((xs [int 2])))))(fn f () t (var v [int 3] #(1 2 3)) (return (t/a v)))"
"array is not as long as its field"))
(test-assert "and so must a literal"
(reports? "(sum t ((a ((xs [int 2])))))(fn f () t (return (t/a #(1 2 3))))"
"array is not as long as its field"))
(test-assert "not filling it with zeros either"
(reports? "(sum t ((a ((xs [int 2])))))(fn f () t (return (t/a #(1))))"
"array is not as long as its field"))
(test-assert "an array field takes an array"
(reports? "(sum t ((a ((xs [int 2])))))(fn f () t (var p (* int) 0) (return (t/a p)))"
"an array field takes an array"))
@@ -458,6 +468,20 @@ ahead of its pub forms."
(test-assert "not even as an argument"
(reports? (sum-src "(= out (match s ((circle (r)) r) (else 0.0)))")
"match is a statement"))
(test-assert "nor as an if's test"
(reports? (sum-src "(if (match s ((circle (r)) 1) (else 0)) (= out 1.0))")
"match is a statement"))
(test-assert "nor as a while's"
(reports? (sum-src "(while (match s ((circle (r)) 1) (else 0)) (= out 1.0))")
"match is a statement"))
(test-assert "nor in a for's header"
(reports? (sum-src "(for (var i int 0) (match s ((circle (r)) 1) (else 0)) (++ i)"
" (= out 1.0))")
"match is a statement"))
(test-assert "but an if's branches are statements, the else among them"
(emits? (sum-src "(if (== out 0.0) (match s ((circle (r)) (= out r)) (else (= out 1.0)))"
" (match s ((circle (r)) (= out 2.0)) (else (= out 3.0))))")
"out = 3.0;"))
(test-assert "but a case body is a statement"
(emits? (sum-src "(switch 1 (case 1 (match s ((circle (r)) (= out r))"
" (else (= out 0.0)))))")
@@ -503,6 +527,15 @@ ahead of its pub forms."
"held by value"))
(test-assert "returned"
(interface-reports? "(record cell ((v int))) (pub fn f () cell)" "held by value"))
(test-assert "or taken by a function a pub one takes"
(interface-reports? "(record cell ((v int))) (pub fn take ((cb (fn ((c cell)) void))) void)"
"held by value"))
(test-assert "or returned by one"
(interface-reports? "(record cell ((v int))) (pub fn take ((cb (fn () cell))) void)"
"held by value"))
(test "but a pointer there is still a pointer"
'((record cell))
(interface-of "(record cell ((v int))) (pub fn take ((cb (fn ((c (* cell))) void))) void)"))
(test-assert "or taken by a pub method"
(interface-reports? "(record cell ((v int))) (ops cell (pub fn get ((self cell)) int))"
"held by value"))

View File

@@ -1,12 +1,14 @@
# The failure paths.
#
# Both need a process to show themselves, so neither fits the unit
# suite: sexc has to fail when cc fails -- exiting 0 after a failed
# compile makes every driver, sextest included, read it as success --
# and it has to clean up its temporary .c when its own emission throws.
# Each needs a process to show itself, so none fits the unit suite:
# sexc has to fail when cc fails -- exiting 0 after a failed compile
# makes every driver, sextest included, read it as success -- it has to
# clean up its temporary .c when its own emission throws, and it has to
# refuse `-o -' for an executable, which cc would write to a file named
# `-'.
#
# Everything is built inside a scratch TMPDIR, so nothing is left here
# to clean up.
# Everything is built inside a scratch directory, so nothing is left
# here to clean up.
SEXC ?= ../../sexc
@@ -21,6 +23,10 @@ check:
echo "exit code FAILED: sexc reported success after cc failed"; \
rm -rf $$d; exit 1; \
fi; \
if (cd $$d && $(abspath $(SEXC)) $(CURDIR)/hello.sex -o - >/dev/null 2>&1) || [ -e $$d/- ]; then \
echo "exit code FAILED: -o - built an executable"; \
rm -rf $$d; exit 1; \
fi; \
rm -rf $$d; echo "exit code ok"
.PHONY: check

View File

@@ -1,6 +1,6 @@
(compilation "-- -std=c11 -pedantic-errors")
(input)
(output "c11: 42 43 6")
(output "c11: 42 43 6 4 6")
(return 0)
;;; C11 is the floor, and this is the program that holds it there: the
@@ -10,7 +10,8 @@
;;;
;;; A capturing closure is the one that leans on C11 itself, through
;;; max_align_t in the environment and `_Static_assert' on its size;
;;; the record, the method and the match are here for what they emit.
;;; the record, the method and the match are here for what they emit,
;;; and the globals for initializers that have to be constants.
(include stdio.h)
@@ -22,6 +23,9 @@
(sum shape ((square ((side int))) (dot ())))
(var corner point #(point : 2 3))
(var unit shape (shape/square 1))
(fn sides ((s shape)) int
(var n int 0)
(match s
@@ -34,6 +38,7 @@
(var k int 1)
(var add-k (closure ((int)) int)
(closure ((v int)) int (k) (return (+ v k))))
(printf "c11: %d %d %d\n"
(.area p) (add-k (.area p)) (+ (sides (shape/square 1)) (sides (shape/dot)) 2))
(printf "c11: %d %d %d %d %d\n"
(.area p) (add-k (.area p)) (+ (sides (shape/square 1)) (sides (shape/dot)) 2)
(sides unit) (.area corner))
(return 0))

View File

@@ -409,14 +409,14 @@
arglist))
;;; The last element is a bound unless what precedes it is still
;;; waiting for a type name -- a `*', a qualifier, a tag's keyword. C
;;; spells a type with one name at most, so a name after a name, or
;;; after a grouped type, can only be the bound:
;;; waiting for a type name -- a `*', a tag's keyword, a qualifier with
;;; no type before it. C spells a type with one name at most, so a name
;;; after a name, or after a grouped type, can only be the bound:
;;;
;;; (¤ int 4) four of int (¤ unsigned int) unsized
;;; (¤ pthread-t CAP) CAP of pthread-t (¤ struct point) unsized
;;; (¤ (* T) CAP) CAP of (* T) (¤ const mytype) unsized
;;; (¤ * size-t) unsized
;;; (¤ int const N) N of const int (¤ * size-t) unsized
;;;
;;; TYPE is the whole `(¤ ...)' form.
(define (array-bound? type)
@@ -426,8 +426,13 @@
(cond
((not (symbol? bound)) #t)
((or (memq bound +c-specifiers+) (memq bound +c-qualifiers+)) #f)
(else (not (or (memq preceding '(* struct union enum))
(memq preceding +c-qualifiers+))))))))
((memq preceding '(* struct union enum)) #f)
((memq preceding +c-qualifiers+)
(any (lambda (word)
(not (or (memq word '(* struct union enum))
(memq word +c-qualifiers+))))
(drop-right (cdr type) 2)))
(else #t)))))
;;; What one element of a written array type is:
;;; (¤ struct point 2) -> (struct point), (¤ * const char 2) -> (* const char)