# an integrated Ludus interpreter (try (os/cd "janet") ([_] nil)) # for REPL (import /scanner :as s) (import /parser :as p) (import /validate :as v) (import /interpreter :as i) (import /errors :as e) (import /base :as b) (import /load-prelude :as prelude) (import spork/json :as j) (comment The API from the old Clojure Ludus interpreter returns an object with four fields: * `console`: an array of lines to be printed to the console * `result`: a string representation of the result of running the script * `draw`: an array of arrays that represent p5 calls, e.g. `["line", 0, 0, 100, 100]` * `errors`: an array of errors, which are just strings This new scene will have to return a JSON POJSO: {:console "..." :result "..." :draw [...] :errors [...]} ) (defn run [source] (when (= :error prelude/pkg) (error "could not load prelude")) (def ctx @{:^parent prelude/ctx}) (def errors @[]) (def draw @[]) (var result @"") (def console @"") (def out @{:errors errors :draw draw :result result :console console}) (def scanned (s/scan source)) (when (any? (scanned :errors)) (break (do (each err (scanned :errors) (e/scan-error err))))) (def parsed (p/parse scanned)) (when (any? (parsed :errors)) (break (each err (parsed :errors) (e/parse-error err)))) (def validated (v/valid parsed ctx)) (when (any? (validated :errors)) (break (each err (validated :errors) (e/validation-error err)))) # (setdyn :out console) (try (set result (i/interpret (parsed :ast) ctx)) ([err] (comment setdyn :out stdout) (e/runtime-error err))) # (setdyn :out stdout) (set (out :result) result) result) (do (def source ` forward! (100) p5_calls `) (-> source run) ) (comment Next up: * postlude! * testing turtle graphics )