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 {
|
||||
& (:goto, (x, y)) -> assoc (state, :position, (x, y))
|
||||
& & (:goto, (x, y)) -> assoc (state, :position, (x, y))
|
||||
& & (:home) -> do state >
|
||||
& & assoc (_, :position, (0, 0)) >
|
||||
& & assoc (_, :heading, 0)
|
||||
& & (:clear) -> do state >
|
||||
& & assoc (state, :position, (0, 0)) >
|
||||
& & assoc (_, :heading, 0)
|
||||
& (:right, turns) -> update (state, :heading, add (_, turns))
|
||||
& (:left, turns) -> update (state, :heading, sub (_, turns))
|
||||
& & (:right, turns) -> update (state, :heading, add (_, turns))
|
||||
& & (:left, turns) -> update (state, :heading, sub (_, turns))
|
||||
& (:forward, steps) -> {
|
||||
& print! ("matched forward")
|
||||
& let #{heading, position, ...} = state
|
||||
& print! ("extracted {heading} and {position} from state")
|
||||
& let unit = heading/vector (heading)
|
||||
& print! ("unit vector at {heading}: {unit}")
|
||||
& let vect = mult (steps, unit)
|
||||
& update (state, :position, add (vect, _))
|
||||
& }
|
||||
& (:back, steps) -> {
|
||||
& let #{heading, position, ...} = state
|
||||
& let unit = heading/vector (heading)
|
||||
& let vect = mult (steps, unit)
|
||||
& update (state, :position, sub (_, vect))
|
||||
& print! ("update vector: {vect}")
|
||||
& let new_state = update (state, :position, add (vect, _))
|
||||
& print! ("new state: {new_state}")
|
||||
& new_state
|
||||
& }
|
||||
& & (: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)
|
||||
& & (:pendown) -> assoc (state, :pendown?, true)
|
||||
& & (:penwidth, pixels) -> assoc (state, :penwidth, pixels)
|
||||
|
@ -34,12 +40,7 @@
|
|||
& & (:hide) -> assoc (state, :visible?, false)
|
||||
& & (:background, _) -> state
|
||||
& }
|
||||
|
||||
box foos = []
|
||||
|
||||
repeat 4 {
|
||||
update! (foos, append (_, :foo))
|
||||
}
|
||||
|
||||
do foos > unbox > count
|
||||
let #{heading, position, ...x} = state
|
||||
let unit = heading/vector (heading)
|
||||
unit
|
||||
|
||||
|
|
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
|
||||
self.emit_op(Op::PushBinding);
|
||||
self.emit_byte(dict_stack_pos);
|
||||
self.stack_depth += 1;
|
||||
|
||||
for pair in pairs.iter().take(pairs_len) {
|
||||
let (PairPattern(key, _), _) = pair else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user