Pristine Ack-5.5
[Ack-5.5.git] / doc / em / types.nr
1 .bp
2 .P1 "TYPE REPRESENTATIONS"
3 .PP
4 The representations used for typed objects are not precisely
5 specified by EM.
6 Sometimes we only specify that a typed object occupies a
7 certain amount of space and state no further restrictions.
8 If one wants to have a different representation of the value of
9 an object on the stack one has to use a convert instruction
10 in most cases.
11 We do specify some relations between the representations of
12 types.
13 This allows some intermixed use of operators for different types
14 on the same object(s).
15 For example, the instruction ZER pushes signed and
16 unsigned integers with the value zero and empty sets.
17 ZER has as only argument the size of the object.
18 .QQ
19 The representation of floating point numbers is a good example,
20 it allows widely varying implementations.
21 The only ways to create floating point numbers are via
22 initialization and via conversions from integer numbers.
23 Only by using conversions to integers and comparing
24 two floating point numbers with each other, can these numbers
25 be converted to human readable output.
26 Implementations may use base 10, base 2 or any other
27 base for exponents, and have freedom in choosing the range of
28 exponent and mantissa.
29 .QQ
30 Other types are more precisely described.
31 In the following paragraphs a description will be given of the
32 restrictions imposed on the representation of the types used.
33 A number \fBn\fP used in these paragraphs indicates the size of
34 the object in \fIbits\fP.
35 .P2 "Unsigned integers"
36 .PP
37 The range of unsigned integers is 0..
38 .Ex 2 "\fBn\fP" -1.
39 A binary representation is assumed.
40 The order of the bits within an object is knowingly left
41 unspecified.
42 Discussing bit order within each 8-bit byte is academic,
43 so the only real freedom of this specification lies in the byte
44 order.
45 We really do not care whether an implementation of a 4-byte
46 integer has its bytes in a particular order of significance.
47 This of course means that some sequences of instructions have
48 unpredictable effects.
49 For example:
50 .DS
51 LOC 258 ; STL 0 ; LAL 0 ; LOI 1      ( wordsize >=2 )
52 .DE
53 The value on the stack after executing this sequence
54 can be anything,
55 but will most likely be 1 or 2.
56 .QQ
57 Conversion between unsigned integers of different sizes have to
58 be done with explicit convert instructions.
59 One cannot simply pad an unsigned integer with zero's at either end
60 and expect a correct result.
61 .QQ
62 We assume existence of at least single word unsigned arithmetic
63 in any implementation.
64 .P2 "Signed Integers"
65 .PP
66 The range of signed integers is
67 .Ex \-2 "\fBn\fP\-1" ~..
68 .Ex 2 "\fBn\fP\-1" \-1,
69 in other words the range of signed integers of \fBn\fP bits
70 using two's complement arithmetic.
71 The representation is the same as for unsigned integers except the range
72 .Ex 2 "\fBn\fP\-1" ~..
73 .Ex 2 "\fBn\fP" \-1
74 is mapped on the
75 range 
76 .Ex \-2 "\fBn\fP\-1" ~..~\-1.
77 In other words, the most significant bit is used as sign bit.
78 The convert instructions between signed and unsigned integers
79 of the same size can be used to catch errors.
80 .QQ
81 The value 
82 .Ex \-2 "\fBn\fP\-1" 
83 is used for undefined
84 signed integers.
85 EM implementations should trap when this value is used in an
86 operation on signed integers.
87 The instruction mask, accessed with SIM and LIM \-~see chapter 9~\-,
88 can be used to disable such traps.
89 .QQ
90 We assume existence of at least single word signed arithmetic
91 in any implementation.
92 .P2 "Floating point values"
93 .PP
94 Floating point values must have a signed mantissa and a signed
95 exponent.
96 Although no base is specified, base 2 is the normal choice,
97 because the FEF instruction pushes the exponent in base 2.
98 .QQ
99 The implementation of floating point arithmetic is optional.
100 The compilers currently in use have runtime parameters for the
101 size of the floating point values they should use.
102 Common choices are 4 and/or 8 bytes.
103 .P2 Pointers
104 .PP
105 EM has two kinds of pointers: for instruction and for data
106 space.
107 Each kind can only be used for its own space, conversion between
108 these two subtypes is impossible.
109 We assume that pointers have a range from 0 upwards.
110 Any implementation may have holes in the pointer range between
111 fragments.
112 One can of course not expect to be able to address two megabyte
113 of memory using a 2-byte pointer.
114 Normally, a 2-byte pointer allows up to 65536 bytes of
115 addressable memory.
116 .QQ
117 Pointer representation has one restriction.
118 The pointer with the same representation as the integer zero of
119 the same size should be invalid.
120 Some languages and/or runtime systems represent the nil
121 pointer as zero.
122 .P2 "Bit sets"
123 .PP
124 All bit sets of size \fBn\fP are subsets of the set
125 {~i~|~i>=0,~i<\fBn\fP~}.
126 A bit set contains a bit for each element showing its
127 presence or absence.
128 Bit sets are subdivided into words.
129 The word with the lowest EM address governs the subset
130 {~i~|~i>=0,~i<\fBm\fP~}, where \fBm\fP is the number of bits in
131 a word.
132 The next higher words each govern the next higher \fBm\fP set elements.
133 The relation between a set with size of
134 a word and an unsigned integer word is that
135 the value of the unsigned integer is the summation of the
136 2\v'-0.5m'i\v'0.5m' where i is in the set.
137 .QQ
138 Example: a 2-word bit set (wordsize 2) containing the
139 elements 1, 6, 8, 15, 18, 21, 27 and 28 is composed of two
140 integers, e.g. at addresses 40 and 42.
141 The word at 40 contains the value 33090 (or~\-32446),
142 the word at 42 contains the value 6180.