Built-in classes

Sather - Language Specification
Prev |  | Next

# Chapter 13. Built-in classes

This section provides a short description of classes that are a part of every Sather implementation and which may not be modified. The detailed semantics and precise interface are specified in the class library documentation.

- '$OB' is automatically a supertype of every type. Variables declared by this type may hold any object. It has no features.

- 'AREF{T}' is a reference array class. Any reference class which includes it obtains an array of elements of type T in addition to any attributes it has defined. In such classes, new has a single integer argument that specifies the size of the array portion. It defines routines and iters named: 'asize', 'aget', 'aset', 'aclear', 'acopy', 'aelt!', 'aset!', and 'aind!'. Array indices start at zero. 'AVAL{T}' is the immutable class analog of 'AREF'. Classes which include 'AVAL' must define asize as an integer constant which determines the size of the array portion. 'ARRAY{T}' includes from 'AREF' and defines general purpose array objects. They may be directly constructed by array creation expressions (See Array creation expressions).

- 'TUP' names a set of parameterized immutable types called tuples, one for each number of parameters. Each has as many attributes as parameters and they are named 't1', 't2', etc. Each is declared by the type of the corresponding parameter (e.g. 'TUP{INT,FLT}' has attributes 't1:INT' and 't2:FLT'). It defines 'create' with an argument corresponding to each attribute.

- The literal form for a number of primitive types were introduced on See Literal Expressions:

  Table 13-1.

  Type | Initial value | Description
  --- | --- | ---
  BOOL | false | Immutable objects which represent boolean values.
  CHAR | '\0' | Immutable objects which represent characters. The number of bits in a 'CHAR' object is less than or equal to the number in an 'INT' object.
  STR | "" (void) | Reference objects which represent strings for characters. 'void' is a representation for the null string.
  INT | 0 | Immutable objects which represent efficient integers. The size is defined by the Sather implementation but must be at least 32 bits. The two's complement representation is used to represent negative values. Bit operations are supported in addition to numerical operations.
  INTI | 0i | Reference objects which represent infinite precision integers.
  FLT | 0.0 | Immutable objects which represent single precision floating point values as defined by the IEEE-754-1985 standard.
  FLTD | 0.0d | Immutable objects which represent double precision floating point values.
  FLTI | 0.0i | Reference objects which represent arbitrary precision floating point objects.

- SYS defines a number of routines for accessing system information:

  Table 13-2.

  Routine | Description
  --- | ---
  is_eq(ob1, ob2:$OB):BOOL | Tests two objects for equality. If the arguments are of different type, it returns 'false'. If both objects are immutable, this is a recursive test on the arguments' attributes. If they are reference types, it returns 'true' if the arguments are the same object. It is a fatal error to call with external, closure, or void reference arguments.
  is_lt(ob1, ob2:$OB):BOOL | Defines an arbitrary total order on objects. This never returns true if 'is_eq' would return true with the same arguments. It is a fatal error to call with external, closure, or void reference arguments.
  hash(ob:$OB):INT | Defines an arbitrary hash function. For reference arguments, this is a hash of the pointer; for immutable types, a recursive hash of all attributes. Hash values for two objects are guaranteed to be identical when 'is_eq' would return true, but the converse is not true.
  type(ob:$OB):INT | Returns the concrete type of an object encoded as an 'INT'.
  str_for_type(i:INT):STR | Returns a string representation associated with the integer. Useful for debugging in combination with 'type' above.
  destroy(ob:$OB) | Explicitly deallocates an object. Sather is garbage collected and casual use of 'destroy' is discouraged. Sather implementations must provide a way of detecting accesses to destroyed objects (a fatal error).

  $FINALIZE defines the single routine finalize. Any class whose objects need to perform special operations before they are garbage collected should subtype from $FINALIZE. The finalize routine will be called once on such objects before the program terminates. This may happen at any time, even concurrently with other code, and no guarantee is made about the order of finalization of objects which refer to each other. Finalization will only occur once, even if new references are created to the object during finalization. Because few guarantees can be made about the environment in which finalization occurs, finalization is considered dangerous and should only be used in the rare cases that conventional coding will not suffice.

Prev | Home | Next
main | Up | Conventions