Predefined routines

This chapter describes all predefined ("built-in") procedures and functions in MPW Oberon. MPW Oberon supports all standard procedures and functions defined the language report. It incorporates a few additional procedures for Macintosh specific problems and for floating-point arithmetic.

The Macintosh has more than 600 ROM routines available, which are described in Inside Macintosh. Those routines ease implementation of the Macintosh user interfaces and provide program services. Access to these routines is provided by the MPW Oberon interface files contained in the OInterfaces folder.

Standard procedures and functions of the Oberon language are predeclared. Predeclared entities act as if they were declared in a block surrounding the program, so no conflict arises from a declaration that redefines the same identifier.

Note: Predefined procedures and functions cannot be used as actual parameters for procedures and functions.

  1. Arithmetic procedures and functions
  2. Dynamic allocation procedures
  3. Logical bit functions and procedures
  4. Miscellaneous procedures and functions
  5. Program termination
  6. Set procedures
  7. String procedures and functions
  8. Type transfer functions
  9. The SYSTEM module

Arithmetic procedures and functions

The MPW Oberon arithmetic functions that take parameters of real types reside in the Macintosh ROM and/or the MC68881. The compiler generates the code necessary to call then from Oberon source text. Any result returned by an arithmetic function is an approximation with the exception of the ABS function whose result is exact. Functions that do not have parameters of real types are implemented by code generated by the compiler.

When the -mc68881 option is specified on the command line, the compiler generates direct call to the MC68881 for several functions describes below.

Note: The numeric type COMPUTATIONAL defined in Inside Macintosh is not supported by MPW Oberon.

Note: If an operation fails (e.g. SQRT(-1)) no run-time exception is generated. The FPU simply returns a not-a-number (NAN) indicating that error. See the processor handbook of the MC68881 and the documentation about SANE for further details and methods to produce exceptions.

The ABS function

ABS(x)
The ABS function returns the absolute value of a numeric value. Its parameter x is a numeric value. ABS(x) returns the absolute value of x, with the same type.

The ACOS function

ACOS(x)
The ACOS function returns the principal value, in radians, of the arccosine of a numeric value. Its parameter x is a numeric value in range -1..1. ACOS(x) returns the arccosine of x, with the type LONGREAL.

Note: The ACOS function is non-standard Oberon and only available when the -mc68881 option is specified on the command line.

The ASH function

ASH(x, n)
The ASH function returns the product of x and 2n. The result is computed by shifting x by n positions arithmetically to the left (n>0) or right (n<0). The parameters x and n are expressions with a value of type SHORTINT, INTEGER, or LONGINT. The types of the arguments may be different. The type of the result is the type of x.

Note: You should use ASH function for dividing by a powers of 2, since MPW Oberon does not performs this optimization. The operator DIV works correctly even if you compute "-1 DIV 2".

The ASIN function

ASIN(x)
The ASIN function returns the principal value, in radians, of the arcsine of a numeric value. Its parameter x is a numeric value in range -1..1. ASIN(x) returns the arcsine of x, with the type LONGREAL.

Note: The ASIN function is non-standard Oberon and only available when the -mc68881 option is specified on the command line.

The ATAN function

ATAN(x)
The ATAN function returns a LONGREAL value that is the principal value, in radians, of the arctangent of a numeric value. Its parameter x is a numeric value. All numeric values of x are valid including ±∞.

Note: The ATAN function is non-standard Oberon.

The ATANH function

ATANH(x)
The ATANH function returns the hyperbolic arctangent of a numeric value. Its parameter x is a numeric value. ATANH(x) returns the hyperbolic arctangent of x, with the type LONGREAL.

Note: The ATANH function is non-standard Oberon and only available when the -mc68881 option is specified on the command line.

The COS function

COS(x)
The COS function returns a LONGREAL value that is the cosine of a numeric value. Its parameter x is a numeric value. This value is assumed to represent an angle in radians. If x is infinite, a diagnostic NAN is produced and the invalid operation signal is set.

Note: The COS function is non-standard Oberon.

The COSH function

