Skip to content

Commit dd83e69

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Add 64-bit integer semantics to the specification.
Change-Id: I4dd2dfece2a78a4f96074886771036ee2942470f Reviewed-on: https://dart-review.googlesource.com/38020 Commit-Queue: Lasse R.H. Nielsen <[email protected]> Reviewed-by: Leaf Petersen <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent a10eda4 commit dd83e69

File tree

1 file changed

+68
-28
lines changed

1 file changed

+68
-28
lines changed

docs/language/dartLangSpec.tex

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
% - Make `async` *not* a reserved word inside async functions.
5050
% - Added 'Class Member Conflicts', simplifying and adjusting rules about
5151
% member declaration conflicts beyond "`n` declared twice in one scope".
52+
% - Specify that integer literals are limited to signed 64-bit values,
53+
% and that the `int` class is intended as signed 64-bit integer, but
54+
% that platforms may differ.
5255
%
5356
% 1.15
5457
% - Change how language specification describes control flow.
@@ -3279,7 +3282,7 @@ \subsection{Numbers}
32793282
\LMLabel{numbers}
32803283

32813284
\LMHash{}
3282-
A {\em numeric literal} is either a decimal or hexadecimal integer of arbitrary size, or a decimal double.
3285+
A {\em numeric literal} is either a decimal or hexadecimal numeral representing an integer value, or a decimal double representation.
32833286

