diff --git a/src/compiler.rs b/src/compiler.rs index 0088f34..0c921cf 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -431,6 +431,9 @@ impl Chunk { self.bytecode[idx] = self.bytecode.len() as u8 - idx as u8 + 2; } } + Fn(lfn) => { + let fn_chunk = Chunk::new() + } _ => todo!(), } } diff --git a/src/main.rs b/src/main.rs index 9b57c3c..7a65c1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,6 +41,9 @@ pub fn run(src: &'static str) { return; } + // ::sigh:: The AST should be 'static + // This simplifies lifetimes, and + // in any event, the AST should live forever let parsed: &'static Spanned = Box::leak(Box::new(parse_result.unwrap())); let mut chunk = Chunk::new(parsed, "test", src); diff --git a/src/parser.rs b/src/parser.rs index 0556d42..e9a77e6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -51,6 +51,12 @@ impl fmt::Display for StringPart { } } +pub struct LFn { + name: &'static str, + clauses: Vec>, + doc: Option<&'static str>, +} + #[derive(Clone, Debug, PartialEq, Dissectible)] pub enum Ast { // a special Error node @@ -83,7 +89,7 @@ pub enum Ast { Box>>, Box>, ), - Fn(&'static str, Vec>, Option<&'static str>), + Fn(LFn), FnDeclaration(&'static str), Panic(Box>), Do(Vec>), diff --git a/src/value.rs b/src/value.rs index bb8ca4f..d42585b 100644 --- a/src/value.rs +++ b/src/value.rs @@ -9,11 +9,11 @@ use std::rc::Rc; pub struct LFn { pub name: &'static str, pub body: Vec>, - pub doc: Option<&'static str>, - pub enclosing: Vec<(usize, Value)>, - pub has_run: bool, - pub input: &'static str, - pub src: &'static str, + // pub doc: Option<&'static str>, + // pub enclosing: Vec<(usize, Value)>, + // pub has_run: bool, + // pub input: &'static str, + // pub src: &'static str, pub chunk: Chunk, } @@ -31,7 +31,7 @@ pub enum Value { List(Box>), Dict(Box>), Box(Rc>), - Fn(Rc>), + Fn(Rc), } impl std::fmt::Display for Value { @@ -72,6 +72,7 @@ impl std::fmt::Display for Value { .join(", ") ), Box(value) => write!(f, "box {}", value.as_ref().borrow()), + Fn(lfn) => write!(f, "fn {}", lfn.name), _ => todo!(), } } @@ -115,6 +116,7 @@ impl Value { } String(s) => s.as_ref().clone(), Box(x) => format!("box {{ {} }}", x.as_ref().borrow().show(ctx)), + Fn(lfn) => format!("fn {}", lfn.name), _ => todo!(), } }