diff --git a/src/compiler.rs b/src/compiler.rs index d5cf245..0088f34 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -77,7 +77,7 @@ pub struct Binding { } #[derive(Clone, Debug, PartialEq)] -pub struct Chunk<'a> { +pub struct Chunk { pub bindings: Vec, scope_depth: isize, num_bindings: usize, @@ -86,8 +86,8 @@ pub struct Chunk<'a> { pub spans: Vec, pub strings: Vec<&'static str>, pub keywords: Vec<&'static str>, - pub nodes: Vec<&'a Ast>, - pub ast: &'a Ast, + pub nodes: Vec<&'static Ast>, + pub ast: &'static Ast, pub span: SimpleSpan, pub src: &'static str, pub name: &'static str, @@ -103,8 +103,8 @@ fn is_binding(expr: &Spanned) -> bool { } } -impl<'a> Chunk<'a> { - pub fn new(ast: &'a Spanned, name: &'static str, src: &'static str) -> Chunk<'a> { +impl Chunk { + pub fn new(ast: &'static Spanned, name: &'static str, src: &'static str) -> Chunk { Chunk { bindings: vec![], scope_depth: -1, @@ -132,7 +132,7 @@ impl<'a> Chunk<'a> { self.keywords.iter().position(|s| *s == kw) } - pub fn visit(&mut self, node: &'a Spanned) { + pub fn visit(&mut self, node: &'static Spanned) { let root_node = self.ast; let root_span = self.span; let (ast, span) = node; diff --git a/src/main.rs b/src/main.rs index 87fb76a..9b57c3c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,12 +6,13 @@ const DEBUG_RUN: bool = true; mod memory_sandbox; mod spans; +use crate::spans::Spanned; mod lexer; use crate::lexer::lexer; mod parser; -use crate::parser::parser; +use crate::parser::{parser, Ast}; mod validator; @@ -40,9 +41,9 @@ pub fn run(src: &'static str) { return; } - let parsed = parse_result.unwrap(); + let parsed: &'static Spanned = Box::leak(Box::new(parse_result.unwrap())); - let mut chunk = Chunk::new(&parsed, "test", src); + let mut chunk = Chunk::new(parsed, "test", src); chunk.compile(); if DEBUG_COMPILE { chunk.disassemble(); diff --git a/src/value.rs b/src/value.rs index b51c71b..bb8ca4f 100644 --- a/src/value.rs +++ b/src/value.rs @@ -14,6 +14,7 @@ pub struct LFn { pub has_run: bool, pub input: &'static str, pub src: &'static str, + pub chunk: Chunk, } #[derive(Clone, Debug, PartialEq)] diff --git a/src/vm.rs b/src/vm.rs index f4dfe35..347c237 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -32,7 +32,7 @@ pub struct Trace { pub struct Vm<'a> { pub stack: Vec, - pub chunk: &'a Chunk<'a>, + pub chunk: &'a Chunk, pub ip: usize, pub return_register: Value, pub matches: bool,