COSH(x)
The COSH function returns the hyperbolic cosine of a numeric value. Its parameter x is a numeric value. COSH(x) returns the hyperbolic cosine of x, with the type LONGREAL.

Note: The COSH function is non-standard Oberon and only available when the -mc68881 option is specified on the command line.

The DEC procedure

DEC(x[,n])
The DEC procedure decrements a variable. Its parameter x is a reference to a variable of type SHORTINT, INTEGER, or LONGINT and n is an expression with a value of type SHORTINT, INTEGER, LONGINT. The second parameter is optional and defaults to 1. The DEC procedure decrements the specified variable by its second argument. You may write "x:=x-n" instead of "DEC(x,n)".

The EXP function

EXP(x)
The EXP function returns a LONGREAL value that is the natural exponential of a numeric value. Its parameter x is a numeric value. If x is infinite, a diagnostic NAN is produced and the invalid operation signal is set.

Note: The EXP function is non-standard Oberon.

The EXPM1 function

EXPM1(x)
The EXPM1 function returns a LONGREAL value that is the natural exponential of x-1. Its parameter x is a numeric value. If x is infinite, a diagnostic NAN is produced and the invalid operation signal is set.

Note: The EXPM1 function is non-standard Oberon.

The INC procedure

INC(x[,n])
The INC procedure decrements a variable. Its parameter x is a reference to a variable of type SHORTINT, INTEGER, or LONGINT and n is an expression with a value of type SHORTINT, INTEGER, LONGINT. The second parameter is optional and defaults to 1. The INC procedure increments the specified variable by its second argument. You may write "x:=x+n" instead of "INC(x,n)".

The LOG2 function

LOG2(x)
The LOG2 function returns the logarithm to the base 2 of a numeric value. Its parameter x is a numeric value. LOG2(x) returns the logarithm to the base 2 of x, with the type LONGREAL.

Note: The LOG2 function is non-standard Oberon.

The LN function

LN(x)
The LN function returns a LONGREAL value that is the natural logarithm of a numeric value. Its parameter x is a numeric value. If x is nonnegative, LN(x) returns the natural logarithm of x. If x is negative, a diagnostic NAN is produced and the invalid operation signal is set.

Note: The LN function is non-standard Oberon.

The LNP1 function

LNP1(x)
The LNP1 function returns the natural logarithm of x+1. Its parameter is a numeric value. LNP1(x) returns the natural logarithm of x+1, with the type LONGREAL.

Note: The LNP1 function is non-standard Oberon.

The ODD function

ODD(x)
The ODD function tests whether a whole number value is odd, returning a BOOLEAN value. Its parameter x is an expression with a value of type SHORTINT, INTEGER, or LONGINT. ODD(x) returns TRUE if x is odd and FALSE otherwise.

The SIN function

SIN(x)
The SIN function returns a LONGREAL value that is the sine of a numeric value. Its parameter x is a numeric value. This value is assumed to represent an angle in radians. If x is infinite, a diagnostic NAN is produced and the invalid operation signal is set.

Note: The SIN function is non-standard Oberon.

The SINH function

SINH(x)
The SINH function returns the hyperbolic sine of a numeric value. Its parameter x is a numeric value. SINH(x) returns the hyperbolic sine of x, with the type LONGREAL.

Note: The SINH function is non-standard Oberon and only available when the -mc68881 option is specified on the command line.

The SQRT function

SQRT(x)
The SQRT function returns a LONGREAL value that is the square root of a numeric value. Its parameter x is a numeric value. If x is nonnegative, SQRT(x) returns the square root of x. If x is negative, a diagnostic NAN is produced and the invalid operation signal is set.

Note: The SQRT function is non-standard Oberon.

The TAN function

TAN(x)
The TAN function returns a LONGREAL value that is the tangent of a numeric value. Its parameter x is a numeric value and is assumed to represent an angle in radians. If x is infinite, a diagnostic NAN is produced and the invalid operation signal is set.

Note: The TAN function is non-standard Oberon.

The TANH function

