Skip to content

Commit 9e6af83

Browse files
committed
Main
1 parent 7cadf4d commit 9e6af83

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
@@ -8657,13 +8657,11 @@ \subsection{Constants}
86578657
respectively a constant type expression
86588658
if{}f $T$ is a potentially constant type expression
86598659
respectively a constant type expression.
8660-
\item
8661-
A type variable is a potentially constant type expression.
86628660
\item
86638661
%% TODO(eernst): This does not allow for type variables introduced by
86648662
%% the type itself. `Function<X>(X)` could be a constant type expression,
86658663
%% but that is not covered by the current rules: `X` is a type variable,
8666-
%% and they are never allowed.
8664+
%% and they are never constant type expressions.
86678665
A function type
86688666
\code{$R$ Function<\metavar{typeParameters}>(\metavar{parameterTypes})}
86698667
(where $R$ and \code{<\metavar{typeParameters}>} may be omitted)
@@ -8673,9 +8671,11 @@ \subsection{Constants}
86738671
(if present) contain only potentially constant type expressions
86748672
respectively constant type expressions.
86758673
\item
8676-
The type \VOID is a potentially constant and a constant type expression.
8674+
The type \VOID{} is a potentially constant and a constant type expression.
8675+
\item
8676+
The type \DYNAMIC{} is a potentially constant and a constant type expression.
86778677
\item
8678-
The type \DYNAMIC is a potentially constant and a constant type expression.
8678+
A type variable is a potentially constant type expression.
86798679
\end{itemize}
86808680

86818681
% Being potentially constant is entirely structural, not type based,
@@ -20690,6 +20690,76 @@ \subsection{Parts}
2069020690
\subsection{Scripts}
2069120691
\LMLabel{scripts}
2069220692

