~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/nbody-java/hycomp.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-06-11 15:45:24 UTC
  • mfrom: (1.2.1) (2.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130611154524-rppb3w6tixlegv4n
Tags: 1.4.7~20130611~a1eb425-1
* New snapshot release
* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 *  contributor license agreements.  See the NOTICE file distributed with
 
4
 *  this work for additional information regarding copyright ownership.
 
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 *  (the "License"); you may not use this file except in compliance with
 
7
 *  the License.  You may obtain a copy of the License at
 
8
 *
 
9
 *     http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
11
 *  Unless required by applicable law or agreed to in writing, software
 
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
 
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 *  See the License for the specific language governing permissions and
 
15
 *  limitations under the License.
 
16
 */
 
17
 
 
18
#if !defined(hycomp_h)
 
19
#define hycomp_h
 
20
 
 
21
/**
 
22
 * USE_PROTOTYPES:         Use full ANSI prototypes.
 
23
 *
 
24
 * CLOCK_PRIMS:            We want the timer/clock prims to be used
 
25
 *
 
26
 * LITTLE_ENDIAN:          This is for the intel machines or other
 
27
 *                         little endian processors. Defaults to big endian.
 
28
 *
 
29
 * NO_LVALUE_CASTING:      This is for compilers that don't like the left side
 
30
 *                         of assigns to be cast.  It hacks around to do the
 
31
 *                         right thing.
 
32
 *
 
33
 * ATOMIC_FLOAT_ACCESS:    So that float operations will work.
 
34
 *
 
35
 * LINKED_USER_PRIMITIVES: Indicates that user primitives are statically linked
 
36
 *                         with the VM executeable.
 
37
 *
 
38
 * OLD_SPACE_SIZE_DIFF:    The 68k uses a different amount of old space.
 
39
 *                         This "legitimizes" the change.
 
40
 *
 
41
 * SIMPLE_SIGNAL:          For machines that don't use real signals in C.
 
42
 *                         (eg: PC, 68k)
 
43
 *
 
44
 * OS_NAME_LOOKUP:         Use nlist to lookup user primitive addresses.
 
45
 *
 
46
 * VMCALL:                 Tag for all functions called by the VM.
 
47
 *
 
48
 * VMAPICALL:              Tag for all functions called via the PlatformFunction
 
49
 *                         callWith: mechanism.
 
50
 *
 
51
 * SYS_FLOAT:              For some math functions where extended types (80 or 96 bits) are returned
 
52
 *                         Most platforms return as a double
 
53
 *
 
54
 * FLOAT_EXTENDED:         If defined, the type name for extended precision floats.
 
55
 *
 
56
 * PLATFORM_IS_ASCII:      Must be defined if the platform is ASCII
 
57
 *
 
58
 * EXE_EXTENSION_CHAR:     the executable has a delimiter that we want to stop at as part of argv[0].
 
59
 */
 
60
 
 
61
 /**
 
62
 * By default order doubles in the native (that is big/little endian) ordering.
 
63
 */
 
64
 
 
65
#define HY_PLATFORM_DOUBLE_ORDER
 
66
 
 
67
/**
 
68
 * Define common types:
 
69
 * <ul>
 
70
 * <li><code>U_32 / I_32</code>  - unsigned/signed 32 bits</li>
 
71
 * <li><code>U_16 / I_16</code>  - unsigned/signed 16 bits</li>
 
72
 * <li><code>U_8 / I_8</code>    - unsigned/signed 8 bits (bytes -- not to be
 
73
 *                                 confused with char)</li>
 
74
 * </ul>
 
75
 */
 
76
 
 
77
typedef int I_32;
 
78
typedef short I_16;
 
79
typedef signed char I_8; /* chars can be unsigned */
 
80
typedef unsigned int U_32;
 
81
typedef unsigned short U_16;
 
82
typedef unsigned char U_8;
 
83
 
 
84
/**
 
85
 * Define platform specific types:
 
86
 * <ul>
 
87
 * <li><code>U_64 / I_64</code>  - unsigned/signed 64 bits</li>
 
88
 * </ul>
 
89
 */
 
90
 
 
91
#if defined(LINUX) || defined(FREEBSD) || defined(AIX) || defined(MACOSX) || defined(__CYGWIN32__)
 
92
 
 
93
#define DATA_TYPES_DEFINED
 
94
 
 
95
/* NOTE: Linux supports different processors -- do not assume 386 */
 
96
#if defined(HYX86_64) || defined(HYIA64) || defined(HYPPC64) || defined(HYS390X)
 
97
 
 
98
typedef unsigned long int U_64;         /* 64bits */
 
99
typedef long int I_64;
 
100
#define TOC_UNWRAP_ADDRESS(wrappedPointer) ((void *) (wrappedPointer)[0])
 
101
#define TOC_STORE_TOC(dest,wrappedPointer) (dest = ((UDATA*)wrappedPointer)[1])
 
102
 
 
103
#define HY_WORD64
 
104
 
 
105
#else
 
106
 
 
107
typedef long long I_64;
 
108
typedef unsigned long long U_64;
 
109
 
 
110
#endif
 
111
 
 
112
#if defined(HYS390X) || defined(HYS390) || defined(HYPPC64) || defined(HYPPC32)
 
113
#define HY_BIG_ENDIAN
 
114
#else
 
115
#define HY_LITTLE_ENDIAN
 
116
#endif
 
117
 
 
118
#if defined(HYPPC32) && defined(LINUX)
 
119
#define VA_PTR(valist) (&valist[0])
 
120
#endif
 
121
 
 
122
typedef double SYS_FLOAT;
 
123
#define HYCONST64(x) x##LL
 
124
#define NO_LVALUE_CASTING
 
125
#define FLOAT_EXTENDED  long double
 
126
#define PLATFORM_IS_ASCII
 
127
#define PLATFORM_LINE_DELIMITER "\012"
 
128
#define DIR_SEPARATOR '/'
 
129
#define DIR_SEPARATOR_STR "/"
 
130
#define PATH_SEPARATOR ':'
 
131
#define PATH_SEPARATOR_STR ":"
 
132
#if defined(AIX)
 
133
#define LIBPATH_ENV_VAR "LIBPATH"
 
134
#else
 
135
#if defined(MACOSX)
 
136
#define LIBPATH_ENV_VAR "DYLD_LIBRARY_PATH"
 
137
#else
 
138
#define LIBPATH_ENV_VAR "LD_LIBRARY_PATH"
 
139
#endif
 
140
#endif
 
141
#if defined(MACOSX)
 
142
#define PLATFORM_DLL_EXTENSION ".dylib"
 
143
#else
 
144
#define PLATFORM_DLL_EXTENSION ".so"
 
145
#endif
 
146
 
 
147
/**
 
148
 * No priorities on Linux
 
149
 */
 
150
 
 
151
#define HY_PRIORITY_MAP {0,0,0,0,0,0,0,0,0,0,0,0}
 
152
 
 
153
typedef U_32 BOOLEAN;
 
154
 
 
155
#endif
 
156
 
 
157
/* Win32 - Windows 3.1 & NT using Win32 */
 
158
#if defined(WIN32)
 
159
 
 
160
#define HY_LITTLE_ENDIAN
 
161
 
 
162
/* Define 64-bit integers for Windows */
 
163
typedef __int64 I_64;
 
164
typedef unsigned __int64 U_64;
 
165
 
 
166
typedef double SYS_FLOAT;
 
167
#define NO_LVALUE_CASTING
 
168
#define VMAPICALL _stdcall
 
169
#define VMCALL _cdecl
 
170
#define EXE_EXTENSION_CHAR  '.'
 
171
 
 
172
#define DIR_SEPARATOR '\\'
 
173
#define DIR_SEPARATOR_STR "\\"
 
174
#define PATH_SEPARATOR ';'
 
175
#define PATH_SEPARATOR_STR ";"
 
176
#define LIBPATH_ENV_VAR "PATH"
 
177
 
 
178
/* Modifications for the Alpha running WIN-NT */
 
179
#if defined(_ALPHA_)
 
180
#undef small                    /* defined as char in rpcndr.h */
 
181
typedef double FLOAT_EXTENDED;
 
182
#endif
 
183
 
 
184
#define HY_PRIORITY_MAP { \
 
185
  THREAD_PRIORITY_IDLE,             /* 0 */\
 
186
  THREAD_PRIORITY_LOWEST,           /* 1 */\
 
187
  THREAD_PRIORITY_BELOW_NORMAL,     /* 2 */\
 
188
  THREAD_PRIORITY_BELOW_NORMAL,     /* 3 */\
 
189
  THREAD_PRIORITY_BELOW_NORMAL,     /* 4 */\
 
190
  THREAD_PRIORITY_NORMAL,           /* 5 */\
 
191
  THREAD_PRIORITY_ABOVE_NORMAL,     /* 6 */\
 
192
  THREAD_PRIORITY_ABOVE_NORMAL,     /* 7 */\
 
193
  THREAD_PRIORITY_ABOVE_NORMAL,     /* 8 */\
 
194
  THREAD_PRIORITY_ABOVE_NORMAL,     /* 9 */\
 
195
  THREAD_PRIORITY_HIGHEST,          /*10 */\
 
196
  THREAD_PRIORITY_TIME_CRITICAL     /*11 */}
 
