continue work on compiling functions
This commit is contained in:
parent
9f4e630544
commit
a4f12c8f7d
|
@ -431,6 +431,9 @@ impl Chunk {
|
||||||
self.bytecode[idx] = self.bytecode.len() as u8 - idx as u8 + 2;
|
self.bytecode[idx] = self.bytecode.len() as u8 - idx as u8 + 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Fn(lfn) => {
|
||||||
|
let fn_chunk = Chunk::new()
|
||||||
|
}
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ pub fn run(src: &'static str) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ::sigh:: The AST should be 'static
|
||||||
|
// This simplifies lifetimes, and
|
||||||
|
// in any event, the AST should live forever
|
||||||
let parsed: &'static Spanned<Ast> = Box::leak(Box::new(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);
|
||||||
|
|
|
@ -51,6 +51,12 @@ impl fmt::Display for StringPart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct LFn {
|
||||||
|
name: &'static str,
|
||||||
|
clauses: Vec<Spanned<Ast>>,
|
||||||
|
doc: Option<&'static str>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Dissectible)]
|
#[derive(Clone, Debug, PartialEq, Dissectible)]
|
||||||
pub enum Ast {
|
pub enum Ast {
|
||||||
// a special Error node
|
// a special Error node
|
||||||
|
@ -83,7 +89,7 @@ pub enum Ast {
|
||||||
Box<Option<Spanned<Self>>>,
|
Box<Option<Spanned<Self>>>,
|
||||||
Box<Spanned<Self>>,
|
Box<Spanned<Self>>,
|
||||||
),
|
),
|
||||||
Fn(&'static str, Vec<Spanned<Self>>, Option<&'static str>),
|
Fn(LFn),
|
||||||
FnDeclaration(&'static str),
|
FnDeclaration(&'static str),
|
||||||
Panic(Box<Spanned<Self>>),
|
Panic(Box<Spanned<Self>>),
|
||||||
Do(Vec<Spanned<Self>>),
|
Do(Vec<Spanned<Self>>),
|
||||||
|
|
14
src/value.rs
14
src/value.rs
|
@ -9,11 +9,11 @@ use std::rc::Rc;
|
||||||
pub struct LFn {
|
pub struct LFn {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub body: Vec<Spanned<Ast>>,
|
pub body: Vec<Spanned<Ast>>,
|
||||||
pub doc: Option<&'static str>,
|
// pub doc: Option<&'static str>,
|
||||||
pub enclosing: Vec<(usize, Value)>,
|
// pub enclosing: Vec<(usize, Value)>,
|
||||||
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,
|
pub chunk: Chunk,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ pub enum Value {
|
||||||
List(Box<Vector<Value>>),
|
List(Box<Vector<Value>>),
|
||||||
Dict(Box<HashMap<usize, Value>>),
|
Dict(Box<HashMap<usize, Value>>),
|
||||||
Box(Rc<RefCell<Value>>),
|
Box(Rc<RefCell<Value>>),
|
||||||
Fn(Rc<RefCell<LFn>>),
|
Fn(Rc<LFn>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Value {
|
impl std::fmt::Display for Value {
|
||||||
|
@ -72,6 +72,7 @@ impl std::fmt::Display for Value {
|
||||||
.join(", ")
|
.join(", ")
|
||||||
),
|
),
|
||||||
Box(value) => write!(f, "box {}", value.as_ref().borrow()),
|
Box(value) => write!(f, "box {}", value.as_ref().borrow()),
|
||||||
|
Fn(lfn) => write!(f, "fn {}", lfn.name),
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,6 +116,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
String(s) => s.as_ref().clone(),
|
String(s) => s.as_ref().clone(),
|
||||||
Box(x) => format!("box {{ {} }}", x.as_ref().borrow().show(ctx)),
|
Box(x) => format!("box {{ {} }}", x.as_ref().borrow().show(ctx)),
|
||||||
|
Fn(lfn) => format!("fn {}", lfn.name),
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user