From 6bf4dde4878dc334280fdcb47163832a381c5c97 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sun, 19 May 2024 18:38:44 -0400 Subject: [PATCH] do expressions --- janet/interpreter.janet | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/janet/interpreter.janet b/janet/interpreter.janet index 47ecd32..40ef568 100644 --- a/janet/interpreter.janet +++ b/janet/interpreter.janet @@ -324,8 +324,12 @@ (defn- partial [the-fn args] (todo "partially applied functions")) (defn- call-fn [the-fn args] - (print "calling fn " (the-fn :name)) - (print "with args " args) + (print "calling " (b/show the-fn)) + (print "with args " (b/show args)) + (when (or + (= :function (type the-fn)) + (= :cfunction (type the-fn))) + (break (the-fn ;args))) (def clauses (the-fn :body)) (def len (length clauses)) (when (the-fn :match) (break ((the-fn :match) 0 args))) @@ -360,7 +364,7 @@ (match types [:fn :tuple] (call-fn prev curr) [:fn :partial] (partial prev curr) - [:function :tuple] (prev ;curr) + [:function :tuple] (call-fn prev curr) [:keyword :args] (get (first curr) prev :^nil) [:dict :keyword] (get prev curr :^nil) [:nil :keyword] :^nil @@ -384,7 +388,15 @@ (print "done with inner terms, applying last term") (apply-synth-term prev (interpret last-term ctx))) -(defn- doo [ast ctx] (todo "do expressions")) +(defn- doo [ast ctx] + (def terms (ast :data)) + (var prev (interpret (first terms) ctx)) + (def last-term (last terms)) + (for i 1 (-> terms length dec) + (def curr (interpret (terms i) ctx)) + (set prev (call-fn curr [prev]))) + (def last-fn (interpret last-term ctx)) + (call-fn last-fn [prev])) (defn- pkg [ast ctx] (todo "pkgs"))