next up previous
Next: Static Data Up: User-level Constructs Previous: Data Modification

Expressions

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.



+,-

Sum/difference expression.
Syntax:

 ( val +  val)

( val - val)

Elements:
val, val ---
Expressions for values to add.

Description:

Evaluates to the sum or difference of the values of the two sub-expressions taken as mod- integers.



&

Bitwise logical AND expression.
Syntax:

 ( val &  val)

Elements:
val, val ---
Expressions for values to AND.

Description:

Evaluates to the bitwise logical AND of the word values of the two sub-expressions.



<<, >>

Logical left/right shift expression.
Syntax:

 ( val <<  amt)

( val >> amt)

Elements:
val ---
Expression for the value to be shifted.
amt ---
Expression for the amount to shift by.

Description:

This evaluates to the value of val logically shifted left or right as a 32-bit word, by amt bit-positions.



*

Pointer dereference expression.
Syntax:

 (*  address)

Elements:
address ---
Expression that evaluates to a memory address.

Description:

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.



*/

Fractional product expression.
Syntax:

 ( integer */  fraction)

Elements:
integer ---
An expression whose value is taken as a signed integer.
fraction ---
An expression whose value is taken as fraction between -1 and 1.

Description:

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.



'137
(underscore)

Array dereference expression.
Syntax:

 ( array '137  index)

Elements:
array ---
Expression for the address of element 0 of an array in memory.
index ---
Expression for the index of the array element to access.

Description:

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.



next up previous
Next: Static Data Up: User-level Constructs Previous: Data Modification



Michael Frank
Mon Nov 3 16:33:38 EST 1997