The slot after a defn's parameters is unconditionally a type. Parse.decl no
longer takes a set of type names, and is_type_form, qualified_type, types_in,
declared_types and prelude_types are gone with the pre-pass that fed them.
What they were for: (Option f64) and (Some 1) are the same s-expression, so the
parser decided which it had by looking the head up in a set of the file's own
type names. Sound -- one top-level namespace means a name cannot be both a type
and a value -- and brittle, because the set had to be complete. It was wrong
twice in one day, the second time parsing (defn f [] (Rune {.code 65}) (bar))
as a function returning a Rune with a one-form body, silently, in every file in
the language.
Two things fall out. A type the parser could not have known -- a struct
declared further down the file, rl/Vector2 behind an unresolved alias, a
prelude type -- never needed recognising, only placing. And a mistyped type is
a mistyped type: (defn f [] f65 0.0) reaches the resolver's near-miss check and
says did you mean f64, where it used to be read as the first form of the body
and reported as an unknown name.
Unit is written (). The old spelling is refused with a message naming the new
one, the rule the colon-to-dot change followed. Internally it is still
Tname "Unit" and Types.Unit, so the resolver, the shim and the emitter did not
change; Cimport still builds Tname "Unit" for C's void without going through
the parser. Types.to_string prints () though -- that printer prints what a
person would write for every other type it knows, [i32], {K V}, (Ptr T), and
Unit was the odd one out once the source spelling moved.
Dropping prelude_types removes one of the two reasons Macro.reduce may only
drop defns: the memoised set a bootstrap build could have poisoned is gone, so
the remaining reason is the plain one.
45 lines
1.5 KiB
Plaintext
45 lines
1.5 KiB
Plaintext
;;;; unless, which used to be a special form in parse.ml and is a defmacro in
|
|
;;;; the prelude now. plan.org milestone 5 says the five conditional sugars are
|
|
;;;; special forms only until macros land; this is the first one to stop being
|
|
;;;; one, and running this file means the expander compiled a macro into a
|
|
;;;; shared object, dlopened it into the compiler, and called it -- before the
|
|
;;;; first line below was parsed.
|
|
;;;;
|
|
;;;; Nothing here is new syntax. Every line of it compiled the same way before
|
|
;;;; the move, which is the point: the test for the feature is the corpus that
|
|
;;;; was written against the special form.
|
|
|
|
(defn classify [n i32] string
|
|
(let [out "even"]
|
|
(unless (= 0 (% n 2))
|
|
(set out "odd"))
|
|
out))
|
|
|
|
(defn main [] i32
|
|
;; One body form, the common case.
|
|
(unless false (println "the test was false"))
|
|
(unless true (println "NOT PRINTED"))
|
|
|
|
;; Several, which is what the do in the expansion is for.
|
|
(unless false
|
|
(print "a")
|
|
(print "b")
|
|
(println "c"))
|
|
|
|
;; A computed test, so the argument is a form the macro had to put back
|
|
;; rather than a literal it could have ignored.
|
|
(let [n 7]
|
|
(unless (< n 3) (println "7 is not less than 3")))
|
|
|
|
;; Inside a function that returns a value, and inside a loop: the expansion
|
|
;; is an if with no else, so it is () and it does not decide the body's
|
|
;; value.
|
|
(println (classify 4))
|
|
(println (classify 5))
|
|
|
|
(let [seen 0]
|
|
(dotimes [i 5]
|
|
(unless (= i 2) (set seen (+ seen 1))))
|
|
(print seen) (println ""))
|
|
0)
|