Fix the bugs. Not all of them.
This commit is contained in:
parent
efb33cc1be
commit
6a1906c1ae
|
@ -876,8 +876,13 @@
|
|||
|
||||
(defn get-line [source line]
|
||||
(if line
|
||||
(let [lines (clojure.string/split source #"\n")]
|
||||
(clojure.string/trim (nth lines (dec line))))))
|
||||
(let [lines (clojure.string/split source #"\n")
|
||||
numlines (count lines)
|
||||
gettable? (> numlines line)]
|
||||
(if gettable?
|
||||
(clojure.string/trim (nth lines (dec line)))
|
||||
nil))
|
||||
))
|
||||
|
||||
(def runtime-error
|
||||
#?(
|
||||
|
@ -895,7 +900,7 @@
|
|||
interpreted (interpret-ast parsed base-ctx)
|
||||
namespace (dissoc interpreted ::data/type ::data/name ::data/struct)
|
||||
context (ns->ctx namespace)]
|
||||
(println "Prelude fully loaded.")
|
||||
; (println "Prelude fully loaded.")
|
||||
context))
|
||||
|
||||
; ;; TODO: update this to use new parser pipeline & new AST representation
|
||||
|
@ -948,7 +953,7 @@
|
|||
(println "On line" (get-in (ex-data e) [:ast :token :line]))
|
||||
(println ">>> " (get-line source (get-in (ex-data e) [:ast :token :line])))
|
||||
(println (ex-message e))
|
||||
(pp/pprint (ex-data e))
|
||||
;(pp/pprint (ex-data e))
|
||||
(throw e)
|
||||
))))
|
||||
|
||||
|
|
|
@ -40,3 +40,14 @@
|
|||
]
|
||||
#?(:clj clj_result :cljs (clj->js clj_result))
|
||||
))
|
||||
|
||||
(do
|
||||
(def res (run "
|
||||
fd! (100)
|
||||
rt! (0.25)
|
||||
fd! (100)
|
||||
pencolor! (200)
|
||||
fd! (50)
|
||||
"))
|
||||
(:draw res)
|
||||
)
|
|
@ -1,20 +1,22 @@
|
|||
& this file runs after any given interpretation
|
||||
& the goal is to output any global state
|
||||
& this does not have base loaded into it: must be pure ludus
|
||||
|
||||
if turtle_state() :visible? then render_turtle! () else nil
|
||||
|
||||
let console_msgs = deref (console)
|
||||
set! (console, [])
|
||||
let console_msgs = flush! ()
|
||||
|
||||
let (r, g, b, a) = deref (bgcolor)
|
||||
set! (bgcolor, colors :black)
|
||||
make! (bgcolor, colors :black)
|
||||
|
||||
let draw_calls = deref (p5_calls)
|
||||
set! (p5_calls, [])
|
||||
make! (p5_calls, [])
|
||||
|
||||
#{
|
||||
& :result result is provided elsewhere
|
||||
& :errors [] & if we get here there are no errors
|
||||
:console console_msgs
|
||||
:draw concat ([(:background, r, g, b, a)], draw_calls)
|
||||
:draw concat (
|
||||
[(:background, r, g, b, a), (:stroke, 255, 255, 255, 255)]
|
||||
draw_calls)
|
||||
}
|
|
@ -127,6 +127,15 @@ fn append {
|
|||
|
||||
ref console = []
|
||||
|
||||
fn flush! {
|
||||
"Clears the console, and returns the messages."
|
||||
() -> {
|
||||
let msgs = deref (console)
|
||||
make! (console, [])
|
||||
msgs
|
||||
}
|
||||
}
|
||||
|
||||
fn add_msg! {
|
||||
"Adds a message to the console."
|
||||
(msgs) -> {
|
||||
|
@ -708,7 +717,9 @@ let turtle_angle = 0.375
|
|||
let turtle_color = (100, 100, 100, 100)
|
||||
|
||||
fn render_turtle! () -> {
|
||||
print! ("Rendering turtle")
|
||||
let state = do turtle_states > deref > last
|
||||
print! ("Collected state.")
|
||||
if state :visible?
|
||||
then {
|
||||
add_call! ((:push))
|
||||
|
@ -739,19 +750,19 @@ fn state/call () -> {
|
|||
let states = deref (turtle_states)
|
||||
let curr = last (states)
|
||||
let prev = nth (states, sub (count (states), 2))
|
||||
print! ("Curr, prev, command", curr, prev, cmd)
|
||||
& print! ("Curr, prev, command", curr, prev, cmd)
|
||||
match cmd with {
|
||||
:forward -> if curr :pendown?
|
||||
then make_line (curr :position, prev :position)
|
||||
then make_line (prev :position, curr :position)
|
||||
else nil
|
||||
:back -> if curr :pendown?
|
||||
then make_line (curr :position, prev :position)
|
||||
then make_line (prev :position, curr :position)
|
||||
else nil
|
||||
:home -> if curr :pendown?
|
||||
then make_line (curr :position, prev :position)
|
||||
then make_line (prev :position, curr :position)
|
||||
else nil
|
||||
:goto -> if curr :pendown?
|
||||
then make_line (curr :position, prev :position)
|
||||
then make_line (prev :position, curr :position)
|
||||
else nil
|
||||
:penwidth -> (:strokeWeight, curr :penwidth)
|
||||
:pencolor -> {
|
||||
|
@ -859,6 +870,8 @@ fn apply_command {
|
|||
"Takes a turtle state and a command and calculates a new state."
|
||||
(state, command) -> match command with {
|
||||
(:goto, (x, y)) -> assoc (state, :position, (x, y))
|
||||
(:home) -> assoc (state, :position, (0, 0))
|
||||
(:clear) -> assoc (state, :position, (0, 0))
|
||||
(:right, turns) -> update (state, :heading, sub (_, turns))
|
||||
(:left, turns) -> update (state, :heading, add (_, turns))
|
||||
(:forward, steps) -> {
|
||||
|
@ -928,6 +941,7 @@ ns prelude {
|
|||
inc
|
||||
dec
|
||||
print!
|
||||
flush!
|
||||
console
|
||||
show
|
||||
prn!
|
||||
|
@ -995,6 +1009,7 @@ ns prelude {
|
|||
ceil
|
||||
round
|
||||
range
|
||||
colors
|
||||
forward!, fd!
|
||||
back!, bk!
|
||||
right!, rt!
|
||||
|
@ -1008,6 +1023,6 @@ ns prelude {
|
|||
pencolor, penwidth
|
||||
heading/vector
|
||||
turtle_state
|
||||
p5_calls, turtle_states, turtle_commands
|
||||
p5_calls, turtle_states, turtle_commands, bgcolor
|
||||
render_turtle!
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user