Compare commits

..

No commits in common. "b8b720b877c017864020419deb3c6361cd90f7ce" and "5ae47428404cb4199291b29ec6351de6f2fa55e0" have entirely different histories.

2 changed files with 13 additions and 31 deletions

View File

@ -316,14 +316,10 @@ pub struct Compiler<'a> {
loop_info: Vec<LoopInfo>, loop_info: Vec<LoopInfo>,
} }
fn is_binding(expr: &Spanned<Ast>) -> bool { fn is_let(expr: &Spanned<Ast>) -> bool {
let (ast, _) = expr; let (ast, _) = expr;
use Ast::*; use Ast::*;
match ast { matches!(ast, Let(..))
Let(..) | LBox(..) => true,
Fn(name, ..) => !name.is_empty(),
_ => false,
}
} }
impl<'a> Compiler<'a> { impl<'a> Compiler<'a> {
@ -467,7 +463,6 @@ impl<'a> Compiler<'a> {
} }
fn pop(&mut self) { fn pop(&mut self) {
println!("Popping from: {}", self.ast);
self.emit_op(Op::Pop); self.emit_op(Op::Pop);
self.stack_depth -= 1; self.stack_depth -= 1;
} }
@ -520,7 +515,7 @@ impl<'a> Compiler<'a> {
self.scope_depth += 1; self.scope_depth += 1;
let stack_depth = self.stack_depth; let stack_depth = self.stack_depth;
for expr in lines.iter().take(lines.len() - 1) { for expr in lines.iter().take(lines.len() - 1) {
if is_binding(expr) { if is_let(expr) {
self.visit(expr); self.visit(expr);
} else { } else {
self.visit(expr); self.visit(expr);
@ -851,8 +846,8 @@ impl<'a> Compiler<'a> {
self.emit_op(Op::PushBinding); self.emit_op(Op::PushBinding);
self.stack_depth += 1; self.stack_depth += 1;
// let biter = self.bindings.iter().rev(); let biter = self.bindings.iter().rev();
for binding in self.bindings.iter() { for binding in biter {
if binding.name == *fn_name { if binding.name == *fn_name {
self.emit_byte(binding.stack_pos); self.emit_byte(binding.stack_pos);
break; break;
@ -1261,21 +1256,12 @@ impl<'a> Compiler<'a> {
} }
} }
} }
Do(terms) => { Arguments(..)
let mut terms = terms.iter(); | Placeholder
let first = terms.next().unwrap(); | Do(..)
// put the first value on the stack | Splat(..)
self.visit(first); | InterpolatedPattern(..)
for term in terms { | Splattern(..) => todo!(),
self.visit(term);
self.emit_op(Op::Call);
self.emit_byte(1);
self.stack_depth -= 1;
}
}
Arguments(..) | Placeholder | Splat(..) | InterpolatedPattern(..) | Splattern(..) => {
todo!()
}
And | Or => unreachable!(), And | Or => unreachable!(),
} }
} }

View File

@ -76,13 +76,9 @@ pub fn run(src: &'static str) {
pub fn main() { pub fn main() {
env::set_var("RUST_BACKTRACE", "1"); env::set_var("RUST_BACKTRACE", "1");
let src = " let src = "
fn increase (x) -> add (x, 1) fn foo () -> :foo
fn double (x) -> mult (x, 2) foo
fn halve (x) -> div (x, 2)
do 1 > increase > double > increase > halve
"; ";