197
 
 
198
#endif /* defined(WIN32) */
 
199
 
 
200
#if defined(ZOS)
 
201
 
 
202
#define HY_BIG_ENDIAN
 
203
 
 
204
#define DATA_TYPES_DEFINED
 
205
typedef unsigned int   BOOLEAN;
 
206
#if defined (HYS390X)
 
207
typedef unsigned long U_64;
 
208
typedef long I_64;
 
209
#else
 
210
typedef signed long long        I_64;
 
211
typedef unsigned long long      U_64;
 
212
#endif
 
213
 
 
214
typedef double                          SYS_FLOAT;
 
215
 
 
216
#define HYCONST64(x) x##LL
 
217
 
 
218
#define NO_LVALUE_CASTING
 
219
#define PLATFORM_LINE_DELIMITER "\012"
 
220
#define DIR_SEPARATOR '/'
 
221
#define DIR_SEPARATOR_STR "/"
 
222
#define PATH_SEPARATOR ':'
 
223
#define PATH_SEPARATOR_STR ":"
 
224
#define LIBPATH_ENV_VAR "LIBPATH"
 
225
 
 
226
#define VA_PTR(valist) (&valist[0])
 
227
 
 
228
typedef struct {
 
229
#if !defined(HYS390X)
 
230
        char stuff[16];
 
231
#endif
 
232
        char *ada;
 
233
        void (*rawFnAddress)();
 
234
} HyFunctionDescriptor_T;
 
235
 
 
236
#define TOC_UNWRAP_ADDRESS(wrappedPointer) (((HyFunctionDescriptor_T *) (wrappedPointer))->rawFnAddress)
 
237
 
 
238
#define PLATFORM_DLL_EXTENSION ".so"
 
239
 
 
240
#ifdef HYS390X
 
241
#ifndef HY_WORD64
 
242
#define HY_WORD64
 
243
#endif /* ifndef HY_WORD64 */
 
244
#endif /* HYS390X */
 
245
 
 
246
#endif /* ZOS */
 
247
 
 
248
 
 
249
#if !defined(VMCALL)
 
250
#define VMCALL
 
251
#define VMAPICALL
 
252
#endif
 
253
#define PVMCALL VMCALL *
 
254
 
 
255
#define GLOBAL_DATA(symbol) ((void*)&(symbol))
 
256
#define GLOBAL_TABLE(symbol) GLOBAL_DATA(symbol)
 
257
 
 
258
/**
 
259
 * Define platform specific types:
 
260
 * <ul>
 
261
 * <li><code>UDATA</code>        - unsigned data, can be used as an integer or
 
262
 *                                 pointer storage</li>
 
263
 * <li><code>IDATA</code>        - signed data, can be used as an integer or
 
264
 *                                 pointer storage</li>
 
265
 * </ul>
 
266
 */
 