TANH(x)
The TANH function returns the hyperbolic tangent of a numeric value. Its parameter x is a numeric value. TANH(x) returns the hyperbolic tangent of x as a LONGREAL value.

Note: The TANH function is non-standard Oberon and only available when the -mc68881 option is specified on the command line.

Dynamic allocation procedures

The procedures describes in this section allow to allocate and release dynamic variables. Dynamic variables are used for data structures whose size depend on the problem. Dynamic structures are allocated on the heap. MPW Oberon used the application's heap maintained by the Memory Manager. See the chapter "Memory Manager" in Inside Macintosh: Memory for details of memory allocation on the Macintosh.

You may use the NEW procedure described in this section to allocate dynamic structures an the heap. In addition, the routine NewHandle provided by the Memory Manager can be used to allocate space on the heap. When allocating memory for structures whose elements are type checked always use the NEW procedure since the NewHandle procedure does not put in to proper type tag.

Note: MPW Oberon does currently not support garbage collection as found in the Oberon system. Garbage collection will be added in a subsequent release. You may use the standard procedure DISPOSE to dispose of memory blocks allocated with NEW.

Note: The behavior of the standard procedures NEW and DISPOSE are modified by the -nc option. When the -nc option is given on the command line, the standard procedure NEW will clear newly allocated block using the NewPtrClear or NewHandleClear function. The standard procedure DISPOSE will clear the pointer variable. This modification makes programming using dynamic variables a little bit safer but it may increase the run time of your program. Use the -nc option only for testing your application.

The MASTERPTR function

MASTERPTR(p)
The MASTERPTR function returns the master pointer of a variable. Its argument is a variable reference of a handle type. Its result is the master pointer pointed to by its argument. The value returned by MASTERPTR is compatible with any pointer or handle type. See the chapter "Memory Manager" in Inside Macintosh: Memory for further details about master pointers.

The MASTERPTR may be used for explicitly dereferencing variables and address computations. In most cases explicit dereferencing should be left to the compiler.

Note: The MASTERPTR function is not standard Oberon. It should be used with caution.

The NEW procedure

NEW(p[,l1,…,ln])
The procedure NEW allocates a dynamic variable and sets a pointer variable to point to it. The parameter p is a variable reference that refers to a variable of any pointer type. In MPW Oberon the variable reference may also refer to a variable of a handle type, i.e. a type declared using "HANDLE TO" instead of "POINTER TO".

The optional parameters are expression with value of types SHORTINT, INTEGER, or LONGINT. They are used in allocating dynamic variables for types declared as open arrays. For each dimension of the array whose length is not specified an expression must be given.

Note: The NEW procedure is not the same as NewPtr or NewHandle functions described in Inside Macintosh: Memory. When you call NewPtr or NewHandle you give a size value in bytes and the result does not have a type. The result of NEW always points to an identified variable of a specific type whose tag is properly inserted by NEW.

If the heap does not contain enough free space to allocate the new variable, p is set to NIL and a subsequent call to the MemError function will return a nonzero result. See the chapter "Memory Manager" in Inside Macintosh: Memory for further details about the MemError function and for a descriptions of methods and functions used for handling low memory situations.

Note: You may also the NEW procedure exported by the module SYSTEM to allocate memory for dynamic variables. SYSTEM.NEW allows to allocate memory by specifying their size in bytes. See "The SYSTEM module" for further information about the SYSTEM.NEW procedure.

Note: The behavior of the NEW procedure is modified by the -nc option. If the -nc option is given on the command line, NEW will clear allocated blocks using NewPtrClear or NewHandleClear.

The DISPOSE procedure

DISPOSE(p)
The DISPOSE procedure deallocates an identified variable of an object. The parameter p is a variable reference to a variable of any pointer type or of a handle type. It is a variable parameter.

Dispose releases the space allocated by the variable. It is an error if p is undefined or NIL. After DISPOSE executes, the value of p is undefined. All other references to the identified variable are also undefined. Note that p is not modified by DISPOSE.

Note: DISPOSE is a non-standard procedure not supported by the Oberon system or other compilers. It is provided since MPW Oberon does currently not support garbage collection.

