[fine] More tests and also comparisons
This commit is contained in:
parent
55749af917
commit
7fb88ef199
5 changed files with 101 additions and 4 deletions
|
|
@ -36,6 +36,10 @@ pub enum Instruction {
|
|||
LoadExternFunction(usize), // NOTE: FUNKY, might want to indirect this index.
|
||||
Call(usize),
|
||||
Return,
|
||||
StringAdd,
|
||||
CompareBool,
|
||||
CompareString,
|
||||
CompareFloat,
|
||||
}
|
||||
|
||||
pub enum Export {
|
||||
|
|
@ -366,7 +370,11 @@ fn compile_binary_expression(c: &mut Compiler, t: TreeRef, tr: &Tree) -> CR {
|
|||
match tr.nth_token(1)?.kind {
|
||||
TokenKind::Plus => {
|
||||
compile_expression(c, tr.nth_tree(2)?);
|
||||
c.push(Instruction::FloatAdd);
|
||||
c.push(match c.semantics.type_of(t) {
|
||||
Type::F64 => Instruction::FloatAdd,
|
||||
Type::String => Instruction::StringAdd,
|
||||
_ => Instruction::Panic,
|
||||
});
|
||||
}
|
||||
TokenKind::Minus => {
|
||||
compile_expression(c, tr.nth_tree(2)?);
|
||||
|
|
@ -404,6 +412,25 @@ fn compile_binary_expression(c: &mut Compiler, t: TreeRef, tr: &Tree) -> CR {
|
|||
|
||||
c.patch(jump_end_index, |i| Instruction::Jump(i));
|
||||
}
|
||||
TokenKind::EqualEqual => {
|
||||
let arg_tree = tr.nth_tree(2)?;
|
||||
let arg_type = c.semantics.type_of(arg_tree);
|
||||
|
||||
compile_expression(c, tr.nth_tree(2)?);
|
||||
|
||||
if arg_type.compatible_with(&Type::Nothing) {
|
||||
c.push(Instruction::Discard);
|
||||
c.push(Instruction::Discard);
|
||||
c.push(Instruction::PushTrue);
|
||||
} else {
|
||||
c.push(match arg_type {
|
||||
Type::F64 => Instruction::CompareFloat,
|
||||
Type::String => Instruction::CompareString,
|
||||
Type::Bool => Instruction::CompareBool, // ?
|
||||
_ => Instruction::Panic,
|
||||
});
|
||||
}
|
||||
}
|
||||
_ => ice!(c, t, "Unsupported binary expression"),
|
||||
}
|
||||
OK
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue