Compare commits

..

No commits in common. "20cb689d12d8f08a62e03376236813b058d69d70" and "6a4e2ccd17dbbc77c58532dc9f29df145e7dad5c" have entirely different histories.

7 changed files with 22 additions and 1452 deletions

View File

@ -44,7 +44,7 @@
:dict (dict-str value)
:set
(string/join (map stringify (keys value)) ", ")
:box (stringify (value :^value))
:ref (stringify (value :^value))
:fn (string "fn " (value :name))
:applied (string "fn " (value :name))
:function (string "builtin " (string value))
@ -68,7 +68,7 @@
:list (string "[" (stringify x) "]")
:dict (string "#{" (stringify x) "}")
:set (string "${" (stringify x) "}")
:box (string "box " (x :name) " [ " (stringify x) " ]")
:ref (string "box " (x :name) " [ " (stringify x) " ]")
:pkg (show-pkg x)
(stringify x)))

View File

@ -1,34 +1,10 @@
(import spork/json :as j)
(import /base :as b)
(defn- get-line [source line]
((string/split "\n" source) (dec line)))
(defn scan-error [e out] (set (out :errors) e) (j/encode out))
(defn parse-error [e]
(def msg (e :msg))
(def line-num (get-in e [:token :line]))
(def source (get-in e [:token :source]))
(def source-line (get-line source line-num))
(print "Parsing error: " msg)
(print "On line " line-num ":")
(print source-line))
(defn parse-error [e out] (set (out :errors) e) (j/encode out))
(defn validation-error [e]
(def msg (e :msg))
(def line-num (get-in e [:node :token :line]))
(def source (get-in e [:node :token :source]))
(def source-line (get-line source line-num))
(case msg
"unbound name"
(do
(print "Validation error: " msg " " (get-in e [:node :data]))
(print "on line " line-num)
(print source-line)
)
)
)
(defn validation-error [e out] (set (out :errors) e) (j/encode out))
(defn runtime-error [e out] (set (out :errors) e) (j/encode out))

View File

@ -340,7 +340,7 @@
(defn- ref [ast ctx]
(def {:data value-ast :name name} ast)
(def value (interpret value-ast ctx))
(def box @{:^type :box :^value value :name name})
(def box @{:^type :ref :^value value :name name})
(set (ctx name) box)
box)

View File

@ -16,16 +16,16 @@ The API from the old Clojure Ludus interpreter returns an object with four field
* `errors`: an array of errors, which are just strings
This new scene will have to return a JSON POJSO:
{:console "..." :result "..." :draw [...] :errors [...]}
{:console [...] :result "..." :draw [...] :errors [...]}
)
(def prelude-src (slurp "prelude.ld"))
(def prelude-scanned (s/scan prelude-src))
(def prelude-parsed (p/parse prelude-scanned))
(def parse-errors (prelude-parsed :errors))
(when (any? parse-errors) (each err parse-errors (e/parse-error err)))
(def prelude-validated (v/valid prelude-parsed @{"base" b/base}))
(each err (prelude-validated :errors) (e/validation-error err))
(def console @"")
(setdyn :out console)
(print "foo")
(pp {:a 1 :b 2})
(setdyn :out stdout)
(print "collected out")
(print console)
(defn run [source]
(def errors @[])
@ -44,7 +44,7 @@ This new scene will have to return a JSON POJSO:
(break (-> :errors validated (e/validation-error out))))
(setdyn :out console)
(try
(set result (b/show (i/interpret (parsed :ast) @{:^parent b/base})))
(set result (b/show (i/interpret (parsed :ast) @{})))
([err] (e/runtime-error err out)))
(set (out :result) result)
(j/encode out))
@ -56,7 +56,7 @@ This new scene will have to return a JSON POJSO:
(run source))
(def source `
let foo = fn () -> :bar
fn foo () -> :foo
foo ()
`)

View File

@ -1,7 +1,7 @@
### A recursive descent parser for Ludus
### We still need to scan some things
(try (os/cd "janet") ([_] nil)) # when in repl to do relative imports
# (try (os/cd "janet") ([_] nil)) # when in repl to do relative imports
(import ./scanner :as s)
(defmacro declare
@ -773,7 +773,7 @@
(defn- lambda [parser]
(def origin (current parser))
(expect parser :fn) (advance parser)
@{:type :fn :data ((fn-simple parser) :clauses) :token origin})
@{:type :fn :data (fn-simple parser) :token origin})
(defn- fnn [parser]
(if (= :lparen (-> parser peek type)) (break (lambda parser)))
@ -1104,7 +1104,6 @@
(def origin (current parser))
(def lines @[])
(while (not (check parser :eof))
(accept-many parser :newline)
(array/push lines (capture toplevel parser))
(capture terminator parser))
{:type :script :data lines :token origin})
@ -1117,10 +1116,10 @@
# (do
(comment
(def source `fn () -> 42
(def source `pkg Foo {}
`)
(def scanned (s/scan source))
# (print "\n***NEW PARSE***\n")
(def a-parser (new-parser scanned))
(def parsed (fnn a-parser))
(def parsed (pkg a-parser))
)

File diff suppressed because it is too large Load Diff

View File

@ -173,7 +173,7 @@ Deferred until a later iteration of Ludus:
:dict
:list
:fn
:box
:ref
:pkg
])
@ -296,7 +296,7 @@ Deferred until a later iteration of Ludus:
(defn- fnn [validator]
(def ast (validator :ast))
(def name (ast :name))
(print "function name: " name)
# (print "function name: " name)
(def status (validator :status))
(def tail? (status :tail))
(set (status :tail) true)