32843287
\begin{grammar}
32853288
{\bf numericLiteral:}NUMBER;
@@ -3290,55 +3293,79 @@ \subsection{Numbers}
32903293
{`\escapegrammar .}' DIGIT+ EXPONENT?
32913294
.
32923295

3293-
{\bf EXPONENT:}(`e' $|$ `E') ('+' $|$ `-`)? DIGIT+
3296+
{\bf EXPONENT:}(`e' $|$ `E') (`+' $|$ `-'')? DIGIT+
32943297
.
32953298

32963299
{\bf HEX\_NUMBER:}`0x' HEX\_DIGIT+;
32973300
`0X' HEX\_DIGIT+
32983301
.
32993302

3300-
{\bf HEX\_DIGIT:}`a'{\escapegrammar ..}'f';
3301-
`A'{\escapegrammar ..}'F';
3303+
{\bf HEX\_DIGIT:}`a'{\escapegrammar ..}`f';
3304+
`A'{\escapegrammar ..}`F';
33023305
DIGIT
33033306
.
33043307
\end{grammar}
33053308

33063309
\LMHash{}
3307-
If a numeric literal begins with the prefix `0x' or `0X',
3308-
it denotes the integer represented by the hexadecimal numeral
3310+
A numeric literal starting with `0x' or `0X'
3311+
is a {\em hexadecimal integer literal}.
3312+
It has the numeric integer value of the hexadecimal numeral
33093313
following `0x' (respectively `0X').
3310-
Otherwise, if the numeric literal contains only decimal digits,
3311-
it denotes an integer represented as a decimal numeral.
3312-
In either case the literal evaluates to an instance of the class \code{int}
3313-
with the integer value represented by that numeral.
3314-
Otherwise, the numeric literal contains either a decimal point or an exponent part
3315-
and it evaluates to a an instance of the `double` class
3316-
representing a 64 bit double precision floating point number
3317-
as specified by the IEEE 754 standard.
33183314

33193315
\LMHash{}
3320-
In principle, the range of integers supported by a Dart implementations is unlimited.
3321-
In practice, it is limited by available memory.
3322-
Implementations may also be limited by other considerations.
3316+
A numeric literal that contains only decimal digits is a {\em decimal integer literal}.
3317+
It has the numeric integer value of the decimal numeral.
3318+
3319+
\LMHash{}
3320+
An {\em integer literal} is either a hexadecimal integer literal or a decimal integer literal.
3321+
The static type of an integer literal is \code{int}.
3322+
3323+
\LMHash{}
3324+
A numeric literal that is not an integer literal is a {\em double literal}.
3325+
\commentary{A double literal always contains either a decimal point or an exponent part.}
3326+
The static type of a double literal is \code{double}.
3327+
3328+
\LMHash{}
3329+
A hexadecimal integer literal with numeric value $i$ is a compile-time
3330+
error if $i \ge{} 2^{64}$, unless it is prefixed by a unary minus operator,
3331+
in which case it is a compile-time error if $i \gt{} 2^{63}$.
3332+
If the \code{int} class is implemented as signed 64-bit two's complement integers,
3333+
$i \ge{} 2^63$, and the literal is not prefixed by a unary minus operator, then
3334+
the literal evaluates to an instance of the \code{int} class representing the integer value $i - 2^64$.
3335+
Otherwise the literal evaluates to an instance of the \code{int} class representing
3336+
the integer value $i$,
3337+
and it is a compile-time error if the integer $i$ cannot be represented exactly
3338+
by an instance of \code{int}.
3339+
3340+
\LMHash{}
3341+
A decimal integer literal with numeric value $i$ is a compile-time error
3342+
if $i \ge{} 2^{63}$, unless $i$ is prefixed by a unary minus operator,
3343+
in which case it is only a compile-time error if $i \gt{} 2^{63}$.
3344+
Otherwise the literal evaluates to an instance of the \code{int} class representing
3345+
the integer value $i$.
3346+
It is a compile-time error if the value $i$ cannot be represented exactly
3347+
by an instance of \code{int}.
3348+
3349+
\LMHash{}
3350+
A double literal evaluates to a an instance of the \code{double} class
3351+
representing a 64 bit double precision floating point number
3352+
as specified by the IEEE 754 standard.
33233353

33243354
\commentary{
3325-
For example, implementations may choose to limit the range to facilitate efficient compilation to Javascript.
3326-
These limitations should be relaxed as soon as technologically feasible.
3355+
Integers in Dart are designed to be implemented as
3356+
64-bit two's complement integer representations.
3357+
In practice, implementations may be limited by other considerations.
3358+
For example, Dart compiled to JavaScript may use the JavaScript number type,
3359+
equivalent to Dart \code{double}, to represent integers, and if so,
3360+
integer literals with more than 53 bits of precision cannot be represented
3361+
exactly.
33273362
}
33283363

33293364
\LMHash{}
33303365
It is a compile-time error for a class to extend, mix in or implement \code{int}.
33313366
It is a compile-time error for a class to extend, mix in or implement \code{double}.
33323367
It is a compile-time error for any class other than \code{int} and \code{double} to extend, mix in or implement \code{num}.
33333368

3334-
\LMHash{}
3335-
An {\em integer literal} is either a hexadecimal integer literal or a decimal integer literal.
3336-
The static type of an integer literal is \code{int}.
3337-
3338-
\LMHash{}
3339-
A {\em literal double} is a numeric literal that is not an integer literal.
3340-
The static type of a literal double is \code{double}.
3341-
33423369

33433370
\subsection{Booleans}
33443371
\LMLabel{booleans}
@@ -6544,7 +6571,20 @@ \subsection{Unary Expressions}
65446571
%The expression $-e$ is equivalent to the method invocation \code{$e$.-()}. The expression \code{-\SUPER{}} is equivalent to the method invocation \code{\SUPER{}.-()}.
65456572

65466573
\LMHash{}
6547-
An expression of the form \code{$op$ $e$} is equivalent to the method invocation \code{$e.op()$}.
6574+
If $e$ is an expression is of the form \code{-$l$}
6575+
where $l$ is an integer literal (\ref{numbers}) with numerical integer value $i$,
6576+
then it is a compile-time error if $i \gt{} 2^{63}$.
6577+
Otherwise, when $0 \le{} i \le{} 2^{63}$, the static type of $e$ is \code{int}
6578+
and $e$ evaluates to an instance of the class \code{int}
6579+
representing the integer value $-i$,
6580+
and it is a compile-time error if the integer $-i$ cannot be represented exactly
6581+
by an instance of \code{int}.
6582+
\rationale{This treats \code{-$l$} where $l$ is an integer literal as an atomic signed numeral.
6583+
It does not {\em evaluate} $l$ as an individual expression because \code{-9223372036854775808}
6584+
should represent a valid \code{int} even if \code{9223372036854775808} does not.}
6585+
6586+
\LMHash{}
6587+
Any other expression of the form \code{$op$ $e$} is equivalent to the method invocation \code{$e.op()$}.
65486588
An expression of the form \code{$op$ \SUPER{}} is equivalent to the method invocation (\ref{superInvocation}) \code{\SUPER{}.$op()$}.
65496589

65506590

0 commit comments

Comments
 (0)