| 1 | #ifndef INTERNAL_H |
|---|
| 2 | #define INTERNAL_H |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | #include "env.h" |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | #define UR_CTERM_LEN 1 |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | #define UR_CTX_UNORDERED -1 |
|---|
| 13 | |
|---|
| 14 | #define BIN_THREAD_TMP 0 |
|---|
| 15 | |
|---|
| 16 | #define BLK_THREAD_HOLD 0 |
|---|
| 17 | #define BLK_GLOBAL_WORD 1 |
|---|
| 18 | #define BLK_GLOBAL_VAL 2 |
|---|
| 19 | #define BLK_CTX_STACK 3 |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #define isGlobalIndex(n) (n < 0) |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | #define initGCArray(af) \ |
|---|
| 27 | (af)->freeCount = 0; \ |
|---|
| 28 | (af)->freeList = -2 |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | #define tBlockPtr(n) (((UBlock*) ut->blocks.arr.ptr.v) + (n)) |
|---|
| 33 | #define tBlock(bc) tBlockPtr( bc->series.n ) |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | #define LOCK_GLOBAL mutexLock( ut->env->mutex ); |
|---|
| 37 | #define UNLOCK_GLOBAL mutexUnlock( ut->env->mutex ); |
|---|
| 38 | |
|---|
| 39 | #define LOCK_ATOMS LOCK_GLOBAL |
|---|
| 40 | #define UNLOCK_ATOMS UNLOCK_GLOBAL |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | #define UR_IS_ANY2(cell, t1, t2) \ |
|---|
| 44 | (ur_is(cell, t1) || ur_is(cell, t2)) |
|---|
| 45 | |
|---|
| 46 | #define UR_IS_ANY3(cell, t1, t2, t3) \ |
|---|
| 47 | ((1 << ur_type(cell)) & ((1<<t1) | (1<<t2) | (1<<t3))) |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | #define CUSTOM_DT(type) ut->env->customDT[type - UT_BI_COUNT] |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | typedef struct |
|---|
| 54 | { |
|---|
| 55 | uint32_t hash; |
|---|
| 56 | uint16_t nameIndex; |
|---|
| 57 | uint16_t nameLen; |
|---|
| 58 | |
|---|
| 59 | uint16_t head; |
|---|
| 60 | uint16_t chain; |
|---|
| 61 | } |
|---|
| 62 | AtomRec; |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | #define UR_EXPAND_1(type,arr,elem) \ |
|---|
| 79 | ur_arrayReserve(arr, sizeof(type), arr->used+1); \ |
|---|
| 80 | elem = ((type*) (arr->ptr.v)) + arr->used; \ |
|---|
| 81 | ++arr->used |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | #define ur_portDev(cell) \ |
|---|
| 85 | (((UPortDevice**) ur_env->devices.ptr.v)[(cell)->port.deviceId]) |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | #ifdef LANG_THUNE |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | typedef struct |
|---|
| 92 | { |
|---|
| 93 | int16_t code; |
|---|
| 94 | int16_t _pad; |
|---|
| 95 | } |
|---|
| 96 | CEId; |
|---|
| 97 | |
|---|
| 98 | typedef struct |
|---|
| 99 | { |
|---|
| 100 | int16_t code; |
|---|
| 101 | int16_t skip; |
|---|
| 102 | int32_t n; |
|---|
| 103 | UCell* cell; |
|---|
| 104 | } |
|---|
| 105 | CECell; |
|---|
| 106 | |
|---|
| 107 | typedef struct |
|---|
| 108 | { |
|---|
| 109 | int16_t code; |
|---|
| 110 | int16_t _pad; |
|---|
| 111 | int32_t blkN; |
|---|
| 112 | } |
|---|
| 113 | CEEnd; |
|---|
| 114 | |
|---|
| 115 | typedef struct |
|---|
| 116 | { |
|---|
| 117 | int16_t code; |
|---|
| 118 | int16_t _pad; |
|---|
| 119 | uint32_t n; |
|---|
| 120 | uint32_t it; |
|---|
| 121 | } |
|---|
| 122 | CEEval; |
|---|
| 123 | |
|---|
| 124 | typedef struct |
|---|
| 125 | { |
|---|
| 126 | int16_t code; |
|---|
| 127 | uint16_t flags; |
|---|
| 128 | int32_t n; |
|---|
| 129 | int32_t it; |
|---|
| 130 | } |
|---|
| 131 | CELoop; |
|---|
| 132 | |
|---|
| 133 | typedef struct |
|---|
| 134 | { |
|---|
| 135 | int16_t code; |
|---|
| 136 | int16_t locals; |
|---|
| 137 | int32_t bodyN; |
|---|
| 138 | int32_t sigN; |
|---|
| 139 | |
|---|
| 140 | } |
|---|
| 141 | CEFunc; |
|---|
| 142 | |
|---|
| 143 | typedef union |
|---|
| 144 | { |
|---|
| 145 | UCell cell; |
|---|
| 146 | CEId id; |
|---|
| 147 | CECell cp; |
|---|
| 148 | CEEnd end; |
|---|
| 149 | CEEval eval; |
|---|
| 150 | CELoop loop; |
|---|
| 151 | CECell iter; |
|---|
| 152 | CECell reduce; |
|---|
| 153 | CEFunc func; |
|---|
| 154 | } |
|---|
| 155 | CEntry; |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | #define CC_FUNC 0 |
|---|
| 159 | #define CC_FUNC_LOOP 1 |
|---|
| 160 | #define CC_EVAL 2 |
|---|
| 161 | #define CC_EVAL_RUNNING 3 |
|---|
| 162 | #define CC_REDUCE 4 |
|---|
| 163 | #define CC_FOREVER 5 |
|---|
| 164 | #define CC_LOOP 6 |
|---|
| 165 | #define CC_ITER 7 |
|---|
| 166 | #define CC_EACH 8 |
|---|
| 167 | #define CC_CATCH 9 |
|---|
| 168 | #define CC_TERM 10 |
|---|
| 169 | #define CC_END 11 |
|---|
| 170 | #define CC_COUNT (CC_END+1) |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | #define CC_LEN_FUNC 1 |
|---|
| 174 | #define CC_LEN_EVAL 1 |
|---|
| 175 | #define CC_LEN_FOREVER 1 |
|---|
| 176 | #define CC_LEN_LOOP 2 |
|---|
| 177 | #define CC_LEN_REDUCE 1 |
|---|
| 178 | #define CC_LEN_ITER 2 |
|---|
| 179 | #define CC_LEN_CATCH 3 |
|---|
| 180 | #define CC_LEN_TERM 1 |
|---|
| 181 | #define CC_LEN_END 1 |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | #if 0 |
|---|
| 185 | #define CEHOLD_COUNT(ce) (ce->hold.types & 15) |
|---|
| 186 | #define CEHOLD_TYPE_0(ce) ((ce->hold.types >> 4) & 15) |
|---|
| 187 | #define CEHOLD_TYPE_1(ce) ((ce->hold.types >> 8) & 15) |
|---|
| 188 | #define CEHOLD_TYPE_2(ce) ((ce->hold.types >> 12) & 15) |
|---|
| 189 | |
|---|
| 190 | #define PUSHC_HOLD_S1(s1) \ |
|---|
| 191 | UR_TOC->code = CC_HOLD; \ |
|---|
| 192 | UR_TOC->types = (_holdMap[s1->type] << 4) | 1; \ |
|---|
| 193 | UR_TOC->n[0] = s1->series.n; \ |
|---|
| 194 | UR_C_GROW |
|---|
| 195 | |
|---|
| 196 | #define PUSHC_HOLD_S2(s1,s2) \ |
|---|
| 197 | UR_TOC->code = CC_HOLD; \ |
|---|
| 198 | UR_TOC->types = (_holdMap[s2->type] << 8) | (_holdMap[s1->type] << 4) | 2; \ |
|---|
| 199 | UR_TOC->n[0] = s1->series.n; \ |
|---|
| 200 | UR_TOC->n[1] = s2->series.n; \ |
|---|
| 201 | UR_C_GROW |
|---|
| 202 | |
|---|
| 203 | #define POPC_HOLD UR_C_DEC |
|---|
| 204 | #endif |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | #define OP_NOP 0 |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | #define OP_DROP 3 |
|---|
| 211 | #define OP_DUP 4 |
|---|
| 212 | #define OP_DUP2 5 |
|---|
| 213 | #define OP_OVER 6 |
|---|
| 214 | #define OP_SWAP 7 |
|---|
| 215 | #define OP_NIP 8 |
|---|
| 216 | #define OP_TUCK 9 |
|---|
| 217 | #define OP_ROT 10 |
|---|
| 218 | #define OP_ROT_R 11 |
|---|
| 219 | #define OP_DO 12 |
|---|
| 220 | #define OP_PROC 13 |
|---|
| 221 | #define OP_ITER 14 |
|---|
| 222 | #define OP_EACH 15 |
|---|
| 223 | #define OP_RECURSE 16 |
|---|
| 224 | #define OP_RETURN 17 |
|---|
| 225 | #define OP_THROW 18 |
|---|
| 226 | #define OP_TRY 19 |
|---|
| 227 | #define OP_IF_TRUE 20 |
|---|
| 228 | #define OP_IF_SOME 21 |
|---|
| 229 | #define OP_IF_FALSE 22 |
|---|
| 230 | #define OP_OR_ELSE 23 |
|---|
| 231 | #define OP_IF 24 |
|---|
| 232 | #define OP_HALT 25 |
|---|
| 233 | #define OP_QUIT 26 |
|---|
| 234 | #define OP_INCREMENT 27 |
|---|
| 235 | #define OP_DECREMENT 28 |
|---|
| 236 | #define OP_INC_WORD 29 |
|---|
| 237 | #define OP_DEC_WORD 30 |
|---|
| 238 | #define OP_VERIFY 31 |
|---|
| 239 | #define OP_FOREVER 32 |
|---|
| 240 | #define OP_LOOP 33 |
|---|
| 241 | #define OP_REDUCE 34 |
|---|
| 242 | #define OP_DO_FUNC 35 |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | #define UR_TOC ((CEntry*) ut->toc) |
|---|
| 247 | #define UR_BOC ((CEntry*) ut->cstack) |
|---|
| 248 | |
|---|
| 249 | #ifdef DEBUG |
|---|
| 250 | #define UR_C_GROW \ |
|---|
| 251 | ++ut->toc; \ |
|---|
| 252 | assert( (char*)ut->toc < (char*)ut->localFT ) |
|---|
| 253 | #else |
|---|
| 254 | #define UR_C_GROW ++ut->toc |
|---|
| 255 | #endif |
|---|
| 256 | |
|---|
| 257 | #define UR_C_DEC --ut->toc |
|---|
| 258 | #define UR_C_DECN(n) ut->toc -= n |
|---|
| 259 | #endif |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | #ifdef LANG_RUNE |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | #define OP_NOP 0 |
|---|
| 266 | #define OP_DO 1 |
|---|
| 267 | #define OP_THROW 2 |
|---|
| 268 | #define OP_REDUCE 3 |
|---|
| 269 | #define OP_HALT 4 |
|---|
| 270 | #define OP_QUIT 5 |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | #define UR_TOC ut->toc |
|---|
| 274 | #define UR_BOC ut->cstack |
|---|
| 275 | #define UR_C_GROW ++ut->toc |
|---|
| 276 | #define UR_C_DEC --ut->toc |
|---|
| 277 | #endif |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | #define UR_CALL_OP ut->callOp |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | struct LocalFrame |
|---|
| 284 | { |
|---|
| 285 | UCell* cell; |
|---|
| 286 | int32_t n; |
|---|
| 287 | }; |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | #define UR_LF_BEG ((LocalFrame*) ut->localFT) |
|---|
| 291 | #define UR_LF_END ((LocalFrame*)(ut->cstack + UR_CSTACK_SIZE)) |
|---|
| 292 | #define UR_LF_PUSH --ut->localFT |
|---|
| 293 | #define UR_LF_POP ++ut->localFT |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | #endif |
|---|