Note: The behavior of the DISPOSE procedure is modified by the -nc option. If this option is specified on the command line, DISPOSE will clear the variable referred to by p.

The SETMASTERPTR procedure

SETMASTERPTR(v, p)
The SETMASTERPTR procedure set the master pointer of a variable of a handle type. Its parameter v is a variable reference of a handle type and p is a an expression with a value of a pointer type.

Note: The SETMASTERPTR procedure is not standard Oberon.

Warning: You should use the SETMASTERPTR procedure very carefully. Incorrect use of this procedure may corrupt the application heap in very subtle ways. This applies especially if the Memory Manager is working in 24-bit mode.

Logical bit functions and procedures

This section describes a set of procedures and functions for bit manipulations. The routines correspond to a set of essentially identical instructions of the M68000.

Many of the routines correspond to Inside Macintosh routines. However MPW Oberon generates more efficient code than calls the these routines, so you should use the function described below.

Any argument of the routines may be specified as SHORTINT, INTEGER, or LONGINT. If the types of two arguments differ, the smaller argument is 0-extended to match the larger argument in size.

Note: Bit numbering for these routines follows the convention of the M68000 microprocessor, not the convention used in Inside Macintosh. Bit 0 is the low-order bit and bit 31 is the high-order bit.

Note: All functions described in this section are not standard Oberon.

The BAND function

BAND(x,y)
BAND returns the logical AND of two integer values. Its parameters x and y are expressions of type SHORTINT, INTEGER, or LONGINT. Its result is the logical AND of its arguments as a value of the larger type of its arguments' types.

The BCLR function

BCLR(x,bit)
BCLR clears the specified bit in x. Its parameter x is a reference to a value and bit is an expression, both of type SHORTINT, INTEGER, or LONGINT. The value of bit is taken modulo 32.

The BNOT function

BNOT(x)
BNOT returns the 1's-complement of an integer value. Its parameter x is an expression with a value of type SHORTINT, INTEGER, or LONGINT. Its result is the 1's-complement of x, with the same type.

The BOR function

BOR(x,y)
BOR returns the logical OR of two integer values. Its parameters x and y are expressions of type SHORTINT, INTEGER, or LONGINT. Its result is the logical OR of x and y as a value of the larger type of its parameters' types.

The BSET function

BSET(x,bit)
BSET sets the specified bit in x. Its parameter x is a reference to a value and bit is an expression, both of type SHORTINT, INTEGER, or LONGINT. The value of bit is taken modulo 32.

The BTST function

BTST(x,bit)
The parameter bit is an whole-value number that indicates the bit of x to be tested. BTST return TRUE, if the specified bit has the value 1 and returns FALSE otherwise. The value of bit is taken modulo 32.

The BXOR function

BXOR(x,y)
BXOR returns the logical exclusive-OR of two integer values. Its parameters x and y are expressions of type SHORTINT, INTEGER, or LONGINT. Its result is the logical exclusive-OR of x and y as a value of the larger type of its parameters' types.

Miscellaneous procedures and functions

This section describes some procedures and functions predefined by MPW Oberon which could not be categorized.

The LEN function

LEN(a[,dim])
The LEN function returns the number of elements if an array. Its parameter a is a reference to an array variable and dim is an expression of type SHORTINT, INTEGER, or LONGINT. The second parameter defaults to 0. LEN returns the length of the dimension dim of array a. The first dimension is 0. The result of LEN is undefined if dim is greater than number of dimensions of a.

The MAX function

MAX(type)
The MAX function returns the maximum value of a type. Its parameter type is an identifier denoting a standard type. MAX(type) returns the maximum value of the specified type as a value with the same type as specified. In the case of the standard type SET, the value returned is of type INTEGER and specifies the greatest element that may be added to a set.

The MIN function

MIN(type)
The MIN function returns the minimum value of a type. Its parameter type is an identifier denoting a standard type. MIN(type) returns the minimum value of the specified type as a value with the same type as specified. In the case of the standard type SET, the value returned is of type INTEGER and specifies the smallest element that may be added to a set.

