Skip to content

Commit

Permalink
fixing #478
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Mar 4, 2012
1 parent 055c573 commit 0f3dbc4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
1 change: 0 additions & 1 deletion j/char.j
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ promote_rule(::Type{Char}, ::Type{Uint64}) = Uint64
+(x::Char, y::Char) = int(x) + int(y)
-(x::Char, y::Char) = int(x) - int(y)
*(x::Char, y::Char) = int(x) * int(y)
/(x::Char, y::Char) = int(x) * int(y)

div(x::Char, y::Char) = div(int(x), int(y))
fld(x::Char, y::Char) = div(int(x), int(y))
Expand Down
60 changes: 33 additions & 27 deletions j/inference.j
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,10 @@ ast_rettype(ast) = ast.args[3].typ
# saved type inference data there.
function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
#dbg =
#dotrace = true#is(linfo,sizestr)
local ast::Expr
#dotrace = true
local ast::Expr, tfunc_idx
curtype = None
redo = false
# check cached t-functions
tf = def.tfunc
if !is(tf,())
Expand All @@ -826,11 +828,14 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
for i = 1:length(codearr)
if typeseq(typearr[i],atypes)
code = codearr[i]
if isa(code, Tuple)
# compressed tree format
return (code, code[3])
assert(isa(code, Tuple))
if code[5]
curtype = code[3]
redo = true
tfunc_idx = i
break
end
return (code, ast_rettype(code))
return (code, code[3])
end
end
end
Expand Down Expand Up @@ -888,13 +893,8 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
# our stack frame
frame = CallStack(ast0, linfo.module, atypes, inference_stack)
inference_stack = frame
curtype = None
frame.result = curtype

local s, sv

while true

rec = false

s = { () | i=1:n }
Expand Down Expand Up @@ -1048,29 +1048,35 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
end
#print("\n",ast,"\n")
#print("==> ", frame.result,"\n")
if !rec || typeseq(curtype, frame.result)
break
if redo && typeseq(curtype, frame.result)
rec = false
end
curtype = frame.result
end # while

fulltree = type_annotate(ast, s, sv, frame.result, vars)

fulltree.args[3] = inlining_pass(fulltree.args[3], vars)
tuple_elim_pass(fulltree)
linfo.inferred = true
if !rec
fulltree.args[3] = inlining_pass(fulltree.args[3], vars)
tuple_elim_pass(fulltree)
linfo.inferred = true
end

compr = ccall(:jl_compress_ast, Any, (Any,), fulltree)

compressed = ccall(:jl_compress_ast, Any, (Any,), fulltree)
fulltree = compressed
#compressed = fulltree
if is(def.tfunc,())
def.tfunc = ({},{})
end
push(def.tfunc[1]::Array{Any,1}, atypes)
push(def.tfunc[2]::Array{Any,1}, compressed)
if !redo
if is(def.tfunc,())
def.tfunc = ({},{})
end
compr = (compr[1],compr[2],compr[3],compr[4],rec)
push(def.tfunc[1]::Array{Any,1}, atypes)
push(def.tfunc[2]::Array{Any,1}, compr)
elseif !rec
codearr = def.tfunc[2]
compr = codearr[tfunc_idx]
codearr[tfunc_idx] = (compr[1],compr[2],compr[3],compr[4],false)
end

inference_stack = (inference_stack::CallStack).prev
return (fulltree, frame.result)
return (compr, frame.result)
end

function record_var_type(e::Symbol, t, decls)
Expand Down
1 change: 1 addition & 0 deletions j/int.j
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ promote_rule(::Type{Uint64}, ::Type{Int64}) = Uint64
*(x::Uint64, y::Uint64) = boxui64(mul_int(unbox64(x), unbox64(y)))

/(x::Integer, y::Integer) = float64(x)/float64(y)
inv(x::Integer) = 1.0/float64(x)

div{T<:Signed}(x::T, y::T) = div(int(x),int(y))
rem{T<:Signed}(x::T, y::T) = rem(int(x),int(y))
Expand Down
3 changes: 0 additions & 3 deletions j/operators.j
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ for op = (:+, :*, :&, :|, :$, :min, :max)
end
end

# fallback division:
/{T<:Real}(x::T, y::T) = float64(x)/float64(y)

\(x,y) = y/x

# .<op> defaults to <op>
Expand Down
3 changes: 3 additions & 0 deletions test/corelib.j
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ let a36 = boo32_64()
@assert a36[1]==1 && a36[2]==2
end

@assert (10.^[-1])[1] == 0.1
@assert (10.^[-1.])[1] == 0.1

# hash table
h = HashTable()
for i=1:10000
Expand Down

0 comments on commit 0f3dbc4

Please sign in to comment.