Document expressions

This commit is contained in:
2026-02-13 22:54:22 +01:00
parent d7c27f1c63
commit fe055aa1ae
3 changed files with 311 additions and 77 deletions

View File

@@ -124,35 +124,3 @@ begin
e := E.one
end.
\end{lstlisting}
\chapter{Type operations}
\chapter{Cast}
\begin{grammar}
<cast> = `cast' `(' <expression> `:\@' <type> `)'.
\end{grammar}
The type of an object can be reinterpreted with a cast expression: \\
\verb|cast(object: Type)|.
\chapter{Traits}
\begin{grammar}
<trait-identifier> = `#' <identifier>.
<trait> = <trait-identifier> `(' [<types>] `)'.
\end{grammar}
Traits allow to query some information about the types, like their size or
field offset or alignment. Calling a trait looks like a procedure call but
traits names start with a \verb|#| and their arguments are type expressions and
not value expressions.
Supported compiler traits:
\begin{itemize}
\item \verb|#size(T)| queries type size.
\item \verb|#align(T)| queries type alignment.
\item \verb|#offset(T, F)| queries the offset of the field \verb|F| in the record \verb|T|.
\end{itemize}