Compile binexps
This commit is contained in:
parent
95b773de7f
commit
10d51cc29c
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
fn main()
|
fn main()
|
||||||
89
|
25 % 20
|
||||||
end
|
end
|
||||||
|
@ -212,7 +212,6 @@ impl CodeGen for Function {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl CodeGen for Expression {
|
impl CodeGen for Expression {
|
||||||
fn codegen(&self, context: LLVMContextRef, builder: LLVMBuilderRef) -> LLVMValueRef {
|
fn codegen(&self, context: LLVMContextRef, builder: LLVMBuilderRef) -> LLVMValueRef {
|
||||||
use self::Expression::*;
|
use self::Expression::*;
|
||||||
@ -221,7 +220,22 @@ impl CodeGen for Expression {
|
|||||||
|
|
||||||
match self {
|
match self {
|
||||||
&BinExp(ref op, ref left, ref right) => {
|
&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) => {
|
&Number(ref n) => {
|
||||||
let native_val = *n as u64;
|
let native_val = *n as u64;
|
||||||
|
Loading…
Reference in New Issue
Block a user