Skip to content

Commit

Permalink
follow up #596 (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Nov 28, 2023
1 parent 9d50726 commit 9afdf71
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
5 changes: 3 additions & 2 deletions bin/generate_builtins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,12 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
elseif name === :arraysize
maxarg = 2
end
fcall = generate_fcall_nargs(name, minarg, maxarg)
_scopedname = "$mod.$name"
fcall = generate_fcall_nargs(_scopedname, minarg, maxarg)
rname = repr(name)
print(io,
"""
elseif @static isdefined($mod, $rname) && f === $name
elseif @static (isdefined($mod, $rname) && $_scopedname isa Core.Builtin) && f === $_scopedname
$fcall
""")
end
Expand Down
60 changes: 30 additions & 30 deletions src/builtins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,65 +330,65 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
call_expr.args[3] = @lookup(frame, args[3])
return Some{Any}(Core.eval(moduleof(frame), call_expr))
end
elseif @static isdefined(Core, :arrayref) && f === :arrayref
elseif @static (isdefined(Core, :arrayref) && Core.arrayref isa Core.Builtin) && f === Core.arrayref
if nargs == 1
return Some{Any}(arrayref(@lookup(frame, args[2])))
return Some{Any}(Core.arrayref(@lookup(frame, args[2])))
elseif nargs == 2
return Some{Any}(arrayref(@lookup(frame, args[2]), @lookup(frame, args[3])))
return Some{Any}(Core.arrayref(@lookup(frame, args[2]), @lookup(frame, args[3])))
elseif nargs == 3
return Some{Any}(arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4])))
return Some{Any}(Core.arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4])))
elseif nargs == 4
return Some{Any}(arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5])))
return Some{Any}(Core.arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5])))
elseif nargs == 5
return Some{Any}(arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6])))
return Some{Any}(Core.arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6])))
else
return Some{Any}(arrayref(getargs(args, frame)...))
return Some{Any}(Core.arrayref(getargs(args, frame)...))
end
elseif @static isdefined(Core, :arrayset) && f === :arrayset
elseif @static (isdefined(Core, :arrayset) && Core.arrayset isa Core.Builtin) && f === Core.arrayset
if nargs == 1
return Some{Any}(arrayset(@lookup(frame, args[2])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2])))
elseif nargs == 2
return Some{Any}(arrayset(@lookup(frame, args[2]), @lookup(frame, args[3])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2]), @lookup(frame, args[3])))
elseif nargs == 3
return Some{Any}(arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4])))
elseif nargs == 4
return Some{Any}(arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5])))
elseif nargs == 5
return Some{Any}(arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6])))
elseif nargs == 6
return Some{Any}(arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6]), @lookup(frame, args[7])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6]), @lookup(frame, args[7])))
else
return Some{Any}(arrayset(getargs(args, frame)...))
return Some{Any}(Core.arrayset(getargs(args, frame)...))
end
elseif @static isdefined(Core, :arrayset) && f === :arrayset
elseif @static (isdefined(Core, :arrayset) && Core.arrayset isa Core.Builtin) && f === Core.arrayset
if nargs == 1
return Some{Any}(arrayset(@lookup(frame, args[2])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2])))
elseif nargs == 2
return Some{Any}(arrayset(@lookup(frame, args[2]), @lookup(frame, args[3])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2]), @lookup(frame, args[3])))
elseif nargs == 3
return Some{Any}(arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4])))
elseif nargs == 4
return Some{Any}(arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5])))
elseif nargs == 5
return Some{Any}(arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6])))
elseif nargs == 6
return Some{Any}(arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6]), @lookup(frame, args[7])))
return Some{Any}(Core.arrayset(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6]), @lookup(frame, args[7])))
else
return Some{Any}(arrayset(getargs(args, frame)...))
return Some{Any}(Core.arrayset(getargs(args, frame)...))
end
elseif @static isdefined(Core, :const_arrayref) && f === :const_arrayref
elseif @static (isdefined(Core, :const_arrayref) && Core.const_arrayref isa Core.Builtin) && f === Core.const_arrayref
if nargs == 1
return Some{Any}(const_arrayref(@lookup(frame, args[2])))
return Some{Any}(Core.const_arrayref(@lookup(frame, args[2])))
elseif nargs == 2
return Some{Any}(const_arrayref(@lookup(frame, args[2]), @lookup(frame, args[3])))
return Some{Any}(Core.const_arrayref(@lookup(frame, args[2]), @lookup(frame, args[3])))
elseif nargs == 3
return Some{Any}(const_arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4])))
return Some{Any}(Core.const_arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4])))
elseif nargs == 4
return Some{Any}(const_arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5])))
return Some{Any}(Core.const_arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5])))
elseif nargs == 5
return Some{Any}(const_arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6])))
return Some{Any}(Core.const_arrayref(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5]), @lookup(frame, args[6])))
else
return Some{Any}(const_arrayref(getargs(args, frame)...))
return Some{Any}(Core.const_arrayref(getargs(args, frame)...))
end
elseif f === Core.Intrinsics.llvmcall
return Some{Any}(Core.Intrinsics.llvmcall(getargs(args, frame)...))
Expand Down
4 changes: 4 additions & 0 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -993,3 +993,7 @@ end
@test (@interpret string("", "pcre_h.jl")) == string("", "pcre_h.jl")
@test (@interpret Base.strcat("", "build_h.jl")) == Base.strcat("", "build_h.jl")
end

# test for using generic functions that were previously builtin
func_arrayref(a, i) = Core.arrayref(true, a, i)
@test 2 == @interpret func_arrayref([1,2,3], 2)

0 comments on commit 9afdf71

Please sign in to comment.