Skip to content

Commit

Permalink
fix: start the stack pointer from one address lower than the minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
heypoom committed Oct 5, 2023
1 parent 244ba6a commit d3ae610
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/register/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Registers {

// Initialize the stack pointer.
v.set(PC, 0);
v.set(SP, MIN_STACK_ADDR);
v.set(SP, MIN_STACK_ADDR - 1);

v
}
Expand Down
2 changes: 1 addition & 1 deletion tests/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ mod tests {
let mut m: M = vec![I::Push(10), I::Push(3), I::Sub].into();
m.run();

assert_eq!(m.mem.read_stack(2), [0, 7]);
assert_eq!(m.stack().peek(), 7);
}
}
6 changes: 3 additions & 3 deletions tests/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ mod tests {

m.tick();
m.tick();
assert_eq!(m.mem.read_stack(3), [0, 5, 10]);
assert_eq!(m.mem.read_stack(2), [5, 10]);

m.tick();
assert_eq!(m.mem.read_stack(3), [0, 15, 0]);
assert_eq!(m.stack().peek(), 15);

m.tick();
assert_eq!(m.stack().peek(), 3);

m.tick();
assert_eq!(m.mem.read_stack(3), [0, 12, 0]);
assert_eq!(m.stack().peek(), 12);
}
}
4 changes: 2 additions & 2 deletions tests/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod tests {
assert_eq!(m.mem.read_stack(5), [0, 0, 0, 0, 0]);

m.run();
assert_eq!(m.mem.read_stack(6), [0, 104, 101, 108, 108, 111]);
assert_eq!(m.mem.read_stack(5), [104, 101, 108, 108, 111]);
}

#[test]
Expand Down Expand Up @@ -50,6 +50,6 @@ mod tests {
let s_addr = ms.add_str("poom");
m.mem.load_code(vec![I::LoadString(s_addr)]);
m.tick();
assert_eq!(m.mem.read_stack(5), [0, 112, 111, 111, 109]);
assert_eq!(m.mem.read_stack(4), [112, 111, 111, 109]);
}
}

0 comments on commit d3ae610

Please sign in to comment.