more insts

This commit is contained in:
minish 2025-10-08 15:26:58 -04:00
parent e960a12e96
commit cb15876d9d
Signed by: min
SSH Key Fingerprint: SHA256:mf+pUTmK92Y57BuCjlkBdd82LqztTfDCQIUp0fCKABc
1 changed files with 9 additions and 20 deletions

View File

@ -203,6 +203,7 @@ pub enum Inst {
/* pop a1? ; pop a2? */ /* pop a1? ; pop a2? */
Eq(bool, bool, Val, Val), Eq(bool, bool, Val, Val),
Gt(bool, bool, Val, Val), Gt(bool, bool, Val, Val),
GtEq(bool, bool, Val, Val),
/* is conditional? ; what condition? */ /* is conditional? ; what condition? */
Skip(bool, bool, i16), Skip(bool, bool, i16),
/* is conditional? ; what condition? ; pop result? */ /* is conditional? ; what condition? ; pop result? */
@ -347,8 +348,7 @@ impl<'a> FuncBuild<'a> {
} }
fn translate(&mut self, e: Expr) -> Val { fn translate(&mut self, e: Expr) -> Val {
// println!("{e:?}"); match e {
let outp = match e {
/* organisational */ /* organisational */
Expr::Block(mut b) => { Expr::Block(mut b) => {
let last = b.exprs.pop(); let last = b.exprs.pop();
@ -358,12 +358,14 @@ impl<'a> FuncBuild<'a> {
// yield last expr // yield last expr
last.map_or(Val::Nil, |e| self.translate(e)) last.map_or(Val::Nil, |e| self.translate(e))
} }
/* 1 to 1 literals */ /* 1 to 1 literals */
Expr::Literal(Literal::Boolean(b)) => Val::Bool(b), Expr::Literal(Literal::Boolean(b)) => Val::Bool(b),
Expr::Literal(Literal::Float(f)) => Val::Float64(f), Expr::Literal(Literal::Float(f)) => Val::Float64(f),
Expr::Literal(Literal::Integer(i)) => Val::Int64(i), Expr::Literal(Literal::Integer(i)) => Val::Int64(i),
Expr::Literal(Literal::Nil) => Val::Nil, Expr::Literal(Literal::Nil) => Val::Nil,
Expr::Literal(Literal::String(s)) => Val::String(s), Expr::Literal(Literal::String(s)) => Val::String(s),
/* vars */ /* vars */
Expr::Literal(Literal::Ident(id, Some(rs))) => { Expr::Literal(Literal::Ident(id, Some(rs))) => {
Val::Stack(self.find(&id), rs.now == rs.meta.total.get()) Val::Stack(self.find(&id), rs.now == rs.meta.total.get())
@ -438,27 +440,14 @@ impl<'a> FuncBuild<'a> {
Expr::Or(l, r) => self.gen_binop(*l, *r, Inst::Or), Expr::Or(l, r) => self.gen_binop(*l, *r, Inst::Or),
Expr::EqualTo(l, r) => self.gen_binop(*l, *r, Inst::Eq), Expr::EqualTo(l, r) => self.gen_binop(*l, *r, Inst::Eq),
Expr::GreaterThan(l, r) => self.gen_binop(*l, *r, Inst::Gt), Expr::GreaterThan(l, r) => self.gen_binop(*l, *r, Inst::Gt),
Expr::GreaterThanOrEqualTo(l, r) => self.gen_binop(*l, *r, Inst::GtEq),
Expr::Not(r) => self.gen_unop(*r, Inst::Not), Expr::Not(r) => self.gen_unop(*r, Inst::Not),
Expr::NotEqualTo(l, r) => { Expr::NotEqualTo(l, r) => self.translate(Expr::Not(Box::new(Expr::EqualTo(l, r)))),
let (v1, v2) = (self.translate(*l), self.translate(Expr::Not(r))); Expr::LessThan(l, r) => self.translate(Expr::GreaterThan(r, l)),
let (a1, a2) = self.check_drop2(&v1, &v2);
self.insts.push(Inst::Eq(a1, a2, v1, v2)); e => unimplemented!("{e:?}"),
Val::Stack(self.push_any(), true) }
}
Expr::LessThan(l, r) => {
let (v1, v2) = (self.translate(*l), self.translate(*r));
let (a1, a2) = self.check_drop2(&v1, &v2);
self.insts.push(Inst::Gt(a2, a1, v2, v1));
Val::Stack(self.push_any(), true)
}
_ => unimplemented!(),
};
// println!("CHECK {:?} {:?}", self.insts.last(), self.local.values());
outp
} }
} }