Cherry pick dynamic library implementation from ScritchUI branch.
[SquirrelJME.git] / nanocoat / include / sjme / nvm.h
blobdfdaa96f3e039410b2bd08bef0a3c4d8a38e3ce9
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 * SquirrelJME NanoCoat Virtual Machine Header Definitions.
13 * @since 2023/07/25
16 #ifndef SQUIRRELJME_NVM_H
17 #define SQUIRRELJME_NVM_H
19 #include <stdlib.h>
20 #include <stdint.h>
21 #include <setjmp.h>
23 #include "sjme/config.h"
25 /* Anti-C++. */
26 #ifdef __cplusplus
27 #ifndef SJME_CXX_IS_EXTERNED
28 #define SJME_CXX_IS_EXTERNED
29 #define SJME_CXX_SQUIRRELJME_NVM_H
30 extern "C" {
31 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
32 #endif /* #ifdef __cplusplus */
34 /*--------------------------------------------------------------------------*/
36 /**
37 * Pastes two tokens together.
39 * @param a The first token.
40 * @param b The second token.
41 * @since 2023/11/15
43 #define SJME_TOKEN_PASTE(a, b) a##b
45 /**
46 * Pasting two tokens but with preprocessing.
48 * @param a The first token.
49 * @param b The second token.
50 * @since 2023/11/16
52 #define SJME_TOKEN_PASTE_PP(a, b) SJME_TOKEN_PASTE(a, b)
54 /**
55 * Pastes three tokens together.
57 * @param a The first token.
58 * @param b The second token.
59 * @param c The third token.
60 * @since 2024/01/03
62 #define SJME_TOKEN_PASTE3(a, b, c) a##b##c
64 /**
65 * Pasting three tokens but with preprocessing.
67 * @param a The first token.
68 * @param b The second token.
69 * @param c The third token.
70 * @since 2024/01/03
72 #define SJME_TOKEN_PASTE3_PP(a, b, c) SJME_TOKEN_PASTE3(a, b, c)
74 /**
75 * Pastes four tokens together.
77 * @param a The first token.
78 * @param b The second token.
79 * @param c The third token.
80 * @param d The fourth token.
81 * @since 2024/01/03
83 #define SJME_TOKEN_PASTE4(a, b, c, d) a##b##c##d
85 /**
86 * Pasting four tokens but with preprocessing.
88 * @param a The first token.
89 * @param b The second token.
90 * @param c The third token.
91 * @param d The fourth token.
92 * @since 2024/01/03
94 #define SJME_TOKEN_PASTE4_PP(a, b, c, d) SJME_TOKEN_PASTE4(a, b, c, d)
96 /**
97 * Pastes five tokens together.
99 * @param a The first token.
100 * @param b The second token.
101 * @param c The third token.
102 * @param d The fourth token.
103 * @param e The fifth token.
104 * @since 2024/01/03
106 #define SJME_TOKEN_PASTE5(a, b, c, d, e) a##b##c##d##e
109 * Pasting five tokens but with preprocessing.
111 * @param a The first token.
112 * @param b The second token.
113 * @param c The third token.
114 * @param d The fourth token.
115 * @param e The fifth token.
116 * @since 2024/01/03
118 #define SJME_TOKEN_PASTE5_PP(a, b, c, d, e) SJME_TOKEN_PASTE5(a, b, c, d, e)
121 * Stringifies the given token.
123 * @param s The token to stringify.
124 * @since 2023/11/24
126 #define SJME_TOKEN_STRING(s) #s
129 * Stringifies the given token.
131 * @param s The token to stringify.
132 * @since 2023/11/24
134 #define SJME_TOKEN_STRING_PP(s) SJME_TOKEN_STRING(s)
137 * Represents a single token.
139 * @param t The token to resolve.
140 * @since 2023/12/17
142 #define SJME_TOKEN_SINGLE(t) t
144 #define SJME_TOKEN_STARS_0
145 #define SJME_TOKEN_STARS_1 *
146 #define SJME_TOKEN_STARS_2 **
147 #define SJME_TOKEN_STARS_3 ***
148 #define SJME_TOKEN_STARS_4 ****
149 #define SJME_TOKEN_STARS_5 *****
150 #define SJME_TOKEN_STARS_6 ******
151 #define SJME_TOKEN_STARS_7 *******
152 #define SJME_TOKEN_STARS_8 ********
153 #define SJME_TOKEN_STARS_9 *********
155 #define SJME_TOKEN_STARS_C0
156 #define SJME_TOKEN_STARS_C1 P
157 #define SJME_TOKEN_STARS_C2 PP
158 #define SJME_TOKEN_STARS_C3 PPP
159 #define SJME_TOKEN_STARS_C4 PPPP
160 #define SJME_TOKEN_STARS_C5 PPPPP
161 #define SJME_TOKEN_STARS_C6 PPPPPP
162 #define SJME_TOKEN_STARS_C7 PPPPPPP
163 #define SJME_TOKEN_STARS_C8 PPPPPPPP
164 #define SJME_TOKEN_STARS_C9 PPPPPPPPP
166 #define SJME_TOKEN_STARS_H0 0
167 #define SJME_TOKEN_STARS_H1 1
168 #define SJME_TOKEN_STARS_H2 1
169 #define SJME_TOKEN_STARS_H3 1
170 #define SJME_TOKEN_STARS_H4 1
171 #define SJME_TOKEN_STARS_H5 1
172 #define SJME_TOKEN_STARS_H6 1
173 #define SJME_TOKEN_STARS_H7 1
174 #define SJME_TOKEN_STARS_H8 1
175 #define SJME_TOKEN_STARS_H9 1
178 * Generic pointer star types.
180 * @param type The type used.
181 * @param numPointerStars The number of pointer stars.
182 * @since 2024/01/09
184 #define SJME_TOKEN_TYPE(type, numPointerStars) \
185 type SJME_TOKEN_SINGLE(SJME_TOKEN_STARS_##numPointerStars)
188 * Semicolon token.
190 * @since 2024/01/09
192 #define SJME_TOKEN_SEMI ;
195 * Does this have pointer stars?
197 * @param numPointerStars The number of pointer stars.
198 * @since 2024/01/09
200 #define SJME_TOKEN_HAS_STARS(numPointerStars) \
201 SJME_TOKEN_SINGLE(SJME_TOKEN_STARS_H##numPointerStars)
203 /** SquirrelJME version string. */
204 #define SQUIRRELJME_VERSION SJME_TOKEN_STRING_PP(SQUIRRELJME_VERSION_TRIM)
207 * Calculates the size of a struct member.
209 * @param type The type of the struct.
210 * @param member The member to check.
211 * @return The size of the given member.
212 * @since 2023/11/16
214 #define SJME_SIZEOF_STRUCT_MEMBER(type, member) \
215 (sizeof((*((type*)0)).member))
218 * Uncommon structure size.
220 * @param structType The structure type.
221 * @param uncommonMember The uncommon member.
222 * @param uncommonSize The uncommon size to use.
223 * @since 2024/01/01
225 #define SJME_SIZEOF_UNCOMMON_N(structType, uncommonMember, uncommonSize) \
226 (sizeof(structType) + (offsetof(structType, \
227 uncommonMember[0]) - offsetof(structType, uncommonMember)) + \
228 (uncommonSize))
231 * Returns the uncommon member.
233 * @param structType The structure type.
234 * @param uncommonMember The uncommon member.
235 * @param uncommonType The uncommon type.
236 * @param base The base structure pointer to access.
237 * @since 2024/01/01
239 #define SJME_UNCOMMON_MEMBER(structType, uncommonMember, uncommonType, base) \
240 ((uncommonType*)(void*)(&((structType*)((base)))->uncommonMember))
243 * Basic data type identifier.
245 * @since 2023/07/25
247 typedef enum sjme_basicTypeId
249 /** Integer. */
250 SJME_BASIC_TYPE_ID_INTEGER = 0,
252 /** Integer. */
253 SJME_JAVA_TYPE_ID_INTEGER = SJME_BASIC_TYPE_ID_INTEGER,
255 /** Long. */
256 SJME_BASIC_TYPE_ID_LONG = 1,
258 /** Long. */
259 SJME_JAVA_TYPE_ID_LONG = SJME_BASIC_TYPE_ID_LONG,
261 /** Float. */
262 SJME_BASIC_TYPE_ID_FLOAT = 2,
264 /** Float. */
265 SJME_JAVA_TYPE_ID_FLOAT = SJME_BASIC_TYPE_ID_FLOAT,
267 /** Double. */
268 SJME_BASIC_TYPE_ID_DOUBLE = 3,
270 /** Double. */
271 SJME_JAVA_TYPE_ID_DOUBLE = SJME_BASIC_TYPE_ID_DOUBLE,
273 /** Object. */
274 SJME_BASIC_TYPE_ID_OBJECT = 4,
276 /** Object. */
277 SJME_JAVA_TYPE_ID_OBJECT = SJME_BASIC_TYPE_ID_OBJECT,
279 /** The number of Java type IDs. */
280 SJME_NUM_JAVA_TYPE_IDS = 5,
282 /** Boolean or byte. */
283 SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE = SJME_NUM_JAVA_TYPE_IDS,
285 /** Character or short type. */
286 SJME_JAVA_TYPE_ID_SHORT_OR_CHAR = 6,
288 /** Void type. */
289 SJME_BASIC_TYPE_ID_VOID = 7,
291 /** Void type. */
292 SJME_JAVA_TYPE_ID_VOID = SJME_BASIC_TYPE_ID_VOID,
294 /** End of extended Java types. */
295 SJME_NUM_EXTENDED_JAVA_TYPE_IDS = 8,
297 /** Short. */
298 SJME_BASIC_TYPE_ID_SHORT = SJME_NUM_EXTENDED_JAVA_TYPE_IDS,
300 /** Character. */
301 SJME_BASIC_TYPE_ID_CHARACTER = 9,
303 /** Specifically boolean. */
304 SJME_BASIC_TYPE_ID_BOOLEAN = 10,
306 /** Specifically jbyte. */
307 SJME_BASIC_TYPE_ID_BYTE = 11,
309 /** Number of basic type IDs. */
310 SJME_NUM_BASIC_TYPE_IDS = 11
311 } sjme_basicTypeId;
314 * Returns the basic type ID of the given type.
316 * @param type The type to get the basic type of.
317 * @since 2023/12/17
319 #define SJME_TYPEOF_BASIC(type) SJME_TOKEN_PASTE_PP(SJME_TYPEOF_BASIC_, type)
322 * Returns the java type ID of the given type.
324 * @param type The type to get the basic type of.
325 * @since 2023/12/17
327 #define SJME_TYPEOF_JAVA(type) SJME_TOKEN_PASTE_PP(SJME_TYPEOF_JAVA_, type)
329 #define SJME_TYPEOF_IS_POINTER_X00 0
330 #define SJME_TYPEOF_IS_POINTER_X10 1
331 #define SJME_TYPEOF_IS_POINTER_X01 1
332 #define SJME_TYPEOF_IS_POINTER_X11 1
335 * Is the given type a pointer?
337 * @param type The type used.
338 * @param numPointerStars The number of pointer stars.
339 * @return If this is a pointer or not.
340 * @since 2024/01/09
342 #define SJME_TYPEOF_IS_POINTER(type, numPointerStars) \
343 SJME_TOKEN_SINGLE(SJME_TOKEN_PASTE3_PP(SJME_TYPEOF_IS_POINTER_X, \
344 SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IS_POINTER_, type), \
345 SJME_TOKEN_PASTE_PP(SJME_TOKEN_STARS_H, numPointerStars)))
347 #define SJME_TYPEOF_IS_NOT_POINTER_X0 1
348 #define SJME_TYPEOF_IS_NOT_POINTER_X1 0
351 * Is the given type not a pointer?
353 * @param type The type used.
354 * @param numPointerStars The number of pointer stars.
355 * @return If this is not a pointer or it is one.
356 * @since 2024/01/09
358 #define SJME_TYPEOF_IS_NOT_POINTER(type, numPointerStars) \
359 SJME_TOKEN_SINGLE(SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IS_NOT_POINTER_X, \
360 SJME_TYPEOF_IS_POINTER(type, numPointerStars)))
362 #define SJME_TYPEOF_IF_POINTER_X0(snippet)
363 #define SJME_TYPEOF_IF_POINTER_X1(snippet) snippet
366 * If the type is a pointer, place the given snippet.
368 * @param type The type used.
369 * @param numPointerStars The number of pointer stars
370 * @param snippet The snippet to place.
371 * @return Either @c snippet or nothing.
372 * @since 2024/01/09
374 #define SJME_TYPEOF_IF_POINTER(type, numPointerStars, snippet) \
375 SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IF_POINTER_X, \
376 SJME_TYPEOF_IS_POINTER(type, numPointerStars))(snippet)
379 * If the type is not a pointer, place the given snippet.
381 * @param type The type used.
382 * @param numPointerStars The number of pointer stars
383 * @param snippet The snippet to place.
384 * @return Either @c snippet or nothing.
385 * @since 2024/01/09
387 #define SJME_TYPEOF_IF_NOT_POINTER(type, numPointerStars, snippet) \
388 SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IF_POINTER_X, \
389 SJME_TYPEOF_IS_NOT_POINTER(type, numPointerStars))(snippet)
391 #define SJME_TYPEOF_IF_POINTER_ORX0(snippet, orSnippet) orSnippet
392 #define SJME_TYPEOF_IF_POINTER_ORX1(snippet, orSnippet) snippet
395 * If the type is a pointer, place the given snippet.
397 * @param type The type used.
398 * @param numPointerStars The number of pointer stars
399 * @param snippet The snippet to place.
400 * @param orSnippet The snippet if it is a pointer.
401 * @return Either @c snippet or nothing.
402 * @since 2024/01/09
404 #define SJME_TYPEOF_IF_POINTER_OR(type, numPointerStars, snippet, orSnippet) \
405 SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IF_POINTER_ORX, \
406 SJME_TYPEOF_IS_POINTER(type, numPointerStars))(snippet, orSnippet)
409 * If the type is not a pointer, place the given snippet.
411 * @param type The type used.
412 * @param numPointerStars The number of pointer stars
413 * @param snippet The snippet to place.
414 * @param orSnippet The snippet if it is a pointer.
415 * @return Either @c snippet or nothing.
416 * @since 2024/01/09
418 #define SJME_TYPEOF_IF_NOT_POINTER_OR(type, numPointerStars, snippet, \
419 orSnippet) \
420 SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IF_POINTER_ORX, \
421 SJME_TYPEOF_IS_NOT_POINTER(type, numPointerStars))(snippet, orSnippet)
424 * Boolean type.
426 * @since 2023/07/25
428 typedef enum sjme_jboolean
430 SJME_JNI_FALSE = 0,
432 SJME_JNI_TRUE = 1
433 } sjme_jboolean;
435 /** Basic @c sjme_jboolean type identifier. */
436 #define SJME_TYPEOF_BASIC_sjme_jboolean SJME_BASIC_TYPE_ID_BOOLEAN
438 /** Java @c sjme_jboolean type identifier. */
439 #define SJME_TYPEOF_JAVA_sjme_jboolean SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE
441 /** Is a pointer for @c sjme_jboolean ? */
442 #define SJME_TYPEOF_IS_POINTER_sjme_jboolean 0
445 * Byte type.
447 * @since 2023/07/25
449 typedef int8_t sjme_jbyte;
451 /** Basic @c sjme_jbyte type identifier. */
452 #define SJME_TYPEOF_BASIC_sjme_jbyte SJME_BASIC_TYPE_ID_BYTE
454 /** Java @c sjme_jbyte type identifier. */
455 #define SJME_TYPEOF_JAVA_sjme_jbyte SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE
457 /** Is a pointer for @c sjme_jbyte ? */
458 #define SJME_TYPEOF_IS_POINTER_sjme_jbyte 0
461 * Unsigned byte type.
463 * @since 2023/08/09
465 typedef uint8_t sjme_jubyte;
467 /** Basic @c sjme_jubyte type identifier. */
468 #define SJME_TYPEOF_BASIC_sjme_jubyte SJME_BASIC_TYPE_ID_BYTE
470 /** Java @c sjme_jubyte type identifier. */
471 #define SJME_TYPEOF_JAVA_sjme_jubyte SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE
473 /** Is a pointer for @c sjme_jubyte ? */
474 #define SJME_TYPEOF_IS_POINTER_sjme_jubyte 0
477 * Short type.
479 * @since 2023/07/25
481 typedef int16_t sjme_jshort;
483 /** Basic @c sjme_jshort type identifier. */
484 #define SJME_TYPEOF_BASIC_sjme_jshort SJME_BASIC_TYPE_ID_SHORT
486 /** Java @c sjme_jshort type identifier. */
487 #define SJME_TYPEOF_JAVA_sjme_jshort SJME_JAVA_TYPE_ID_INTEGER
489 /** Is a pointer for @c sjme_jshort ? */
490 #define SJME_TYPEOF_IS_POINTER_sjme_jshort 0
493 * Character type.
495 * @since 2023/07/25
497 typedef uint16_t sjme_jchar;
499 /** Basic @c sjme_jchar type identifier. */
500 #define SJME_TYPEOF_BASIC_sjme_jchar SJME_BASIC_TYPE_ID_CHARACTER
502 /** Java @c sjme_jchar type identifier. */
503 #define SJME_TYPEOF_JAVA_sjme_jchar SJME_JAVA_TYPE_ID_INTEGER
505 /** Is a pointer for @c sjme_jchar ? */
506 #define SJME_TYPEOF_IS_POINTER_sjme_jchar 0
509 * Integer type.
511 * @since 2023/07/25
513 typedef int32_t sjme_jint;
515 /** Basic @c sjme_jint type identifier. */
516 #define SJME_TYPEOF_BASIC_sjme_jint SJME_BASIC_TYPE_ID_INTEGER
518 /** Java @c sjme_jint type identifier. */
519 #define SJME_TYPEOF_JAVA_sjme_jint SJME_JAVA_TYPE_ID_INTEGER
521 /** Is a pointer for @c sjme_jint ? */
522 #define SJME_TYPEOF_IS_POINTER_sjme_jint 0
525 * Unsigned integer type.
527 * @since 2023/11/20
529 typedef uint32_t sjme_juint;
531 /** Basic @c sjme_juint type identifier. */
532 #define SJME_TYPEOF_BASIC_sjme_juint SJME_BASIC_TYPE_ID_INTEGER
534 /** Java @c sjme_juint type identifier. */
535 #define SJME_TYPEOF_JAVA_sjme_juint SJME_JAVA_TYPE_ID_INTEGER
537 /** Is a pointer for @c sjme_juint ? */
538 #define SJME_TYPEOF_IS_POINTER_sjme_juint 0
541 * C Character.
543 * @since 2024/01/03
545 typedef char sjme_cchar;
547 #if defined(CHAR_BIT) && (CHAR_BIT == 64)
548 /** Basic @c sjme_cchar type identifier. */
549 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_LONG
550 #elif defined(CHAR_BIT) && (CHAR_BIT == 32)
551 /** Basic @c sjme_cchar type identifier. */
552 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_INTEGER
553 #elif defined(CHAR_BIT) && (CHAR_BIT == 16)
554 /** Basic @c sjme_cchar type identifier. */
555 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_SHORT
556 #else
557 /** Basic @c sjme_cchar type identifier. */
558 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_BYTE
559 #endif
561 /** Is a pointer for @c sjme_cchar ? */
562 #define SJME_TYPEOF_IS_POINTER_sjme_cchar 0
565 * Pointer to C string.
567 * @since 2023/12/17
569 typedef sjme_cchar* sjme_lpstr;
571 /** Basic @c sjme_lpstr type identifier. */
572 #define SJME_TYPEOF_BASIC_sjme_lpstr SJME_BASIC_TYPE_ID_OBJECT
574 /** Is a pointer for @c sjme_lpstr ? */
575 #define SJME_TYPEOF_IS_POINTER_sjme_lpstr 1
578 * Pointer to constant C string.
580 * @since 2023/12/17
582 typedef const sjme_cchar* sjme_lpcstr;
584 /** Basic @c sjme_lpcstr type identifier. */
585 #define SJME_TYPEOF_BASIC_sjme_lpcstr SJME_BASIC_TYPE_ID_OBJECT
587 /** Is a pointer for @c sjme_lpcstr ? */
588 #define SJME_TYPEOF_IS_POINTER_sjme_lpcstr 1
591 * Generic pointer.
593 * @since 2023/12/27
595 typedef void* sjme_pointer;
597 /** Basic @c sjme_pointer type identifier. */
598 #define SJME_TYPEOF_BASIC_sjme_pointer SJME_BASIC_TYPE_ID_OBJECT
600 /** Is a pointer for @c sjme_pointer ? */
601 #define SJME_TYPEOF_IS_POINTER_sjme_pointer 1
604 * Integer based pointer.
606 * @since 2024/04/06
608 typedef intptr_t sjme_intPointer;
611 * Long value.
613 * @since 2023/07/25
615 typedef struct sjme_jlong
617 #if defined(SJME_CONFIG_HAS_LITTLE_ENDIAN)
618 /** Low value. */
619 sjme_juint lo;
621 /** High value. */
622 sjme_jint hi;
623 #else
624 /** High value. */
625 sjme_jint hi;
627 /** Low value. */
628 sjme_juint lo;
629 #endif
630 } sjme_jlong;
632 /** Basic @c sjme_jlong type identifier. */
633 #define SJME_TYPEOF_BASIC_sjme_jlong SJME_BASIC_TYPE_ID_LONG
635 /** Java @c sjme_jlong type identifier. */
636 #define SJME_TYPEOF_JAVA_sjme_jlong SJME_JAVA_TYPE_ID_LONG
638 /** Is a pointer for @c sjme_jlong ? */
639 #define SJME_TYPEOF_IS_POINTER_sjme_jlong 0
642 * Float value.
644 * @sinc 2023/07/25
646 typedef struct sjme_jfloat
648 sjme_jint value;
649 } sjme_jfloat;
651 /** Basic @c sjme_jfloat type identifier. */
652 #define SJME_TYPEOF_BASIC_sjme_jfloat SJME_BASIC_TYPE_ID_FLOAT
654 /** Java @c sjme_jfloat type identifier. */
655 #define SJME_TYPEOF_JAVA_sjme_jfloat SJME_JAVA_TYPE_ID_FLOAT
657 /** Is a pointer for @c sjme_jfloat ? */
658 #define SJME_TYPEOF_IS_POINTER_sjme_jfloat 0
661 * Double value.
663 * @sinc 2023/07/25
665 typedef struct sjme_jdouble
667 #if defined(SJME_CONFIG_HAS_LITTLE_ENDIAN)
668 /** Low value. */
669 sjme_juint lo;
671 /** High value. */
672 sjme_juint hi;
673 #else
674 /** High value. */
675 sjme_juint hi;
677 /** Low value. */
678 sjme_juint lo;
679 #endif
680 } sjme_jdouble;
682 /** Basic @c sjme_jdouble type identifier. */
683 #define SJME_TYPEOF_BASIC_sjme_jdouble SJME_BASIC_TYPE_ID_DOUBLE
685 /** Java @c sjme_jdouble type identifier. */
686 #define SJME_TYPEOF_JAVA_sjme_jdouble SJME_JAVA_TYPE_ID_DOUBLE
688 /** Is a pointer for @c sjme_jdouble ? */
689 #define SJME_TYPEOF_IS_POINTER_sjme_jdouble 0
692 * Temporary index.
694 * @since 2023/07/25
696 typedef sjme_jint sjme_tempIndex;
699 * A range of values.
701 * @since 2024/01/03
703 typedef struct sjme_range
705 /** Start of the range. */
706 sjme_jint start;
708 /** End of the range. */
709 sjme_jint end;
710 } sjme_range;
713 * Represents a pointer and a length.
715 * @since 2024/02/04
717 typedef struct sjme_pointerLen
719 /** The pointer to the data. */
720 sjme_pointer pointer;
722 /** The length of the pointer. */
723 sjme_jint length;
724 } sjme_pointerLen;
727 * A wrapper used by front ends, which is reserved for use, which stores a
728 * natively bound object accordingly as needed.
730 * @since 2023/12/06
732 typedef void* sjme_frontEndWrapper;
735 * Any data that is needed by the front end, which is reserved for use.
737 * @since 2023/12/14
739 typedef void* sjme_frontEndData;
742 * This structure stores any front end data as needed.
744 * @since 2023/12/14
746 typedef struct sjme_frontEnd
748 /** Any wrapper as needed. */
749 sjme_frontEndWrapper wrapper;
751 /** Any data as needed. */
752 sjme_frontEndData data;
753 } sjme_frontEnd;
756 * Wraps the given front end pointer.
758 * @param p The pointer to wrap.
759 * @since 2023/12/08
761 #define SJME_FRONT_END_WRAP(p) ((sjme_frontEndWrapper)(p))
763 /** The Java type ID. */
764 typedef sjme_basicTypeId sjme_javaTypeId;
767 * Represents multiple type IDs.
769 * @since 2023/08/09
771 typedef struct sjme_basicTypeIds
773 /** The number of IDs. */
774 sjme_jint count;
776 /** The IDs. */
777 const sjme_javaTypeId ids[sjme_flexibleArrayCount];
778 } sjme_basicTypeIds;
781 * Program counter address.
783 * @since 2023/07/25
785 typedef sjme_jint sjme_pcAddr;
788 * Static linkage type.
790 * @since 2023/07/25
792 typedef sjme_jint sjme_staticLinkageType;
795 * Base object information.
797 * @since 2023/07/25
799 typedef struct sjme_jobjectBase
801 /** The reference count of this object, zero it becomes GCed. */
802 sjme_jint refCount;
803 } sjme_jobjectBase;
806 * Object type.
808 * @since 2023/07/25
810 typedef sjme_jobjectBase* sjme_jobject;
813 * Generic value union.
815 * @since 2024/01/05
817 typedef union sjme_jvalue
819 /** Boolean. */
820 sjme_jboolean z;
822 /** Byte. */
823 sjme_jbyte b;
825 /** Character. */
826 sjme_jchar c;
828 /** Short. */
829 sjme_jshort s;
831 /** Integer. */
832 sjme_jint i;
834 /** Long. */
835 sjme_jlong j;
837 /** Float. */
838 sjme_jfloat f;
840 /** Double. */
841 sjme_jdouble d;
843 /** Object/Reference. */
844 sjme_jobject l;
845 } sjme_jvalue;
848 * Class type.
850 * @since 2023/07/25
852 typedef sjme_jobject sjme_jclass;
854 /** Basic @c sjme_jobject type identifier. */
855 #define SJME_TYPEOF_BASIC_sjme_jobject SJME_BASIC_TYPE_ID_OBJECT
857 /** Java @c sjme_jobject type identifier. */
858 #define SJME_TYPEOF_JAVA_sjme_jobject SJME_BASIC_TYPE_ID_OBJECT
860 /** Is a pointer for @c sjme_jobject ? */
861 #define SJME_TYPEOF_IS_POINTER_sjme_jobject 1
864 * Throwable type.
866 * @since 2023/07/25
868 typedef sjme_jobject sjme_jthrowable;
870 typedef union sjme_anyData
872 /** Integer. */
873 sjme_jint jint;
875 /** Object. */
876 sjme_jobject jobject;
878 /** Temporary index. */
879 sjme_tempIndex tempIndex;
880 } sjme_anyData;
882 typedef struct sjme_any
884 /** Data type used. */
885 sjme_basicTypeId type;
887 /** Data stored within. */
888 sjme_anyData data;
889 } sjme_any;
892 * Represents the virtual machine state.
894 * @since 2023/07/28
896 typedef struct sjme_nvm_state sjme_nvm_state;
899 * Frame of execution within a thread.
901 * @since 2023/07/25
903 typedef struct sjme_nvm_frame sjme_nvm_frame;
906 * Exception stack trace mechanism storage.
908 * @since 2023/12/08
910 typedef volatile struct sjme_exceptTrace sjme_exceptTrace;
912 typedef struct sjme_nvm_thread
914 /** The VM state this thread is in. */
915 sjme_nvm_state* inState;
917 /** The wrapper in the front end. */
918 sjme_frontEnd frontEnd;
920 /** The thread ID. */
921 sjme_jint threadId;
923 /** The top of the stack. */
924 sjme_nvm_frame* top;
926 /** The number of frames. */
927 sjme_jint numFrames;
929 /** Current exception handler go back. */
930 sjme_exceptTrace* except;
931 } sjme_nvm_thread;
933 typedef struct sjme_static_constValue
935 /** Integer value. */
936 sjme_jint jint;
938 /** Long value. */
939 sjme_jlong jlong;
941 /** Float value. */
942 sjme_jfloat jfloat;
944 /** Double value. */
945 sjme_jdouble jdouble;
947 /** String value. */
948 sjme_lpcstr jstring;
950 /** Class name. */
951 sjme_lpcstr jclass;
952 } sjme_static_constValue;
955 * Represents a field type.
957 * @since 2023/08/10
959 typedef struct sjme_static_fieldType
961 /** The hash code for the field type. */
962 sjme_jint hashCode;
964 /** The field descriptor. */
965 sjme_lpcstr descriptor;
967 /** The basic type. */
968 sjme_basicTypeId basicType;
969 } sjme_static_fieldType;
971 typedef struct sjme_static_classField
973 /** Field name. */
974 sjme_lpcstr name;
976 /** The field type. */
977 const sjme_static_fieldType* type;
979 /** Flags. */
980 sjme_jint flags;
982 /** The constant value type. */
983 sjme_basicTypeId valueType;
985 /** The value. */
986 sjme_static_constValue value;
987 } sjme_static_classField;
989 typedef struct sjme_static_classFields
991 /** The number of fields. */
992 sjme_jint count;
994 /** Fields. */
995 sjme_static_classField fields[sjme_flexibleArrayCount];
996 } sjme_static_classFields;
999 * Type used for method code functions.
1001 * @param currentState The current virtual machine state.
1002 * @param currentThread The current virtual machine thread.
1003 * @return Will return @c SJME_JNI_TRUE if execution completed without throwing
1004 * a @c Throwable object.
1005 * @since 2023/07/25
1007 typedef sjme_jboolean (*sjme_methodCodeFunction)(
1008 struct sjme_nvm_state* currentState,
1009 struct sjme_nvm_thread* currentThread);
1012 * The variable mapping and setup for any given method.
1014 * @since 2023/08/09
1016 typedef struct sjme_static_classCodeLimits
1018 /** The maximum number of @c sjme_basicTypeId local/stack variables. */
1019 const sjme_jubyte maxVariables[SJME_NUM_JAVA_TYPE_IDS];
1020 } sjme_static_classCodeLimits;
1023 * Contains information about method code and how variables should be placed
1024 * on execution and stack handling.
1026 * @since 2023/08/09
1028 typedef struct sjme_static_classCode
1030 /** The variable count and thrown index count used. */
1031 const sjme_static_classCodeLimits* limits;
1033 /** The index where thrown objects are placed. */
1034 sjme_jshort thrownVarIndex;
1036 /** The method code. */
1037 sjme_methodCodeFunction code;
1038 } sjme_static_classCode;
1041 * Represents a standard Java method type, using field descriptors.
1043 * @since 2023/08/10
1045 typedef struct sjme_static_methodType
1047 /** The hash code for the method type. */
1048 sjme_jint hashCode;
1050 /** The descriptor for the method type. */
1051 sjme_lpcstr descriptor;
1053 /** The return type. */
1054 const sjme_static_fieldType* returnType;
1056 /** The number of arguments. */
1057 sjme_jint argCount;
1059 /** The arguments to the method. */
1060 const sjme_static_fieldType* argTypes[0];
1061 } sjme_static_methodType;
1063 typedef struct sjme_static_classMethod
1065 /** Method name. */
1066 sjme_lpcstr name;
1068 /** Flags. */
1069 sjme_jint flags;
1071 /** Name typed. */
1072 const sjme_static_methodType* type;
1074 /** Method code and any pertaining information. */
1075 const sjme_static_classCode* code;
1076 } sjme_static_classMethod;
1078 typedef struct sjme_static_classMethods
1080 /** The number of methods. */
1081 sjme_jint count;
1083 /** Methods. */
1084 sjme_static_classMethod methods[sjme_flexibleArrayCount];
1085 } sjme_static_classMethods;
1087 typedef struct sjme_static_classInterface
1089 sjme_lpcstr interfaceName;
1090 } sjme_static_classInterface;
1092 typedef struct sjme_static_classInterfaces
1094 /** The number of interfaces. */
1095 sjme_jint count;
1097 /** Interfaces. */
1098 sjme_static_classInterface interfaces[sjme_flexibleArrayCount];
1099 } sjme_static_classInterfaces;
1101 typedef struct sjme_static_resource
1103 /** The resource path. */
1104 sjme_lpcstr path;
1106 /** The hash for the path. */
1107 sjme_jint pathHash;
1109 /** The size of the resource. */
1110 sjme_jint size;
1112 /** The resource data. */
1113 const sjme_jbyte data[sjme_flexibleArrayCount];
1114 } sjme_static_resource;
1116 typedef struct sjme_static_linkage_data_classObject
1118 /** The class name. */
1119 sjme_lpcstr className;
1120 } sjme_static_linkage_data_classObject;
1122 typedef struct sjme_static_linkage_data_fieldAccess
1124 /** Is this static? */
1125 sjme_jboolean isStatic;
1127 /** Is this a store? */
1128 sjme_jboolean isStore;
1130 /** The source method name. */
1131 sjme_lpcstr sourceMethodName;
1133 /** The source method type. */
1134 sjme_lpcstr sourceMethodType;
1136 /** The target class. */
1137 sjme_lpcstr targetClass;
1139 /** The target field name. */
1140 sjme_lpcstr targetFieldName;
1142 /** The target field type. */
1143 sjme_lpcstr targetFieldType;
1144 } sjme_static_linkage_data_fieldAccess;
1146 typedef struct sjme_static_linkage_data_invokeSpecial
1148 /** The source method name. */
1149 sjme_lpcstr sourceMethodName;
1151 /** The source method type. */
1152 sjme_lpcstr sourceMethodType;
1154 /** The target class. */
1155 sjme_lpcstr targetClass;
1157 /** The target method name. */
1158 sjme_lpcstr targetMethodName;
1160 /** The target method type. */
1161 sjme_lpcstr targetMethodType;
1162 } sjme_static_linkage_data_invokeSpecial;
1164 typedef struct sjme_static_linkage_data_invokeNormal
1166 /** Is this a static invocation? */
1167 sjme_jboolean isStatic;
1169 /** The source method name. */
1170 sjme_lpcstr sourceMethodName;
1172 /** The source method type. */
1173 sjme_lpcstr sourceMethodType;
1175 /** The target class. */
1176 sjme_lpcstr targetClass;
1178 /** The target method name. */
1179 sjme_lpcstr targetMethodName;
1181 /** The target method type. */
1182 sjme_lpcstr targetMethodType;
1183 } sjme_static_linkage_data_invokeNormal;
1185 typedef struct sjme_static_linkage_data_stringObject
1187 /** The string value. */
1188 sjme_lpcstr string;
1189 } sjme_static_linkage_data_stringObject;
1191 typedef union sjme_static_linkage_data
1193 /** Reference to class object. */
1194 sjme_static_linkage_data_classObject classObject;
1196 /** Field access. */
1197 sjme_static_linkage_data_fieldAccess fieldAccess;
1199 /** Special invocation. */
1200 sjme_static_linkage_data_invokeSpecial invokeSpecial;
1202 /** Normal invocation. */
1203 sjme_static_linkage_data_invokeNormal invokeNormal;
1205 /** String object. */
1206 sjme_static_linkage_data_stringObject stringObject;
1207 } sjme_static_linkage_data;
1210 * Static linkage.
1212 * @since 2023/07/25
1214 typedef struct sjme_static_linkage
1216 /** The type of linkage this is. */
1217 sjme_staticLinkageType type;
1219 /** Linkage data. */
1220 sjme_static_linkage_data data;
1221 } sjme_static_linkage;
1223 typedef struct sjme_static_linkages
1225 /** The number of linkages. */
1226 sjme_jint count;
1228 /** The define linkages. */
1229 sjme_static_linkage linkages[sjme_flexibleArrayCount];
1230 } sjme_static_linkages;
1232 typedef struct sjme_dynamic_linkage_data_classObject
1234 int todo;
1235 } sjme_dynamic_linkage_data_classObject;
1237 typedef struct sjme_dynamic_linkage_data_fieldAccess
1239 int todo;
1240 } sjme_dynamic_linkage_data_fieldAccess;
1242 typedef struct sjme_dynamic_linkage_data_invokeSpecial
1244 int todo;
1245 } sjme_dynamic_linkage_data_invokeSpecial;
1247 typedef struct sjme_dynamic_linkage_data_invokeNormal
1249 int todo;
1250 } sjme_dynamic_linkage_data_invokeNormal;
1252 typedef struct sjme_dynamic_linkage_data_stringObject
1254 int todo;
1255 } sjme_dynamic_linkage_data_stringObject;
1257 typedef union sjme_dynamic_linkage_data
1259 /** Reference to class object. */
1260 sjme_dynamic_linkage_data_classObject classObject;
1262 /** Field access. */
1263 sjme_dynamic_linkage_data_fieldAccess fieldAccess;
1265 /** Special invocation. */
1266 sjme_dynamic_linkage_data_invokeSpecial invokeSpecial;
1268 /** Normal invocation. */
1269 sjme_dynamic_linkage_data_invokeNormal invokeNormal;
1271 /** String object. */
1272 sjme_dynamic_linkage_data_stringObject stringObject;
1273 } sjme_dynamic_linkage_data;
1276 * Dynamic linkage.
1278 * @since 2023/07/25
1280 typedef struct sjme_dynamic_linkage
1282 /** The type of linkage this is. */
1283 sjme_staticLinkageType type;
1285 /** Linkage data. */
1286 sjme_dynamic_linkage_data data;
1287 } sjme_dynamic_linkage;
1290 * Represents the frame of a stack tread.
1292 * @since 2023/11/15
1294 typedef struct sjme_nvm_frameTread
1296 /** The number of items in this tread. */
1297 sjme_jint count;
1299 /** The base index for the stack index. */
1300 sjme_jint stackBaseIndex;
1302 /** The maximum size this tread can be. */
1303 sjme_jint max;
1305 /** Values within the tread. */
1306 union
1308 /** Integer values. */
1309 sjme_jint jints[sjme_flexibleArrayCountUnion];
1311 /** Long values. */
1312 sjme_jlong jlongs[sjme_flexibleArrayCountUnion];
1314 /** Float values. */
1315 sjme_jfloat jfloats[sjme_flexibleArrayCountUnion];
1317 /** Double values. */
1318 sjme_jdouble jdoubles[sjme_flexibleArrayCountUnion];
1320 /** Object references. */
1321 sjme_jobject jobjects[sjme_flexibleArrayCountUnion];
1322 } values;
1323 } sjme_nvm_frameTread;
1326 * Calculates the size of a frame tread for a given type.
1328 * @param type The type to get the size for.
1329 * @param count The number if items to store.
1330 * @return The size in bytes for the tread.
1331 * @since 2023/11/15
1333 #define SJME_SIZEOF_FRAME_TREAD(type, count, baseType) \
1334 (sizeof(sjme_nvm_frameTread) + \
1335 /* Need to handle cases where values could be aligned up... */ \
1336 (offsetof(sjme_nvm_frameTread, values.SJME_TOKEN_PASTE(baseType,s)[0]) - \
1337 offsetof(sjme_nvm_frameTread, values)) + \
1338 (sizeof(type) * (size_t)(count)))
1341 * Calculates the size of a frame tread for a given type via variable.
1343 * @param typeId The type to get the size for.
1344 * @param count The number if items to store.
1345 * @return The size in bytes for the tread.
1346 * @since 2023/11/15
1348 static sjme_inline sjme_attrArtificial size_t SJME_SIZEOF_FRAME_TREAD_VAR(
1349 sjme_javaTypeId typeId, sjme_jint count)
1351 switch (typeId)
1353 case SJME_JAVA_TYPE_ID_INTEGER:
1354 return SJME_SIZEOF_FRAME_TREAD(sjme_jint, count, jint);
1356 case SJME_JAVA_TYPE_ID_LONG:
1357 return SJME_SIZEOF_FRAME_TREAD(sjme_jlong, count, jlong);
1359 case SJME_JAVA_TYPE_ID_FLOAT:
1360 return SJME_SIZEOF_FRAME_TREAD(sjme_jfloat, count, jfloat);
1362 case SJME_JAVA_TYPE_ID_DOUBLE:
1363 return SJME_SIZEOF_FRAME_TREAD(sjme_jdouble, count, jdouble);
1365 case SJME_JAVA_TYPE_ID_OBJECT:
1366 return SJME_SIZEOF_FRAME_TREAD(sjme_jobject, count, jobject);
1369 /* Invalid. */
1370 return 0;
1374 * Represents information on a frame's stack storage.
1376 * @since 2023/11/16
1378 typedef struct sjme_nvm_frameStack
1380 /** The number of items in the stack. */
1381 sjme_jint count;
1383 /** The current limit of this structure. */
1384 sjme_jint limit;
1386 /** The stack order. */
1387 sjme_javaTypeId order[sjme_flexibleArrayCount];
1388 } sjme_nvm_frameStack;
1391 * Calculates the size of a frame stack.
1393 * @param count The number if items to store.
1394 * @return The size in bytes for the tread.
1395 * @since 2023/11/16
1397 #define SJME_SIZEOF_FRAME_STACK(count) \
1398 (sizeof(sjme_nvm_frameStack) + \
1399 (sizeof(sjme_javaTypeId) * (size_t)(count)))
1401 typedef struct sjme_nvm_frameLocalMap
1403 /** The maximum number of locals. */
1404 sjme_jint max;
1406 /** Mapping of a specific variable to a given type index. */
1407 union
1409 sjme_jbyte to[SJME_NUM_JAVA_TYPE_IDS];
1410 } maps[sjme_flexibleArrayCount];
1411 } sjme_nvm_frameLocalMap;
1414 * Calculates the size of the frame local variable map.
1416 * @param count The number of items in the mapping.
1417 * @return The size in bytes of the local mapping.
1418 * @since 2023/11/26
1420 #define SJME_SIZEOF_FRAME_LOCAL_MAP(count) \
1421 (sizeof(sjme_nvm_frameLocalMap) + \
1422 (SJME_SIZEOF_STRUCT_MEMBER(sjme_nvm_frameLocalMap, maps[0]) * (count)))
1424 struct sjme_nvm_frame
1426 /** The thread this frame is in. */
1427 sjme_nvm_thread* inThread;
1429 /** The wrapper in the front end. */
1430 sjme_frontEnd frontEnd;
1432 /** The parent frame. */
1433 sjme_nvm_frame* parent;
1435 /** The frame index in the thread. */
1436 sjme_jint frameIndex;
1438 /** The current program counter. */
1439 sjme_pcAddr pc;
1441 /** Object which is waiting to be thrown for exception handling. */
1442 sjme_jobject waitingThrown;
1444 /** Frame linkage. */
1445 sjme_dynamic_linkage* linkage;
1447 /** Temporary stack. */
1448 sjme_any* tempStack;
1450 /** Reference to this. */
1451 sjme_jobject thisRef;
1453 /** Class reference. */
1454 sjme_jclass classObjectRef;
1456 /** The current stack information. */
1457 sjme_nvm_frameStack* stack;
1459 /** Treads for the stack and locals. */
1460 sjme_nvm_frameTread* treads[SJME_NUM_BASIC_TYPE_IDS];
1462 /** Mapping of local variables to the tread indexes per type. */
1463 const sjme_nvm_frameLocalMap* localMap;
1467 * Contains the payload information.
1469 * @since 2023/07/27
1471 typedef struct sjme_payload_config sjme_payload_config;
1474 * Hook for garbage collection detection and/or cancel capability.
1476 * @param frame The frame this is garbage collecting in.
1477 * @param gcWhat what is being garbage collected?
1478 * @return Returns @c SJME_JNI_TRUE if garbage collection should continue.
1479 * @since 2023/11/17
1481 typedef sjme_jboolean (*sjme_nvm_stateHookGcFunc)(sjme_nvm_frame* frame,
1482 sjme_jobject gcWhat);
1485 * Hooks for alternative function.
1487 * @since 2023/11/17
1489 typedef struct sjme_nvm_stateHooks
1491 /** Garbage collection. */
1492 sjme_nvm_stateHookGcFunc gc;
1493 } sjme_nvm_stateHooks;
1496 * Structure which stores the pooled memory allocator.
1498 * @since 2023/11/18
1500 typedef struct sjme_alloc_pool sjme_alloc_pool;
1503 * Boot parameters for NanoCoat.
1505 * @since 2023/07/27
1507 typedef struct sjme_nvm_bootParam sjme_nvm_bootParam;
1510 * Standard Suite structure.
1512 * @since 2023/12/12
1514 typedef struct sjme_rom_suiteCore sjme_rom_suiteCore;
1517 * Opaque suite structure type.
1519 * @since 2023/12/22
1521 typedef struct sjme_rom_suiteCore* sjme_rom_suite;
1524 * Structure for a single task.
1526 * @since 2023/12/17
1528 typedef struct sjme_nvm_taskCore* sjme_nvm_task;
1531 * Represents the virtual machine state.
1533 * @since 2023/07/28
1535 struct sjme_nvm_state
1537 /** The wrapper in the front end. */
1538 sjme_frontEnd frontEnd;
1540 /** The memory pool to use for allocations. */
1541 sjme_alloc_pool* allocPool;
1543 /** The reserved memory pool. */
1544 sjme_alloc_pool* reservedPool;
1546 /** The copy of the input boot parameters. */
1547 const sjme_nvm_bootParam* bootParamCopy;
1549 /** Hooks for the state. */
1550 const sjme_nvm_stateHooks* hooks;
1552 /* The suite containing all the libraries. */
1553 sjme_rom_suite suite;
1557 * Method initialization start.
1559 * @since 2023/07/25
1561 #define SJME_NANOCOAT_START_CALL ((sjme_pcAddr)-1)
1564 * Method closing end.
1566 * @since 2023/07/25
1568 #define SJME_NANOCOAT_END_CALL ((sjme_pcAddr)-2)
1571 * Error codes.
1573 * @since 2023/11/14
1575 typedef enum sjme_errorCode
1577 /** No error. */
1578 SJME_ERROR_NONE = 1,
1580 /** Generic unknown error. */
1581 SJME_ERROR_UNKNOWN = 0,
1583 /** Generic unknown error. */
1584 SJME_ERROR_UNKNOWN_NEGATIVE = -1,
1586 /** Null arguments. */
1587 SJME_ERROR_NULL_ARGUMENTS = -2,
1589 /** Local variable out of bounds. */
1590 SJME_ERROR_LOCAL_INDEX_INVALID = -3,
1592 /** Stack variable out of bounds. */
1593 SJME_ERROR_STACK_INDEX_INVALID = -4,
1595 /** Stack underflow. */
1596 SJME_ERROR_STACK_UNDERFLOW = -5,
1598 /** Stack overflow. */
1599 SJME_ERROR_STACK_OVERFLOW = -6,
1601 /** Top is not an integer type. */
1602 SJME_ERROR_TOP_NOT_INTEGER = -7,
1604 /** Top is not a long type. */
1605 SJME_ERROR_TOP_NOT_LONG = -8,
1607 /** Top is not a float type. */
1608 SJME_ERROR_TOP_NOT_FLOAT = -9,
1610 /** Top is not a double type. */
1611 SJME_ERROR_TOP_NOT_DOUBLE = -10,
1613 /** Top is not a object type. */
1614 SJME_ERROR_TOP_NOT_OBJECT = -11,
1616 /** Frame is missing stack treads. */
1617 SJME_ERROR_FRAME_MISSING_STACK_TREADS = -12,
1619 /** Invalid read of stack. */
1620 SJME_ERROR_STACK_INVALID_READ = -13,
1622 /** Invalid write of stack. */
1623 SJME_ERROR_STACK_INVALID_WRITE = -14,
1625 /** Invalid read of stack. */
1626 SJME_ERROR_LOCAL_INVALID_READ = -15,
1628 /** Invalid write of stack. */
1629 SJME_ERROR_LOCAL_INVALID_WRITE = -16,
1631 /** Invalid reference pop. */
1632 SJME_ERROR_INVALID_REFERENCE_POP = -17,
1634 /** Invalid reference push. */
1635 SJME_ERROR_INVALID_REFERENCE_PUSH = -18,
1637 /** Failed to garbage collect object. */
1638 SJME_ERROR_COULD_NOT_GC_OBJECT = -19,
1640 /** Object reference count is not zero. */
1641 SJME_ERROR_OBJECT_REFCOUNT_NOT_ZERO = -20,
1643 /** Garbage collection of object cancelled. */
1644 SJME_ERROR_OBJECT_GC_CANCELLED = -21,
1646 /** Out of memory. */
1647 SJME_ERROR_OUT_OF_MEMORY = -22,
1649 /** Pool initialization failed. */
1650 SJME_ERROR_POOL_INIT_FAILED = -23,
1652 /** Invalid argument. */
1653 SJME_ERROR_INVALID_ARGUMENT = -24,
1655 /** Not implemented. */
1656 SJME_ERROR_NOT_IMPLEMENTED = -25,
1658 /** Invalid tread read. */
1659 SJME_ERROR_TREAD_INVALID_READ = -26,
1661 /** Invalid tread write. */
1662 SJME_ERROR_TREAD_INVALID_WRITE = -27,
1664 /** There are no suites available. */
1665 SJME_ERROR_NO_SUITES = -28,
1667 /** Classpath cannot be obtained by both ID and Name. */
1668 SJME_ERROR_CLASS_PATH_BY_BOTH = -29,
1670 /** Illegal state. */
1671 SJME_ERROR_ILLEGAL_STATE = -30,
1673 /** A library was not found. */
1674 SJME_ERROR_LIBRARY_NOT_FOUND = -31,
1676 /** Boot failure. */
1677 SJME_ERROR_BOOT_FAILURE = -32,
1679 /** Generic JNI exception. */
1680 SJME_ERROR_JNI_EXCEPTION = -33,
1682 /** Memory has been corrupted. */
1683 SJME_ERROR_MEMORY_CORRUPTION = -34,
1685 /** Index out of bounds. */
1686 SJME_ERROR_INDEX_OUT_OF_BOUNDS = -35,
1688 /** Unsupported operation. */
1689 SJME_ERROR_UNSUPPORTED_OPERATION = -36,
1691 /** Resource not found. */
1692 SJME_ERROR_RESOURCE_NOT_FOUND = -37,
1694 /** Unexpected end of file. */
1695 SJME_ERROR_UNEXPECTED_EOF = -38,
1697 /** Invalid identifier. */
1698 SJME_ERROR_INVALID_IDENTIFIER = -39,
1700 /** Invalid binary name. */
1701 SJME_ERROR_INVALID_BINARY_NAME = -40,
1703 /** Invalid field type. */
1704 SJME_ERROR_INVALID_FIELD_TYPE = -41,
1706 /** Invalid method type. */
1707 SJME_ERROR_INVALID_METHOD_TYPE = -42,
1709 /** Invalid class name. */
1710 SJME_ERROR_INVALID_CLASS_NAME = -43,
1712 /** Could not load library. */
1713 SJME_ERROR_COULD_NOT_LOAD_LIBRARY = -44,
1715 /** Invalid library symbol. */
1716 SJME_ERROR_INVALID_LIBRARY_SYMBOL = -45,
1718 /** The number of error codes. */
1719 SJME_NUM_ERROR_CODES = -46
1720 } sjme_errorCode;
1723 * Propagates an error code which allows others to run accordingly.
1725 * @param error The current error code.
1726 * @param expression The result from the expression.
1727 * @return If @c expression is an error, that will be returned otherwise
1728 * the value in @c error provided @c error is not an error.
1729 * @since 2024/01/18
1731 sjme_errorCode sjme_error_also(
1732 sjme_errorCode error, sjme_errorCode expression);
1735 * Similar to @c sjme_error_also except this allows multiple error expressions
1736 * to be passed until the final is done via @c sjme_error_alsoVEnd() .
1738 * @param error The current error state.
1739 * @param ... All of the expressions, ends on @c sjme_error_alsoVEnd() .
1740 * @return The resultant error code.
1741 * @since 2024/01/18
1743 sjme_errorCode sjme_error_alsoV(
1744 sjme_errorCode error, ...);
1747 * The end expression for @c sjme_error_alsoV() .
1749 * @return The ending sequence for error codes.
1750 * @since 2024/01/18
1752 sjme_errorCode sjme_error_alsoVEnd(void);
1755 * Is this expression considered an error?
1757 * @param error The expression.
1758 * @since 2023/12/08
1760 sjme_jboolean sjme_error_is(
1761 sjme_errorCode error);
1764 * Determines the default error code to use.
1766 * @param error The error code.
1767 * @return Either @c error or a default error.
1768 * @since 2023/12/29
1770 sjme_errorCode sjme_error_default(
1771 sjme_errorCode error);
1774 * Determines the default error code to use.
1776 * @param error The error code.
1777 * @param otherwise The other error code rather than @c SJME_ERROR_UNKNOWN.
1778 * @return Either @c error or @c otherwise if the former is not valid.
1779 * @since 2023/12/29
1781 sjme_errorCode sjme_error_defaultOr(
1782 sjme_errorCode error, sjme_errorCode otherwise);
1784 /*--------------------------------------------------------------------------*/
1786 /* Anti-C++. */
1787 #ifdef __cplusplus
1788 #ifdef SJME_CXX_SQUIRRELJME_NVM_H
1790 #undef SJME_CXX_SQUIRRELJME_NVM_H
1791 #undef SJME_CXX_IS_EXTERNED
1792 #endif /* #ifdef SJME_CXX_SQUIRRELJME_NVM_H */
1793 #endif /* #ifdef __cplusplus */
1795 #endif /* SQUIRRELJME_NVM_H */