Skip to content

Commit d35b17d

Browse files
committed
Main
1 parent 15520f3 commit d35b17d

File tree

1 file changed

+86
-68
lines changed

1 file changed

+86
-68
lines changed

specification/dartLangSpec.tex

Lines changed: 86 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8608,13 +8608,11 @@ \subsection{Constants}
86088608
respectively a constant type expression
86098609
if{}f $T$ is a potentially constant type expression
86108610
respectively a constant type expression.
8611-
\item
8612-
A type variable is a potentially constant type expression.
86138611
\item
86148612
%% TODO(eernst): This does not allow for type variables introduced by
86158613
%% the type itself. `Function<X>(X)` could be a constant type expression,
86168614
%% but that is not covered by the current rules: `X` is a type variable,
8617-
%% and they are never allowed.
8615+
%% and they are never constant type expressions.
86188616
A function type
86198617
\code{$R$ Function<\metavar{typeParameters}>(\metavar{parameterTypes})}
86208618
(where $R$ and \code{<\metavar{typeParameters}>} may be omitted)
@@ -8624,9 +8622,11 @@ \subsection{Constants}
86248622
(if present) contain only potentially constant type expressions
86258623
respectively constant type expressions.
86268624
\item
8627-
The type \VOID is a potentially constant and a constant type expression.
8625+
The type \VOID{} is a potentially constant and a constant type expression.
8626+
\item
8627+
The type \DYNAMIC{} is a potentially constant and a constant type expression.
86288628
\item
8629-
The type \DYNAMIC is a potentially constant and a constant type expression.
8629+
A type variable is a potentially constant type expression.
86308630
\end{itemize}
86318631

86328632
% Being potentially constant is entirely structural, not type based,
@@ -20440,6 +20440,76 @@ \subsection{Parts}
2044020440
\subsection{Scripts}
2044120441
\LMLabel{scripts}
2044220442

