forked from alex-eg/sex
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.
33 lines
978 B
Scheme
33 lines
978 B
Scheme
(input)
|
|
(output "conditional operand: 75"
|
|
"cast as object of .: 7"
|
|
"cast of bitwise: 1"
|
|
"cast of conditional: 44"
|
|
"define body: 6")
|
|
(return 0)
|
|
|
|
;;; A Sex form is parenthesised by construction, and C is not: whatever
|
|
;;; the writer leaves bare, C regroups by its own precedence. Each line
|
|
;;; below came out regrouped, and all but the member access still
|
|
;;; compiled -- computing 4, 257, 300, and 4 from `2 * 1 + 2'.
|
|
|
|
(include stdio.h)
|
|
|
|
(record wanted ((distance int)))
|
|
|
|
(define SUM (+ 1 2))
|
|
|
|
(pub fn main () int
|
|
(var compared int 4)
|
|
(printf "conditional operand: %d\n" (/ 300 (if (> compared 0) compared 1)))
|
|
|
|
(var w wanted #(wanted : 7))
|
|
(var pa (* const void) (& w))
|
|
(printf "cast as object of .: %d\n" (. (cast pa (* const wanted)) distance))
|
|
|
|
(var x int 1)
|
|
(printf "cast of bitwise: %d\n" (cast (| x 256) u8))
|
|
(printf "cast of conditional: %d\n" (cast (if x 300 1) u8))
|
|
(printf "define body: %d\n" (* 2 SUM))
|
|
(return 0))
|