Types

AlignmentDefinitionAtomsStructuresArrays

Alignment and Padding

In Ocean you have (a) little control over alignment and the amount of padding used: either it is allowed and the system decides the amount based on the alignment constraints, or you indicate that padding is illegal and no padding (not even a bit) is inserted.

Definition

type-name          ::= identifier
base-type          ::= atom
                    |  structure
                    |  array
                    |  class
full-type          ::= [[force] change] [[force] check] base-type
define-type        ::= full-type type-name
Convention:

Atoms

enum-elem          ::= enum-value [list-start known-integer-value list-end]
enum-def           ::= enum-elem [or enum-elem]...
range-def          ::= known-integer-value range known-integer-value
atom-constr        ::= extend s enum-type-name [s]
                    |  align s lit-float [s]
		    |  order s (big_endian|little_endian) [s]
atom               ::= range [atom-constr [sep atom-const]...] spec range-def
		    |  enum [atom-constr [sep atom-const]...] spec enum-def
                    |  range-def
                    |  enum-def
context             :  the current type

The most basic form of a type is either a range of integer values, or a set of enum values. The amount of bits reserved is the minimum to store all the possible values without an offset, so 62..63 will still use 6 bits. If a negative value is present in the range or as a defined value of an enum-value, the range is automaticly two's complement, and all positive values will have a leading reset-bit.

If you need an 'offset' value, that is binary zero does not indicate the value zero, use unit alias to create a 'shifted' value.

The alignment default value is default 0 (for don't-care). It can either be an integer, in chich case it indicates the modulo of the byte-alignment, or a float 0.0 < a < 1 which indicates the modulo of the bit-alignment.

Bit allocation will always start at the lsb (least significant bit),

All these types are weakly alterable and unchecked.

known-integer-value : an expression which can be computed during compile time and results in an integer
Atom Aspects
lowest
The lowest value till now, expressed as a lit-integer.
If no value has been defined yet, it is expressed as '0' (zero).
highest
The highest value till now, expressed as a lit-integer.
If no value has been defined yet, it is expressed as '0' (zero).
bits
The amount of bits needed to store this type till now, expressed as a lit-integer.
If no value has been defined yet, it is expressed as '0' (zero).
steps
in case of a continuous range equivalent to (1 + highest - lowest),
otherwise the count of discrete values till now, expressed as a lit-integer.
If no value has been defined yet, it is expressed as '0' (zero).
unit
The unit, expressed as a unit-label. Atoms without a unit have the unit ``
'first': ::@::highest+7 | 'third': ::@::highest+7

Now first equals 7 and third equals 14; if we insert 'second' then we do not need te change `third`.

Structures

pointer-name       ::= identifier
count-label        ::= label [s]
  format           ::= identifier
access-label       ::= label [s]
  format           ::= identifier [s] sep identifier
reference          ::= counted [s] [count-label] pointer-name
                    |  owner s pointer-name
                    |  pointer s pointer-name
                    |  access [s] [access-label] pointer-name
struct-part        ::= full-type s var-names [s] ( sep | concat )
variant-part       ::= enum-value spec full-type s var-names or-else
union-part         ::= full-type s var-names or-else
struct-constr      ::= reference
                    |  align s lit-float [s]
                    |  invariant
structure          ::= list-start struct-part list-end
		    |  structure [struct-constr [sep struct-constr]] spec list-start struct-part... list-end
                    |  union spec list-start union-part... list-end
		    |  variant spec list-start spec identifier sep variant-part... list-end
counted
defines a reference counted structure. The count-label is the name if the field (in the structure) used to do access count. If it is not there, Ocean will prepend a 32bit unsigned integer in the structure.
Note that if the user provided field is signed that any negative value is read as 'locked', allowing 'the' pre-allocated versions.
owner
there can only be one (and not less than one) owner of this structure. Both the owner and the structure must be allocated by the same allocator: both the, or my for example.
pointer
...
access
...

A structure collects a number of different types into one type. Items will keep their ordering, but padding is optional: if you use the concatenation symbol (//), then the next item will have no alignment (even on the bit level!). Note that this can cause severe performance degrading if you use this on say Floats.

'Simple' structures have no reference information, so you can not have pointers to them. However, passing them with 'that' to a function is still allowed.

( 'float'|'integer' type;
  Boolean flag1//
  Boolean flag2,
  variant ( :type,
    'float' : Float float,
    'integer' : Integer integer,
  ) _,  # an unnamed (so 'inlined') variant
)
Structure Aspects
size
The size of the structure till now, expressed as a lit-integer.
If no parts have been defined yet, it is expressed as '0' (zero).
unit
The unit, expressed as a unit-label. Structures without a unit have the unit ``

Array

array-size         ::= lit-integer
                    |  context
                    |  atom-type
		    |  class-with-hash-interface
simple-array       ::= index-start [array-size [s]] index-end full-type
array              ::= simple-array
                    |  array ownership simple-array
Arrays can be:
fixed size
by either having a lifixed sized (always with an integer index)
dynamic size
sized (with any class implementing the Hash interface as index).
Array Aspects
fixed
'0' or '1' depending if the array is fixed_size
hash
'0' or '1' depending if the array is a hash
index
the type-name or type definition of the index
unit
The unit, expressed as a unit-label. Arrays without a unit have the unit ``