Skip to content

Commit

Permalink
more WIP: rename __LOCATION__ -> &meta
Browse files Browse the repository at this point in the history
and use for `@__FILE__` and `@__LINE__` macros.
  • Loading branch information
ihnorton committed Sep 29, 2015
1 parent cebd013 commit eb73258
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,7 @@ export
# Macros
# parser internal
@__FILE__,
@__LINE__,
@int128_str,
@uint128_str,
@big_str,
Expand Down
9 changes: 7 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,6 @@ function source_dir()
p === nothing ? p : dirname(p)
end

macro __FILE__() source_path() end

function include_from_node1(_path::AbstractString)
path, prev = _include_dependency(_path)
tls = task_local_storage()
Expand Down Expand Up @@ -461,3 +459,10 @@ function recompile_stale(mod, cachefile)
end
end
end

macro __MACROCALL_META__() :( $(symbol("&meta")) ) end
macro __MACROCALL_LINE__() :( $(symbol("&meta")).args[1]) end
macro __MACROCALL_FILE__() :( string($(symbol("&meta")).args[2]) ) end

macro __LINE__() @__MACROCALL_LINE__ end
macro __FILE__() @__MACROCALL_FILE__ end
2 changes: 1 addition & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,7 @@
(with-space-sensitive
(let* ((head (parse-unary-prefix s))
(t (peek-token s))
(loc (line-number-node s)))
(loc (line-number-node s)))
(cond
((ts:space? s)
`(macrocall ,(macroify-name head) ,loc
Expand Down
2 changes: 1 addition & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@
(symbol? (cadr (cadr e))))
`(macro ,(symbol (string #\@ (cadr (cadr e))))
,(expand-binding-forms
`(-> (tuple __LOCATION__ ,@(cddr (cadr e)))
`(-> (tuple &meta ,@(cddr (cadr e)))
,(caddr e)))))
((symbol? (cadr e)) ;; already expanded
e)
Expand Down
2 changes: 1 addition & 1 deletion test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ let d = (@doc @m2_11993)
No documentation found.
```julia
@m2_11993(__LOCATION__)
@m2_11993(&meta)
```
""")
end
Expand Down
4 changes: 2 additions & 2 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

using Base.Test

@test @__LINE__ == 5
@test @__LINE__() == 5

include("test_sourcepath.jl")
thefname = "the fname!//\\&\0\1*"
@test include_string("include_string_test() = @__FILE__", thefname)() == Base.source_path()
@test include_string("include_string_test() = @__FILE__", thefname)() == thefname[1:end-3]
@test include_string("Base.source_path()", thefname) == Base.source_path()
@test basename(@__FILE__) == "loading.jl"
@test isabspath(@__FILE__)
5 changes: 2 additions & 3 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,11 @@ macro test999_str(args...); args; end

# issue 11970
@test parseall("""
macro f(args...) end; @f ""
macro f(args...) end; @f ""
""") == Expr(:toplevel,
Expr(:macro, Expr(:call, :f, Expr(:..., :args)), Expr(:block,)),
Expr(:macrocall,
symbol("@f"), LineNumberNode(symbol("/cmn/julia/test/parse.jl"),1),
""))
symbol("@f"), LineNumberNode(symbol(@__FILE__),1),""))

# integer parsing
@test is(parse(Int32,"0",36),Int32(0))
Expand Down

0 comments on commit eb73258

Please sign in to comment.