♻️ refactor: extract a single step method for State

main
_ 2023-09-29 16:27:50 -05:00
parent f0d4f25cec
commit a9e14d0f47
3 changed files with 557 additions and 540 deletions

View File

@ -57,14 +57,16 @@ fn main () {
dbg! (&chunk);
}
let mut vm = State::default ();
let upvalues = State::upvalues_from_args ([exe_name].into_iter ().chain (args));
let mut vm = State::new (&chunk, &upvalues);
if std::env::var("LUA_DEBUG").is_ok() {
vm.debug_print = true;
}
let upvalues = State::upvalues_from_args ([exe_name].into_iter ().chain (args));
vm.breakpoints = breakpoints;
vm.execute_chunk (&chunk, &upvalues);
vm.execute_chunk ();
}

File diff suppressed because it is too large Load Diff

View File

@ -23,9 +23,9 @@ fn calculate_hash<T: Hash>(t: &T) -> u64 {
/// and returns the output
fn run_chunk (args: &[&str], chunk: &Chunk) -> Vec <Value> {
let mut vm = State::default ();
let upvalues = State::upvalues_from_args (args.into_iter ().map (|s| s.to_string ()));
vm.execute_chunk (chunk, &upvalues)
let mut vm = State::new (chunk, &upvalues);
vm.execute_chunk ()
}
/// Takes arguments and Lua bytecode, loads it, runs it,
@ -118,10 +118,9 @@ fn bools () {
] {
let expected: Vec <Value> = expected;
let mut vm = State::default ();
let upvalues = State::upvalues_from_args (arg.into_iter ().map (|s| s.to_string ()));
let actual = vm.execute_chunk (&chunk, &upvalues);
let mut vm = State::new (&chunk, &upvalues);
let actual = vm.execute_chunk ();
assert_eq! (actual, expected);
}
}
@ -175,9 +174,9 @@ fn floats () {
(vec! ["_exe_name", " "], vec! [3.5.into ()]),
] {
let expected: Vec <Value> = expected;
let mut vm = State::default ();
let upvalues = State::upvalues_from_args (arg.into_iter ().map (|s| s.to_string ()));
let actual = vm.execute_chunk (&chunk, &upvalues);
let mut vm = State::new (&chunk, &upvalues);
let actual = vm.execute_chunk ();
assert_eq! (actual, expected);
}
@ -197,9 +196,9 @@ fn fma () {
(vec! ["_exe_name"], vec! [122.into ()]),
] {
let expected: Vec <Value> = expected;
let mut vm = State::default ();
let upvalues = State::upvalues_from_args (arg.into_iter ().map (|s| s.to_string ()));
let actual = vm.execute_chunk (&chunk, &upvalues);
let mut vm = State::new (&chunk, &upvalues);
let actual = vm.execute_chunk ();
assert_eq! (actual, expected);
}