actually fix splatted dict pattern stack discipline
This commit is contained in:
parent
49e46d045b
commit
24f57c1529
41
sandbox.ld
41
sandbox.ld
|
@ -1,29 +1,35 @@
|
||||||
& let state = #{:position (0, 0), :heading 0, :pencolor :white}
|
let state = #{:position (0, 0), :heading 0, :pencolor :white}
|
||||||
|
|
||||||
& let command = (:forward, 10)
|
let command = (:forward, 10)
|
||||||
|
|
||||||
& match command with {
|
& match command with {
|
||||||
& (:goto, (x, y)) -> assoc (state, :position, (x, y))
|
& & (:goto, (x, y)) -> assoc (state, :position, (x, y))
|
||||||
& & (:home) -> do state >
|
& & (:home) -> do state >
|
||||||
& & assoc (_, :position, (0, 0)) >
|
& & assoc (_, :position, (0, 0)) >
|
||||||
& & assoc (_, :heading, 0)
|
& & assoc (_, :heading, 0)
|
||||||
& & (:clear) -> do state >
|
& & (:clear) -> do state >
|
||||||
& & assoc (state, :position, (0, 0)) >
|
& & assoc (state, :position, (0, 0)) >
|
||||||
& & assoc (_, :heading, 0)
|
& & assoc (_, :heading, 0)
|
||||||
& (:right, turns) -> update (state, :heading, add (_, turns))
|
& & (:right, turns) -> update (state, :heading, add (_, turns))
|
||||||
& (:left, turns) -> update (state, :heading, sub (_, turns))
|
& & (:left, turns) -> update (state, :heading, sub (_, turns))
|
||||||
& (:forward, steps) -> {
|
& (:forward, steps) -> {
|
||||||
|
& print! ("matched forward")
|
||||||
& let #{heading, position, ...} = state
|
& let #{heading, position, ...} = state
|
||||||
|
& print! ("extracted {heading} and {position} from state")
|
||||||
& let unit = heading/vector (heading)
|
& let unit = heading/vector (heading)
|
||||||
|
& print! ("unit vector at {heading}: {unit}")
|
||||||
& let vect = mult (steps, unit)
|
& let vect = mult (steps, unit)
|
||||||
& update (state, :position, add (vect, _))
|
& print! ("update vector: {vect}")
|
||||||
& }
|
& let new_state = update (state, :position, add (vect, _))
|
||||||
& (:back, steps) -> {
|
& print! ("new state: {new_state}")
|
||||||
& let #{heading, position, ...} = state
|
& new_state
|
||||||
& let unit = heading/vector (heading)
|
|
||||||
& let vect = mult (steps, unit)
|
|
||||||
& update (state, :position, sub (_, vect))
|
|
||||||
& }
|
& }
|
||||||
|
& & (:back, steps) -> {
|
||||||
|
& & let #{heading, position, ...} = state
|
||||||
|
& & let unit = heading/vector (heading)
|
||||||
|
& & let vect = mult (steps, unit)
|
||||||
|
& & update (state, :position, sub (_, vect))
|
||||||
|
& & }
|
||||||
& & (:penup) -> assoc (state, :pendown?, false)
|
& & (:penup) -> assoc (state, :pendown?, false)
|
||||||
& & (:pendown) -> assoc (state, :pendown?, true)
|
& & (:pendown) -> assoc (state, :pendown?, true)
|
||||||
& & (:penwidth, pixels) -> assoc (state, :penwidth, pixels)
|
& & (:penwidth, pixels) -> assoc (state, :penwidth, pixels)
|
||||||
|
@ -34,12 +40,7 @@
|
||||||
& & (:hide) -> assoc (state, :visible?, false)
|
& & (:hide) -> assoc (state, :visible?, false)
|
||||||
& & (:background, _) -> state
|
& & (:background, _) -> state
|
||||||
& }
|
& }
|
||||||
|
let #{heading, position, ...x} = state
|
||||||
box foos = []
|
let unit = heading/vector (heading)
|
||||||
|
unit
|
||||||
repeat 4 {
|
|
||||||
update! (foos, append (_, :foo))
|
|
||||||
}
|
|
||||||
|
|
||||||
do foos > unbox > count
|
|
||||||
|
|
||||||
|
|
12023
sandbox_run.txt
12023
sandbox_run.txt
File diff suppressed because it is too large
Load Diff
|
@ -717,6 +717,7 @@ impl<'a> Compiler<'a> {
|
||||||
// drop every value in the pattern
|
// drop every value in the pattern
|
||||||
self.emit_op(Op::PushBinding);
|
self.emit_op(Op::PushBinding);
|
||||||
self.emit_byte(dict_stack_pos);
|
self.emit_byte(dict_stack_pos);
|
||||||
|
self.stack_depth += 1;
|
||||||
|
|
||||||
for pair in pairs.iter().take(pairs_len) {
|
for pair in pairs.iter().take(pairs_len) {
|
||||||
let (PairPattern(key, _), _) = pair else {
|
let (PairPattern(key, _), _) = pair else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user