From bc17fe50063935ba956e3d000d881caf8833719d Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Tue, 14 May 2024 18:52:11 -0400 Subject: [PATCH] successfully flag tail calls --- janet/validate.janet | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) 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) )