Permalink
Browse files

Good bye Ruby thursday

  • Loading branch information...
asterite committed Nov 14, 2013
1 parent 6a9543f commit ad2e815e271aaa7f478cababd478b14e5b789789
@@ -890,10 +890,12 @@ module Crystal
@builder.position_at_end then_block
accept(node.then)
add_branched_block_value(branch, node.then.type?, @last)
@builder.br branch.exit_block
@builder.position_at_end else_block
accept(node.else)
add_branched_block_value(branch, node.else.type?, @last)
@builder.br branch.exit_block
close_branched_block(branch)
@@ -1187,6 +1189,11 @@ module Crystal
end
def codegen_assign_target(target : Var, value, llvm_value)
if target.type == @mod.void
@vars[target.name] = LLVMVar.new(llvm_nil, @mod.void)
return
end
var = declare_var(target)
ptr = var.pointer
codegen_assign(ptr, target.type, value.type, llvm_value)
@@ -1220,6 +1227,12 @@ module Crystal
if target_type == value_type
value = @builder.load value if target_type.union? || (instance_var && (target_type.c_struct? || target_type.c_union?))
@builder.store value, pointer
# Hack until we fix it in the type inference
elsif value_type.is_a?(HierarchyType) && value_type.base_type == target_type
union_ptr = union_value value
union_ptr = cast_to_pointer union_ptr, target_type
union = @builder.load(union_ptr)
@builder.store union, pointer
# elsif target_type.number?
# value = cast_number(target_type, value_type, value)
# @builder.store value, pointer
@@ -1300,7 +1313,9 @@ module Crystal
var = @vars[node.name]
var_type = var.type
@last = var.pointer
if var_type == node.type
if var_type == @mod.void
# Nothing to do
elsif var_type == node.type
@last = @builder.load(@last) unless var.treated_as_pointer || var_type.union?
elsif var_type.is_a?(NilableType)
if node.type.nil_type?
@@ -1580,7 +1595,6 @@ module Crystal
end
copy = alloca llvm_type(arg.type), "block_#{arg.name}"
codegen_assign copy, arg.type, exp_type, @last
new_vars[arg.name] = LLVMVar.new(copy, arg.type)
end
@@ -53,8 +53,10 @@ module Crystal
def create_llvm_type(type : UnionType)
max_size = 0
type.union_types.each do |subtype|
size = size_of(llvm_type(subtype))
max_size = size if size > max_size
unless subtype.void?
size = size_of(llvm_type(subtype))
max_size = size if size > max_size
end
end
max_size /= 4
max_size = 1 if max_size == 0
@@ -131,11 +133,14 @@ module Crystal
max_size = 0
max_type :: LibLLVM::TypeRef
type.vars.each do |name, var|
llvm_type = llvm_embedded_type(var.type)
size = size_of(llvm_type)
if size > max_size
max_size = size
max_type = llvm_type
var_type = var.type
unless var_type.void?
llvm_type = llvm_embedded_type(var_type)
size = size_of(llvm_type)
if size > max_size
max_size = size
max_type = llvm_type
end
end
end
@@ -54,6 +54,8 @@ module Crystal
exit 1
end
filename = File.expand_path(filename) #unless filename == '-'
if @run
output_filename = String.new(C.tmpnam(nil))
else
@@ -640,6 +640,7 @@ module Crystal
if @buffer[1].ident_part_or_end?
scan_ident(start, start_column)
else
next_char
filename = @filename
@token.type = :STRING
@token.value = filename.is_a?(String) ? File.dirname(filename) : "-"
@@ -651,6 +652,7 @@ module Crystal
if @buffer[1].ident_part_or_end?
scan_ident(start, start_column)
else
next_char
@token.type = :STRING
@token.value = @filename
return @token
@@ -661,6 +663,7 @@ module Crystal
if @buffer[1].ident_part_or_end?
scan_ident(start, start_column)
else
next_char
@token.type = :INT
@token.value = @line_number
return @token
@@ -342,9 +342,12 @@ module Crystal
block_vars[arg.name] = arg
end
block_visitor = TypeVisitor.new(mod, block_vars, (node.scope || @scope), @parent, @call, @owner, @untyped_def, @typed_def, @arg_types, @free_vars, @yield_vars, @type_filter_stack)
block_visitor.block = node
node.body.accept block_visitor
pushing_type_filters(new_type_filter) do
block_visitor = TypeVisitor.new(mod, block_vars, (node.scope || @scope), @parent, @call, @owner, @untyped_def, @typed_def, @arg_types, @free_vars, @yield_vars, @type_filter_stack)
block_visitor.block = node
node.body.accept block_visitor
end
false
end
@@ -130,6 +130,10 @@ module Crystal
false
end
def void?
false
end
def hierarchy_type
self
end
@@ -1006,6 +1010,9 @@ module Crystal
end
class VoidType < PrimitiveType
def void?
true
end
end
class ValueType < NonGenericClassType

0 comments on commit ad2e815

Please sign in to comment.