diff --git a/janet/validate.janet b/janet/validate.janet index ca1e408..33b7472 100644 --- a/janet/validate.janet +++ b/janet/validate.janet @@ -13,7 +13,7 @@ Tracking here, before I start writing this code, the kinds of validation we're h * [x] recur not called outside of `loop` forms * [x] `loop` form arity checking * [x] arity checking of explicit named function calls -* [ ] flag tail calls +* [x] flag tail calls Imports are for a later iteration of Ludus: * [ ] no circular imports DEFERRED @@ -290,7 +290,14 @@ Imports are for a later iteration of Ludus: (defn- pkg-root [validator]) # * [ ] flag tail calls (where last term is not-partial args) -(defn- tail-call [validator]) +(defn- tail-call [validator] + (def ast (validator :ast)) + (when (ast :partial) (break validator)) + (def status (validator :status)) + (when (not (status :tail)) (break validator)) + (def data (ast :data)) + (def args (last data)) + (set (args :tail-call) true)) # * [ ] arity checking if first term is name that resolves to a function and args aren't partial # XXX: now just check number of args against arity map @@ -579,16 +586,16 @@ Imports are for a later iteration of Ludus: (do #(comment (def source ` -fn foo { - () -> :bar - (x) -> :foo - (x, y, ...z) -> :baz +fn bar () -> :bar +fn foo () -> match :foo with { + a -> bar () + b -> :baz } -foo (4) `) (def scanned (s/scan source)) (def parsed (p/parse scanned)) (def validator (new-validator parsed)) (pp validator) -((validate validator) :errors) +(validate validator) +(pp parsed) )