267
/* FIXME: POINTER64 */
 
268
#if defined(HYX86_64) || defined(HYIA64) || defined(HYPPC64) || defined(HYS390X) || defined(POINTER64)
 
269
 
 
270
typedef I_64 IDATA;
 
271
typedef U_64 UDATA;
 
272
 
 
273
#else /* this is default for non-64bit systems */
 
274
 
 
275
typedef I_32 IDATA;
 
276
typedef U_32 UDATA;
 
277
 
 
278
#endif /* defined(HYX86_64) */
 
279
 
 
280
#if !defined(DATA_TYPES_DEFINED)
 
281
/* no generic U_64 or I_64 */
 
282
 
 
283
/* don't typedef BOOLEAN since it's already def'ed on Win32 */
 
284
#define BOOLEAN UDATA
 
285
 
 
286
#ifndef HY_BIG_ENDIAN
 
287
#define HY_LITTLE_ENDIAN
 
288
#endif
 
289
 
 
290
#endif
 
291
 
 
292
#if !defined(HYCONST64)
 
293
#define HYCONST64(x) x##L
 
294
#endif
 
295
 
 
296
#if !defined(HY_DEFAULT_SCHED)
 
297
 
 
298
/**
 
299
 * By default, pthreads platforms use the <code>SCHED_OTHER</code> thread
 
300
 * scheduling policy.
 
301
 */
 
302
 
 
303
#define HY_DEFAULT_SCHED SCHED_OTHER
 
304
#endif
 
305
 
 
306
#if !defined(HY_PRIORITY_MAP)
 
307
 
 
308
/**
 
309
 * If no priority map if provided, priorities will be determined
 
310
 * algorithmically.
 
311
 */
 
312
 
 
313
#endif
 
314
 
 
315
#if !defined(FALSE)
 
316
#define FALSE   ((BOOLEAN) 0)
 
317
#if !defined(TRUE)
 
318
#define TRUE    ((BOOLEAN) (!FALSE))
 
319
#endif
 
320
#endif
 
321
 
 
322
#if !defined(NULL)
 
323
#if defined(__cplusplus)
 
324
#define NULL    (0)
 
325
#else
 
326
#define NULL    ((void *)0)
 
327
#endif
 
328
#endif
 
329
#define USE_PROTOTYPES
 
330
#if defined(USE_PROTOTYPES)
 
331
#define PROTOTYPE(x)  x
 
332
#define VARARGS   , ...
 
333
#else
 
334
#define PROTOTYPE(x)  ()
 
335
#define VARARGS
 
336
#endif
 
337
 
 
338
/**
 
339
 * Assign the default line delimiter, if it was not set.
 
340
 */
 
341
 
 
342
#if !defined(PLATFORM_LINE_DELIMITER)
 
343
#define PLATFORM_LINE_DELIMITER "\015\012"
 
344
#endif
 
345
 
 
346
/**
 
347
 * Set the max path length, if it was not set.
 
348
 */
 
349
 
 
350
#if !defined(MAX_IMAGE_PATH_LENGTH)
 
351
#define MAX_IMAGE_PATH_LENGTH (2048)
 
352
#endif
 
353
typedef double ESDOUBLE;
 
354
typedef float ESSINGLE;
 
355
 
 
356
/**
 
357
 * Helpers for U_64s.
 
358
 */
 
359
 
 
360
#define CLEAR_U64(u64)  (u64 = (U_64)0)
 
361
#define LOW_LONG(l) (*((U_32 *) &(l)))
 
362
#define HIGH_LONG(l)  (*(((U_32 *) &(l)) + 1))
 
363
#define I8(x)       ((I_8) (x))
 
364
#define I8P(x)      ((I_8 *) (x))
 
