fixed closure/function contexts work with forward declaration & mutual recursion
This commit is contained in:
parent
f80aa7a8dc
commit
a25ece5a68
|
@ -359,8 +359,21 @@
|
|||
# For now, this should be enough to tall the thing
|
||||
(defn- fnn [ast ctx]
|
||||
(def {:name name :data clauses :doc doc} ast)
|
||||
(def the-fn @{:name name :^type :fn :body clauses :ctx (table/to-struct ctx) :doc doc})
|
||||
(set (ctx name) the-fn))
|
||||
(print "defining fn " name)
|
||||
(def closure (table/to-struct ctx))
|
||||
(def the-fn @{:name name :^type :fn :body clauses :ctx closure :doc doc})
|
||||
(when (not= :^not-found (resolve-name name ctx))
|
||||
(print "fn "name" was forward declared")
|
||||
(def fwd (resolve-name name ctx))
|
||||
(set (fwd :body) clauses)
|
||||
(set (fwd :ctx) closure)
|
||||
(set (fwd :doc) doc)
|
||||
(print "fn " name " has been defined")
|
||||
(pp fwd)
|
||||
(break fwd))
|
||||
(pp the-fn)
|
||||
(set (ctx name) the-fn)
|
||||
the-fn)
|
||||
|
||||
(defn- is_placeholder [x] (= x :_))
|
||||
|
||||
|
@ -612,17 +625,18 @@
|
|||
# (when (has-errors? validated) (break (validated :errors)))
|
||||
# (def cleaned (get-in parsed [:ast :data 1]))
|
||||
# (pp cleaned)
|
||||
(interpret (parsed :ast) @{:^parent b/ctx})
|
||||
# (try (interpret (parsed :ast) @{:^parent b/ctx})
|
||||
# ([e] (print "Ludus panicked!: "
|
||||
# (if (struct? e) (error (e :msg)) (error e)))))
|
||||
# (interpret (parsed :ast) @{:^parent b/ctx})
|
||||
(try (interpret (parsed :ast) @{:^parent b/ctx})
|
||||
([e] (print "Ludus panicked!: "
|
||||
(if (struct? e) (error (e :msg)) (error e)))))
|
||||
)
|
||||
|
||||
(do
|
||||
(set source `
|
||||
fn myadd (x, y) -> add (x, y)
|
||||
let add = myadd(2, _)
|
||||
add (3)
|
||||
fn foo
|
||||
fn bar () -> foo ()
|
||||
fn foo () -> :foo
|
||||
bar ()
|
||||
`)
|
||||
(def result (run))
|
||||
(b/show result)
|
||||
|
|
Loading…
Reference in New Issue
Block a user