🐛 bug: fix tests
parent
55ea0c233e
commit
3698feeb90
|
@ -16,7 +16,7 @@ pub struct Upvalue {
|
||||||
pub kind: u8,
|
pub kind: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive (Clone, Debug)]
|
#[derive (Clone, Debug, Default)]
|
||||||
pub struct Block {
|
pub struct Block {
|
||||||
pub instructions: Vec <Instruction>,
|
pub instructions: Vec <Instruction>,
|
||||||
pub constants: Vec <Value>,
|
pub constants: Vec <Value>,
|
||||||
|
@ -202,7 +202,10 @@ impl State {
|
||||||
|
|
||||||
pub fn new_with_args <I: Iterator <Item = String>> (chunk: Chunk, mut si: Interner, args: I) -> Self {
|
pub fn new_with_args <I: Iterator <Item = String>> (chunk: Chunk, mut si: Interner, args: I) -> Self {
|
||||||
let upvalues = Self::upvalues_from_args (&mut si, args);
|
let upvalues = Self::upvalues_from_args (&mut si, args);
|
||||||
let current_block = Rc::clone (&chunk.blocks [0]);
|
let current_block = match chunk.blocks.get (0) {
|
||||||
|
Some (x) => Rc::clone (&x),
|
||||||
|
None => Default::default (),
|
||||||
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
// TODO: Stack is actually supposed to grow to a limit of
|
// TODO: Stack is actually supposed to grow to a limit of
|
||||||
|
@ -507,7 +510,10 @@ impl State {
|
||||||
|
|
||||||
fn set_stack_top (&mut self, frame: StackFrame) {
|
fn set_stack_top (&mut self, frame: StackFrame) {
|
||||||
self.stack_top = frame;
|
self.stack_top = frame;
|
||||||
self.current_block = Rc::clone (&self.chunk.blocks [frame.block_idx]);
|
self.current_block = match self.chunk.blocks.get (frame.block_idx) {
|
||||||
|
Some (x) => Rc::clone (&x),
|
||||||
|
None => Default::default (),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch (&self) -> &Instruction {
|
fn fetch (&self) -> &Instruction {
|
||||||
|
@ -1041,8 +1047,8 @@ impl State {
|
||||||
|
|
||||||
pub fn set_chunk (&mut self, chunk: Chunk) {
|
pub fn set_chunk (&mut self, chunk: Chunk) {
|
||||||
self.stack = vec! [];
|
self.stack = vec! [];
|
||||||
self.set_stack_top (Default::default ());
|
|
||||||
self.chunk = chunk;
|
self.chunk = chunk;
|
||||||
|
self.set_stack_top (Default::default ());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_string (&mut self, s: &str) -> Value {
|
pub fn to_string (&mut self, s: &str) -> Value {
|
||||||
|
|
|
@ -39,8 +39,7 @@ fn run_bytecode (vm: &mut State, args: &[&str], bc: &[u8]) -> Vec <Value> {
|
||||||
|
|
||||||
/// Takes arguments and Lua source code,
|
/// Takes arguments and Lua source code,
|
||||||
/// invokes `luac` to compile it to bytecode,
|
/// invokes `luac` to compile it to bytecode,
|
||||||
/// runs it,
|
/// runs it, and returns the output
|
||||||
/// and returns the output
|
|
||||||
|
|
||||||
fn run_source (vm: &mut State, args: &[&str], s: &str) -> Vec <Value> {
|
fn run_source (vm: &mut State, args: &[&str], s: &str) -> Vec <Value> {
|
||||||
let bc = loader::compile_bytecode (s.as_bytes ().to_vec ()).unwrap ();
|
let bc = loader::compile_bytecode (s.as_bytes ().to_vec ()).unwrap ();
|
||||||
|
@ -97,7 +96,7 @@ fn bools () {
|
||||||
si.to_value ("print"),
|
si.to_value ("print"),
|
||||||
],
|
],
|
||||||
upvalues: vec! [],
|
upvalues: vec! [],
|
||||||
},
|
}.into (),
|
||||||
Block {
|
Block {
|
||||||
instructions: vec! [
|
instructions: vec! [
|
||||||
Inst::Test (0, false),
|
Inst::Test (0, false),
|
||||||
|
@ -111,7 +110,7 @@ fn bools () {
|
||||||
],
|
],
|
||||||
constants: vec! [],
|
constants: vec! [],
|
||||||
upvalues: vec! [],
|
upvalues: vec! [],
|
||||||
},
|
}.into (),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -173,7 +172,7 @@ fn floats () {
|
||||||
upvalues: vec! [],
|
upvalues: vec! [],
|
||||||
};
|
};
|
||||||
let chunk = Chunk {
|
let chunk = Chunk {
|
||||||
blocks: vec! [block],
|
blocks: vec! [block.into ()],
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut vm = crate::State::new_with_args (Chunk::default (), si, vec! [].into_iter());
|
let mut vm = crate::State::new_with_args (Chunk::default (), si, vec! [].into_iter());
|
||||||
|
|
Loading…
Reference in New Issue