Skip to content

Commit 0f3dbc4

Browse files
committed
fixing #478
1 parent 055c573 commit 0f3dbc4

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

j/char.j

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ promote_rule(::Type{Char}, ::Type{Uint64}) = Uint64
4242
+(x::Char, y::Char) = int(x) + int(y)
4343
-(x::Char, y::Char) = int(x) - int(y)
4444
*(x::Char, y::Char) = int(x) * int(y)
45-
/(x::Char, y::Char) = int(x) * int(y)
4645

4746
div(x::Char, y::Char) = div(int(x), int(y))
4847
fld(x::Char, y::Char) = div(int(x), int(y))

j/inference.j

+33-27
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,10 @@ ast_rettype(ast) = ast.args[3].typ
816816
# saved type inference data there.
817817
function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
818818
#dbg =
819-
#dotrace = true#is(linfo,sizestr)
820-
local ast::Expr
819+
#dotrace = true
820+
local ast::Expr, tfunc_idx
821+
curtype = None
822+
redo = false
821823
# check cached t-functions
822824
tf = def.tfunc
823825
if !is(tf,())
@@ -826,11 +828,14 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
826828
for i = 1:length(codearr)
827829
if typeseq(typearr[i],atypes)
828830
code = codearr[i]
829-
if isa(code, Tuple)
830-
# compressed tree format
831-
return (code, code[3])
831+
assert(isa(code, Tuple))
832+
if code[5]
833+
curtype = code[3]
834+
redo = true
835+
tfunc_idx = i
836+
break
832837
end
833-
return (code, ast_rettype(code))
838+
return (code, code[3])
834839
end
835840
end
836841
end
@@ -888,13 +893,8 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
888893
# our stack frame
889894
frame = CallStack(ast0, linfo.module, atypes, inference_stack)
890895
inference_stack = frame
891-
curtype = None
892896
frame.result = curtype
893897

894-
local s, sv
895-
896-
while true
897-
898898
rec = false
899899

900900
s = { () | i=1:n }
@@ -1048,29 +1048,35 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
10481048
end
10491049
#print("\n",ast,"\n")
10501050
#print("==> ", frame.result,"\n")
1051-
if !rec || typeseq(curtype, frame.result)
1052-
break
1051+
if redo && typeseq(curtype, frame.result)
1052+
rec = false
10531053
end
1054-
curtype = frame.result
1055-
end # while
10561054

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

1059-
fulltree.args[3] = inlining_pass(fulltree.args[3], vars)
1060-
tuple_elim_pass(fulltree)
1061-
linfo.inferred = true
1057+
if !rec
1058+
fulltree.args[3] = inlining_pass(fulltree.args[3], vars)
1059+
tuple_elim_pass(fulltree)
1060+
linfo.inferred = true
1061+
end
1062+
1063+
compr = ccall(:jl_compress_ast, Any, (Any,), fulltree)
10621064

1063-
compressed = ccall(:jl_compress_ast, Any, (Any,), fulltree)
1064-
fulltree = compressed
1065-
#compressed = fulltree
1066-
if is(def.tfunc,())
1067-
def.tfunc = ({},{})
1068-
end
1069-
push(def.tfunc[1]::Array{Any,1}, atypes)
1070-
push(def.tfunc[2]::Array{Any,1}, compressed)
1065+
if !redo
1066+
if is(def.tfunc,())
1067+
def.tfunc = ({},{})
1068+
end
1069+
compr = (compr[1],compr[2],compr[3],compr[4],rec)
1070+
push(def.tfunc[1]::Array{Any,1}, atypes)
1071+
push(def.tfunc[2]::Array{Any,1}, compr)
1072+
elseif !rec
1073+
codearr = def.tfunc[2]
1074+
compr = codearr[tfunc_idx]
1075+
codearr[tfunc_idx] = (compr[1],compr[2],compr[3],compr[4],false)
1076+
end
10711077

10721078
inference_stack = (inference_stack::CallStack).prev
1073-
return (fulltree, frame.result)
1079+
return (compr, frame.result)
10741080
end
10751081

10761082
function record_var_type(e::Symbol, t, decls)

j/int.j

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ promote_rule(::Type{Uint64}, ::Type{Int64}) = Uint64
211211
*(x::Uint64, y::Uint64) = boxui64(mul_int(unbox64(x), unbox64(y)))
212212

213213
/(x::Integer, y::Integer) = float64(x)/float64(y)
214+
inv(x::Integer) = 1.0/float64(x)
214215

215216
div{T<:Signed}(x::T, y::T) = div(int(x),int(y))
216217
rem{T<:Signed}(x::T, y::T) = rem(int(x),int(y))

j/operators.j

-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ for op = (:+, :*, :&, :|, :$, :min, :max)
5353
end
5454
end
5555

56-
# fallback division:
57-
/{T<:Real}(x::T, y::T) = float64(x)/float64(y)
58-
5956
\(x,y) = y/x
6057

6158
# .<op> defaults to <op>

test/corelib.j

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ let a36 = boo32_64()
3737
@assert a36[1]==1 && a36[2]==2
3838
end
3939

40+
@assert (10.^[-1])[1] == 0.1
41+
@assert (10.^[-1.])[1] == 0.1
42+
4043
# hash table
4144
h = HashTable()
4245
for i=1:10000

0 commit comments

Comments
 (0)