Compare commits
No commits in common. "3a8a236f01864983676fda00dbd755f3a9926b7c" and "3e9f38ef5c511e221184833a7e6436525e154afb" have entirely different histories.
3a8a236f01
...
3e9f38ef5c
|
@ -1,54 +0,0 @@
|
||||||
# A tree walk interpreter for ludus
|
|
||||||
|
|
||||||
(var interpret nil)
|
|
||||||
|
|
||||||
(defn- iff [ast ctx]
|
|
||||||
(def [condition then else] (ast :data))
|
|
||||||
(if (interpret condition ctx)
|
|
||||||
(interpret then ctx)
|
|
||||||
(interpret else ctx)))
|
|
||||||
|
|
||||||
(defn- script [ast ctx]
|
|
||||||
(print "interpreting script")
|
|
||||||
(def lines (ast :data))
|
|
||||||
(var result nil)
|
|
||||||
(each line lines
|
|
||||||
(print "interpreting script line")
|
|
||||||
(set result (interpret line ctx)))
|
|
||||||
result)
|
|
||||||
|
|
||||||
(defn- interpret* [ast ctx]
|
|
||||||
(print "interpreting ast node " (ast :type))
|
|
||||||
(case (ast :type)
|
|
||||||
:nil nil
|
|
||||||
:number (ast :data)
|
|
||||||
:bool (ast :data)
|
|
||||||
:string (ast :data)
|
|
||||||
:keyword (ast :data)
|
|
||||||
:if (iff ast ctx)
|
|
||||||
:script (script ast ctx)))
|
|
||||||
|
|
||||||
(set interpret interpret*)
|
|
||||||
|
|
||||||
# repl
|
|
||||||
(try (os/cd "janet") ([_] nil))
|
|
||||||
(import ./scanner :as s)
|
|
||||||
(import ./parser :as p)
|
|
||||||
(import ./validate :as v)
|
|
||||||
|
|
||||||
(var source nil)
|
|
||||||
|
|
||||||
(defn run []
|
|
||||||
(def scanned (s/scan source))
|
|
||||||
(def parsed (p/parse scanned))
|
|
||||||
(def validated (v/valid parsed))
|
|
||||||
(pp parsed)
|
|
||||||
(interpret (parsed :ast) @{}))
|
|
||||||
|
|
||||||
|
|
||||||
(do
|
|
||||||
(set source `
|
|
||||||
if false then :bar else :baz
|
|
||||||
`)
|
|
||||||
(run)
|
|
||||||
)
|
|
|
@ -1,7 +1,7 @@
|
||||||
### A recursive descent parser for Ludus
|
### A recursive descent parser for Ludus
|
||||||
|
|
||||||
### We still need to scan some things
|
### We still need to scan some things
|
||||||
(try (os/cd "janet") ([_] nil)) # when in repl to do relative imports
|
#(os/cd "janet") # when in repl to do relative imports
|
||||||
(import ./scanner :as s)
|
(import ./scanner :as s)
|
||||||
|
|
||||||
(defmacro declare
|
(defmacro declare
|
||||||
|
@ -1090,8 +1090,8 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# (do
|
(do
|
||||||
(comment
|
#(comment
|
||||||
(def source `
|
(def source `
|
||||||
loop (1, 2) with (x, y) -> :bar
|
loop (1, 2) with (x, y) -> :bar
|
||||||
`)
|
`)
|
||||||
|
|
|
@ -21,9 +21,9 @@ Imports are for a later iteration of Ludus:
|
||||||
* [ ] correct imports DEFERRED
|
* [ ] correct imports DEFERRED
|
||||||
)
|
)
|
||||||
|
|
||||||
(try (os/cd "janet") ([_] nil))
|
|
||||||
|
(import ./recursive :as p)
|
||||||
(import ./scanner :as s)
|
(import ./scanner :as s)
|
||||||
(import ./parser :as p)
|
|
||||||
|
|
||||||
(defn- new-validator [parser]
|
(defn- new-validator [parser]
|
||||||
(def ast (parser :ast))
|
(def ast (parser :ast))
|
||||||
|
@ -583,12 +583,8 @@ Imports are for a later iteration of Ludus:
|
||||||
|
|
||||||
(set validate validate*)
|
(set validate validate*)
|
||||||
|
|
||||||
(defn valid [ast]
|
(do
|
||||||
(def validator (new-validator ast))
|
#(comment
|
||||||
(validate validator))
|
|
||||||
|
|
||||||
# (do
|
|
||||||
(comment
|
|
||||||
(def source `
|
(def source `
|
||||||
fn bar () -> :bar
|
fn bar () -> :bar
|
||||||
fn foo () -> match :foo with {
|
fn foo () -> match :foo with {
|
||||||
|
@ -598,4 +594,8 @@ fn foo () -> match :foo with {
|
||||||
`)
|
`)
|
||||||
(def scanned (s/scan source))
|
(def scanned (s/scan source))
|
||||||
(def parsed (p/parse scanned))
|
(def parsed (p/parse scanned))
|
||||||
(valid parsed))
|
(def validator (new-validator parsed))
|
||||||
|
(pp validator)
|
||||||
|
(validate validator)
|
||||||
|
(pp parsed)
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user