The SIZE function

SIZE(type)
The SIZE function returns the number of bytes needed for the representation of the specified type. Its parameter type is a identifier denoting a type either a predefined one or a user-defined type. Its result is the number of bytes needed to allocate a variable of the given type as a value of type LONGINT.

Note: If the -ulm option is specified, the SIZE function is exported by module SYSTEM.

The SWAP function

SWAP(x,y)
The SWAP procedure swaps the contents of two variables. Its parameters x and y are references to variables of the same type. SWAP allows you two swap the contents of two variables without the use of an temporary variable. Since SWAP is implemented as a tight loop, it will be faster than swapping using a temporary variable.

Note: The SWAP procedure is not standard Oberon

Program termination

The procedures HALT and ASSERT let you terminate your program execution unconditionally or conditionally respectively.

The ASSERT procedure

ASSERT(condition)
ASSERT causes an immediate exit from the main program base on the condition specified. Its parameter condition is a expression with a BOOLEAN value. If the condition is FALSE, ASSERT will terminate the program. The Shell variable {Status} is not modified by the ASSERT procedure.

Note: MPW Oberon suppresses code generation for the ASSERT procedure if the -noass option is specified on the command line. You may use conditional compilation to achieve the same effect.

The HALT procedure

HALT(x)
HALT causes an immediate exit from the main program and sets the Shell variable {Status}. Its parameter x is an expression of type SHORTINT, INTEGER, or LONGINT. The value of this expression will be found in the Shell variable {Status} after the program terminated. If the program does not run as a tool under MPW, the parameter value is ignored.

Set procedures

The procedures INCL and EXCL used to add elements a set or remove them from a set. MPW Oberon supports sets with up to 32 elements.

The EXCL procedure

EXCL(s,n)
EXCL removes an element from a set. Its parameter s is a reference to a variable of type SET and n is an expression with a value of type SHORTINT, INTEGER, or LONGINT. The specified element is removed from s where the element number is taken modulo 32.

The INCL procedure

INCL(s,n)
INCL adds an element to a set. Its parameter s is a reference to a variable of type SET and n is an expression with a value of type SHORTINT, INTEGER, or LONGINT. The specified element is added to s where the element number is taken modulo 32.

String procedures and functions

The string procedures and functions accept all types defined as ARRAY OR CHAR. They may be passed both open array and arrays of fixed length. Strings in Oberon have the same format as in C, i.e. they are null-terminated. This means, that you can not define a string containing a null character.

The APPEND procedure

APPEND(suffix,dest)
The APPEND procedure concatenates two strings. Its parameter suffix is either a literal string or a reference to an array of character and dest is a reference to an array of character. Parameter suffix is appended to parameter dest and the result is placed in dest. If the result has more characters than will fit into the dest parameter it is clipped accordingly. The result is always terminated by a null character.

Note: The APPEND procedure is not standard Oberon.

The CAP function

CAP(ch)
The CAP function returns the uppercase equivalent of its parameter. Its parameter ch is an expression with a CHAR value. Its result is a CHAR value. If ch is a lower case character, CAP will return its uppercase equivalent. Otherwise CAP does not modify ch.

The COPY procedure

COPY(source, dest)
The COPY procedure copies a string into a variable. Its parameter source is either a literal string or a reference to an array of characters and dest is a reference to an array of characters. If source contains more characters than dest can hold, it is truncated by COPY. The final string is always terminated by a null character.

The LENGTH function

LENGTH(x)
The LENGTH function returns the number of characters in x. Its parameter x is either a literal string or a reference to an array of characters. Its result is the number of characters in the string as a LONGINT value. LENGTH stops counting at the first null character encountered.

Note: The LENGTH function is not standard Oberon.

Type transfer functions

Type transfer functions transfer a value from an expression of one type to an expression of another type.

The CHR function

CHR(x)
The CHR function returns the CHAR value corresponding to a whole-number value. Its parameter x is an expression with a SHORTINT, INTEGER, or LONGINT value. CHR(x) returns the CHAR value whose ordinal value (ASCII code) is x, if x in the range 0..255. If x is not within the range 0..255, CHR returns the CHAR value whose value is defined by the LSB of x.

