Compile fixes.
[SquirrelJME.git] / nanocoat / include / sjme / stdTypes.h
blob11d2c6d29260059c54d44ad30bb83d4cbe7ca9e4
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 /**
11 * Standard C types.
13 * @since 2024/08/09
16 #ifndef SQUIRRELJME_STDTYPES_H
17 #define SQUIRRELJME_STDTYPES_H
19 #include <stdlib.h>
20 #include <stdint.h>
22 #include "sjme/config.h"
24 /* Anti-C++. */
25 #ifdef __cplusplus
26 #ifndef SJME_CXX_IS_EXTERNED
27 #define SJME_CXX_IS_EXTERNED
28 #define SJME_CXX_SQUIRRELJME_STDTYPES_H
29 extern "C"
31 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
32 #endif /* #ifdef __cplusplus */
34 /*--------------------------------------------------------------------------*/
36 /**
37 * Basic data type identifier.
39 * @since 2023/07/25
41 typedef enum sjme_basicTypeId
43 /** Integer. */
44 SJME_BASIC_TYPE_ID_INTEGER = 0,
46 /** Integer. */
47 SJME_JAVA_TYPE_ID_INTEGER = SJME_BASIC_TYPE_ID_INTEGER,
49 /** Long. */
50 SJME_BASIC_TYPE_ID_LONG = 1,
52 /** Long. */
53 SJME_JAVA_TYPE_ID_LONG = SJME_BASIC_TYPE_ID_LONG,
55 /** Float. */
56 SJME_BASIC_TYPE_ID_FLOAT = 2,
58 /** Float. */
59 SJME_JAVA_TYPE_ID_FLOAT = SJME_BASIC_TYPE_ID_FLOAT,
61 /** Double. */
62 SJME_BASIC_TYPE_ID_DOUBLE = 3,
64 /** Double. */
65 SJME_JAVA_TYPE_ID_DOUBLE = SJME_BASIC_TYPE_ID_DOUBLE,
67 /** Object. */
68 SJME_BASIC_TYPE_ID_OBJECT = 4,
70 /** Object. */
71 SJME_JAVA_TYPE_ID_OBJECT = SJME_BASIC_TYPE_ID_OBJECT,
73 /** The number of Java type IDs. */
74 SJME_NUM_JAVA_TYPE_IDS = 5,
76 /** Boolean or byte. */
77 SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE = SJME_NUM_JAVA_TYPE_IDS,
79 /** Character or short type. */
80 SJME_JAVA_TYPE_ID_SHORT_OR_CHAR = 6,
82 /** Void type. */
83 SJME_BASIC_TYPE_ID_VOID = 7,
85 /** Void type. */
86 SJME_JAVA_TYPE_ID_VOID = SJME_BASIC_TYPE_ID_VOID,
88 /** End of extended Java types. */
89 SJME_NUM_EXTENDED_JAVA_TYPE_IDS = 8,
91 /** Short. */
92 SJME_BASIC_TYPE_ID_SHORT = SJME_NUM_EXTENDED_JAVA_TYPE_IDS,
94 /** Character. */
95 SJME_BASIC_TYPE_ID_CHARACTER = 9,
97 /** Specifically boolean. */
98 SJME_BASIC_TYPE_ID_BOOLEAN = 10,
100 /** Specifically jbyte. */
101 SJME_BASIC_TYPE_ID_BYTE = 11,
103 /** Number of basic type IDs. */
104 SJME_NUM_BASIC_TYPE_IDS = 11
105 } sjme_basicTypeId;
108 * Boolean type.
110 * @since 2023/07/25
112 typedef enum sjme_jboolean
114 SJME_JNI_FALSE = 0,
116 SJME_JNI_TRUE = 1
117 } sjme_jboolean;
119 /** Basic @c sjme_jboolean type identifier. */
120 #define SJME_TYPEOF_BASIC_sjme_jboolean SJME_BASIC_TYPE_ID_BOOLEAN
122 /** Java @c sjme_jboolean type identifier. */
123 #define SJME_TYPEOF_JAVA_sjme_jboolean SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE
125 /** Is a pointer for @c sjme_jboolean ? */
126 #define SJME_TYPEOF_IS_POINTER_sjme_jboolean 0
129 * Byte type.
131 * @since 2023/07/25
133 typedef int8_t sjme_jbyte;
135 /** Basic @c sjme_jbyte type identifier. */
136 #define SJME_TYPEOF_BASIC_sjme_jbyte SJME_BASIC_TYPE_ID_BYTE
138 /** Java @c sjme_jbyte type identifier. */
139 #define SJME_TYPEOF_JAVA_sjme_jbyte SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE
141 /** Is a pointer for @c sjme_jbyte ? */
142 #define SJME_TYPEOF_IS_POINTER_sjme_jbyte 0
145 * Promoted @c sjme_jbyte .
147 * @since 2024/06/20
149 typedef int sjme_jbyte_promoted;
152 * Unsigned byte type.
154 * @since 2023/08/09
156 typedef uint8_t sjme_jubyte;
158 /** Basic @c sjme_jubyte type identifier. */
159 #define SJME_TYPEOF_BASIC_sjme_jubyte SJME_BASIC_TYPE_ID_BYTE
161 /** Java @c sjme_jubyte type identifier. */
162 #define SJME_TYPEOF_JAVA_sjme_jubyte SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE
164 /** Is a pointer for @c sjme_jubyte ? */
165 #define SJME_TYPEOF_IS_POINTER_sjme_jubyte 0
168 * Promoted @c sjme_jubyte .
170 * @since 2024/06/20
172 typedef int sjme_jubyte_promoted;
175 * Short type.
177 * @since 2023/07/25
179 typedef int16_t sjme_jshort;
181 /** Basic @c sjme_jshort type identifier. */
182 #define SJME_TYPEOF_BASIC_sjme_jshort SJME_BASIC_TYPE_ID_SHORT
184 /** Java @c sjme_jshort type identifier. */
185 #define SJME_TYPEOF_JAVA_sjme_jshort SJME_JAVA_TYPE_ID_INTEGER
187 /** Is a pointer for @c sjme_jshort ? */
188 #define SJME_TYPEOF_IS_POINTER_sjme_jshort 0
191 * Promoted @c sjme_jshort .
193 * @since 2024/06/20
195 typedef int sjme_jshort_promoted;
198 * Character type.
200 * @since 2023/07/25
202 typedef uint16_t sjme_jchar;
204 /** Basic @c sjme_jchar type identifier. */
205 #define SJME_TYPEOF_BASIC_sjme_jchar SJME_BASIC_TYPE_ID_CHARACTER
207 /** Java @c sjme_jchar type identifier. */
208 #define SJME_TYPEOF_JAVA_sjme_jchar SJME_JAVA_TYPE_ID_INTEGER
210 /** Is a pointer for @c sjme_jchar ? */
211 #define SJME_TYPEOF_IS_POINTER_sjme_jchar 0
214 * Promoted @c sjme_jchar .
216 * @since 2024/06/20
218 typedef int sjme_jchar_promoted;
221 * Integer type.
223 * @since 2023/07/25
225 typedef int32_t sjme_jint;
227 /** Basic @c sjme_jint type identifier. */
228 #define SJME_TYPEOF_BASIC_sjme_jint SJME_BASIC_TYPE_ID_INTEGER
230 /** Java @c sjme_jint type identifier. */
231 #define SJME_TYPEOF_JAVA_sjme_jint SJME_JAVA_TYPE_ID_INTEGER
233 /** Is a pointer for @c sjme_jint ? */
234 #define SJME_TYPEOF_IS_POINTER_sjme_jint 0
237 * Unsigned integer type.
239 * @since 2023/11/20
241 typedef uint32_t sjme_juint;
243 /** Basic @c sjme_juint type identifier. */
244 #define SJME_TYPEOF_BASIC_sjme_juint SJME_BASIC_TYPE_ID_INTEGER
246 /** Java @c sjme_juint type identifier. */
247 #define SJME_TYPEOF_JAVA_sjme_juint SJME_JAVA_TYPE_ID_INTEGER
249 /** Is a pointer for @c sjme_juint ? */
250 #define SJME_TYPEOF_IS_POINTER_sjme_juint 0
253 * Fixed point.
255 * @since 2024/06/27
257 typedef sjme_jint sjme_fixed;
260 * C Character.
262 * @since 2024/01/03
264 typedef char sjme_cchar;
266 #if defined(CHAR_BIT) && (CHAR_BIT == 64)
267 /** Basic @c sjme_cchar type identifier. */
268 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_LONG
269 #elif defined(CHAR_BIT) && (CHAR_BIT == 32)
270 /** Basic @c sjme_cchar type identifier. */
271 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_INTEGER
272 #elif defined(CHAR_BIT) && (CHAR_BIT == 16)
273 /** Basic @c sjme_cchar type identifier. */
274 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_SHORT
275 #else
276 /** Basic @c sjme_cchar type identifier. */
277 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_BYTE
278 #endif
280 /** Is a pointer for @c sjme_cchar ? */
281 #define SJME_TYPEOF_IS_POINTER_sjme_cchar 0
283 #if defined(SJME_CONFIG_HAS_ARCH_IA16)
285 * Pointer to C string.
287 * @since 2023/12/17
289 typedef sjme_cchar huge* sjme_lpstr;
290 #else
292 * Pointer to C string.
294 * @since 2023/12/17
296 typedef sjme_cchar* sjme_lpstr;
297 #endif
299 /** Basic @c sjme_lpstr type identifier. */
300 #define SJME_TYPEOF_BASIC_sjme_lpstr SJME_BASIC_TYPE_ID_OBJECT
302 /** Is a pointer for @c sjme_lpstr ? */
303 #define SJME_TYPEOF_IS_POINTER_sjme_lpstr 1
305 #if defined(SJME_CONFIG_HAS_ARCH_IA16)
307 * Pointer to constant C string.
309 * @since 2023/12/17
311 typedef const sjme_cchar huge* sjme_lpcstr;
312 #else
314 * Pointer to constant C string.
316 * @since 2023/12/17
318 typedef const sjme_cchar* sjme_lpcstr;
319 #endif
321 /** Basic @c sjme_lpcstr type identifier. */
322 #define SJME_TYPEOF_BASIC_sjme_lpcstr SJME_BASIC_TYPE_ID_OBJECT
324 /** Is a pointer for @c sjme_lpcstr ? */
325 #define SJME_TYPEOF_IS_POINTER_sjme_lpcstr 1
327 #if defined(SJME_CONFIG_HAS_ARCH_IA16)
329 * Generic pointer.
331 * @since 2023/12/27
333 typedef void huge* sjme_pointer;
334 #else
336 * Generic pointer.
338 * @since 2023/12/27
340 typedef void* sjme_pointer;
341 #endif
343 /** Basic @c sjme_pointer type identifier. */
344 #define SJME_TYPEOF_BASIC_sjme_pointer SJME_BASIC_TYPE_ID_OBJECT
346 /** Is a pointer for @c sjme_pointer ? */
347 #define SJME_TYPEOF_IS_POINTER_sjme_pointer 1
349 #if defined(SJME_CONFIG_HAS_ARCH_IA16)
351 * Generic pointer to const data.
353 * @since 2023/12/27
355 typedef const void huge* sjme_cpointer;
356 #else
358 * Generic pointer to const data.
360 * @since 2023/12/27
362 typedef const void* sjme_cpointer;
363 #endif
365 /** Basic @c sjme_cpointer type identifier. */
366 #define SJME_TYPEOF_BASIC_sjme_cpointer SJME_BASIC_TYPE_ID_OBJECT
368 /** Is a pointer for @c sjme_cpointer ? */
369 #define SJME_TYPEOF_IS_POINTER_sjme_cpointer 1
372 * Buffer type.
374 * @since 2024/08/13
376 typedef sjme_pointer sjme_buffer;
379 * Const buffer type.
381 * @since 2024/08/13
383 typedef sjme_cpointer sjme_cbuffer;
386 * Integer based pointer.
388 * @since 2024/04/06
390 typedef intptr_t sjme_intPointer;
392 /** Calculates a pointer offset. */
393 #define SJME_POINTER_OFFSET(base, off) \
394 (sjme_pointer)(((sjme_intPointer)(base)) + ((sjme_intPointer)(off)))
396 #if defined(SJME_CONFIG_HAS_POINTER64)
397 #define SJME_TYPEOF_BASIC_sjme_intPointer SJME_TYPEOF_BASIC_sjme_jpointer
398 #else
399 #define SJME_TYPEOF_BASIC_sjme_intPointer SJME_TYPEOF_BASIC_sjme_juint
400 #endif
402 #define SJME_TYPEOF_IS_POINTER_sjme_intPointer 0
405 * Long value.
407 * @since 2023/07/25
409 typedef union sjme_jlong
411 /** Parts of the long. */
412 struct
414 #if defined(SJME_CONFIG_HAS_LITTLE_ENDIAN)
415 /** Low value. */
416 sjme_juint lo;
418 /** High value. */
419 sjme_jint hi;
420 #else
421 /** High value. */
422 sjme_jint hi;
424 /** Low value. */
425 sjme_juint lo;
426 #endif
427 } part;
429 /** The full long. */
430 int64_t full;
431 } sjme_jlong;
433 /** Basic @c sjme_jlong type identifier. */
434 #define SJME_TYPEOF_BASIC_sjme_jlong SJME_BASIC_TYPE_ID_LONG
436 /** Java @c sjme_jlong type identifier. */
437 #define SJME_TYPEOF_JAVA_sjme_jlong SJME_JAVA_TYPE_ID_LONG
439 /** Is a pointer for @c sjme_jlong ? */
440 #define SJME_TYPEOF_IS_POINTER_sjme_jlong 0
443 * Float value.
445 * @sinc 2023/07/25
447 typedef struct sjme_jfloat
449 sjme_jint value;
450 } sjme_jfloat;
452 /** Basic @c sjme_jfloat type identifier. */
453 #define SJME_TYPEOF_BASIC_sjme_jfloat SJME_BASIC_TYPE_ID_FLOAT
455 /** Java @c sjme_jfloat type identifier. */
456 #define SJME_TYPEOF_JAVA_sjme_jfloat SJME_JAVA_TYPE_ID_FLOAT
458 /** Is a pointer for @c sjme_jfloat ? */
459 #define SJME_TYPEOF_IS_POINTER_sjme_jfloat 0
462 * Double value.
464 * @sinc 2023/07/25
466 typedef struct sjme_jdouble
468 #if defined(SJME_CONFIG_HAS_LITTLE_ENDIAN)
469 /** Low value. */
470 sjme_juint lo;
472 /** High value. */
473 sjme_juint hi;
474 #else
475 /** High value. */
476 sjme_juint hi;
478 /** Low value. */
479 sjme_juint lo;
480 #endif
481 } sjme_jdouble;
483 /** Basic @c sjme_jdouble type identifier. */
484 #define SJME_TYPEOF_BASIC_sjme_jdouble SJME_BASIC_TYPE_ID_DOUBLE
486 /** Java @c sjme_jdouble type identifier. */
487 #define SJME_TYPEOF_JAVA_sjme_jdouble SJME_JAVA_TYPE_ID_DOUBLE
489 /** Is a pointer for @c sjme_jdouble ? */
490 #define SJME_TYPEOF_IS_POINTER_sjme_jdouble 0
493 * Temporary index.
495 * @since 2023/07/25
497 typedef sjme_jint sjme_tempIndex;
500 * A range of values.
502 * @since 2024/01/03
504 typedef struct sjme_range
506 /** Start of the range. */
507 sjme_jint start;
509 /** End of the range. */
510 sjme_jint end;
511 } sjme_range;
514 * Represents a pointer and a length.
516 * @since 2024/02/04
518 typedef struct sjme_pointerLen
520 /** The pointer to the data. */
521 sjme_pointer pointer;
523 /** The length of the pointer. */
524 sjme_jint length;
525 } sjme_pointerLen;
527 /** The Java type ID. */
528 typedef sjme_basicTypeId sjme_javaTypeId;
531 * Represents multiple type IDs.
533 * @since 2023/08/09
535 typedef struct sjme_basicTypeIds
537 /** The number of IDs. */
538 sjme_jint count;
540 /** The IDs. */
541 const sjme_javaTypeId ids[sjme_flexibleArrayCount];
542 } sjme_basicTypeIds;
545 * Base object information.
547 * @since 2023/07/25
549 typedef struct sjme_jobjectBase sjme_jobjectBase;
552 * Object type.
554 * @since 2023/07/25
556 typedef sjme_jobjectBase* sjme_jobject;
558 /** Basic @c sjme_jobject type identifier. */
559 #define SJME_TYPEOF_BASIC_sjme_jobject SJME_BASIC_TYPE_ID_OBJECT
561 /** Java @c sjme_jobject type identifier. */
562 #define SJME_TYPEOF_JAVA_sjme_jobject SJME_BASIC_TYPE_ID_OBJECT
564 /** Is a pointer for @c sjme_jobject ? */
565 #define SJME_TYPEOF_IS_POINTER_sjme_jobject 1
568 * Generic value union.
570 * @since 2024/01/05
572 typedef union sjme_jvalue
574 /** Boolean. */
575 sjme_jboolean z;
577 /** Byte. */
578 sjme_jbyte b;
580 /** Character. */
581 sjme_jchar c;
583 /** Short. */
584 sjme_jshort s;
586 /** Integer. */
587 sjme_jint i;
589 /** Long. */
590 sjme_jlong j;
592 /** Float. */
593 sjme_jfloat f;
595 /** Double. */
596 sjme_jdouble d;
598 /** Object/Reference. */
599 sjme_jobject l;
600 } sjme_jvalue;
603 * Structure which stores the pooled memory allocator.
605 * @since 2023/11/18
607 typedef struct sjme_alloc_pool sjme_alloc_pool;
609 /*--------------------------------------------------------------------------*/
611 /* Anti-C++. */
612 #ifdef __cplusplus
613 #ifdef SJME_CXX_SQUIRRELJME_STDTYPES_H
615 #undef SJME_CXX_SQUIRRELJME_STDTYPES_H
616 #undef SJME_CXX_IS_EXTERNED
617 #endif /* #ifdef SJME_CXX_SQUIRRELJME_STDTYPES_H */
618 #endif /* #ifdef __cplusplus */
620 #endif /* SQUIRRELJME_STDTYPES_H */