diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-10 20:49:06 +0100 |
|---|---|---|
| committer | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-10 20:49:06 +0100 |
| commit | 0f25e98b903f6608d09ad8bfd9ca5d00fec4cec6 (patch) | |
| tree | d7518611c65b6f41244c4381c1b5fcc9ce0e2f14 | |
| parent | be4559ed0af1d12401365b5ffeae99885842314f (diff) | |
| download | sylt-0f25e98b903f6608d09ad8bfd9ca5d00fec4cec6.tar.gz | |
simplify frames
| -rw-r--r-- | src/compiler.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index 7f0d32d..1f3d9d8 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -132,10 +132,17 @@ struct Frame { stack: Vec<Variable>, upvalues: Vec<Variable>, scope: usize, - variables_below: usize, } impl Frame { + fn new() -> Self { + Self { + stack: Vec::new(), + upvalues: Vec::new(), + scope: 0, + } + } + fn find_local(&self, name: &str) -> Option<Variable> { for var in self.stack.iter().rev() { if var.name == name && var.active { @@ -189,12 +196,7 @@ pub(crate) struct Compiler { macro_rules! push_frame { ($compiler:expr, $block:expr, $code:tt) => { { - $compiler.frames.push(Frame { - stack: Vec::new(), - upvalues: Vec::new(), - scope: 0, - variables_below: $compiler.frame().variables_below + $compiler.stack().len(), - }); + $compiler.frames.push(Frame::new()); // Return value stored as a variable $compiler.define_variable("", Type::Unknown, &mut $block).unwrap(); @@ -240,12 +242,7 @@ impl Compiler { tokens, current_file: PathBuf::from(current_file), - frames: vec![Frame { - stack: Vec::new(), - upvalues: Vec::new(), - scope: 0, - variables_below: 0, - }], + frames: vec![Frame::new()], panic: false, errors: vec![], |
