Variables and constants count as expression, as do the more complex parenthesized expressions described here. Expressions may be nested arbitrarily deeply. Parentheses for all the subexpressions must all be explicitly present. Currently, all expression operations are of the infix style, where the symbol for the operator appears as the second member of the list; however new kinds of expressions may exist later.
Currently available expression operations include +, -, &, <<, >>, *, */, '137, and others for internal use by the compiler.
There are also relational operators =, <, >, <=, >=, != which may currently only be used at top-level expressions in if conditions. They are not yet documented individually yet, but they have the expected behavior of signed integer comparison. Conceptually they return 1 if the relation holds, and 0 otherwise.
Inside expressions, only expression constructs may be used. Expression constructs may never be used in place of statements.
Expressions are generally evaluated twice each time they are used, once in the forward direction to generate the result, and once in the reverse direction to uncompute it.
There is currently no way within the language to define a new type of expression operator, but this may change later.
( val - val)
( val + val)
Evaluates to the sum or difference of the values of the two sub-expressions taken as mod- integers.
( val & val)
Evaluates to the bitwise logical AND of the word values of the two sub-expressions.
( val >> amt)
( val << amt)
This evaluates to the value of val logically shifted left or right as a 32-bit word, by amt bit-positions.
(* address)
This evaluates to a copy of the contents of the memory location at the given address. However, this expression may also be used as a place which may be modified by any of the data-modification statements above, in which case the actual contents of the location, not a copy, is modified.
It is an error for the contents of an address to be referred to by a subexpression of a statement that modifies that same address; if this is done, behavior thenceforth will be unpredictable.
( integer */ fraction)
This rather odd operator returns the signed 32-bit integer product of the two values, taking one as a signed 32-bit integer and the other as a signed 32-bit fixed-precision fraction between 0 and 1. Another way of saying this is that it is the product of two integers, divided by . Or, it is the upper word of the 64-bit product of the two integers, rather than the lower word.
This operation is useful for doing fixed-precision fractional arithmetic. It is used by the single existing significant test program sch.r.
Since the Pendulum architecture naturally does not support this rather unusual operation directly, the compiler transforms it into a call to the standard library routine SMF (Signed Multiplication by Fraction). SMF is itself written in R, but for efficiency it uses some optimized constructs not yet intended for general use.
( array '137 index)
This type of expression evaluates to a copy of the contents of the element numbered index in the sequential array of memory locations whose element number 0 is pointed to by array. However, this expression may also be used as a place in any of the data-modification statements, in which case it is the real array element that will be modified, not just a copy of it.
It is an error for an array element or other memory location to be examined by an subexpression of a statement that ends up modifying that location.