19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 10), a literal (see Section 13.1), a spawn expression (see Section 13.24), an aggregate expression (see Section<br />

13.28), or a comprehension (see Section 13.29). In the latter case, the constructed value is the result of the normal<br />

completion of such an evaluation.<br />

4.2 Normal and Abrupt Completion of Evaluation<br />

Conceptually, an expression is evaluated until it completes. Evaluation of an expression may complete normally,<br />

resulting in a value, or it may complete abruptly. Each abrupt completion has an associated value which caused the<br />

abrupt completion: the value is either an exception value that is thrown and uncaught or the exit value of an exit<br />

expression (described in Section 13.13). In addition to programmer-defined exceptions thrown explicitly by a throw<br />

expression (described in Section 13.25), there are predefined exceptions thrown by the <strong>Fortress</strong> standard libraries. For<br />

example, dividing an integer by zero (using the / operator) causes a DivideByZeroException to be thrown.<br />

When an expression completes abruptly, control passes to the dynamically immediately enclosing expression. This<br />

continues until the abrupt completion is handled either by a try expression (described in Section 13.26) if an exception<br />

is being thrown or by an appropriately tagged label expression (described in Section 13.13) if an exit<br />

expression was executed. If abrupt completion is not handled within a thread and its outermost expression completes<br />

abruptly, the thread itself completes abruptly. If the main thread of a program completes abruptly, the program as a<br />

whole also completes abruptly.<br />

4.3 Memory and Memory Operations<br />

In this specification, the term memory refers to a set of abstract locations; the memory is used to model sharing and<br />

mutation. A location has an associated type, and a value of that type (i.e., the type of the value is a subtype of the type<br />

of the location); we say that the location contains its associated value. Unlike values, locations can have non-object<br />

trait types.<br />

<strong>The</strong>re are three kinds of operations that can be performed on memory: allocation, reads, and writes. Reads and writes<br />

are collectively called memory accesses. Intuitively, a read operation takes a location and returns the value contained<br />

in that location, and a write operation takes a location and a value of the location’s type and changes the contents of<br />

the location so the location contains the given value. Accesses need not take place in the order in which they occur in<br />

the program text; a detailed account of memory behavior appears in Chapter 21.<br />

Allocation creates a new location of a given type. Allocation occurs when a mutable variable is declared, or when a<br />

reference object is constructed. In the latter case, a new location is allocated for each field of the object. Abstractly,<br />

locations are never reclaimed; in practice, memory reclamation is handled by garbage collection.<br />

A freshly allocated location is uninitialized. <strong>The</strong> type system and memory model in <strong>Fortress</strong> guarantee that an initializing<br />

write is performed to every location, and that this write occurs before any read of the location. Any location whose<br />

value can be written after initialization is mutable. Any location whose value cannot be written after initialization<br />

is immutable. Mutable locations include mutable variables and settable fields of a reference object. Immutable<br />

locations include non-transient , non-settable fields of a reference object.<br />

4.4 Threads and Parallelism<br />

<strong>The</strong>re are two kinds of threads in <strong>Fortress</strong>: implicit threads and spawned (or explicit) threads. Spawned threads are<br />

objects created by the spawn construct, described in Section 13.24.<br />

37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!