;; Macro bodies the .fln printer must classify from their definitions: ;; test_syntax converts this file, runs both and wants the same output. ;; Counts its body forms: a let taking in the form after it would change the ;; count, so the body is not one a let may be flattened in. (defmacro counted [& body] (let [two (= (length body) 2)] `(do (println ~(if two (Form.Sym {.s "true"}) (Form.Sym {.s "false"}))) ~@body))) ;; Replaces the prelude's unless, and counts too. (defmacro unless [& args] (let [two (= (length args) 3)] `(do (println ~(if two (Form.Sym {.s "true"}) (Form.Sym {.s "false"}))) ~@(form-rest args 1)))) ;; The body once in a do and once as a vector's elements. (defmacro vtwice [& body] `(do ~@body (println (length [~@body])))) ;; The first body form is the loop's test. (defmacro labelled [& body] `(while :l ~@body)) ;; A guard that only asks whether there is a body: a body run in order. (defmacro guarded [& args] (if (< (length args) 1) `(do) `(do ~@args))) (defn main [] i32 (counted (let [x 1] (println x)) (println 2)) (unless false (let [y 3] (println y)) (println 4)) (vtwice (let [z 5] (println z) z) 6) (labelled (let [go false] go) (println 9)) (let [g 0] (guarded (let [g 1] (println g)) (println g))) 0)