Skip to content

Commit

Permalink
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/compiler/crystal/codegen/exception.cr
Original file line number Diff line number Diff line change
@@ -134,6 +134,7 @@ class Crystal::CodeGenVisitor
if a_rescue_name = a_rescue.name
context.vars = context.vars.dup
get_exception_fun = main_fun(GET_EXCEPTION_NAME)
set_current_debug_location node if @debug
exception_ptr = call get_exception_fun, [bit_cast(unwind_ex_obj, get_exception_fun.params.first.type)]
exception = int2ptr exception_ptr, LLVMTyper::TYPE_ID_POINTER
unless a_rescue.type.virtual?
12 changes: 7 additions & 5 deletions src/compiler/crystal/semantic/new.cr
Original file line number Diff line number Diff line change
@@ -206,7 +206,7 @@ module Crystal
exps << assign
exps << init
exps << If.new(RespondsTo.new(obj.clone, "finalize"),
Call.new(Path.global("GC"), "add_finalizer", obj.clone))
Call.new(Path.global("GC"), "add_finalizer", obj.clone).at(self))
exps << obj

# Forward block argument if any
@@ -219,6 +219,8 @@ module Crystal
end

def self.argless_new(instance_type)
loc = instance_type.locations.try &.first?

# This creates:
#
# def new
@@ -227,16 +229,16 @@ module Crystal
# x
# end
var = Var.new("x")
alloc = Call.new(nil, "allocate")
alloc = Call.new(nil, "allocate").at(loc)
assign = Assign.new(var, alloc)

call = Call.new(Path.global("GC"), "add_finalizer", var.clone).at(loc)
exps = Array(ASTNode).new(3)
exps << assign
exps << If.new(RespondsTo.new(var.clone, "finalize"),
Call.new(Path.global("GC"), "add_finalizer", var.clone))
exps << If.new(RespondsTo.new(var.clone, "finalize"), call)
exps << var.clone

a_def = Def.new("new", body: exps)
a_def = Def.new("new", body: exps).at(loc)
a_def.new = true
a_def
end
3 changes: 2 additions & 1 deletion src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
@@ -1261,7 +1261,8 @@ module Crystal
next_token_skip_space

if rescues || a_ensure
ex = ExceptionHandler.new(exp, rescues, a_else, a_ensure).at_end(end_location)
ex = ExceptionHandler.new(exp, rescues, a_else, a_ensure).at(exp).at_end(end_location)
ex.at(exp.location || rescues.try(&.first?).try(&.location) || a_ensure.try(&.location))
ex.implicit = true if implicit
{ex, end_location}
else

0 comments on commit 4343d16

Please sign in to comment.