Skip to content

Commit

Permalink
get rid of typecache since Base treat type signatures as pure Exprs a…
Browse files Browse the repository at this point in the history
…s well
  • Loading branch information
ylxdzsw committed Jul 15, 2018
1 parent 0af03d8 commit 276ae18
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ os:
- osx
- linux
julia:
- nightly
- 0.7
script:
- julia -e 'Pkg.clone(pwd()); Pkg.test("Fire")'
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The Fire.jl package is licensed under the MIT License:

> Copyright (c) 2017: Zhang ShiWei.
> Copyright (c) 2017-2018: Zhang ShiWei.
>
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
Expand Down
28 changes: 9 additions & 19 deletions src/Fire.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ const REQUIRED = 0x01
const OPTIONAL = 0x02
const VARLENGTH = 0x03

const entries = FuncDef[]
const typecache = Dict(1=>String)
const typecount = (c -> () -> c += 1)(1)
const entries = FuncDef[]

function __init__()
atexit(parse_command_line)
Expand All @@ -41,39 +39,31 @@ function parse_function_definition(f)

for def in defs
if isa(def, Symbol)
push!(args.args, Expr(:tuple, quot(def), :($typecache[1]), REQUIRED))
push!(args.args, Expr(:tuple, quot(def), String, REQUIRED))
elseif def.head == :(::)
x = typecount()
def.args[2] = :( $typecache[$x] = $(def.args[2]) )
push!(args.args, Expr(:tuple, quot(def.args[1]), :($typecache[$x]), REQUIRED))
push!(args.args, Expr(:tuple, quot(def.args[1]), esc(def.args[2]), REQUIRED))
elseif def.head == :kw
if isa(def.args[1], Symbol)
push!(args.args, Expr(:tuple, quot(def.args[1]), :($typecache[1]), OPTIONAL, quot(def.args[2])))
push!(args.args, Expr(:tuple, quot(def.args[1]), String, OPTIONAL, quot(def.args[2])))
else
x = typecount()
def.args[1].args[2] = :( $typecache[$x] = $(def.args[1].args[2]) )
push!(args.args, Expr(:tuple, quot(def.args[1].args[1]), :($typecache[$x]), OPTIONAL, quot(def.args[2])))
push!(args.args, Expr(:tuple, quot(def.args[1].args[1]), esc(def.args[1].args[2]), OPTIONAL, quot(def.args[2])))
end
elseif def.head == :(...)
def = def.args[1]
if isa(def, Symbol)
push!(args.args, Expr(:tuple, quot(def), :($typecache[1]), VARLENGTH))
push!(args.args, Expr(:tuple, quot(def), String, VARLENGTH))
else
x = typecount()
def.args[2] = :( $typecache[$x] = $(def.args[2]) )
push!(args.args, Expr(:tuple, quot(def.args[1]), :($typecache[$x]), VARLENGTH))
push!(args.args, Expr(:tuple, quot(def.args[1]), esc(def.args[2]), VARLENGTH))
end
elseif def.head == :parameters
for def in def.args
if def.head != :kw
error("Fire.jl don't support var length keyword argument")
end
if isa(def.args[1], Symbol)
push!(kwargs.args, Expr(:tuple, quot(def.args[1]), :($typecache[1]), quot(def.args[2])))
push!(kwargs.args, Expr(:tuple, quot(def.args[1]), String, quot(def.args[2])))
else
x = typecount()
def.args[1].args[2] = :( $typecache[$x] = $(def.args[1].args[2]) )
push!(kwargs.args, Expr(:tuple, quot(def.args[1].args[1]), :($typecache[$x]), quot(def.args[2])))
push!(kwargs.args, Expr(:tuple, quot(def.args[1].args[1]), esc(def.args[1].args[2]), quot(def.args[2])))
end
end
else
Expand Down

0 comments on commit 276ae18

Please sign in to comment.