Skip to content

Commit

Permalink
ref(vm): remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
taizu-jin committed Sep 25, 2023
1 parent f518408 commit 7bc8620
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ impl<W> VM<W>
where
W: Writer,
{
#[allow(dead_code)]
fn new(bytecode: Bytecode, writer: W) -> Self {
let globals: Box<_> = vec![Object::Null; GLOBAL_SIZE].try_into().unwrap();
Self::with_state(bytecode, writer, globals)
}

pub fn with_state(bytecode: Bytecode, writer: W, globals: Box<[Object; GLOBAL_SIZE]>) -> Self {
let Bytecode {
instructions,
Expand Down Expand Up @@ -647,18 +641,22 @@ mod tests {
where
T: PartialEq<Object> + GetInput + GetErrorMessage + Debug,
{
let mut globals: Box<_> = vec![Object::Null; GLOBAL_SIZE].try_into().unwrap();

for test in tests {
let program = parse(test.input().into());

let mut compiler = Compiler::new();
compiler.compile(program)?;

let mut vm = VM::new(compiler.bytecode(), DummyWriter::default());
let mut vm = VM::with_state(compiler.bytecode(), DummyWriter::default(), globals);
vm.run()?;

let stack_element = vm.last_popped_stack_elem();

assert_eq!(test, stack_element, "{}", test.message(&stack_element))
assert_eq!(test, stack_element, "{}", test.message(&stack_element));

globals = vm.consume();
}

Ok(())
Expand Down Expand Up @@ -999,13 +997,15 @@ mod tests {
"WRITE: 'some string'.", "some string";
"WRITE: / 'some', / 'string'.", "\n", "some", "\n", "string");

let mut globals: Box<_> = vec![Object::Null; GLOBAL_SIZE].try_into().unwrap();

for test in tests {
let program = parse(test.input.into());

let mut compiler = Compiler::new();
compiler.compile(program)?;

let mut vm = VM::new(compiler.bytecode(), DummyWriter::default());
let mut vm = VM::with_state(compiler.bytecode(), DummyWriter::default(), globals);
vm.run()?;

assert_eq!(
Expand All @@ -1023,6 +1023,8 @@ mod tests {
got, want
);
}

globals = vm.consume();
}

Ok(())
Expand Down

0 comments on commit 7bc8620

Please sign in to comment.