20443+
\LMHash{}%
20444+
Let $L$ be a library that exports a declaration $D$ named \code{main}.
20445+
It is a \Error{compile-time error} unless $D$ is
20446+
a non-getter function declaration.
20447+
It is a \Error{compile-time error} if $D$ declares
20448+
more than two required positional parameters,
20449+
or if there are any required named parameters.
20450+
It is a \Error{compile-time error} if $D$ declares
20451+
at least one positional parameter,
20452+
and the first positional parameter has a type which is
20453+
not a supertype of \code{List<String>}.
20454+
20455+
\LMHash{}%
20456+
Implementations are free to impose any additional restrictions on
20457+
the signature of \code{main}.
20458+
20459+
\LMHash{}%
20460+
A \Index{script} is a library that exports a declaration named \code{main}.
20461+
A script $L$ is executed as follows:
20462+
20463+
\LMHash{}%
20464+
First, $L$ is compiled as a library as specified above.
20465+
Then, the top-level function defined by \code{main}
20466+
in the exported namespace of $L$ is invoked as follows:
20467+
20468+
\LMHash{}%
20469+
If \code{main} can be called with two positional arguments,
20470+
it is invoked with the following two actual arguments:
20471+
20472+
\begin{itemize}
20473+
\item
20474+
An object whose run-time type implements \code{List<String>}.
20475+
\item
20476+
An object specified when the current isolate $i$ was created,
20477+
(\commentary{%
20478+
for example through the invocation of \code{Isolate.spawnUri}
20479+
that spawned $i$%
20480+
}),
20481+
or the null object if no such object was supplied.
20482+
A dynamic error occurs if
20483+
the run-time type of this object is not a subtype of
20484+
the declared type of the corresponding parameter of \code{main}.
20485+
\end{itemize}
20486+
20487+
\LMHash{}%
20488+
If \code{main} cannot be called with two positional arguments,
20489+
but it can be called with one positional argument,
20490+
it is invoked with an object whose run-time type implements \code{List<String>}
20491+
as the only argument.
20492+
20493+
\LMHash{}%
20494+
If \code{main} cannot be called with one or two positional arguments,
20495+
it is invoked with no arguments.
20496+
20497+
\LMHash{}%
20498+
In each of the above three cases,
20499+
an implementation is free to provide additional arguments
20500+
allowed by the signature of \code{main}
20501+
(\commentary{%
20502+
the above rules ensure that the corresponding parameters are optional%
20503+
}).
20504+
But the implementation must ensure that a dynamic error occurs
20505+
if an actual argument does not have a run-time type which is
20506+
a subtype of the declared type of the parameter.
20507+
20508+
\LMHash{}%
20509+
A Dart program will typically be executed by executing a script.
20510+
The procedure whereby this script is chosen is implementation specific.
20511+
20512+
----------------------------------------------------------------------
2044320513
\LMHash{}%
2044420514
A \Index{script} is a library whose exported namespace (\ref{exports}) includes
2044520515
a top-level function declaration named \code{main}
@@ -24035,72 +24105,20 @@ \subsubsection{Null promotion}
2403524105
These are extended as per
2403624106
[separate proposal](https://github.com/dart-lang/language/blob/master/resources/type-system/flow-analysis.md).
2403724107

24038-
\subsubsection{The main function}
24108+
\subsubsection{Runtime type equality operator}
2403924109

2404024110
!!!TODO!!!
2404124111

24042-
The section 'Scripts' in the language specification is replaced by the
24043-
following:
24044-
24045-
Let $L$ be a library that exports a declaration $D$ named \code{main}.
24046-
It is a \Error{compile-time error} unless $D$ is a non-getter function
24047-
declaration. It is a \Error{compile-time error} if $D$ declares more
24048-
than two required positional parameters, or if there are any required
24049-
named parameters. It is a \Error{compile-time error} if $D$ declares
24050-
at least one positional parameter, and the first positional parameter
24051-
has a type which is not a supertype of \code{List<String>}.
24052-
24053-
Implementations are free to impose any additional restrictions on the
24054-
signature of \code{main}.
24055-
24056-
A _script_ is a library that exports a declaration named \code{main}.
24057-
A script $L$ is executed as follows:
24058-
24059-
First, $L$ is compiled as a library as specified above.
24060-
Then, the top-level function defined by \code{main}
24061-
in the exported namespace of $L$ is invoked as follows:
24062-
24063-
If \code{main} can be called with two positional arguments,
24064-
it is invoked with the following two actual arguments:
24065-
24066-
\begin{itemize}
24067-
\item An object whose run-time type implements \code{List<String>}.
24068-
\item An object specified when the current isolate $i$ was created,
24069-
for example through the invocation of \code{Isolate.spawnUri} that spawned $i$,
24070-
or the null object if no such object was supplied.
24071-
A dynamic error occurs if the run-time type of this object is not a
24072-
subtype of the declared type of the corresponding parameter of \code{main}.
24073-
\end{itemize}
24074-
24075-
If \code{main} cannot be called with two positional arguments, but it can be
24076-
called with one positional argument, it is invoked with an object whose
24077-
run-time type implements \code{List<String>} as the only argument.
24078-
24079-
If \code{main} cannot be called with one or two positional arguments, it is
24080-
invoked with no arguments.
24081-
24082-
In each of the above three cases, an implementation is free to provide
24083-
additional arguments allowed by the signature of \code{main}
24084-
(\commentary{the above rules ensure that the corresponding parameters are optional}).
24085-
But the implementation must ensure that a dynamic error occurs if an
24086-
actual argument does not have a run-time type which is a subtype of
24087-
the declared type of the parameter.
24088-
24089-
A Dart program will typically be executed by executing a script. The
24090-
procedure whereby this script is chosen is implementation specific.
24091-
24092-
\subsection{Runtime semantics}
24093-
24094-
\subsubsection{Runtime type equality operator}
24095-
24096-
Two objects $T_1$ and $T_2$ which are instances of \code{Type} (that is, runtime type
24097-
objects) are considered equal if and only if the runtime type objects $T_1$ and
24098-
$T_2$ corresponds to the types $S_1$ and $S_2$ respectively, and the normal forms
24099-
\NormalizedTypeOf{$S_1$} and \NormalizedTypeOf{$S_2$} are syntactically equal up to equivalence of
24100-
bound variables. Note that we do not equate primitive top types. \code{List<\VOID>}
24101-
and \code{List<\DYNAMIC>} are still considered distinct runtime type objects. Note
24102-
that we also do not equate function
24103-
types which differ in the placement of \REQUIRED{} on parameter types.
24112+
Two objects $T_1$ and $T_2$ which are instances of \code{Type} (that
24113+
is, runtime type objects) are considered equal if and only if the
24114+
runtime type objects $T_1$ and $T_2$ corresponds to the types $S_1$
24115+
and $S_2$ respectively, and the normal forms \NormalizedTypeOf{$S_1$}
24116+
and \NormalizedTypeOf{$S_2$} are syntactically equal up to equivalence
24117+
of bound variables. Note that we do not equate primitive top types.
24118+
\code{List<\VOID>} and \code{List<\DYNAMIC>} are still considered
24119+
distinct runtime type objects. Note that we also do not equate
24120+
function types which differ in the placement of \REQUIRED{} on
24121+
parameter types.
2410424122

2410524123
\subsubsection{Constant evaluation and canonicalization}
2410624124

0 commit comments

Comments
 (0)