From 142d78417491d0b8ae2f30a1b5e600589d4572ac Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Mon, 10 Feb 2020 15:24:45 +0300 Subject: [PATCH] COntinue spec --- doc/spec/03.02.compilation_units.tex | 2 +- doc/spec/03.04.expressions.tex | 2 +- doc/spec/05.driver_options.tex | 12 +++++-- doc/spec/06.standard_library.tex | 54 ++++++++++++++++++++++++++++ doc/spec/Makefile | 6 ++-- doc/spec/spec.tex | 1 - 6 files changed, 69 insertions(+), 8 deletions(-) diff --git a/doc/spec/03.02.compilation_units.tex b/doc/spec/03.02.compilation_units.tex index d8648990a..0eec2f5cc 100644 --- a/doc/spec/03.02.compilation_units.tex +++ b/doc/spec/03.02.compilation_units.tex @@ -18,5 +18,5 @@ which can be imported by an end-user application. The concrete syntax for compilation unit is shown on Fig.~\ref{compilation_unit}. Besides optional imports a unit must contain a \nonterm{scopeExpression}, which may contain some definitions and computations. Note, a unit can not be empty. The computations described in -a unit are performed at unit initialization time (see~\ref{separate_compilation}). +a unit are performed at unit initialization time (see Chapter~\ref{sec:driver}). diff --git a/doc/spec/03.04.expressions.tex b/doc/spec/03.04.expressions.tex index 9c8476885..6b833efdb 100644 --- a/doc/spec/03.04.expressions.tex +++ b/doc/spec/03.04.expressions.tex @@ -115,7 +115,7 @@ designate integer constants 1 and 0 respectively, character constant is implicit of one-byte characters. Infix constants allow to reference a functional value associated with corresponding infix operator, and functional constant (\emph{lambda-expression}) designates an anonymous functional value in the form of closure. -\subsection{\lstinline|skip| and \lstinline|return| Expressions} +\subsection{\texttt{skip} and \texttt{return} Expressions} Expression \lstinline|skip| can be used to designate a no-value when no action is needed (for example, in the body of unit which contains only declarations). \lstinline|return| expression can be used to immediately copmlete the execution of current function call; optional return value can be specified. diff --git a/doc/spec/05.driver_options.tex b/doc/spec/05.driver_options.tex index 4396ff061..033fdb904 100644 --- a/doc/spec/05.driver_options.tex +++ b/doc/spec/05.driver_options.tex @@ -23,12 +23,20 @@ The driver operates in a few modes: all external units object files, generating executable. \end{itemize} +In the native modes, the driver also creates import files ("\texttt{.i}") which are required for external units import to +work properly. These files has to reside in the same directory as object files for corresponding units. + +Each natively compiled object file implicitly references all imported units; the top-level expression of each +unit is compiled into \emph{unit initialization procedure}, which calls unit initialization procedures of +all imported units in the same order these unites were imported. It is guaranteed that unit initialization +procedure for each unit will be called only once (regardless of the imports' shape for the whole application). + Additionally, the following options can be given to the driver: \begin{itemize} \item "\texttt{-I $path$}"~--- specifies a path to look for external units. Multiples instances of this option can be given in driver's invocation, and the paths are looked up in that order. -\item "\texttt{-dp}"~--- forced the driver to dump the AST of compiled unit. The dump is written in the file with the same +\item "\texttt{-dp}"~--- forces the driver to dump the AST of compiled unit. The dump is written in the file with the same basename as the source one, with the extension replaced with "\texttt{.ast}". \item "\texttt{-ds}"~--- forces the driver to sump stack machine code. The option is only in effect in stack interpreter on native mode. The sump is written in the file "\texttt{.sm}". @@ -38,4 +46,4 @@ Additionally, the following options can be given to the driver: Apart from the paths specified by the "\texttt{-I}" option the driver uses the environment variable "\texttt{LAMA\_STD}" to locate the runtime and standard libraries (see~\ref{sec:stdlib}). Thus, the units from standard libraries are accessible -without any "-I" option given. +without any "\texttt{-I}" option given. diff --git a/doc/spec/06.standard_library.tex b/doc/spec/06.standard_library.tex index 94309ef60..bb3e2d4cc 100644 --- a/doc/spec/06.standard_library.tex +++ b/doc/spec/06.standard_library.tex @@ -1 +1,55 @@ \chapter{Standard Library} +\label{sec:stdlib} + +The standard library is comprised of the runtime for the language and the set of pre-shipped units written in \lama itself. + +\section{Unit \texttt{Std}} + +The unit "\texttt{Std}" provides the interface for the runtime of the language. The implementation of +entities, defined in "\texttt{Std}", reside in the runtime itself. The import of "\texttt{Std}" +is added implicitly by the compiler and can not be specified by an end user. + +The following declarations are accessible: + +\paragraph{\lstinline|fun read ()|}~--- reads an integer value from the standard input, printing a prompt "\texttt{>}". + +\paragraph{\lstinline|fun write (int)|}~--- writes an integer value to the standard output. + +\paragraph{\lstinline|sysargs|}~--- a variable which holds an array of command-lines arguments of the application (including the +name of the executable itself). + +\paragraph{\lstinline|fun makeArray (size)|}~--- creates a fresh array of a given length. The elements of the array are left uninitialized. + +\paragraph{\lstinline|fun makeString (size)|}~--- creates a fresh string of a given length. The elements of the string are left uninitialized. + +\paragraph{\lstinline|fun stringcat (list)|}~--- takes a list of strings and returns the concatenates all its elements. + +\paragraph{\lstinline|fun matchSubString (subj, patt, pos)|}~--- takes two strings "\texttt{subj}" and "\text{patt}" and integer position "\texttt{pos}" and +checks if a substing of "\texttt{subj}" starting at position "\texttt{pos}" is equal to "\text{patt}"; returns integer value. + +\lstinline|fun sprintf (fmt, ...)| +\lstinline|fun substring (str, pos, len)| +\lstinline|infix ++ at + (str1, str2)| + +\lstinline|fun clone (value)| +\lstinline|fun hash (value)| +\lstinline|fun compare (value1, value2)| + +\lstinline|fun fst (value)| +\lstinline|fun snd (value)| +\lstinline|fun hd (value)| +\lstinline|fun tl (value)| + +\lstinline|fun readLine ()| +\lstinline|fun printf (fmt, ...)| +\lstinline|fun fopen (fname, mode)| +\lstinline|fun fclose (file)| +\lstinline|fun fread (fname)| +\lstinline|fun fwrite (fname, contents)| +\lstinline|fun fprintf (file, fmt, ...)| + +\lstinline|fun regexp (str)| +\lstinline|fun regexpMatch (pattern, subj, pos)| + +\lstinline|fun failure (fmt, ...)| + diff --git a/doc/spec/Makefile b/doc/spec/Makefile index daa39256e..58a09a4b4 100644 --- a/doc/spec/Makefile +++ b/doc/spec/Makefile @@ -1,7 +1,7 @@ all: pdflatex spec.tex - bibtem spec - pdflatex.tex + bibtex spec + pdflatex spec.tex clean: - rm -Rf *~ *.log *.aux + rm -Rf *~ *.log *.aux *.toc *.bbl *.blg *.out diff --git a/doc/spec/spec.tex b/doc/spec/spec.tex index 710bbd963..1bd2343b9 100644 --- a/doc/spec/spec.tex +++ b/doc/spec/spec.tex @@ -26,7 +26,6 @@ \usepackage{subcaption} \usepackage{placeins} \usepackage{xspace} -\usepackage{ostap} \usepackage{bm} \makeatletter