From 7bc8620fa5f5791370bc1fd225829a5e63f6efcb Mon Sep 17 00:00:00 2001 From: taizu-jin Date: Mon, 25 Sep 2023 14:20:17 +0300 Subject: [PATCH] ref(vm): remove dead code --- src/vm.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/vm.rs b/src/vm.rs index 117d30e..b84e158 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -88,12 +88,6 @@ impl VM 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, @@ -647,18 +641,22 @@ mod tests { where T: PartialEq + 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(()) @@ -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!( @@ -1023,6 +1023,8 @@ mod tests { got, want ); } + + globals = vm.consume(); } Ok(())