From eb732584b90cc4e76fefae7eaa06f103e73979c1 Mon Sep 17 00:00:00 2001 From: Isaiah Norton Date: Mon, 28 Sep 2015 17:46:22 -0400 Subject: [PATCH] more WIP: rename __LOCATION__ -> &meta and use for `@__FILE__` and `@__LINE__` macros. --- base/exports.jl | 1 + base/loading.jl | 9 +++++++-- src/julia-parser.scm | 2 +- src/julia-syntax.scm | 2 +- test/docs.jl | 2 +- test/loading.jl | 4 ++-- test/parse.jl | 5 ++--- 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/base/exports.jl b/base/exports.jl index cfc1574f57046..c562ac2d913f9 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1348,6 +1348,7 @@ export # Macros # parser internal @__FILE__, + @__LINE__, @int128_str, @uint128_str, @big_str, diff --git a/base/loading.jl b/base/loading.jl index fd6ab8755f89a..dbb4abed327a4 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -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() @@ -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 diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 6674fc13b352a..9d437c5b6c4a5 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -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 diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index e2d272d184058..7b13e47713f22 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -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) diff --git a/test/docs.jl b/test/docs.jl index a97a47ce2f282..2f2e9b853ae5d 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -289,7 +289,7 @@ let d = (@doc @m2_11993) No documentation found. ```julia - @m2_11993(__LOCATION__) + @m2_11993(&meta) ``` """) end diff --git a/test/loading.jl b/test/loading.jl index 0e7f05aeeba76..74787d3276ce3 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -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__) diff --git a/test/parse.jl b/test/parse.jl index d8f4ca7856a3e..4c3a67467064f 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -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))