From dd52ec406e181b1a6ed7151c70cc4e423b0a5bff Mon Sep 17 00:00:00 2001 From: Ary Borenszweig <aborenszweig@manas.com.ar> Date: Fri, 2 Aug 2013 11:54:45 -0300 Subject: [PATCH] Fixed bootstrap's codegen specs --- bootstrap/crystal/codegen.cr | 27 +++++++++++-------- bootstrap/crystal/llvm.cr | 4 +-- .../spec/crystal/codegen/primitives_spec.cr | 4 +-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/bootstrap/crystal/codegen.cr b/bootstrap/crystal/codegen.cr index dad8783734..1d6ea92571 100644 --- a/bootstrap/crystal/codegen.cr +++ b/bootstrap/crystal/codegen.cr @@ -64,8 +64,21 @@ module Crystal puts "TODO: codegen #{node}" end - def visit(node : IntLiteral) - @last = LLVM::Int32.from_i(node.value.to_i) + def visit(node : NumberLiteral) + case node.kind + when :i8, :u8 + @last = LLVM::Int8.from_i(node.value.to_i) + when :i16, :u16 + @last = LLVM::Int16.from_i(node.value.to_i) + when :i32, :u32 + @last = LLVM::Int32.from_i(node.value.to_i) + when :i64, :u64 + @last = LLVM::Int32.from_i(node.value.to_i64) + when :f32 + @last = LLVM::Float.from_s(node.value) + when :f64 + @last = LLVM::Double.from_s(node.value) + end end def visit(node : BoolLiteral) @@ -75,15 +88,7 @@ module Crystal def visit(node : LongLiteral) @last = LLVM::Int64.from_i(node.value.to_i) end - - def visit(node : FloatLiteral) - @last = LLVM::Float.from_s(node.value) - end - - def visit(node : DoubleLiteral) - @last = LLVM::Double.from_s(node.value) - end - + def visit(node : CharLiteral) @last = LLVM::Int8.from_i(node.value[0].ord) end diff --git a/bootstrap/crystal/llvm.cr b/bootstrap/crystal/llvm.cr index 90d49995fb..5e3c6fb2ce 100644 --- a/bootstrap/crystal/llvm.cr +++ b/bootstrap/crystal/llvm.cr @@ -24,7 +24,7 @@ lib LibLLVM("LLVM-3.1") fun int_type = LLVMIntType(bits : Int32) : TypeRef fun float_type = LLVMFloatType() : TypeRef fun double_type = LLVMDoubleType() : TypeRef - fun const_int = LLVMConstInt(int_type : TypeRef, value : Int32, sign_extend : Int32) : ValueRef + fun const_int = LLVMConstInt(int_type : TypeRef, value : UInt64, sign_extend : Int32) : ValueRef fun const_real_of_string = LLVMConstRealOfString(real_type : TypeRef, value : Char*) : ValueRef fun create_jit_compiler_for_module = LLVMCreateJITCompilerForModule (jit : ExecutionEngineRef*, m : ModuleRef, opt_level : Int32, error : Char**) : Int32 fun run_function = LLVMRunFunction (ee : ExecutionEngineRef, f : ValueRef, num_args : Int32, args : Int32) : GenericValueRef @@ -142,7 +142,7 @@ module LLVM end def from_i(value) - LibLLVM.const_int(@type, value, 0) + LibLLVM.const_int(@type, value.to_u64, 0) end end diff --git a/bootstrap/spec/crystal/codegen/primitives_spec.cr b/bootstrap/spec/crystal/codegen/primitives_spec.cr index 9a6b680586..319a0a3e1c 100644 --- a/bootstrap/spec/crystal/codegen/primitives_spec.cr +++ b/bootstrap/spec/crystal/codegen/primitives_spec.cr @@ -22,10 +22,10 @@ describe "Code gen: primitives" do end it "codegens f32" do - run("1; 2.5_f32").to_f32.should eq(2.5_f32) + run("2.5_f32").to_f32.should eq(2.5_f32) end it "codegens f64" do - run("1; 2.5_f64").to_f64.should eq(2.5_f64) + run("2.5_f64").to_f64.should eq(2.5_f64) end end -- GitLab