Compare commits
No commits in common. "bbd41a0f748aa0bdde811f98a1ba230448fc4904" and "3903f10c8dd9637bd2d1afed1c18fbcbd0e7fef4" have entirely different histories.
bbd41a0f74
...
3903f10c8d
|
@ -362,6 +362,7 @@
|
|||
(def the-fn @{:name name :^type :fn :body clauses :ctx ctx})
|
||||
(set (ctx name) the-fn))
|
||||
|
||||
# TODO
|
||||
(defn- is_placeholder [x] (= x :_))
|
||||
|
||||
(var call-fn nil)
|
||||
|
@ -388,8 +389,6 @@
|
|||
(print "Janet function")
|
||||
(break (the-fn ;args)))
|
||||
(def clauses (the-fn :body))
|
||||
(when (= :nothing clauses)
|
||||
(error {:node the-fn :value args :msg "cannot call function before it is defined"}))
|
||||
(def len (length clauses))
|
||||
(when (the-fn :match) (break ((the-fn :match) 0 args)))
|
||||
(defn match-fn [i args]
|
||||
|
@ -553,18 +552,15 @@
|
|||
# (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) @{})
|
||||
([e] (print "Ludus panicked!: "
|
||||
(if (struct? e) (error (e :msg)) (error e)))))
|
||||
(interpret (parsed :ast) @{:^parent b/ctx})
|
||||
# (try (interpret (parsed :ast) @{})
|
||||
# ([e] (print "Ludus panicked!: "
|
||||
# (if (struct? e) (error (e :msg)) (error e)))))
|
||||
)
|
||||
|
||||
(do
|
||||
(set source `
|
||||
fn foo
|
||||
fn bar () -> foo ()
|
||||
fn foo () -> :foo
|
||||
bar ()
|
||||
let #{:a ay, :b (:ok, bee), ...c} = #{:a 1, :b (:ok, 42), :c 3}
|
||||
`)
|
||||
(def result (run))
|
||||
# (b/show result)
|
||||
|
|
|
@ -786,7 +786,7 @@
|
|||
(def data (case (-> parser current type)
|
||||
:lbrace (fn-clauses parser)
|
||||
:lparen (fn-simple parser)
|
||||
:nothing))
|
||||
(panic parser (string "expected clause or clauses, got " (-> current parser type)))))
|
||||
@{:type :fn :name name :data data :token origin})
|
||||
([err] err)))
|
||||
|
||||
|
@ -1130,9 +1130,7 @@
|
|||
(do
|
||||
# (comment
|
||||
(def source `
|
||||
fn foo
|
||||
fn bar
|
||||
fn () -> :baz
|
||||
print! ("hello")
|
||||
`)
|
||||
(def scanned (s/scan source))
|
||||
(print "\n***NEW PARSE***\n")
|
||||
|
|
|
@ -90,9 +90,6 @@ Deferred until a later iteration of Ludus:
|
|||
(set (validator :ctx) parent)
|
||||
validator)
|
||||
|
||||
(defn- resolve-local [ctx name]
|
||||
(get ctx name))
|
||||
|
||||
(defn- resolve-name [ctx name]
|
||||
(when (nil? ctx) (break nil))
|
||||
(def node (get ctx name))
|
||||
|
@ -275,24 +272,6 @@ Deferred until a later iteration of Ludus:
|
|||
(match-clauses validator clauses)
|
||||
validator)
|
||||
|
||||
(defn- declare [validator fnn]
|
||||
(def status (validator :status))
|
||||
(def declared (get status :declared @{}))
|
||||
(set (declared fnn) true)
|
||||
(set (status :declared) declared)
|
||||
(print "declared function " (fnn :name))
|
||||
(pp declared)
|
||||
validator)
|
||||
|
||||
(defn- define [validator fnn]
|
||||
(def status (validator :status))
|
||||
(def declared (get status :declared @{}))
|
||||
(set (declared fnn) nil)
|
||||
(set (status :declared) declared)
|
||||
(print "defined function " (fnn :name))
|
||||
(pp declared)
|
||||
validator)
|
||||
|
||||
(defn- fnn [validator]
|
||||
(def ast (validator :ast))
|
||||
(def name (ast :name))
|
||||
|
@ -302,22 +281,18 @@ Deferred until a later iteration of Ludus:
|
|||
(set (status :tail) true)
|
||||
(when name
|
||||
(def ctx (validator :ctx))
|
||||
(def resolved (ctx name))
|
||||
(when (and resolved (not= :nothing (resolved :data)))
|
||||
(def resolved (resolve-name ctx name))
|
||||
(when resolved
|
||||
(def {:line line :input input} (get-in ctx [name :token]))
|
||||
(array/push (validator :errors)
|
||||
{:node ast :msg (string "name is already bound on line " line " of " input)}))
|
||||
(when (and resolved (= :nothing (resolved :data)))
|
||||
(define validator resolved))
|
||||
(set (ctx name) ast))
|
||||
(def data (ast :data))
|
||||
(when (= data :nothing)
|
||||
(break (declare validator ast)))
|
||||
(match-clauses validator data)
|
||||
(match-clauses validator (ast :data))
|
||||
(set (status :tail) tail?)
|
||||
(def clauses (ast :data))
|
||||
(def rest-arities @{})
|
||||
(def arities @{:rest rest-arities})
|
||||
(each clause data
|
||||
(each clause clauses
|
||||
(print "CLAUSE:")
|
||||
(pp clause)
|
||||
(def patt (first clause))
|
||||
|
@ -339,7 +314,7 @@ Deferred until a later iteration of Ludus:
|
|||
(set (validator :ast) expr)
|
||||
(validate validator)
|
||||
(def name (ast :name))
|
||||
(def resolved (ctx name))
|
||||
(def resolved (resolve-name ctx name))
|
||||
(when resolved
|
||||
(def {:line line :input input} (get-in ctx [name :token]))
|
||||
(array/push (validator :errors)
|
||||
|
@ -751,33 +726,26 @@ Deferred until a later iteration of Ludus:
|
|||
|
||||
(set validate validate*)
|
||||
|
||||
(defn- cleanup [validator]
|
||||
(def declared (get-in validator [:status :declared] {}))
|
||||
(when (any? declared)
|
||||
(each declaration declared
|
||||
(array/push (validator :errors) {:node declaration :msg "declared fn, but not defined"})))
|
||||
validator)
|
||||
|
||||
(defn valid [ast &opt ctx]
|
||||
(default ctx @{})
|
||||
(def validator (new-validator ast))
|
||||
(def base-ctx @{:^parent ctx})
|
||||
(set (validator :ctx) base-ctx)
|
||||
(validate validator)
|
||||
(cleanup validator))
|
||||
(validate validator))
|
||||
|
||||
(import ./base :as b)
|
||||
|
||||
(do
|
||||
# (comment
|
||||
(def source `
|
||||
fn foo
|
||||
fn bar () -> foo ()
|
||||
fn foo () -> bar ()
|
||||
fn foo {
|
||||
() -> foo (:foo)
|
||||
}
|
||||
|
||||
foo ()
|
||||
`)
|
||||
(def scanned (s/scan source))
|
||||
(def parsed (p/parse scanned))
|
||||
(def validated (valid parsed))
|
||||
# (get-in validated [:status :declared])
|
||||
# (validated :ctx)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user