365
#define U16(x)      ((U_16) (x))
 
366
#define I16(x)      ((I_16) (x))
 
367
#define I16P(x)     ((I_16 *) (x))
 
368
#define U32(x)      ((U_32) (x))
 
369
#define I32(x)      ((I_32) (x))
 
370
#define I32P(x)     ((I_32 *) (x))
 
371
#define U16P(x)     ((U_16 *) (x))
 
372
#define U32P(x)     ((U_32 *) (x))
 
373
#define OBJP(x)     ((HyObject *) (x))
 
374
#define OBJPP(x)    ((HyObject **) (x))
 
375
#define OBJPPP(x)   ((HyObject ***) (x))
 
376
#define CLASSP(x)   ((Class *) (x))
 
377
#define CLASSPP(x)  ((Class **) (x))
 
378
#define BYTEP(x)    ((BYTE *) (x))
 
379
 
 
380
/**
 
381
 * Test - was conflicting with OS2.h
 
382
 */
 
383
 
 
384
#define ESCHAR(x)   ((CHARACTER) (x))
 
385
#define FLT(x)      ((FLOAT) x)
 
386
#define FLTP(x)     ((FLOAT *) (x))
 
387
#if defined(NO_LVALUE_CASTING)
 
388
#define LI8(x)      (*((I_8 *) &(x)))
 
389
#define LI8P(x)     (*((I_8 **) &(x)))
 
390
#define LU16(x)     (*((U_16 *) &(x)))
 
391
#define LI16(x)     (*((I_16 *) &(x)))
 
392
#define LU32(x)     (*((U_32 *) &(x)))
 
393
#define LI32(x)     (*((I_32 *) &(x)))
 
394
#define LI32P(x)    (*((I_32 **) &(x)))
 
395
#define LU16P(x)    (*((U_16 **) &(x)))
 
396
#define LU32P(x)    (*((U_32 **) &(x)))
 
397
#define LOBJP(x)    (*((HyObject **) &(x)))
 
398
#define LOBJPP(x)   (*((HyObject ***) &(x)))
 
399
#define LOBJPPP(x)  (*((HyObject ****) &(x))
 
400
#define LCLASSP(x)  (*((Class **) &(x)))
 
401
#define LBYTEP(x)   (*((BYTE **) &(x)))
 
402
#define LCHAR(x)    (*((CHARACTER) &(x)))
 
403
#define LFLT(x)     (*((FLOAT) &x))
 
404
#define LFLTP(x)    (*((FLOAT *) &(x)))
 
405
#else
 
406
#define LI8(x)      I8((x))
 
407
#define LI8P(x)     I8P((x))
 
408
#define LU16(x)     U16((x))
 
409
#define LI16(x)     I16((x))
 
410
#define LU32(x)     U32((x))
 
411
#define LI32(x)     I32((x))
 
412
#define LI32P(x)    I32P((x))
 
413
#define LU16P(x)    U16P((x))
 
414
#define LU32P(x)    U32P((x))
 
415
#define LOBJP(x)    OBJP((x))
 
416
#define LOBJPP(x)   OBJPP((x))
 
417
#define LOBJPPP(x)  OBJPPP((x))
 
418
#define LIOBJP(x)   IOBJP((x))
 
419
#define LCLASSP(x)  CLASSP((x))
 
420
#define LBYTEP(x)   BYTEP((x))
 
421
#define LCHAR(x)    CHAR((x))
 
422
#define LFLT(x)     FLT((x))
 
423
#define LFLTP(x)    FLTP((x))
 
424
#endif
 
425
 
 
426
/**
 
427
 * Macros for converting between words and longs and accessing bits.
 
428
 */
 
429
 
 
430
#define HIGH_WORD(x)  U16(U32((x)) >> 16)
 
431
#define LOW_WORD(x)   U16(U32((x)) & 0xFFFF)
 
432
#define LOW_BIT(o)    (U32((o)) & 1)
 
433
#define LOW_2_BITS(o) (U32((o)) & 3)
 
