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.

40.1 <strong>The</strong> Trait <strong>Fortress</strong>.Core.LinearSequence<br />

A value of type LinearSequenceT, n is a sequence of n things of type T , where n may be any natural number.<br />

Note that its length is statically fixed and may be described by a static expression. <strong>The</strong> general intent is that such a<br />

sequence will reside in a contiguous region of memory, typically belonging to a single processor or processor node,<br />

and that any element (indicated by an integer index) may be fetched or updated quickly by that processor or processor<br />

node.<br />

If T is not a value type, then LinearSequenceT, n describes a sequence of references, and a variable of type<br />

LinearSequenceT, n occupies an amount of storage equal to n times the amount of storage required to hold a<br />

reference. If T is a value type, then LinearSequenceT, n describes a sequence of “unboxed” values, and a variable<br />

of type LinearSequenceT, n occupies an amount of storage equal to n times the amount of storage required to<br />

hold one value of type T .<br />

Linear sequences, unlike arrays, are not too fancy. <strong>The</strong> main things you can do with linear sequences are subscripting<br />

and subscripted assignment, as well as assignment of entire sequences. <strong>The</strong>y also support the concatenation operator<br />

‖ . For example:<br />

x: LinearSequenceThread, 3<br />

y: LinearSequenceThread, 6<br />

z: LinearSequenceThread, 5 = x‖y[3 # 2]<br />

Note in this example that the lengths are statically checkable. <strong>The</strong> range 3 #2 is a range of constant size 2, so y[3 # 2]<br />

is known to be of type LinearSequenceThread, 2 . Indeed, only ranges of static size with element type IndexInt<br />

may be used to subscript a linear sequence.<br />

value trait LinearSequenceT extends Object,nat n comprises {}<br />

coercion nat b,bool bigEndianSequence<br />

(x:BinaryLinearEndianSequenceb, n,bigEndianSequence)<br />

where { T extends BinaryWordb }<br />

coercion nat b,bool bigEndianBytes,bool bigEndianBits,bool bigEndianSequence<br />

(x:BinaryEndianLinearEndianSequenceb,bigEndianBytes,bigEndianBits,<br />

n,bigEndianSequence)<br />

where { T extends BinaryEndianWordb,bigEndianBytes,bigEndianBits }<br />

coercion nat b,bool bigEndianBytes,bool bigEndianBits,bool bigEndianSequence<br />

(x:BinaryEndianLinearEndianSequenceb,bigEndianBytes,bigEndianBits,<br />

n,bigEndianSequence)<br />

where { T extends BinaryWordb }<br />

opr [j: IndexInt]:T throws { IndexOutOfBoundsException }<br />

opr nat k[j: IntegerStatick]: T where { k < n }<br />

opr nat m[r: RangeOfStaticSizeIndexInt, m]:LinearSequenceT, m<br />

throws { IndexOutOfBoundsException } where { m ≤ n }<br />

opr int a,nat m,int c[r:StaticRangea, m, c]:LinearSequenceT, m<br />

where { 0 ≤ a < n, 0 ≤ a + m · c < n }<br />

opr [j: IndexInt] := (v: T): LinearSequenceT, n throws { IndexOutOfBoundsException }<br />

opr nat k[j: IntegerStatick] := (v: T):LinearSequenceT, n where { k < n }<br />

opr nat m[r: RangeOfStaticSizeIndexInt, m] := (v: LinearSequenceT, m):<br />

LinearSequenceT, n<br />

throws { IndexOutOfBoundsException } where { m ≤ n }<br />

opr int a,nat m,int c[r:StaticRangea, m, c] := (v: LinearSequenceT, m):<br />

LinearSequenceT, n<br />

where { 0 ≤ a < n, 0 ≤ a + m · c < n }<br />

update(j:IndexInt, v: T):LinearSequenceT, n throws { IndexOutOfBoundsException }<br />

272

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

Saved successfully!

Ooh no, something went wrong!