From d93b5c0a2e4d0b067dc46a12c94c8e090ee74b33 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 11 Jan 2017 00:36:16 -0800 Subject: [PATCH] Still cranking away at conditional compilation --- compile.schala | 5 ++--- src/compilation.rs | 8 +++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/compile.schala b/compile.schala index 9530579..183d747 100644 --- a/compile.schala +++ b/compile.schala @@ -1,9 +1,8 @@ a = 1 if a { - a = 40 + a = 42 } else { - a = 2 + a = 23 } -a = a - 1 a diff --git a/src/compilation.rs b/src/compilation.rs index e2490a4..207b02e 100644 --- a/src/compilation.rs +++ b/src/compilation.rs @@ -19,7 +19,6 @@ pub fn compilation_sequence(ast: AST, sourcefile: &str) { }; compile_ast(ast, ll_filename); - println!("YOLO"); Command::new("llc") .arg("-filetype=obj") .arg(ll_filename) @@ -32,7 +31,6 @@ pub fn compilation_sequence(ast: AST, sourcefile: &str) { .output() .expect("failed to run gcc"); - println!("ai"); for filename in [obj_filename].iter() { Command::new("rm") .arg(filename) @@ -181,16 +179,20 @@ impl CodeGen for Expression { LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry"); let merge_block = LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry"); + LLVMWrap::BuildCondBr(data.builder, is_nonzero, then_block, else_block); LLVMWrap::PositionBuilderAtEnd(data.builder, then_block); + let then_return = then_expr.codegen(data); LLVMWrap::BuildBr(data.builder, merge_block); + + LLVMWrap::PositionBuilderAtEnd(data.builder, else_block); let else_return = match *else_expr { Some(ref e) => e.codegen(data), None => zero, }; LLVMWrap::BuildBr(data.builder, merge_block); - LLVMWrap::PositionBuilderAtEnd(data.builder, else_block); + LLVMWrap::PositionBuilderAtEnd(data.builder, merge_block); zero } Block(ref exprs) => {