diff --git a/NEWS.md b/NEWS.md index aefdb6a142ac8..b5eb728f1cc8d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,18 +6,14 @@ New language features * An *exception stack* is maintained on each task to make exception handling more robust and enable root cause analysis using `catch_stack` ([#28878]). - Language changes ---------------- - * the constructor `BigFloat(::BigFloat)` now respects the global precision setting and always - returns a `BigFloat` with precision equal to `precision(BigFloat)` ([#29127]). The optional - `precision` argument to override the global setting is now a keyword instead of positional - argument ([#29157]). * Parser inputs ending with a comma are now consistently treated as incomplete. Previously they were sometimes parsed as tuples, depending on whitespace ([#28506]). - * `Regex` and `TimeZone` now behave like scalars when used in broadcasting ([#29913], [#30159]). - * `Char` now behaves like a read-only 0-dimensional array ([#29819]). + * Big integer literals and command syntax (backticks) are now parsed with the name of + the macro (`@int128_str`, `@uint128_str`, `@big_str`, `@cmd`) qualified to refer + to the `Core` module ([#29968]). New library functions --------------------- @@ -26,7 +22,6 @@ New library functions * `isnothing(::Any)` function, to check whether something is a `Nothing`, returns a `Bool` ([#29679]). * `getpid(::Process)` method ([#24064]). - Standard library changes ------------------------ @@ -38,6 +33,12 @@ Standard library changes * `edit` can now be called on a module to edit the file that defines it ([#29636]). * `diff` now supports arrays of arbitrary dimensionality and can operate over any dimension ([#29827]). * `sprandn` now supports result types like `ComplexF64` or `Float32` ([#30083]). + * The constructor `BigFloat(::BigFloat)` now respects the global precision setting and always + returns a `BigFloat` with precision equal to `precision(BigFloat)` ([#29127]). The optional + `precision` argument to override the global setting is now a keyword instead of positional + argument ([#29157]). + * `Regex` and `TimeZone` now behave like scalars when used in broadcasting ([#29913], [#30159]). + * `Char` now behaves like a read-only 0-dimensional array ([#29819]). Compiler/Runtime improvements ----------------------------- diff --git a/base/boot.jl b/base/boot.jl index 613cc686685c6..03b389b0f7e1f 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -457,6 +457,14 @@ end atdoc = (source, mod, str, expr) -> Expr(:escape, expr) atdoc!(λ) = global atdoc = λ +# macros for big integer syntax +macro int128_str end +macro uint128_str end +macro big_str end + +# macro for command syntax +macro cmd end + # simple stand-alone print definitions for debugging abstract type IO end diff --git a/base/sysimg.jl b/base/sysimg.jl index e110b5c4b55a9..8e0dd138b9cea 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -72,7 +72,7 @@ convert(::Type{T}, arg) where {T<:VecElement} = T(arg) convert(::Type{T}, arg::T) where {T<:VecElement} = arg # init core docsystem -import Core: @doc, @__doc__, WrappedException +import Core: @doc, @__doc__, WrappedException, @int128_str, @uint128_str, @big_str, @cmd if isdefined(Core, :Compiler) import Core.Compiler.CoreDocs Core.atdoc!(CoreDocs.docm) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index f4e7b661a86ff..b9f80af1b5dd7 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -408,10 +408,10 @@ ((eq? pred char-bin?) (fix-uint-neg neg (sized-uint-literal n s 1))) (is-float32-literal (numchk n s) (float n)) (n (if (and (integer? n) (> n 9223372036854775807)) - `(macrocall @int128_str (null) ,s) + `(macrocall (core @int128_str) (null) ,s) n)) - ((within-int128? s) `(macrocall @int128_str (null) ,s)) - (else `(macrocall @big_str (null) ,s)))))) + ((within-int128? s) `(macrocall (core @int128_str) (null) ,s)) + (else `(macrocall (core @big_str) (null) ,s)))))) (define (fix-uint-neg neg n) (if neg @@ -427,7 +427,7 @@ ((<= l 16) (numchk n s) (uint16 n)) ((<= l 32) (numchk n s) (uint32 n)) ((<= l 64) (numchk n s) (uint64 n)) - ((<= l 128) `(macrocall @uint128_str (null) ,s)) + ((<= l 128) `(macrocall (core @uint128_str) (null) ,s)) (else (error "Hex or binary literal too large for UInt128"))))) (define (sized-uint-oct-literal n s) @@ -440,7 +440,7 @@ (else (uint64 n))) (begin (if (equal? s "0o") (numchk n s)) (if (oct-within-uint128? s) - `(macrocall @uint128_str (null) ,s) + `(macrocall (core @uint128_str) (null) ,s) (error "Octal literal too large for UInt128")))))) (define (strip-leading-0s s) @@ -471,9 +471,9 @@ (>= 0 (compare-num-strings s "170141183460469231731687303715884105727")))) (define (large-number? t) - (and (pair? t) - (eq? (car t) 'macrocall) - (memq (cadr t) '(@int128_str @uint128_str @big_str)))) + (and (pair? t) (eq? (car t) 'macrocall) + (pair? (cadr t)) (eq? (car (cadr t)) 'core) + (memq (cadadr t) '(@int128_str @uint128_str @big_str)))) ;; skip to end of comment, starting at #: either #... or #= .... =#. (define (skip-comment port) @@ -996,10 +996,10 @@ (if (eq? op '-) (if (large-number? num) (if (eqv? (cadddr num) "-170141183460469231731687303715884105728") - `(macrocall @big_str (null) "170141183460469231731687303715884105728") + `(macrocall (core @big_str) (null) "170141183460469231731687303715884105728") `(,(car num) ,(cadr num) ,(caddr num) ,(string.tail (cadddr num) 1))) (if (= num -9223372036854775808) - `(macrocall @int128_str (null) "9223372036854775808") + `(macrocall (core @int128_str) (null) "9223372036854775808") (- num))) num)) @@ -2340,7 +2340,7 @@ ;; command syntax ((eqv? t #\`) (take-token s) - `(macrocall @cmd ,(line-number-node s) ,(parse-raw-literal s #\`))) + `(macrocall (core @cmd) ,(line-number-node s) ,(parse-raw-literal s #\`))) ((or (string? t) (number? t) (large-number? t)) (take-token s)) diff --git a/test/syntax.jl b/test/syntax.jl index e0729116069e1..fea8b74e94840 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -759,7 +759,7 @@ end @test :(x`s\`"\x\$\\`) == :(@x_cmd "s`\"\\x\\\$\\") # Check multiline command literals -@test :(@cmd "multiline\ncommand\n") == :``` +@test Expr(:macrocall, GlobalRef(Core, Symbol("@cmd")), LineNumberNode(@__LINE__, Symbol(@__FILE__)), "multiline\ncommand\n") == :``` multiline command ```