Skip to content

Commit eb73258

Browse files
committed
more WIP: rename __LOCATION__ -> &meta
and use for `@__FILE__` and `@__LINE__` macros.
1 parent cebd013 commit eb73258

File tree

7 files changed

+15
-10
lines changed

7 files changed

+15
-10
lines changed

base/exports.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,7 @@ export
13481348
# Macros
13491349
# parser internal
13501350
@__FILE__,
1351+
@__LINE__,
13511352
@int128_str,
13521353
@uint128_str,
13531354
@big_str,

base/loading.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ function source_dir()
290290
p === nothing ? p : dirname(p)
291291
end
292292

293-
macro __FILE__() source_path() end
294-
295293
function include_from_node1(_path::AbstractString)
296294
path, prev = _include_dependency(_path)
297295
tls = task_local_storage()
@@ -461,3 +459,10 @@ function recompile_stale(mod, cachefile)
461459
end
462460
end
463461
end
462+
463+
macro __MACROCALL_META__() :( $(symbol("&meta")) ) end
464+
macro __MACROCALL_LINE__() :( $(symbol("&meta")).args[1]) end
465+
macro __MACROCALL_FILE__() :( string($(symbol("&meta")).args[2]) ) end
466+
467+
macro __LINE__() @__MACROCALL_LINE__ end
468+
macro __FILE__() @__MACROCALL_FILE__ end

src/julia-parser.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@
20362036
(with-space-sensitive
20372037
(let* ((head (parse-unary-prefix s))
20382038
(t (peek-token s))
2039-
(loc (line-number-node s)))
2039+
(loc (line-number-node s)))
20402040
(cond
20412041
((ts:space? s)
20422042
`(macrocall ,(macroify-name head) ,loc

src/julia-syntax.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@
11811181
(symbol? (cadr (cadr e))))
11821182
`(macro ,(symbol (string #\@ (cadr (cadr e))))
11831183
,(expand-binding-forms
1184-
`(-> (tuple __LOCATION__ ,@(cddr (cadr e)))
1184+
`(-> (tuple &meta ,@(cddr (cadr e)))
11851185
,(caddr e)))))
11861186
((symbol? (cadr e)) ;; already expanded
11871187
e)

test/docs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ let d = (@doc @m2_11993)
289289
No documentation found.
290290
291291
```julia
292-
@m2_11993(__LOCATION__)
292+
@m2_11993(&meta)
293293
```
294294
""")
295295
end

test/loading.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
using Base.Test
44

5-
@test @__LINE__ == 5
5+
@test @__LINE__() == 5
66

77
include("test_sourcepath.jl")
88
thefname = "the fname!//\\&\0\1*"
9-
@test include_string("include_string_test() = @__FILE__", thefname)() == Base.source_path()
9+
@test include_string("include_string_test() = @__FILE__", thefname)() == thefname[1:end-3]
1010
@test include_string("Base.source_path()", thefname) == Base.source_path()
1111
@test basename(@__FILE__) == "loading.jl"
1212
@test isabspath(@__FILE__)

test/parse.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,11 @@ macro test999_str(args...); args; end
149149

150150
# issue 11970
151151
@test parseall("""
152-
macro f(args...) end; @f ""
152+
macro f(args...) end; @f ""
153153
""") == Expr(:toplevel,
154154
Expr(:macro, Expr(:call, :f, Expr(:..., :args)), Expr(:block,)),
155155
Expr(:macrocall,
156-
symbol("@f"), LineNumberNode(symbol("/cmn/julia/test/parse.jl"),1),
157-
""))
156+
symbol("@f"), LineNumberNode(symbol(@__FILE__),1),""))
158157

159158
# integer parsing
160159
@test is(parse(Int32,"0",36),Int32(0))

0 commit comments

Comments
 (0)