[GHC] #9224: Add support for binary integer literals
#9224: Add support for binary integer literals -------------------------------------------+------------------------------- Reporter: hvr | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler (Parser) | Version: Keywords: literals | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Easy (less than 1 hour) | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: -------------------------------------------+------------------------------- Currently, Haskell98/2010 support base-10, base-8 (via `0[oO]`-prefix) and base-16 (via `0[xX]`-prefix) integer literals. I hereby propose to add conditional support for base-2 integers via a `0[bB]`-prefix, controlled via a new `-XBinaryLiterals` language extension flag/pragma. The change to the lexer is trivial (see attached patch), however I'm stuck on the lexer using a 32-bit feature-mask, of which all 32bits are already taken, and I'd need a 33th bit for the `BinaryLiteralsBit` flag. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9224> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9224: Add support for binary integer literals -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: (Parser) | Keywords: literals Resolution: | Architecture: Unknown/Multiple Operating System: Unknown/Multiple | Difficulty: Easy (less than 1 Type of failure: None/Unknown | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Comment (by hvr): Initial patch (sans the language-extension) pushed to https://phabricator.haskell.org/D22 for review -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9224#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9224: Add support for binary integer literals -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: (Parser) | Keywords: literals Resolution: | Architecture: Unknown/Multiple Operating System: Unknown/Multiple | Difficulty: Easy (less than 1 Type of failure: None/Unknown | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Description changed by hvr: Old description:
Currently, Haskell98/2010 support base-10, base-8 (via `0[oO]`-prefix) and base-16 (via `0[xX]`-prefix) integer literals.
I hereby propose to add conditional support for base-2 integers via a `0[bB]`-prefix, controlled via a new `-XBinaryLiterals` language extension flag/pragma. The change to the lexer is trivial (see attached patch), however I'm stuck on the lexer using a 32-bit feature-mask, of which all 32bits are already taken, and I'd need a 33th bit for the `BinaryLiteralsBit` flag.
New description: Haskell2010 supports - base-10 (prefix-less), - base-8 (via `0[oO]`-prefix), and - base-16 (via `0[xX]`-prefix) integer literals. I hereby propose to add conditional support for base-2 integers literals via a `0[bB]`-prefix, disabled by default, and controllable via a new `{-# LANGUAGE BinaryLiterals #-}` language extension flag/pragma. The use of a `0b` prefix for indicating binary literals is known from popular programming languages such as Python, Ruby, and Java. -- -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9224#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9224: Add support for binary integer literals -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: (Parser) | Keywords: literals Resolution: | Architecture: Unknown/Multiple Operating System: Unknown/Multiple | Difficulty: Easy (less than 1 Type of failure: None/Unknown | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Comment (by Herbert Valerio Riedel <hvr@…>): In [changeset:"1c0b5fdc9f2b6ea8166cc565383d4cd20432343c/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="1c0b5fdc9f2b6ea8166cc565383d4cd20432343c" Add -XBinaryLiterals language extension (re #9224) Haskell2010 supports - base-10 (prefix-less), - base-8 (via `0[oO]`-prefix), and - base-16 (via `0[xX]`-prefix) integer literals. This commit adds syntax support for base-2 integer literals via the new `0[bB]` prefix. The use of a `0b` prefix for indicating binary literals is known from popular programming languages such as C++14, Perl, Python, Ruby, and Java. This syntax extension is disabled by default and can be enabled via the new `{-# LANGUAGE BinaryLiterals #-}` pragma and/or the new `-XBinaryLiterals` This new extensions requires to upgrade the `ExtsBitmap` type from `Word` to `Word64` as this adds a 33th flag which is not guaranteed to fit into a `Word`. Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org> Differential Revision: https://phabricator.haskell.org/D22 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9224#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9224: Add support for binary integer literals -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: (Parser) | Keywords: literals Resolution: | Architecture: Unknown/Multiple Operating System: Unknown/Multiple | Difficulty: Easy (less than 1 Type of failure: None/Unknown | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Comment (by Herbert Valerio Riedel <hvr@…>): In [changeset:"dab0fa06fa33eeb45cef16c06c41d6c45b102451/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="dab0fa06fa33eeb45cef16c06c41d6c45b102451" Update Cabal to BinaryLiterals-aware 1.20 version In 1c0b5fdc9f2b6ea8166cc565383d4cd20432343c (re #9224) `BinaryLiterals` was temporarily added to T4437's `expectedGhcOnlyExtensions` list. This can now reverted as Cabal has been made aware of `BinaryLiterals` (see haskell/cabal#1970 and haskell/cabal#1972). updates Cabal submodule Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org> }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9224#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9224: Add support for binary integer literals -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: feature request | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: (Parser) | Keywords: literals Resolution: fixed | Architecture: Unknown/Multiple Operating System: Unknown/Multiple | Difficulty: Easy (less than 1 Type of failure: None/Unknown | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Changes (by hvr): * status: new => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9224#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9224: Add support for binary integer literals -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: feature request | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: (Parser) | Resolution: fixed | Keywords: literals Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Lemming): That's pretty useful for bit manipulation! -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9224#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC