forked from alex-eg/sex
keep the writer's own words to the head of a form
They were its own wherever they stood, so a name spelled like one -- (var array int), a parameter `define' -- came out %array, %define.
This commit is contained in:
@@ -954,6 +954,23 @@
|
||||
(emits? "(fn take ((f (fn ((int)) (fn () void)))) void (return))"
|
||||
"take (void (*(*f)(int))())")))
|
||||
|
||||
;; the writer's own words were its own wherever they stood, so a
|
||||
;; name spelled like one came out `%array'
|
||||
(test-group "names the writer has words for"
|
||||
(test-assert "as variables"
|
||||
(emits? (in-fn "(var array int 1) (var define int 2) (var include int 3) (g array define include)")
|
||||
"g(array, define, include)"))
|
||||
(test-assert "as parameters"
|
||||
(emits? "(fn sum ((array (* int)) (pointer int)) int (return (+ [array 0] pointer)))"
|
||||
"sum (int * array, int pointer)"))
|
||||
(test-assert "as fields"
|
||||
(emits? "(struct s ((prototype int) (attribute int)))" "int prototype;"))
|
||||
(test-assert "as a typedef's name, and used as a type"
|
||||
(emits? "(typedef array int) (fn f () void (var a array 1))" " array a = 1;"))
|
||||
(test-assert "while at a form's head they are the writer's still"
|
||||
(emits? "(include stdio.h) (fn f () void (static-assert (== 1 1) \"x\"))"
|
||||
"_Static_assert(1 == 1, \"x\")")))
|
||||
|
||||
;; Operands past what an operator takes were written as they came:
|
||||
;; (< a b c) as C's own chain, which compares a boolean with c
|
||||
(test-group "operator arity"
|
||||
|
||||
Reference in New Issue
Block a user