20693+
\LMHash{}%
20694+
Let $L$ be a library that exports a declaration $D$ named \code{main}.
20695+
It is a \Error{compile-time error} unless $D$ is
20696+
a non-getter function declaration.
20697+
It is a \Error{compile-time error} if $D$ declares
20698+
more than two required positional parameters,
20699+
or if there are any required named parameters.
20700+
It is a \Error{compile-time error} if $D$ declares
20701+
at least one positional parameter,
20702+
and the first positional parameter has a type which is
20703+
not a supertype of \code{List<String>}.
20704+
20705+
\LMHash{}%
20706+
Implementations are free to impose any additional restrictions on
20707+
the signature of \code{main}.
20708+
20709+
\LMHash{}%
20710+
A \Index{script} is a library that exports a declaration named \code{main}.
20711+
A script $L$ is executed as follows:
20712+
20713+
\LMHash{}%
20714+
First, $L$ is compiled as a library as specified above.
20715+
Then, the top-level function defined by \code{main}
20716+
in the exported namespace of $L$ is invoked as follows:
20717+
20718+
\LMHash{}%
20719+
If \code{main} can be called with two positional arguments,
20720+
it is invoked with the following two actual arguments:
20721+
20722+
\begin{itemize}
20723+
\item
20724+
An object whose run-time type implements \code{List<String>}.
20725+
\item
20726+
An object specified when the current isolate $i$ was created,
20727+
(\commentary{%
20728+
for example through the invocation of \code{Isolate.spawnUri}
20729+
that spawned $i$%
20730+
}),
20731+
or the null object if no such object was supplied.
20732+
A dynamic error occurs if
20733+
the run-time type of this object is not a subtype of
20734+
the declared type of the corresponding parameter of \code{main}.
20735+
\end{itemize}
20736+
20737+
\LMHash{}%
20738+
If \code{main} cannot be called with two positional arguments,
20739+
but it can be called with one positional argument,
20740+
it is invoked with an object whose run-time type implements \code{List<String>}
20741+
as the only argument.
20742+
20743+
\LMHash{}%
20744+
If \code{main} cannot be called with one or two positional arguments,
20745+
it is invoked with no arguments.
20746+
20747+
\LMHash{}%
20748+
In each of the above three cases,
20749+
an implementation is free to provide additional arguments
20750+
allowed by the signature of \code{main}
20751+
(\commentary{%
20752+
the above rules ensure that the corresponding parameters are optional%
20753+
}).
20754+
But the implementation must ensure that a dynamic error occurs
20755+
if an actual argument does not have a run-time type which is
20756+
a subtype of the declared type of the parameter.
20757+
20758+
\LMHash{}%
20759+
A Dart program will typically be executed by executing a script.
20760+
The procedure whereby this script is chosen is implementation specific.
20761+
20762+
----------------------------------------------------------------------
2069320763
\LMHash{}%
2069420764
A \Index{script} is a library whose exported namespace (\ref{exports}) includes
2069520765
a top-level function declaration named \code{main}
@@ -24302,72 +24372,20 @@ \subsubsection{Null promotion}
2430224372
These are extended as per
2430324373
[separate proposal](https://github.com/dart-lang/language/blob/master/resources/type-system/flow-analysis.md).
2430424374

24305-
\subsubsection{The main function}
24375+
\subsubsection{Runtime type equality operator}
2430624376

2430724377
!!!TODO!!!
2430824378

24309-
The section 'Scripts' in the language specification is replaced by the
24310-
following:
24311-
24312-
Let $L$ be a library that exports a declaration $D$ named \code{main}.
24313-
It is a \Error{compile-time error} unless $D$ is a non-getter function
24314-
declaration. It is a \Error{compile-time error} if $D$ declares more
24315-
than two required positional parameters, or if there are any required
24316-
named parameters. It is a \Error{compile-time error} if $D$ declares
24317-
at least one positional parameter, and the first positional parameter
24318-
has a type which is not a supertype of \code{List<String>}.
24319-
24320-
Implementations are free to impose any additional restrictions on the
24321-
signature of \code{main}.
24322-
24323-
A _script_ is a library that exports a declaration named \code{main}.
24324-
A script $L$ is executed as follows:
24325-
24326-
First, $L$ is compiled as a library as specified above.
24327-
Then, the top-level function defined by \code{main}
24328-
in the exported namespace of $L$ is invoked as follows:
24329-
24330-
If \code{main} can be called with two positional arguments,
24331-
it is invoked with the following two actual arguments:
24332-
24333-
\begin{itemize}
24334-
\item An object whose run-time type implements \code{List<String>}.
24335-
\item An object specified when the current isolate $i$ was created,
24336-
for example through the invocation of \code{Isolate.spawnUri} that spawned $i$,
24337-
or the null object if no such object was supplied.
24338-
A dynamic error occurs if the run-time type of this object is not a
24339-
subtype of the declared type of the corresponding parameter of \code{main}.
24340-
\end{itemize}
24341-
24342-
If \code{main} cannot be called with two positional arguments, but it can be
24343-
called with one positional argument, it is invoked with an object whose
24344-
run-time type implements \code{List<String>} as the only argument.
24345-
24346-
If \code{main} cannot be called with one or two positional arguments, it is
24347-
invoked with no arguments.
24348-
24349-
In each of the above three cases, an implementation is free to provide
24350-
additional arguments allowed by the signature of \code{main}
24351-
(\commentary{the above rules ensure that the corresponding parameters are optional}).
24352-
But the implementation must ensure that a dynamic error occurs if an
24353-
actual argument does not have a run-time type which is a subtype of
24354-
the declared type of the parameter.
24355-
24356-
A Dart program will typically be executed by executing a script. The
24357-
procedure whereby this script is chosen is implementation specific.
24358-
24359-
\subsection{Runtime semantics}
24360-
24361-
\subsubsection{Runtime type equality operator}
24362-
24363-
Two objects $T_1$ and $T_2$ which are instances of \code{Type} (that is, runtime type
24364-
objects) are considered equal if and only if the runtime type objects $T_1$ and
24365-
$T_2$ corresponds to the types $S_1$ and $S_2$ respectively, and the normal forms
24366-
\NormalizedTypeOf{$S_1$} and \NormalizedTypeOf{$S_2$} are syntactically equal up to equivalence of
24367-
bound variables. Note that we do not equate primitive top types. \code{List<\VOID>}
24368-
and \code{List<\DYNAMIC>} are still considered distinct runtime type objects. Note
24369-
that we also do not equate function
24370-
types which differ in the placement of \REQUIRED{} on parameter types.
24379+
Two objects $T_1$ and $T_2$ which are instances of \code{Type} (that
24380+
is, runtime type objects) are considered equal if and only if the
24381+
runtime type objects $T_1$ and $T_2$ corresponds to the types $S_1$
24382+
and $S_2$ respectively, and the normal forms \NormalizedTypeOf{$S_1$}
24383+
and \NormalizedTypeOf{$S_2$} are syntactically equal up to equivalence
24384+
of bound variables. Note that we do not equate primitive top types.
24385+
\code{List<\VOID>} and \code{List<\DYNAMIC>} are still considered
24386+
distinct runtime type objects. Note that we also do not equate
24387+
function types which differ in the placement of \REQUIRED{} on
24388+
parameter types.
2437124389

2437224390
\subsubsection{Constant evaluation and canonicalization}
2437324391

0 commit comments

Comments
 (0)