-
Notifications
You must be signed in to change notification settings - Fork 26
/
j.h
345 lines (303 loc) · 10.5 KB
/
j.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/* Copyright 1990-2011, Jsoftware Inc. All rights reserved. */
/* License in license.txt. */
/* */
/* Global Definitions */
#include "js.h"
#if SY_WINCE
#include "..\cesrc\cecompat.h"
#endif
#if (SYS & SYS_PCWIN)
#define HEAPCHECK heapcheck()
#else
#define HEAPCHECK
#endif
#if (SYS & SYS_ATARIST)
#define __NO_INLINE__ 1
#endif
#if (SYS & SYS_UNIX - SYS_SGI)
#include <memory.h>
#include <sys/types.h>
#endif
#if (SYS & SYS_ANSILIB)
#include <float.h>
#include <limits.h>
#define link unused_syscall_link
#define qdiv unused_netbsd_qdiv
#include <stdlib.h>
#undef link
#undef qdiv
#else
#define const /*nothing*/ /* blame rx.h */
#endif
#if ! SY_WINCE
#include <errno.h>
#include <stdio.h>
#endif
#include <math.h>
#include <string.h>
#if SY_64
#define IMAX 9223372036854775807L
#define FMTI "%lli"
#define FMTI02 "%02lli"
#define FMTI04 "%04lli"
#define FMTI05 "%05lli"
#else
#define IMAX 2147483647L
#define FMTI "%li"
#define FMTI02 "%02li"
#define FMTI04 "%04li"
#define FMTI05 "%05li"
#endif
#define IMIN (~IMAX) /* ANSI C LONG_MIN is -LONG_MAX */
#if (SYS & SYS_AMIGA)
#define XINF "\177\377\000\000\000\000\000\000"
#define XNAN "\177\361\000\000\000\000\000\000"
#endif
#if (SYS & SYS_ARCHIMEDES)
#define XINF "\000\000\360\177\000\000\000\000"
#define XNAN "\000\000\370\377\000\000\000\000"
#endif
#if (SYS & SYS_DEC5500) || SY_WINCE_SH
#define XINF "\000\000\000\000\000\000\360\177"
#define XNAN "\000\000\000\000\000\000\370\377"
#endif
#if (SYS & SYS_MACINTOSH)
/* for old versions of ThinkC */
/* #define XINF "\177\377\000\000\000\000\000\000\000\000\000\000" */
/* #define XNAN "\377\377\100\000\100\000\000\000\000\000\000\000" */
/* for ThinkC 7.0 or later */
#define XINF "\177\377\177\377\000\000\000\000\000\000\000\000"
#define XNAN "\377\377\377\377\100\000\000\000\000\000\000\000"
#endif
#if (SYS & SYS_SUN4+SYS_SUNSOL2)
#define XINF "\177\360\000\000\000\000\000\000"
#define XNAN "\177\377\377\377\377\377\377\377"
#endif
#if (SYS & SYS_VAX)
#define XINF "\377\177\377\377\377\377\377\377"
#define XNAN "\377\177\377\377\377\377\377\376" /* not right */
#endif
#if (SY_WINCE_MIPS || SY_WINCE_SH)
#if WIN32_PLATFORM_PSPC
#define XINF "\000\000\000\000\000\000\360\177"
#define XNAN "\377\377\377\377\377\377\367\177"
#else
#define XINF "\000\000\000\000\000\000\360\177"
#define XNAN "\001\000\000\000\000\000\360\177"
#endif
#endif
#if SY_WINCE_ARM
#define XINF "\000\000\000\000\000\000\360\177"
#define XNAN "\000\000\000\000\000\000\370\177"
#endif
#if (SYS & SYS_LILENDIAN)
#ifndef XINF
#define XINF "\000\000\000\000\000\000\360\177"
#define XNAN "\000\000\000\000\000\000\370\377"
#endif
#endif
#ifndef XINF
#define XINF "\177\360\000\000\000\000\000\000"
#define XNAN "\177\370\000\000\000\000\000\000"
#endif
#ifndef PI
#define PI ((D)3.14159265358979323846)
#endif
#define P2 ((D)6.28318530717958647693)
#ifndef OVERFLOW
#define OVERFLOW ((D)8.988465674311578e307)
#endif
#ifndef UNDERFLOW
#define UNDERFLOW ((D)4.450147717014403e-308)
#endif
#define NALP 256 /* size of alphabet */
#define NETX 2000 /* size of error display buffer */
#define NPP 20 /* max value for quad pp */
#define RMAX IMAX /* max rank */
#define NPATH 1024 /* max length for path names, */
/* including trailing 0 byte */
#if SY_WINCE
#define NFCALL 100L /* wince named fn call depth */
#define NFDEP 200L /* wince fn call depth */
#endif
#if SYS & SYS_MACOSX
#define NFCALL 9000L /* darwin named fn call depth */
#define NFDEP 18000L /* darwin fn call depth */
#endif
#ifndef NFCALL
#define NFCALL 10000L /* all other named fn call depth */
#define NFDEP 20000L /* all other fn call depth */
#endif
#define NTSTACK 2000L /* size of stack for temps */
#define IIDOT 0 /* modes for indexofsub() */
#define IICO 1
#define INUBSV 2
#define INUB 3
#define ILESS 4
#define INUBI 5
#define IEPS 6
#define II0EPS 7
#define II1EPS 8
#define IJ0EPS 9
#define IJ1EPS 10
#define ISUMEPS 11
#define IANYEPS 12
#define IALLEPS 13
#define IIFBEPS 14
#define IPHOFFSET 30 /* offset for prehashed versions */
#define IPHIDOT 30
#define IPHICO 31
#define IPHLESS 34
#define IPHEPS 36
#define IPHI0EPS 37
#define IPHI1EPS 38
#define IPHJ0EPS 39
#define IPHJ1EPS 40
#define IPHSUMEPS 41
#define IPHANYEPS 42
#define IPHALLEPS 43
#define IPHIFBEPS 44
#if SY_64 && SY_WIN32
#define jfloor jfloor1
#else
#define jfloor floor
#endif
#define BB 8 /* # bits in a byte */
#if SY_64
#define BW 64 /* # bits in a word */
#else
#define BW 32
#endif
#define ABS(a) (0<=(a)?(a):-(a))
#define ACX(a) {AC(a)=IMAX/2;}
#define ASSERT(b,e) {if(!(b)){jsignal(e); R 0;}}
#define ASSERTD(b,s) {if(!(b)){jsigd((s)); R 0;}}
#define ASSERTMTV(w) {RZ(w); ASSERT(1==AR(w),EVRANK); ASSERT(!AN(w),EVLENGTH);}
#define ASSERTN(b,e,nm) {if(!(b)){jt->curname=(nm); jsignal(e); R 0;}}
#define ASSERTSYS(b,s) {if(!(b)){jsignal(EVSYSTEM); jtwri(jt,MTYOSYS,"",(I)strlen(s),s); R 0;}}
#define ASSERTW(b,e) {if(!(b)){if((e)<=NEVM)jsignal(e); else jt->jerr=(e); R;}}
#define CALL1(f,w,fs) ((f)(jt, (w),(A)(fs)))
#define CALL2(f,a,w,fs) ((f)(jt,(a),(w),(A)(fs)))
#define DF1(f) A f(J jt, A w,A self)
#define DF2(f) A f(J jt,A a,A w,A self)
#define DO(n,stm) {I i=0,_n=(n); for(;i<_n;i++){stm}}
#define DQ(n,stm) {I i=(n)-1; for(;i>=0;--i){stm}}
#define ds(c) pst[(UC)(c)]
#define EPILOG(z) R gc(z,_ttop)
#define FDEPDEC(d) {jt->fdepi-=d;}
#define FDEPINC(d) {ASSERT(jt->fdepn>=d+jt->fdepi,EVSTACK); jt->fdepi+=d;}
#define FCONS(x) fdef(CFCONS,VERB,jtnum1,jtnum2,0L,0L,(x),0L,RMAX,RMAX,RMAX)
#define FEQ(u,v) (ABS((u)-(v))<=jt->fuzz*MAX(ABS(u),ABS(v)))
#define F1(f) A f(J jt, A w)
#define F2(f) A f(J jt,A a,A w)
#define F1RANK(m,f,self) {RZ( w); if(m<AR(w) )R rank1ex( w,(A)self,(I)m, f);}
#define F2RANK(l,r,f,self) {RZ(a&&w); if(l<AR(a)||r<AR(w))R rank2ex(a,w,(A)self,(I)l,(I)r,f);}
#define GA(v,t,n,r,s) RZ(v=ga(t,(I)(n),(I)(r),(I*)(s)))
#define HN 3L
#define IC(w) (AR(w) ? *AS(w) : 1L)
#define ICMP(z,w,n) memcmp((z),(w),(n)*SZI)
#define ICPY(z,w,n) memcpy((z),(w),(n)*SZI)
#define INF(x) ((x)==inf||(x)==infm)
#define IX(n) apv((n),0L,1L)
#define JATTN {if(*jt->adbreak&&!jt->breakignore){jsignal(EVATTN); R 0;}}
#define JBREAK0 {if(2<=*jt->adbreak&&!jt->breakignore){jsignal(EVBREAK); R 0;}}
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MC memcpy
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MLEN (SY_64?63:31)
#define NAN0 (_clearfp())
#define NAN1 {if(_SW_INVALID&_clearfp()){jsignal(EVNAN); R 0;}}
#define NAN1V {if(_SW_INVALID&_clearfp()){jsignal(EVNAN); R ;}}
#define PROLOG I _ttop=jt->tbase+jt->ttop
#define R return
#define RE(exp) {if((exp),jt->jerr)R 0;}
#define RER {if(er){jt->jerr=er; R;}}
#define RESETERR {jt->etxn=jt->jerr=0;}
#define RNE(exp) {R jt->jerr?0:(exp);}
#define RZ(exp) {if(!(exp))R 0;}
#define SBSV(x) (jt->sbsv+(I)(x))
#define SBUV(x) (jt->sbuv+(I)(x))
#define SGN(a) ((0<(a))-(0>(a)))
#define SMAX 65535
#define SMIN (-65536)
#define SZA ((I)sizeof(A))
#define SZD ((I)sizeof(D))
#define SZI ((I)sizeof(I))
#define VAL1 '\001'
#define VAL2 '\002'
#if SYS & SYS_LILENDIAN
#define B0000 0x00000000
#define B0001 0x01000000
#define B0010 0x00010000
#define B0011 0x01010000
#define B0100 0x00000100
#define B0101 0x01000100
#define B0110 0x00010100
#define B0111 0x01010100
#define B1000 0x00000001
#define B1001 0x01000001
#define B1010 0x00010001
#define B1011 0x01010001
#define B1100 0x00000101
#define B1101 0x01000101
#define B1110 0x00010101
#define B1111 0x01010101
#define BS00 0x0000
#define BS01 0x0100
#define BS10 0x0001
#define BS11 0x0101
#else
#define B0000 0x00000000
#define B0001 0x00000001
#define B0010 0x00000100
#define B0011 0x00000101
#define B0100 0x00010000
#define B0101 0x00010001
#define B0110 0x00010100
#define B0111 0x00010101
#define B1000 0x01000000
#define B1001 0x01000001
#define B1010 0x01000100
#define B1011 0x01000101
#define B1100 0x01010000
#define B1101 0x01010001
#define B1110 0x01010100
#define B1111 0x01010101
#define BS00 0x0000
#define BS01 0x0001
#define BS10 0x0100
#define BS11 0x0101
#endif
#include "ja.h"
#include "jc.h"
#include "jtype.h"
#include "jt.h"
#include "jlib.h"
#include "je.h"
#include "jerr.h"
#include "va.h"
#include "vq.h"
#include "vx.h"
#include "vz.h"
#include "vdx.h"
#include "m.h"
#include "a.h"
#include "s.h"
// JPFX("here we are\n")
// JPF("size is %i\n", v)
// JPF("size and extra: %i %i\n", (v,x))
#define JPFX(s) {char b[1000]; sprintf(b, s); jsto(gjt,MTYOFM,b);}
#define JPF(s,v) {char b[1000]; sprintf(b, s, v); jsto(gjt,MTYOFM,b);}
extern J gjt; // global for JPF (procs without jt)
#if SY_WINCE_MIPS
/* strchr fails for CE MIPS - neg chars - spellit fails in ws.c for f=.+. */
#define strchr(a,b) strchr(a, (UC)b)
#endif
#if SYS & SYS_UNIX
#include <fenv.h>
#define _isnan isnan
#define _SW_INVALID FE_INVALID
static inline UINT _clearfp(void){int r=fetestexcept(FE_ALL_EXCEPT);
feclearexcept(FE_ALL_EXCEPT); return r;
}
#endif