Back Contents Next

13. Primitives and Literals

This section introduces those types which the Opal compiler already knows. The compiler provides extra support to many of them in the form of special ways to write object values of these types (known as literals). Other than this they are exactly like all other types and objects.

13.1 Object

Object is not exactly a primitive. For more detailed information on Object see the class library documentation. Object is the root type of all types. It has no super type. Object is in the 'x.lang' module which is always imported. Here are the public methods of Object:

equivalent(obj : Object) -> bool
Returns true if the obj is of the same type and is equal to the object being called on. Equal is defined by default to be a memberwise comparison using the equivalent. BUGBUG: maybe should called ~=

class
This is a read only property which holds a reference to the class object of the object's class.

hashCode() -> long
Returns a unique hash code for this object. Classes which override equals() will most likely want to override this as well. BUGBUG: maybe should called #

toString() -> string
Returns a string representation of the object. Most classes will want to override this. Useful for debugging and other outputting.

create clone() -> Object
Returns a bitwise copy of the object. Subclasses should override to provide smarter behavior. Return type is equal to class type since this method is created for every object.

13.2 Class

One direct subclass of Object is Class. It describes the members of objects of a particular type. Class is a normal type except that the compiler automatically creates instances of class. Their is no way for the programmer to directly create an instance of Class. The Class class is in the 'x.reflect' module. For information on the public members of Class see the class library documentation.

13.3 Void

The type 'void' is the most unique type. It is the null type. That is the type which represents the lack of a type or object value. It may be used in return types to indicate that a method does not return. There are not and can never be instances of void. The void type defines no properties or methods. The void class cannot be invoked to create an instance and has no create methods. Entites may not declare void as a super or interface type. Patterns may not declare void parameters.

13.4 Boolean

The 'bool' type is the basic unit of logical value. It may have two values, true or false. The bool type is declared const abstract and has no methods except those it gets from object and the logical operators. There are two objects which are anonymous const sub types of bool, they are the bool literals (see Bool Literals).

13.5 Characters

Their are two primitive character types. They are 'schar' and 'char'. Both extend the abstract type 'character' which defines all the possible operations to be be perforemed on characters. All three types are const and character is abstract. Since they are const, final should be used to idicate that a character value doesn't change. Schar and char are final types and may not be extended. For each character their is a single object that represents it. For this reason characters can be compared with the '==' operator. No other operators are defined on characters. Charcters may be converted to ubytes and ushorts respectively.

BUGBUG: haven't define how to do this conversion.

13.6 Integers

The integer primitive types are:

byte
sbyte
8 bit integers, unsigned and signed
short
ushort
16 bit integers, signed and unsigned
int
uint
32 bit integers, signed and unsigned
long
ulong
64 bit integers, signed and unsigned
wide
uwide
128 bit integers, signed and unsigned

All primitive integer types implement the interface of integer which extends number. They are each const classes, so final should be used to express invarience in a value. Each value is represented by an indiviual object so that they may be compared with '=='. All arithmatic and comparson operators are defined for them. When different types are mixed in expressions, the operators have been define to carry out promotion. They may be promoted up in size. Also unsigned values may be converted to signed values if a size promotion occurs at the same time.

The standard libaray also provides a 'integer' class which acts as an unbounded integer.

13.7 Reals

The real primitive types are:

single A single precison floating point number.
double A double precison floating point number.

The standard libaray also provides a 'real' class which acts as an unbounded integer.

13.8 Lists and Tuples

BUGBUG write this

13.9 Arrays

BUGBUG write this

13.10 Strings

BUGBUG write this

Back Contents Next

jwalker@cs.oberlin.edu