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

View File

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