Note: Arguments to CHR are not checked until range checking is turned on. Use the $R directive to enable range checking where appropriate.

The ENTIER function

ENTIER(x)
The ENTIER function converts a value of type REAL or LONGREAL to a LONGINT value. Its parameter x is an expression with a value of type REAL or LONGREAL. ENTIER(x) returns a LONGINT result that is largest whole number less than or equal to x.

The HiWrd function

HiWrd(x)
The HiWrd function returns the upper 16 bits of an integer value. Its parameter x is an expression with a value of type LONGINT. HiWrd(x) returns a value of type INTEGER.

Note: HiWrd is no standard Oberon procedure. In standard Oberon HiWrd may be replaced by SHORT(ASH(x, -16)).

The LONG function

LONG(x)
The LONG function returns its parameter unchanged as a value with the next larger numerical type. Its parameter is x is an expression with a SHORTINT, INTEGER, or REAL value. Its result is x as a value of type INTEGER, LONGINT, or LONGREAL respectively.

The LONG function also accepts a literal string constant with four characters as its parameter. Its result is a LONGINT value which is the concatenation of the ordinal number of the string's characters. E.g. LONG("TEXT") yields $54455854. Note that this variant of the LONG function is not standard Oberon.

The LoWrd function

LoWrd(x)
The LoWrd function returns lower 16 bits of an integer value. Its parameter is x is an expression with a LONGINT value. LoWrd(x) returns a value of type INTEGER.

Note: LoWrd is no standard Oberon procedure. In standard Oberon LoWrd may be replaced by SHORT(x) where x is of type LONGINT.

The ORD function

ORD(x)
The ORD function returns the ordinal value of a character. Its parameter x is an expression with a CHAR value. Its result the corresponding ASCII code. Note that x=CHR(ORD(x)).

The SHORT function

SHORT(x)
The SHORT function returns its argument unchanged as a value with the next smaller numerical representation. Its parameter x is an expression with a INTEGER, LONGINT, or LONGREAL value. Its result is x as a value of type SHORTINT, INTEGER, REAL respectively.

Note: The SHORT function does not check whether x fits into the smaller representation. Use this function with care.

The SYSTEM module

The module SYSTEM exports system-specific functions and procedures. The module SYSTEM should be used only in a few modules which directly interact with the underlying operating system. Such modules are not portable and this in indicated by the import of module SYSTEM.

The module SYSTEM exports a type BYTE. Variables of this types are assignment compatible with CHAR and SHORTINT. A formal parameter of type ARRAY OF BYTE accepts any other types wither standard or user-defined.

In addition the module SYSTEM exports a type PTR. A variable of type PTR is assignment compatible with any pointer type. A formal reference parameter of type PTR accepts any other pointer type.

Most of the procedures and functions exported by module SYSTEM are implemented by the compiler with a single or a few instructions. Nevertheless you must import the module SYSTEM to use these functions.

Note: If the -ulm option is specified, the standard procedure SIZE is exported by the module SYSTEM. In addition, the type BYTE is a standard type and not exported from SYSTEM.

Note: The module SYSTEM must also be imported if you declare inline or external procedures.

The ADR function

SYSTEM.ADR(x)
The ADR function return a variable's address. Its parameter x is a variable reference of any type. Its result is the address of x as value as type LONGINT. In MPW Oberon the result of ADR is assignment compatible with any pointer type.

MPW Oberon allows you to pass not only references to variables but also procedures. This is used for passing the address of a procedure to the operating system.

Note: The assignment compatibility with any pointer type and the acceptance of procedures as actual parameters a non-standard Oberon.

The BIT function

SYSTEM.BIT(a,n)
The BIT function check a bit at an address. Its parameter a is an expression with a value of type LONGINT or any pointer type and n is an expression with a value of type SHORTINT, INTEGER, or LONGINT. Its result is a BOOLEAN value which is TRUE, if bit n at address a is set, and FALSE otherwise. Bit numbering follows the convention of the M68000. The number n is taken modulo 8.

