Fix infix generation

This commit is contained in:
Rerumu
2022-05-21 02:47:27 -04:00
parent d5c9028be4
commit 642711e67d
2 changed files with 26 additions and 20 deletions
+15 -7
View File
@@ -5,7 +5,7 @@ use wasm_ast::node::{
UnOp, Value,
};
use crate::analyzer::operator::bin_symbol_of;
use crate::analyzer::operator::{bin_symbol_of, cmp_symbol_of};
use super::manager::{write_separated, write_variable, Driver, Manager};
@@ -133,13 +133,21 @@ impl Driver for BinOp {
impl Driver for CmpOp {
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
let (a, b) = self.op.as_name();
if let Some(symbol) = cmp_symbol_of(self.op) {
write!(w, "(")?;
self.lhs.write(mng, w)?;
write!(w, "{symbol} ")?;
self.rhs.write(mng, w)?;
write!(w, ")")
} else {
let (head, tail) = self.op.as_name();
write!(w, "{a}_{b}(")?;
self.lhs.write(mng, w)?;
write!(w, ", ")?;
self.rhs.write(mng, w)?;
write!(w, ")")
write!(w, "{head}_{tail}(")?;
self.lhs.write(mng, w)?;
write!(w, ", ")?;
self.rhs.write(mng, w)?;
write!(w, ")")
}
}
}