434
#define LOW_3_BITS(o) (U32((o)) & 7)
 
435
#define LOW_4_BITS(o) (U32((o)) & 15)
 
436
#define MAKE_32(h, l) ((U32((h)) << 16) | U32((l)))
 
437
#define MAKE_64(h, l) ((((I_64)(h)) << 32) | (l))
 
438
#if defined(__cplusplus)
 
439
#define HY_CFUNC "C"
 
440
#define HY_CDATA "C"
 
441
#else
 
442
#define HY_CFUNC
 
443
#define HY_CDATA
 
444
#endif
 
445
 
 
446
/**
 
447
 * Macros for tagging functions which read/write the vm thread.
 
448
 */
 
449
 
 
450
#define READSVMTHREAD
 
451
#define WRITESVMTHREAD
 
452
#define REQUIRESSTACKFRAME
 
453
 
 
454
/**
 
455
 * Macro for tagging functions, which never return.
 
456
 */
 
457
 
 
458
#if defined(__GNUC__)
 
459
 
 
460
/**
 
461
 * On GCC, we can actually pass this information on to the compiler.
 
462
 */
 
463
 
 
464
#define NORETURN __attribute__((noreturn))
 
465
#else
 
466
#define NORETURN
 
467
#endif
 
468
 
 
469
/**
 
470
 * On some systems va_list is an array type.  This is probably in
 
471
 * violation of the ANSI C spec, but it's not entirely clear.  Because of
 
472
 * this, we end up with an undesired extra level of indirection if we take
 
473
 * the address of a va_list argument. 
 
474
 *
 
475
 * To get it right, always use the VA_PTR macro
 
476
 */
 
477
 
 
478
#if !defined(VA_PTR)
 
479
#define VA_PTR(valist) (&valist)
 
480
#endif
 
481
#if !defined(TOC_UNWRAP_ADDRESS)
 
482
#define TOC_UNWRAP_ADDRESS(wrappedPointer) (wrappedPointer)
 
483
#endif
 
484
 
 
485
#if !defined(TOC_STORE_TOC)
 
486
#define TOC_STORE_TOC(dest,wrappedPointer)
 
487
#endif
 
488
/**
 
489
 * Macros for accessing I_64 values.
 
490
 */
 
491
 
 
492
#if defined(ATOMIC_LONG_ACCESS)
 
493
#define PTR_LONG_STORE(dstPtr, aLongPtr) ((*U32P(dstPtr) = *U32P(aLongPtr)), (*(U32P(dstPtr)+1) = *(U32P(aLongPtr)+1)))
 
494
#define PTR_LONG_VALUE(dstPtr, aLongPtr) ((*U32P(aLongPtr) = *U32P(dstPtr)), (*(U32P(aLongPtr)+1) = *(U32P(dstPtr)+1)))
 
495
#else
 
496
#define PTR_LONG_STORE(dstPtr, aLongPtr) (*(dstPtr) = *(aLongPtr))
 
497
#define PTR_LONG_VALUE(dstPtr, aLongPtr) (*(aLongPtr) = *(dstPtr))
 
498
#endif
 
499
 
 
500
/**
 
501
 * Macro used when declaring tables which require relocations.
 
502
 */
 
503
 
 
504
#if !defined(HYCONST_TABLE)
 
505
#define HYCONST_TABLE const
 
506
#endif
 
507
 
 
508
/**
 
509
 * ANSI qsort is not always available.
 
510
 */
 
511
 
 
512
#if !defined(HY_SORT)
 
513
#define HY_SORT(base, nmemb, size, compare) qsort((base), (nmemb), (size), (compare))
 
514
#endif
 
515
 
 
516
/**
 
517
 * Helper macros for storing/restoring pointers to jlong.
 
518
 */
 
519
#define jlong2addr(a, x) ((a *)((IDATA)(x)))
 
520
#define addr2jlong(x) ((jlong)((IDATA)(x)))
 
521
 
 
522
#endif /* hycomp_h */