The GET procedure

SYSTEM.GET(a,x)
The GET procedure fetches a value from an address. Its parameter a is an expression with a value of type LONGINT or any pointer type and x is a variable reference of any type. GET fills the specified variable with bytes starting at address a. GET transfers subsequent bytes until x is filled.

The LSH function

SYSTEM.LSH(x, n)
The LSH function returns the product of x and 2n. The result is computed by shifting x by n positions logically to the left (n>0) or right (n<0). The parameters x and n are expressions with a value of type SHORTINT, INTEGER, or LONGINT. The types of the arguments may be different. The type of the result is the type of x.

The MOVE procedure

SYSTEM.MOVE(src,dst,cnt)
The MOVE procedure copies a block of memory. Its parameters dst and src are expressions with a value of type LONGINT or any pointer type and cnt is an expression with a value of type SHORTINT, INTEGER, or LONGINT. MOVE copies cnt bytes starting at address src at to address dst. Since MOVE works by invoking BlockMove, overlapping ranges are handled correctly.

The NEW procedure

SYSTEM.NEW(p,size)
The NEW procedure allocates a dynamic variable. Its parameter p is a variable reference of type LONGINT or any pointer or handle type and size is an expression with a value of type SHORTINT, INTEGER, or LONGINT. Size specifies the size in bytes of the block allocated on the heap. The address of the new block will be stored in p. If there is not enough free space found for the new block, p is set to NIL and the MemError function will return a nonzero value (see the chapter "Memory Manager" in Inside Macintosh: Memory for a description of the MemError function).

The NEW procedure works correctly in conjunction with handle types. If p is a handle type, NEW will allocate a block using the NewHandle function instead of the NewPtr function. This behavior of the NEW procedure is not supported by the Oberon system or other Oberon compilers.

The PUT procedure

SYSTEM.PUT(a,x)
The PUT procedure stores a value at an address. Its parameter a is an expression with a value of type LONGINT or any pointer type and x is an expression with a value of any type. PUT fills bytes starting at address a with the contents of the specified variable. PUT transfers subsequent bytes until x is exhausted.

The ROT function

SYSTEM.ROT(x, n)
The ROT function rotates a value by n bits. The result is computed by shifting x by n positions cyclically to the left (n>0) or right (n<0). The arguments of ROT must be either SHORTINT, INTEGER, or LONGINT. The types of the arguments may be different. The type of the result of the ROT function is the type of x.

The TAS function

SYSTEM.TAS(x)
The TAS function tests and sets a BOOLEAN value. Its parameter x is a variable reference of type BOOLEAN. Its result is the value of the BOOLEAN variable before setting it. The TAS function corresponds to the M68000 instruction with the same mnemonic.

TAS reads the value of the BOOLEAN variable and returns its value. If the value of the variable is FALSE, it is changed to TRUE. If the variable contains TRUE nothing is changed. TAS uses a non-interruptible Read-Modify-Write cycle to perform its task.

Note: The TAS function is available only when the -ulm option is specified on the command line. This function is non-standard Oberon.

The VAL function

SYSTEM.VAL(T, x)
The VAL function returns an expression as a value of another type. Its parameters T is an identifier denoting a type and x an expression with a value of any type. Its result is the value of the expression as a value of the specified type. You may use the VAL function to modify the type of a variable passed by reference.

Warning: The VAL function allows to circumvent the strict type checking of Oberon. Use this function very carefully and only where absolutely necessary. The compiler will emit a warning if it spots a "call" of VAL which is not needed.

Note: The VAL function produces no code. The bits of the expression are not modified in any way. There are only interpreted as a value of the specified type.

Note: MPW Oberon supports an alternative notation for the VAL function in order to improve the readability and ease the task of porting Pascal code. The expression "SYSTEM.VAL(T, x)" may be written as "T(x)". This alternative notation is not standard Oberon.


Previous Section, Next Section, Contents
Jürgen Geßwein; 2. Juni 1995