Unstable-Languages-beta : SIMPLE-THR-2-Expressions.cbs | PLAIN | PDF
\[\KEY{Language} \quad \STRING{SIMPLE-THR}\]
\(\SECT{2}\) Expressions
\[\begin{align*} \KEY{Syntax} \quad \VARDECL{Exp} : \SYNDECL{exp} \ ::= \ & \ \LEX{{(}} \ \SYNREF{exp} \ \LEX{{)}} \\ \ \mid \ & \ \SYNHYPER{../.}{SIMPLE-THR-1-Lexical}{value} \\ \ \mid \ & \ \SYNREF{lexp} \\ \ \mid \ & \ \SYNREF{lexp} \ \LEX{{=}} \ \SYNREF{exp} \\ \ \mid \ & \ \LEX{{+}{+}} \ \SYNREF{lexp} \\ \ \mid \ & \ \LEX{{-}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{(}} \ \SYNREF{exps}\QUERY \ \LEX{{)}} \\ \ \mid \ & \ \LEX{sizeOf} \ \LEX{{(}} \ \SYNREF{exp} \ \LEX{{)}} \\ \ \mid \ & \ \LEX{read} \ \LEX{{(}} \ \LEX{{)}} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{+}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{-}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{*}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{/}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{\PERCENT}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{<}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{<}{=}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{>}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{>}{=}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{=}{=}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{!}{=}} \ \SYNREF{exp} \\ \ \mid \ & \ \LEX{{!}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{\AMPERSAND}{\AMPERSAND}} \ \SYNREF{exp} \\ \ \mid \ & \ \SYNREF{exp} \ \LEX{{|}{|}} \ \SYNREF{exp} \\ \ \mid \ & \ \LEX{spawn} \ \SYNHYPER{../.}{SIMPLE-THR-3-Statements}{block} \end{align*}\] \[\begin{align*} \KEY{Rule} \quad & \LEFTPHRASE \ \LEX{{(}} \ \VARREF{Exp} \ \LEX{{)}} \ \RIGHTPHRASE : \SYNREF{exp} = \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE \end{align*}\] \[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{rval} \LEFTPHRASE \ \_ : \SYNREF{exp} \ \RIGHTPHRASE : \TO \NAMEHYPER{../../../../../Funcons-beta/Values}{Value-Types}{values} \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARHYPER{../.}{SIMPLE-THR-1-Lexical}{V} \ \RIGHTPHRASE = \SEMHYPER{../.}{SIMPLE-THR-1-Lexical}{val} \LEFTPHRASE \ \VAR{V} \ \RIGHTPHRASE \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{LExp} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{assigned} ( \SEMREF{lval} \LEFTPHRASE \ \VAR{LExp} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{LExp} \ \LEX{{=}} \ \VARREF{Exp} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{give} ( \\&\quad\quad \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE , \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Flowing}{sequential} ( \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{assign} ( \SEMREF{lval} \LEFTPHRASE \ \VAR{LExp} \ \RIGHTPHRASE , \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{given} ), \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{given} ) ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \LEX{{+}{+}} \ \VARREF{LExp} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{give} ( \\&\quad\quad \SEMREF{lval} \LEFTPHRASE \ \VAR{LExp} \ \RIGHTPHRASE , \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Flowing}{sequential} ( \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{assign} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{given}, \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{integer-add} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{assigned} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{given} ), 1 ) ), \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{assigned} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{given} ) ) ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \LEX{{-}} \ \VARREF{Exp} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{integer-negate} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp} \ \LEX{{(}} \ \VARREF{Exps}\QUERY \ \LEX{{)}} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Functions}{apply} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE , \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Tuples}{tuple} ( \SEMREF{rvals} \LEFTPHRASE \ \VAR{Exps}\QUERY \ \RIGHTPHRASE ) ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \LEX{sizeOf} \ \LEX{{(}} \ \VARREF{Exp} \ \LEX{{)}} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Sequences}{length} ( \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Vectors}{vector-elements} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE ) ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \LEX{read} \ \LEX{{(}} \ \LEX{{)}} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Interacting}{read} \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{+}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{integer-add} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{-}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{integer-subtract} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{*}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{integer-multiply} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{/}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Computations/Abnormal}{Failing}{checked} \ \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{integer-divide} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{\PERCENT}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Computations/Abnormal}{Failing}{checked} \ \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{integer-modulo} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{<}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{is-less} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{<}{=}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{is-less-or-equal} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{>}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{is-greater} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{>}{=}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{is-greater-or-equal} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{=}{=}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values}{Value-Types}{is-equal} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{!}{=}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Booleans}{not} ( \NAMEHYPER{../../../../../Funcons-beta/Values}{Value-Types}{is-equal} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \LEX{{!}} \ \VARREF{Exp} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Booleans}{not} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{\AMPERSAND}{\AMPERSAND}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Flowing}{if-else} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE , \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Booleans}{false} ) \\ \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \VARREF{Exp}\SUB{1} \ \LEX{{|}{|}} \ \VARREF{Exp}\SUB{2} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Flowing}{if-else} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{1} \ \RIGHTPHRASE , \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Booleans}{true}, \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp}\SUB{2} \ \RIGHTPHRASE ) \end{align*}\]SIMPLE uses natural numbers to identify threads; the use of \(\SHADE{\NAMEHYPER{../../../../../Unstable-Funcons-beta/Computations/Normal}{Indexing}{allocate-index} ( \_ )}\) below associates a natural number with the thread-id given by thread-activate. The use of \(\SHADE{\NAMEHYPER{../../../../../Unstable-Funcons-beta/Computations/Abnormal}{Postponing}{postpone-after-effect} ( \_ )}\) supports automatic release of locks when threads terminate.
\[\begin{align*} \KEY{Rule} \quad & \SEMREF{rval} \LEFTPHRASE \ \LEX{spawn} \ \VARHYPER{../.}{SIMPLE-THR-3-Statements}{Block} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Unstable-Funcons-beta/Computations/Normal}{Indexing}{allocate-index} \\&\quad\quad \NAMEHYPER{../../../../../Unstable-Funcons-beta/Computations/Threads}{Multithreading}{thread-activate} \ \NAMEHYPER{../../../../../Unstable-Funcons-beta/Computations/Threads}{Multithreading}{thread-joinable} \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Thunks}{thunk} \ \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Generic}{closure} \\&\quad\quad\quad\quad \NAMEHYPER{../../../../../Unstable-Funcons-beta/Computations/Abnormal}{Postponing}{postpone-after-effect} \\&\quad\quad\quad\quad\quad \SEMHYPER{../.}{SIMPLE-THR-3-Statements}{exec} \LEFTPHRASE \ \VAR{Block} \ \RIGHTPHRASE \end{align*}\] \[\begin{align*} \KEY{Syntax} \quad \VARDECL{Exps} : \SYNDECL{exps} \ ::= \ & \ \SYNREF{exp} \ \LEFTGROUP \LEX{{,}} \ \SYNREF{exps} \RIGHTGROUP\QUERY \end{align*}\] \[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{rvals} \LEFTPHRASE \ \_ : \SYNREF{exps}\QUERY \ \RIGHTPHRASE : ( \TO \NAMEHYPER{../../../../../Funcons-beta/Values}{Value-Types}{values} )\STAR \\ \KEY{Rule} \quad & \SEMREF{rvals} \LEFTPHRASE \ \ \RIGHTPHRASE = ( \ ) \\ \KEY{Rule} \quad & \SEMREF{rvals} \LEFTPHRASE \ \VARREF{Exp} \ \RIGHTPHRASE = \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE \\ \KEY{Rule} \quad & \SEMREF{rvals} \LEFTPHRASE \ \VARREF{Exp} \ \LEX{{,}} \ \VARREF{Exps} \ \RIGHTPHRASE = \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE , \SEMREF{rvals} \LEFTPHRASE \ \VAR{Exps} \ \RIGHTPHRASE \end{align*}\] \[\begin{align*} \KEY{Syntax} \quad \VARDECL{LExp} : \SYNDECL{lexp} \ ::= \ & \ \SYNHYPER{../.}{SIMPLE-THR-1-Lexical}{id} \mid \SYNREF{lexp} \ \LEX{{[}} \ \SYNREF{exps} \ \LEX{{]}} \end{align*}\] \[\begin{align*} \KEY{Rule} \quad & \LEFTPHRASE \ \VARREF{LExp} \ \LEX{{[}} \ \VARREF{Exp} \ \LEX{{,}} \ \VARREF{Exps} \ \LEX{{]}} \ \RIGHTPHRASE : \SYNREF{lexp} = \\& \LEFTPHRASE \ \VAR{LExp} \ \LEX{{[}} \ \VAR{Exp} \ \LEX{{]}} \ \LEX{{[}} \ \VAR{Exps} \ \LEX{{]}} \ \RIGHTPHRASE \end{align*}\] \[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{lval} \LEFTPHRASE \ \_ : \SYNREF{lexp} \ \RIGHTPHRASE : \TO \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{variables} \\ \KEY{Rule} \quad & \SEMREF{lval} \LEFTPHRASE \ \VARHYPER{../.}{SIMPLE-THR-1-Lexical}{Id} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{bound} ( \SEMHYPER{../.}{SIMPLE-THR-1-Lexical}{id} \LEFTPHRASE \ \VAR{Id} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{lval} \LEFTPHRASE \ \VARREF{LExp} \ \LEX{{[}} \ \VARREF{Exp} \ \LEX{{]}} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Abnormal}{Failing}{checked} \ \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Sequences}{index} ( \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{integer-add} ( 1, \SEMREF{rval} \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE ), \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Vectors}{vector-elements} ( \SEMREF{rval} \LEFTPHRASE \ \VAR{LExp} \ \RIGHTPHRASE ) ) \end{align*}\]