hold operators to the operands they take
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.
This commit is contained in:
@@ -781,7 +781,34 @@ whitespace aside, THEN?"
|
||||
(test-assert "and not one"
|
||||
(reports? (in-fn "(var x bool (>= a))") "a comparison takes two operands"))
|
||||
(test-assert "two is a comparison"
|
||||
(emits? (in-fn "(var x bool (<= a b))") "x = a <= b;")))
|
||||
(emits? (in-fn "(var x bool (<= a b))") "x = a <= b;"))
|
||||
;; ...and (/ a) as `/a', (! a b) as `a ! b'
|
||||
(test-assert "a division takes two or more"
|
||||
(reports? (in-fn "(var x int (/ a))") "takes two operands or more"))
|
||||
(test-assert "so does &&"
|
||||
(reports? (in-fn "(var x bool (&& a))") "takes two operands or more"))
|
||||
(test-assert "a compound assignment takes two"
|
||||
(reports? (in-fn "(+= a b a)") "takes two operands"))
|
||||
(test-assert "a negation takes one"
|
||||
(reports? (in-fn "(var x bool (! a b))") "takes one operand"))
|
||||
(test-assert "a bit-not too"
|
||||
(reports? (in-fn "(var x int (~ a b))") "takes one operand"))
|
||||
(test-assert "minus takes one or more"
|
||||
(reports? (in-fn "(var x int (-))") "takes one operand or more"))
|
||||
(test-assert "and with more than one is still a subtraction"
|
||||
(emits? (in-fn "(var x int (- a b a))") "x = a - b - a;"))
|
||||
;; ++ and -- step each operand in turn
|
||||
(test-assert "a statement steps each operand"
|
||||
(followed-by? (in-fn "(++ a b)") "++a;" "++b;"))
|
||||
(test-assert "so does a for's step, which is one expression"
|
||||
(emits? (in-fn "(for (var i int 0) (< i a) (++ i b) (g i))") "; ++i, ++b)"))
|
||||
(test-assert "and a value is one too, in parens"
|
||||
(emits? (in-fn "(var x int (-- a b))") "x = (--a, --b);"))
|
||||
;; a define's body is pasted, not walked, so it is looked at apart
|
||||
(test-assert "a define's body is held to the same"
|
||||
(reports? "(define BAD (< 1 2 3))" "a comparison takes two operands"))
|
||||
(test-assert "and steps each operand the same way"
|
||||
(emits? "(define (STEP a b) (++ a b))" "#define STEP(a, b) ((++(a), ++(b)))")))
|
||||
|
||||
;; An array bound was taken only when it was an integer literal, so a
|
||||
;; symbolic one fell into the type: `[int N]' came out `int N a[]'.
|
||||
|
||||
Reference in New Issue
Block a user