Compile binexps

This commit is contained in:
greg 2016-12-26 00:48:57 -08:00
parent 95b773de7f
commit 10d51cc29c
2 changed files with 17 additions and 3 deletions

View File

@ -1,5 +1,5 @@
fn main()
89
25 % 20
end

View File

@ -212,7 +212,6 @@ impl CodeGen for Function {
}
}
impl CodeGen for Expression {
fn codegen(&self, context: LLVMContextRef, builder: LLVMBuilderRef) -> LLVMValueRef {
use self::Expression::*;
@ -221,7 +220,22 @@ impl CodeGen for Expression {
match self {
&BinExp(ref op, ref left, ref right) => {
unimplemented!()
let lhs = left.codegen(context, builder);
let rhs = right.codegen(context, builder);
unsafe {
let generator = match op.as_ref() {
"+" => core::LLVMBuildAdd,
"-" => core::LLVMBuildSub,
"*" => core::LLVMBuildMul,
"/" => core::LLVMBuildUDiv,
"%" => core::LLVMBuildSRem,
_ => panic!("Bad operator {}", op),
};
let reg_name = CString::new("temporary").unwrap();
generator(builder, lhs, rhs, reg_name.as_ptr())
}
},
&Number(ref n) => {
let native_val = *n as u64;