get lifetime out of Chunk, thus out of Value
This commit is contained in:
parent
be23ee6c44
commit
9f4e630544
|
@ -77,7 +77,7 @@ pub struct Binding {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Chunk<'a> {
|
pub struct Chunk {
|
||||||
pub bindings: Vec<Binding>,
|
pub bindings: Vec<Binding>,
|
||||||
scope_depth: isize,
|
scope_depth: isize,
|
||||||
num_bindings: usize,
|
num_bindings: usize,
|
||||||
|
@ -86,8 +86,8 @@ pub struct Chunk<'a> {
|
||||||
pub spans: Vec<SimpleSpan>,
|
pub spans: Vec<SimpleSpan>,
|
||||||
pub strings: Vec<&'static str>,
|
pub strings: Vec<&'static str>,
|
||||||
pub keywords: Vec<&'static str>,
|
pub keywords: Vec<&'static str>,
|
||||||
pub nodes: Vec<&'a Ast>,
|
pub nodes: Vec<&'static Ast>,
|
||||||
pub ast: &'a Ast,
|
pub ast: &'static Ast,
|
||||||
pub span: SimpleSpan,
|
pub span: SimpleSpan,
|
||||||
pub src: &'static str,
|
pub src: &'static str,
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
|
@ -103,8 +103,8 @@ fn is_binding(expr: &Spanned<Ast>) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Chunk<'a> {
|
impl Chunk {
|
||||||
pub fn new(ast: &'a Spanned<Ast>, name: &'static str, src: &'static str) -> Chunk<'a> {
|
pub fn new(ast: &'static Spanned<Ast>, name: &'static str, src: &'static str) -> Chunk {
|
||||||
Chunk {
|
Chunk {
|
||||||
bindings: vec![],
|
bindings: vec![],
|
||||||
scope_depth: -1,
|
scope_depth: -1,
|
||||||
|
@ -132,7 +132,7 @@ impl<'a> Chunk<'a> {
|
||||||
self.keywords.iter().position(|s| *s == kw)
|
self.keywords.iter().position(|s| *s == kw)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit(&mut self, node: &'a Spanned<Ast>) {
|
pub fn visit(&mut self, node: &'static Spanned<Ast>) {
|
||||||
let root_node = self.ast;
|
let root_node = self.ast;
|
||||||
let root_span = self.span;
|
let root_span = self.span;
|
||||||
let (ast, span) = node;
|
let (ast, span) = node;
|
||||||
|
|
|
@ -6,12 +6,13 @@ const DEBUG_RUN: bool = true;
|
||||||
mod memory_sandbox;
|
mod memory_sandbox;
|
||||||
|
|
||||||
mod spans;
|
mod spans;
|
||||||
|
use crate::spans::Spanned;
|
||||||
|
|
||||||
mod lexer;
|
mod lexer;
|
||||||
use crate::lexer::lexer;
|
use crate::lexer::lexer;
|
||||||
|
|
||||||
mod parser;
|
mod parser;
|
||||||
use crate::parser::parser;
|
use crate::parser::{parser, Ast};
|
||||||
|
|
||||||
mod validator;
|
mod validator;
|
||||||
|
|
||||||
|
@ -40,9 +41,9 @@ pub fn run(src: &'static str) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let parsed = parse_result.unwrap();
|
let parsed: &'static Spanned<Ast> = 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();
|
chunk.compile();
|
||||||
if DEBUG_COMPILE {
|
if DEBUG_COMPILE {
|
||||||
chunk.disassemble();
|
chunk.disassemble();
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub struct LFn {
|
||||||
pub has_run: bool,
|
pub has_run: bool,
|
||||||
pub input: &'static str,
|
pub input: &'static str,
|
||||||
pub src: &'static str,
|
pub src: &'static str,
|
||||||
|
pub chunk: Chunk,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub struct Trace {
|
||||||
|
|
||||||
pub struct Vm<'a> {
|
pub struct Vm<'a> {
|
||||||
pub stack: Vec<Value>,
|
pub stack: Vec<Value>,
|
||||||
pub chunk: &'a Chunk<'a>,
|
pub chunk: &'a Chunk,
|
||||||
pub ip: usize,
|
pub ip: usize,
|
||||||
pub return_register: Value,
|
pub return_register: Value,
|
||||||
pub matches: bool,
|
pub matches: bool,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user