Compare commits
2 Commits
608ab4ab67
...
24bbef74aa
Author | SHA1 | Date | |
---|---|---|---|
|
24bbef74aa | ||
|
a06014270f |
|
@ -226,6 +226,7 @@
|
|||
(print "value is a dictionary")
|
||||
(value :^type)))
|
||||
(def type (if typed? typed? (type value)))
|
||||
(print "value of type " type)
|
||||
(case type
|
||||
:nil ""
|
||||
:number (string value)
|
||||
|
@ -241,6 +242,8 @@
|
|||
(string/join (map stringify (keys value)) ", ")
|
||||
:ref (stringify (value :^value))
|
||||
:fn (string "fn " (value :name))
|
||||
:function (string "builtin " (string value))
|
||||
:cfunction (string "builtin " (string value))
|
||||
# XXX: pkg, fn
|
||||
))
|
||||
|
||||
|
@ -403,6 +406,7 @@
|
|||
(match types
|
||||
[:fn :tuple] (call-fn prev curr)
|
||||
[:fn :partial] (partial prev curr)
|
||||
[:function :tuple] (prev ;curr)
|
||||
[:keyword :args] (get (first curr) prev :^nil)
|
||||
[:dict :keyword] (get prev curr :^nil)
|
||||
[:nil :keyword] :^nil
|
||||
|
@ -428,6 +432,18 @@
|
|||
|
||||
(defn- doo [ast ctx] (todo "do expressions"))
|
||||
|
||||
(defn- pkg [ast ctx] (todo "pkgs"))
|
||||
|
||||
(defn- ns [ast ctx] (todo "nses"))
|
||||
|
||||
(defn- loopp [ast ctx] (todo "loops"))
|
||||
|
||||
(defn- recur [ast ctx] (todo "recur"))
|
||||
|
||||
(defn- repeatt [ast ctx] (todo "repeat"))
|
||||
|
||||
(defn - testt [ast ctx] (todo "test"))
|
||||
|
||||
(defn- interpret* [ast ctx]
|
||||
(print "interpreting node " (ast :type))
|
||||
(case (ast :type)
|
||||
|
@ -453,6 +469,11 @@
|
|||
:script (script ast ctx)
|
||||
:panic (panic ast ctx)
|
||||
|
||||
# looping forms
|
||||
:loop (loopp ast ctx)
|
||||
:recur (recur ast ctx)
|
||||
:repeat (repeatt ast ctx)
|
||||
|
||||
# named/naming forms
|
||||
:word (word ast ctx)
|
||||
:interpolated (interpolated ast ctx)
|
||||
|
@ -463,7 +484,6 @@
|
|||
# patterned forms
|
||||
:let (lett ast ctx)
|
||||
:match (matchh ast ctx)
|
||||
# :with (withh ast ctx)
|
||||
|
||||
# functions
|
||||
:fn (fnn ast ctx)
|
||||
|
@ -474,6 +494,10 @@
|
|||
# do
|
||||
:do (doo ast ctx)
|
||||
|
||||
# deferred until after computer class
|
||||
# :with (withh ast ctx)
|
||||
# :import (importt ast ctx)
|
||||
|
||||
))
|
||||
|
||||
(set interpret interpret*)
|
||||
|
@ -488,16 +512,24 @@
|
|||
|
||||
(defn- has-errors? [{:errors errors}] (and errors (not (empty? errors))))
|
||||
|
||||
(def base {
|
||||
"ludus-type" ltype
|
||||
"print" print
|
||||
"add" +
|
||||
"sub" -
|
||||
"stringify" stringify
|
||||
})
|
||||
|
||||
(defn run []
|
||||
(def scanned (s/scan source))
|
||||
(when (has-errors? scanned) (break (scanned :errors)))
|
||||
(def parsed (p/parse scanned))
|
||||
(when (has-errors? parsed) (break (parsed :errors)))
|
||||
(def validated (v/valid parsed))
|
||||
(def validated (v/valid parsed base))
|
||||
(when (has-errors? validated) (break (validated :errors)))
|
||||
(def cleaned (get-in parsed [:ast :data 1]))
|
||||
(pp cleaned)
|
||||
(interpret (parsed :ast) @{})
|
||||
# (def cleaned (get-in parsed [:ast :data 1]))
|
||||
# (pp cleaned)
|
||||
(interpret (parsed :ast) @{:^parent base})
|
||||
# (try (interpret (parsed :ast) @{})
|
||||
# ([e] (print "Ludus panicked!: "
|
||||
# (if (struct? e) (error (e :msg)) (error e)))))
|
||||
|
@ -505,9 +537,11 @@
|
|||
|
||||
(do
|
||||
(set source `
|
||||
#{:a 1, :b 2}
|
||||
print
|
||||
`)
|
||||
(def result (run))
|
||||
(stringify result)
|
||||
)
|
||||
|
||||
(string print)
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
Tracking here, before I start writing this code, the kinds of validation we're hoping to accomplish:
|
||||
|
||||
* [ ] ensure called keywords are only called w/ one arg
|
||||
* [ ] validate `with` forms
|
||||
* [ ] first-level property access with pkg, e.g. `Foo :bar`--bar must be on Foo
|
||||
- [ ] accept pkg-kws
|
||||
* [ ] validate dict patterns
|
||||
|
@ -20,9 +19,10 @@ Tracking here, before I start writing this code, the kinds of validation we're h
|
|||
* [x] recur not called outside of `loop` forms
|
||||
* [x] splats come at the end of list, tuple, and dict patterns
|
||||
|
||||
Imports are for a later iteration of Ludus:
|
||||
Deferred until a later iteration of Ludus:
|
||||
* [ ] no circular imports DEFERRED
|
||||
* [ ] correct imports DEFERRED
|
||||
* [ ] validate `with` forms
|
||||
)
|
||||
|
||||
(try (os/cd "janet") ([_] nil))
|
||||
|
@ -344,6 +344,7 @@ Imports are for a later iteration of Ludus:
|
|||
(def fn-word (first data))
|
||||
(def the-fn (resolve-name ctx (fn-word :data)))
|
||||
(when (not the-fn) (break validator))
|
||||
(when (= :function (type the-fn)) (break validator))
|
||||
(print "fn name: " (the-fn :name))
|
||||
(def arities (the-fn :arities))
|
||||
(print "arities: ")
|
||||
|
@ -620,16 +621,24 @@ Imports are for a later iteration of Ludus:
|
|||
|
||||
(set validate validate*)
|
||||
|
||||
(defn valid [ast]
|
||||
(defn valid [ast &opt ctx]
|
||||
(default ctx @{})
|
||||
(def validator (new-validator ast))
|
||||
(def base-ctx @{:^parent ctx})
|
||||
(set (validator :ctx) ctx)
|
||||
(validate validator))
|
||||
|
||||
# (do
|
||||
(comment
|
||||
(defn foo [] :foo)
|
||||
(def base {
|
||||
"foo" foo
|
||||
})
|
||||
|
||||
(do
|
||||
# (comment
|
||||
(def source `
|
||||
let "{foo}" = "bar"
|
||||
foo ()
|
||||
`)
|
||||
(def scanned (s/scan source))
|
||||
(def parsed (p/parse scanned))
|
||||
(valid parsed)
|
||||
(valid parsed base)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user