Pristine Ack-5.5
[Ack-5.5.git] / util / int / text.h
1 /*
2         Accessing the program text
3 */
4
5 /* $Id: text.h,v 2.3 1994/06/24 10:49:25 ceriel Exp $ */
6
7 #define text_loc(a)     (*(text + (p2i(a))))
8
9 /*      The bytes in the text segment are unsigned, and this is what is
10         implemented by the macros btol() and btou().  Some operands,
11         however, are signed; this is indicated in the table by P or N.
12         When an operand is positive, it is guaranteed that the leftmost
13         bit is 0, so we can get the value by doing sign extension.  Likewise,
14         when the operand is negative the leftmost bit will be 1 and again sign
15         extension yields the right value.
16         Actually we should test if this guarantee is indeed upheld, but that
17         is just too expensive.
18 */
19
20 /*      Reading the opcode.
21 */
22 #define nextPCbyte()    (PC+=1, btou(text_loc(PC-1)))
23
24 /*      Shortie arguments consist of the high order value, derived from
25         the opcode and passed as a parameter, and the following byte.
26 */
27 #define S_arg(h)        (PC+=1, ((h)<<8) + btol(text_loc(PC-1)))
28
29 /*      Two-byte arguments consist of the following two bytes.
30 */
31
32 #define L_arg_2()       (PC+=2, (btol(text_loc(PC-1)) | \
33                                 (btos(text_loc(PC-2)) << 8)))
34
35 #define P_arg_2()       (PC+=2, (btol(text_loc(PC-1)) | \
36                                 (btos(text_loc(PC-2)) << 8)))/* should test */
37
38 #define N_arg_2()       (PC+=2, (btol(text_loc(PC-1)) | \
39                                 (btos(text_loc(PC-2)) << 8)))/* should test */
40
41 #define U_arg()         (PC+=2, (btol(text_loc(PC-1)) | \
42                                 (btol(text_loc(PC-2)) << 8)))
43
44 /*      The L-, P-, and N-4-bytes #defines are all equal, because
45         we assume our longs to be 4 bytes long.
46 */
47
48 #define L_arg_4()       (PC+=4, (btol(text_loc(PC-1)) | \
49                                 (btol(text_loc(PC-2)) << 8) | \
50                                 (btol(text_loc(PC-3)) << 16) | \
51                                 (btos(text_loc(PC-4)) << 24)))
52
53 #define P_arg_4()       (PC+=4, (btol(text_loc(PC-1)) | \
54                                 (btol(text_loc(PC-2)) << 8) | \
55                                 (btol(text_loc(PC-3)) << 16) | \
56                                 (btos(text_loc(PC-4)) << 24)))/* should test */
57
58 #define N_arg_4()       (PC+=4, (btol(text_loc(PC-1)) | \
59                                 (btol(text_loc(PC-2)) << 8) | \
60                                 (btol(text_loc(PC-3)) << 16) | \
61                                 (btos(text_loc(PC-4)) << 24)))/* should test */
62
63
64 /*
65  * #defines for argument checks.
66  */
67
68 #define arg_c(n)        ((n < i_minsw || n > i_maxsw) ? \
69                                         (wtrap(WARGC, EILLINS), 0) : n)
70
71 #define arg_d(n)        ((wsize > 2) ? (wtrap(WARGD, EILLINS), 0) : n)
72
73 #define arg_l(n)        ((n < min_off || n > max_off) ? \
74                                         (wtrap(WARGL, EILLINS), 0) : n)
75
76 #define arg_g(p)        ((p >= HB) ? (wtrap(WARGG, EILLINS), i2p(0)) : p)
77
78 #define arg_f(n)        ((n < min_off || n > max_off) ? \
79                                         (wtrap(WARGF, EILLINS), 0) : n)
80
81 #define arg_n(u)        ((u > i_maxuw) ? (wtrap(WARGL, EILLINS), 0) : u)
82
83 #define arg_s(s)        ((s <= 0 || s > max_off || (s & wsizem1)) ? \
84                                 (trap(EODDZ), s) : s)
85
86 #define arg_z(s)        ((s < 0 || s > max_off || (s & wsizem1)) ? \
87                                 (trap(EODDZ), s) : s)
88
89 #define arg_o(s)        ((s < 0 || s > max_off || ((s&wsizem1) && wsize%s)) ? \
90                                 (trap(EODDZ), s) : s)
91
92 #define arg_w(s)        ((s <= 0 || s > max_off || (s & wsizem1)) ? \
93                                 (trap(EODDZ), s) : s)
94
95 #define arg_p(l)        ((l >= NProc) ? (wtrap(WARGP, EILLINS), 0) : l)
96
97 #define arg_r(n)        ((n < 0 || n > 2) ? (wtrap(WARGR, EILLINS), 0) : n)
98
99 /* tests on widths */
100 #define arg_wn(s)       ((s != 1 && s != 2 && s != 4) ? \
101                                 (trap(EODDZ), s) : s)
102
103 #define arg_wf(s)       ((s != 4 && s != 8) ? (trap(EODDZ), s) : s)
104
105 #define arg_wi(s)       (((s != 2 && s != 4) || (s & wsizem1)) ? \
106                                 (trap(EODDZ), s) : s)
107
108 /* special tests */
109 #define arg_lae(p)      ((p > ML) ? (trap(EBADLAE), p) : p)
110
111 #define arg_gto(p)      ((p>=HB) ? (wtrap(WGTOSTACK, EBADGTO), p) : p)
112
113 #define arg_lin(u)      ((u > NLINE) ? (trap(EBADLIN), u) : u)
114