Rename unzip tool.
[SquirrelJME.git] / nanocoat / include / sjme / nvm.h
blob4eb84cc7d420516a605a9fef582ebf25e62b7d7f
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 * Pastes six tokens together.
123 * @param a The first token.
124 * @param b The second token.
125 * @param c The third token.
126 * @param d The fourth token.
127 * @param e The fifth token.
128 * @param f The sixth token.
129 * @since 2024/07/01
131 #define SJME_TOKEN_PASTE6(a, b, c, d, e, f) a##b##c##d##e##f
134 * Pasting six tokens but with preprocessing.
136 * @param a The first token.
137 * @param b The second token.
138 * @param c The third token.
139 * @param d The fourth token.
140 * @param e The fifth token.
141 * @param f The sixth token.
142 * @since 2024/07/01
144 #define SJME_TOKEN_PASTE6_PP(a, b, c, d, e, f) \
145 SJME_TOKEN_PASTE6(a, b, c, d, e, f)
148 * Stringifies the given token.
150 * @param s The token to stringify.
151 * @since 2023/11/24
153 #define SJME_TOKEN_STRING(s) #s
156 * Stringifies the given token.
158 * @param s The token to stringify.
159 * @since 2023/11/24
161 #define SJME_TOKEN_STRING_PP(s) SJME_TOKEN_STRING(s)
164 * Represents a single token.
166 * @param t The token to resolve.
167 * @since 2023/12/17
169 #define SJME_TOKEN_SINGLE(t) t
171 #define SJME_TOKEN_STARS_0
172 #define SJME_TOKEN_STARS_1 *
173 #define SJME_TOKEN_STARS_2 **
174 #define SJME_TOKEN_STARS_3 ***
175 #define SJME_TOKEN_STARS_4 ****
176 #define SJME_TOKEN_STARS_5 *****
177 #define SJME_TOKEN_STARS_6 ******
178 #define SJME_TOKEN_STARS_7 *******
179 #define SJME_TOKEN_STARS_8 ********
180 #define SJME_TOKEN_STARS_9 *********
182 #define SJME_TOKEN_STARS_C0
183 #define SJME_TOKEN_STARS_C1 P
184 #define SJME_TOKEN_STARS_C2 PP
185 #define SJME_TOKEN_STARS_C3 PPP
186 #define SJME_TOKEN_STARS_C4 PPPP
187 #define SJME_TOKEN_STARS_C5 PPPPP
188 #define SJME_TOKEN_STARS_C6 PPPPPP
189 #define SJME_TOKEN_STARS_C7 PPPPPPP
190 #define SJME_TOKEN_STARS_C8 PPPPPPPP
191 #define SJME_TOKEN_STARS_C9 PPPPPPPPP
193 #define SJME_TOKEN_STARS_H0 0
194 #define SJME_TOKEN_STARS_H1 1
195 #define SJME_TOKEN_STARS_H2 1
196 #define SJME_TOKEN_STARS_H3 1
197 #define SJME_TOKEN_STARS_H4 1
198 #define SJME_TOKEN_STARS_H5 1
199 #define SJME_TOKEN_STARS_H6 1
200 #define SJME_TOKEN_STARS_H7 1
201 #define SJME_TOKEN_STARS_H8 1
202 #define SJME_TOKEN_STARS_H9 1
205 * Generic pointer star types.
207 * @param type The type used.
208 * @param numPointerStars The number of pointer stars.
209 * @since 2024/01/09
211 #define SJME_TOKEN_TYPE(type, numPointerStars) \
212 type SJME_TOKEN_SINGLE(SJME_TOKEN_STARS_##numPointerStars)
215 * Semicolon token.
217 * @since 2024/01/09
219 #define SJME_TOKEN_SEMI ;
222 * Does this have pointer stars?
224 * @param numPointerStars The number of pointer stars.
225 * @since 2024/01/09
227 #define SJME_TOKEN_HAS_STARS(numPointerStars) \
228 SJME_TOKEN_SINGLE(SJME_TOKEN_STARS_H##numPointerStars)
230 /** SquirrelJME version string. */
231 #define SQUIRRELJME_VERSION SJME_TOKEN_STRING_PP(SQUIRRELJME_VERSION_TRIM)
234 * Calculates the size of a struct member.
236 * @param type The type of the struct.
237 * @param member The member to check.
238 * @return The size of the given member.
239 * @since 2023/11/16
241 #define SJME_SIZEOF_STRUCT_MEMBER(type, member) \
242 (sizeof((*((type*)0)).member))
245 * Uncommon structure size.
247 * @param structType The structure type.
248 * @param uncommonMember The uncommon member.
249 * @param uncommonSize The uncommon size to use.
250 * @since 2024/01/01
252 #define SJME_SIZEOF_UNCOMMON_N(structType, uncommonMember, uncommonSize) \
253 (sizeof(structType) + (offsetof(structType, \
254 uncommonMember[0]) - offsetof(structType, uncommonMember)) + \
255 (uncommonSize))
258 * Returns the uncommon member.
260 * @param structType The structure type.
261 * @param uncommonMember The uncommon member.
262 * @param uncommonType The uncommon type.
263 * @param base The base structure pointer to access.
264 * @since 2024/01/01
266 #define SJME_UNCOMMON_MEMBER(structType, uncommonMember, uncommonType, base) \
267 ((uncommonType*)(sjme_pointer)(&((structType*)((base)))->uncommonMember))
270 * Basic data type identifier.
272 * @since 2023/07/25
274 typedef enum sjme_basicTypeId
276 /** Integer. */
277 SJME_BASIC_TYPE_ID_INTEGER = 0,
279 /** Integer. */
280 SJME_JAVA_TYPE_ID_INTEGER = SJME_BASIC_TYPE_ID_INTEGER,
282 /** Long. */
283 SJME_BASIC_TYPE_ID_LONG = 1,
285 /** Long. */
286 SJME_JAVA_TYPE_ID_LONG = SJME_BASIC_TYPE_ID_LONG,
288 /** Float. */
289 SJME_BASIC_TYPE_ID_FLOAT = 2,
291 /** Float. */
292 SJME_JAVA_TYPE_ID_FLOAT = SJME_BASIC_TYPE_ID_FLOAT,
294 /** Double. */
295 SJME_BASIC_TYPE_ID_DOUBLE = 3,
297 /** Double. */
298 SJME_JAVA_TYPE_ID_DOUBLE = SJME_BASIC_TYPE_ID_DOUBLE,
300 /** Object. */
301 SJME_BASIC_TYPE_ID_OBJECT = 4,
303 /** Object. */
304 SJME_JAVA_TYPE_ID_OBJECT = SJME_BASIC_TYPE_ID_OBJECT,
306 /** The number of Java type IDs. */
307 SJME_NUM_JAVA_TYPE_IDS = 5,
309 /** Boolean or byte. */
310 SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE = SJME_NUM_JAVA_TYPE_IDS,
312 /** Character or short type. */
313 SJME_JAVA_TYPE_ID_SHORT_OR_CHAR = 6,
315 /** Void type. */
316 SJME_BASIC_TYPE_ID_VOID = 7,
318 /** Void type. */
319 SJME_JAVA_TYPE_ID_VOID = SJME_BASIC_TYPE_ID_VOID,
321 /** End of extended Java types. */
322 SJME_NUM_EXTENDED_JAVA_TYPE_IDS = 8,
324 /** Short. */
325 SJME_BASIC_TYPE_ID_SHORT = SJME_NUM_EXTENDED_JAVA_TYPE_IDS,
327 /** Character. */
328 SJME_BASIC_TYPE_ID_CHARACTER = 9,
330 /** Specifically boolean. */
331 SJME_BASIC_TYPE_ID_BOOLEAN = 10,
333 /** Specifically jbyte. */
334 SJME_BASIC_TYPE_ID_BYTE = 11,
336 /** Number of basic type IDs. */
337 SJME_NUM_BASIC_TYPE_IDS = 11
338 } sjme_basicTypeId;
341 * Returns the basic type ID of the given type.
343 * @param type The type to get the basic type of.
344 * @since 2023/12/17
346 #define SJME_TYPEOF_BASIC(type) SJME_TOKEN_PASTE_PP(SJME_TYPEOF_BASIC_, type)
349 * Returns the java type ID of the given type.
351 * @param type The type to get the basic type of.
352 * @since 2023/12/17
354 #define SJME_TYPEOF_JAVA(type) SJME_TOKEN_PASTE_PP(SJME_TYPEOF_JAVA_, type)
356 #define SJME_TYPEOF_IS_POINTER_X00 0
357 #define SJME_TYPEOF_IS_POINTER_X10 1
358 #define SJME_TYPEOF_IS_POINTER_X01 1
359 #define SJME_TYPEOF_IS_POINTER_X11 1
362 * Is the given type a pointer?
364 * @param type The type used.
365 * @param numPointerStars The number of pointer stars.
366 * @return If this is a pointer or not.
367 * @since 2024/01/09
369 #define SJME_TYPEOF_IS_POINTER(type, numPointerStars) \
370 SJME_TOKEN_SINGLE(SJME_TOKEN_PASTE3_PP(SJME_TYPEOF_IS_POINTER_X, \
371 SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IS_POINTER_, type), \
372 SJME_TOKEN_PASTE_PP(SJME_TOKEN_STARS_H, numPointerStars)))
374 #define SJME_TYPEOF_IS_NOT_POINTER_X0 1
375 #define SJME_TYPEOF_IS_NOT_POINTER_X1 0
378 * Is the given type not a pointer?
380 * @param type The type used.
381 * @param numPointerStars The number of pointer stars.
382 * @return If this is not a pointer or it is one.
383 * @since 2024/01/09
385 #define SJME_TYPEOF_IS_NOT_POINTER(type, numPointerStars) \
386 SJME_TOKEN_SINGLE(SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IS_NOT_POINTER_X, \
387 SJME_TYPEOF_IS_POINTER(type, numPointerStars)))
389 #define SJME_TYPEOF_IF_POINTER_X0(snippet)
390 #define SJME_TYPEOF_IF_POINTER_X1(snippet) snippet
393 * If the type is a pointer, place the given snippet.
395 * @param type The type used.
396 * @param numPointerStars The number of pointer stars
397 * @param snippet The snippet to place.
398 * @return Either @c snippet or nothing.
399 * @since 2024/01/09
401 #define SJME_TYPEOF_IF_POINTER(type, numPointerStars, snippet) \
402 SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IF_POINTER_X, \
403 SJME_TYPEOF_IS_POINTER(type, numPointerStars))(snippet)
406 * If the type is not a pointer, place the given snippet.
408 * @param type The type used.
409 * @param numPointerStars The number of pointer stars
410 * @param snippet The snippet to place.
411 * @return Either @c snippet or nothing.
412 * @since 2024/01/09
414 #define SJME_TYPEOF_IF_NOT_POINTER(type, numPointerStars, snippet) \
415 SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IF_POINTER_X, \
416 SJME_TYPEOF_IS_NOT_POINTER(type, numPointerStars))(snippet)
418 #define SJME_TYPEOF_IF_POINTER_ORX0(snippet, orSnippet) orSnippet
419 #define SJME_TYPEOF_IF_POINTER_ORX1(snippet, orSnippet) snippet
422 * If the type is a pointer, place the given snippet.
424 * @param type The type used.
425 * @param numPointerStars The number of pointer stars
426 * @param snippet The snippet to place.
427 * @param orSnippet The snippet if it is a pointer.
428 * @return Either @c snippet or nothing.
429 * @since 2024/01/09
431 #define SJME_TYPEOF_IF_POINTER_OR(type, numPointerStars, snippet, orSnippet) \
432 SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IF_POINTER_ORX, \
433 SJME_TYPEOF_IS_POINTER(type, numPointerStars))(snippet, orSnippet)
436 * If the type is not a pointer, place the given snippet.
438 * @param type The type used.
439 * @param numPointerStars The number of pointer stars
440 * @param snippet The snippet to place.
441 * @param orSnippet The snippet if it is a pointer.
442 * @return Either @c snippet or nothing.
443 * @since 2024/01/09
445 #define SJME_TYPEOF_IF_NOT_POINTER_OR(type, numPointerStars, snippet, \
446 orSnippet) \
447 SJME_TOKEN_PASTE_PP(SJME_TYPEOF_IF_POINTER_ORX, \
448 SJME_TYPEOF_IS_NOT_POINTER(type, numPointerStars))(snippet, orSnippet)
451 * Boolean type.
453 * @since 2023/07/25
455 typedef enum sjme_jboolean
457 SJME_JNI_FALSE = 0,
459 SJME_JNI_TRUE = 1
460 } sjme_jboolean;
462 /** Basic @c sjme_jboolean type identifier. */
463 #define SJME_TYPEOF_BASIC_sjme_jboolean SJME_BASIC_TYPE_ID_BOOLEAN
465 /** Java @c sjme_jboolean type identifier. */
466 #define SJME_TYPEOF_JAVA_sjme_jboolean SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE
468 /** Is a pointer for @c sjme_jboolean ? */
469 #define SJME_TYPEOF_IS_POINTER_sjme_jboolean 0
472 * Byte type.
474 * @since 2023/07/25
476 typedef int8_t sjme_jbyte;
478 /** Basic @c sjme_jbyte type identifier. */
479 #define SJME_TYPEOF_BASIC_sjme_jbyte SJME_BASIC_TYPE_ID_BYTE
481 /** Java @c sjme_jbyte type identifier. */
482 #define SJME_TYPEOF_JAVA_sjme_jbyte SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE
484 /** Is a pointer for @c sjme_jbyte ? */
485 #define SJME_TYPEOF_IS_POINTER_sjme_jbyte 0
488 * Unsigned byte type.
490 * @since 2023/08/09
492 typedef uint8_t sjme_jubyte;
494 /** Basic @c sjme_jubyte type identifier. */
495 #define SJME_TYPEOF_BASIC_sjme_jubyte SJME_BASIC_TYPE_ID_BYTE
497 /** Java @c sjme_jubyte type identifier. */
498 #define SJME_TYPEOF_JAVA_sjme_jubyte SJME_JAVA_TYPE_ID_BOOLEAN_OR_BYTE
500 /** Is a pointer for @c sjme_jubyte ? */
501 #define SJME_TYPEOF_IS_POINTER_sjme_jubyte 0
504 * Short type.
506 * @since 2023/07/25
508 typedef int16_t sjme_jshort;
510 /** Basic @c sjme_jshort type identifier. */
511 #define SJME_TYPEOF_BASIC_sjme_jshort SJME_BASIC_TYPE_ID_SHORT
513 /** Java @c sjme_jshort type identifier. */
514 #define SJME_TYPEOF_JAVA_sjme_jshort SJME_JAVA_TYPE_ID_INTEGER
516 /** Is a pointer for @c sjme_jshort ? */
517 #define SJME_TYPEOF_IS_POINTER_sjme_jshort 0
520 * Character type.
522 * @since 2023/07/25
524 typedef uint16_t sjme_jchar;
526 /** Basic @c sjme_jchar type identifier. */
527 #define SJME_TYPEOF_BASIC_sjme_jchar SJME_BASIC_TYPE_ID_CHARACTER
529 /** Java @c sjme_jchar type identifier. */
530 #define SJME_TYPEOF_JAVA_sjme_jchar SJME_JAVA_TYPE_ID_INTEGER
532 /** Is a pointer for @c sjme_jchar ? */
533 #define SJME_TYPEOF_IS_POINTER_sjme_jchar 0
536 * Integer type.
538 * @since 2023/07/25
540 typedef int32_t sjme_jint;
542 /** Basic @c sjme_jint type identifier. */
543 #define SJME_TYPEOF_BASIC_sjme_jint SJME_BASIC_TYPE_ID_INTEGER
545 /** Java @c sjme_jint type identifier. */
546 #define SJME_TYPEOF_JAVA_sjme_jint SJME_JAVA_TYPE_ID_INTEGER
548 /** Is a pointer for @c sjme_jint ? */
549 #define SJME_TYPEOF_IS_POINTER_sjme_jint 0
552 * Unsigned integer type.
554 * @since 2023/11/20
556 typedef uint32_t sjme_juint;
558 /** Basic @c sjme_juint type identifier. */
559 #define SJME_TYPEOF_BASIC_sjme_juint SJME_BASIC_TYPE_ID_INTEGER
561 /** Java @c sjme_juint type identifier. */
562 #define SJME_TYPEOF_JAVA_sjme_juint SJME_JAVA_TYPE_ID_INTEGER
564 /** Is a pointer for @c sjme_juint ? */
565 #define SJME_TYPEOF_IS_POINTER_sjme_juint 0
568 * Fixed point.
570 * @since 2024/06/27
572 typedef sjme_jint sjme_fixed;
575 * C Character.
577 * @since 2024/01/03
579 typedef char sjme_cchar;
581 #if defined(CHAR_BIT) && (CHAR_BIT == 64)
582 /** Basic @c sjme_cchar type identifier. */
583 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_LONG
584 #elif defined(CHAR_BIT) && (CHAR_BIT == 32)
585 /** Basic @c sjme_cchar type identifier. */
586 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_INTEGER
587 #elif defined(CHAR_BIT) && (CHAR_BIT == 16)
588 /** Basic @c sjme_cchar type identifier. */
589 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_SHORT
590 #else
591 /** Basic @c sjme_cchar type identifier. */
592 #define SJME_TYPEOF_BASIC_sjme_cchar SJME_BASIC_TYPE_ID_BYTE
593 #endif
595 /** Is a pointer for @c sjme_cchar ? */
596 #define SJME_TYPEOF_IS_POINTER_sjme_cchar 0
598 #if defined(SJME_CONFIG_HAS_ARCH_IA16)
600 * Pointer to C string.
602 * @since 2023/12/17
604 typedef sjme_cchar huge* sjme_lpstr;
605 #else
607 * Pointer to C string.
609 * @since 2023/12/17
611 typedef sjme_cchar* sjme_lpstr;
612 #endif
614 /** Basic @c sjme_lpstr type identifier. */
615 #define SJME_TYPEOF_BASIC_sjme_lpstr SJME_BASIC_TYPE_ID_OBJECT
617 /** Is a pointer for @c sjme_lpstr ? */
618 #define SJME_TYPEOF_IS_POINTER_sjme_lpstr 1
620 #if defined(SJME_CONFIG_HAS_ARCH_IA16)
622 * Pointer to constant C string.
624 * @since 2023/12/17
626 typedef const sjme_cchar huge* sjme_lpcstr;
627 #else
629 * Pointer to constant C string.
631 * @since 2023/12/17
633 typedef const sjme_cchar* sjme_lpcstr;
634 #endif
636 /** Basic @c sjme_lpcstr type identifier. */
637 #define SJME_TYPEOF_BASIC_sjme_lpcstr SJME_BASIC_TYPE_ID_OBJECT
639 /** Is a pointer for @c sjme_lpcstr ? */
640 #define SJME_TYPEOF_IS_POINTER_sjme_lpcstr 1
642 #if defined(SJME_CONFIG_HAS_ARCH_IA16)
644 * Generic pointer.
646 * @since 2023/12/27
648 typedef void huge* sjme_pointer;
649 #else
651 * Generic pointer.
653 * @since 2023/12/27
655 typedef void* sjme_pointer;
656 #endif
658 /** Basic @c sjme_pointer type identifier. */
659 #define SJME_TYPEOF_BASIC_sjme_pointer SJME_BASIC_TYPE_ID_OBJECT
661 /** Is a pointer for @c sjme_pointer ? */
662 #define SJME_TYPEOF_IS_POINTER_sjme_pointer 1
664 #if defined(SJME_CONFIG_HAS_ARCH_IA16)
666 * Generic pointer to const data.
668 * @since 2023/12/27
670 typedef void huge* sjme_cpointer;
671 #else
673 * Generic pointer to const data.
675 * @since 2023/12/27
677 typedef void* sjme_cpointer;
678 #endif
680 /** Basic @c sjme_cpointer type identifier. */
681 #define SJME_TYPEOF_BASIC_sjme_cpointer SJME_BASIC_TYPE_ID_OBJECT
683 /** Is a pointer for @c sjme_cpointer ? */
684 #define SJME_TYPEOF_IS_POINTER_sjme_cpointer 1
687 * Integer based pointer.
689 * @since 2024/04/06
691 typedef intptr_t sjme_intPointer;
693 /** Calculates a pointer offset. */
694 #define SJME_POINTER_OFFSET(base, off) \
695 (sjme_pointer)(((sjme_intPointer)(base)) + ((sjme_intPointer)(off)))
697 #if defined(SJME_CONFIG_HAS_POINTER64)
698 #define SJME_TYPEOF_BASIC_sjme_intPointer SJME_TYPEOF_BASIC_sjme_jpointer
699 #else
700 #define SJME_TYPEOF_BASIC_sjme_intPointer SJME_TYPEOF_BASIC_sjme_juint
701 #endif
703 #define SJME_TYPEOF_IS_POINTER_sjme_intPointer 0
706 * Long value.
708 * @since 2023/07/25
710 typedef union sjme_jlong
712 /** Parts of the long. */
713 struct
715 #if defined(SJME_CONFIG_HAS_LITTLE_ENDIAN)
716 /** Low value. */
717 sjme_juint lo;
719 /** High value. */
720 sjme_jint hi;
721 #else
722 /** High value. */
723 sjme_jint hi;
725 /** Low value. */
726 sjme_juint lo;
727 #endif
728 } part;
730 /** The full long. */
731 int64_t full;
732 } sjme_jlong;
734 /** Basic @c sjme_jlong type identifier. */
735 #define SJME_TYPEOF_BASIC_sjme_jlong SJME_BASIC_TYPE_ID_LONG
737 /** Java @c sjme_jlong type identifier. */
738 #define SJME_TYPEOF_JAVA_sjme_jlong SJME_JAVA_TYPE_ID_LONG
740 /** Is a pointer for @c sjme_jlong ? */
741 #define SJME_TYPEOF_IS_POINTER_sjme_jlong 0
744 * Float value.
746 * @sinc 2023/07/25
748 typedef struct sjme_jfloat
750 sjme_jint value;
751 } sjme_jfloat;
753 /** Basic @c sjme_jfloat type identifier. */
754 #define SJME_TYPEOF_BASIC_sjme_jfloat SJME_BASIC_TYPE_ID_FLOAT
756 /** Java @c sjme_jfloat type identifier. */
757 #define SJME_TYPEOF_JAVA_sjme_jfloat SJME_JAVA_TYPE_ID_FLOAT
759 /** Is a pointer for @c sjme_jfloat ? */
760 #define SJME_TYPEOF_IS_POINTER_sjme_jfloat 0
763 * Double value.
765 * @sinc 2023/07/25
767 typedef struct sjme_jdouble
769 #if defined(SJME_CONFIG_HAS_LITTLE_ENDIAN)
770 /** Low value. */
771 sjme_juint lo;
773 /** High value. */
774 sjme_juint hi;
775 #else
776 /** High value. */
777 sjme_juint hi;
779 /** Low value. */
780 sjme_juint lo;
781 #endif
782 } sjme_jdouble;
784 /** Basic @c sjme_jdouble type identifier. */
785 #define SJME_TYPEOF_BASIC_sjme_jdouble SJME_BASIC_TYPE_ID_DOUBLE
787 /** Java @c sjme_jdouble type identifier. */
788 #define SJME_TYPEOF_JAVA_sjme_jdouble SJME_JAVA_TYPE_ID_DOUBLE
790 /** Is a pointer for @c sjme_jdouble ? */
791 #define SJME_TYPEOF_IS_POINTER_sjme_jdouble 0
794 * Temporary index.
796 * @since 2023/07/25
798 typedef sjme_jint sjme_tempIndex;
801 * A range of values.
803 * @since 2024/01/03
805 typedef struct sjme_range
807 /** Start of the range. */
808 sjme_jint start;
810 /** End of the range. */
811 sjme_jint end;
812 } sjme_range;
815 * Represents a pointer and a length.
817 * @since 2024/02/04
819 typedef struct sjme_pointerLen
821 /** The pointer to the data. */
822 sjme_pointer pointer;
824 /** The length of the pointer. */
825 sjme_jint length;
826 } sjme_pointerLen;
829 * A wrapper used by front ends, which is reserved for use, which stores a
830 * natively bound object accordingly as needed.
832 * @since 2023/12/06
834 typedef sjme_pointer sjme_frontEndWrapper;
837 * Any data that is needed by the front end, which is reserved for use.
839 * @since 2023/12/14
841 typedef sjme_pointer sjme_frontEndData;
844 * This structure stores any front end data as needed.
846 * @since 2023/12/14
848 typedef struct sjme_frontEnd
850 /** Any wrapper as needed. */
851 sjme_frontEndWrapper wrapper;
853 /** Any data as needed. */
854 sjme_frontEndData data;
855 } sjme_frontEnd;
858 * Wraps the given front end pointer.
860 * @param p The pointer to wrap.
861 * @since 2023/12/08
863 #define SJME_FRONT_END_WRAP(p) ((sjme_frontEndWrapper)(p))
865 /** The Java type ID. */
866 typedef sjme_basicTypeId sjme_javaTypeId;
869 * Represents multiple type IDs.
871 * @since 2023/08/09
873 typedef struct sjme_basicTypeIds
875 /** The number of IDs. */
876 sjme_jint count;
878 /** The IDs. */
879 const sjme_javaTypeId ids[sjme_flexibleArrayCount];
880 } sjme_basicTypeIds;
883 * Program counter address.
885 * @since 2023/07/25
887 typedef sjme_jint sjme_pcAddr;
890 * Static linkage type.
892 * @since 2023/07/25
894 typedef sjme_jint sjme_staticLinkageType;
897 * Base object information.
899 * @since 2023/07/25
901 typedef struct sjme_jobjectBase
903 /** The reference count of this object, zero it becomes GCed. */
904 sjme_jint refCount;
905 } sjme_jobjectBase;
908 * Object type.
910 * @since 2023/07/25
912 typedef sjme_jobjectBase* sjme_jobject;
915 * Generic value union.
917 * @since 2024/01/05
919 typedef union sjme_jvalue
921 /** Boolean. */
922 sjme_jboolean z;
924 /** Byte. */
925 sjme_jbyte b;
927 /** Character. */
928 sjme_jchar c;
930 /** Short. */
931 sjme_jshort s;
933 /** Integer. */
934 sjme_jint i;
936 /** Long. */
937 sjme_jlong j;
939 /** Float. */
940 sjme_jfloat f;
942 /** Double. */
943 sjme_jdouble d;
945 /** Object/Reference. */
946 sjme_jobject l;
947 } sjme_jvalue;
950 * Class type.
952 * @since 2023/07/25
954 typedef sjme_jobject sjme_jclass;
956 /** Basic @c sjme_jobject type identifier. */
957 #define SJME_TYPEOF_BASIC_sjme_jobject SJME_BASIC_TYPE_ID_OBJECT
959 /** Java @c sjme_jobject type identifier. */
960 #define SJME_TYPEOF_JAVA_sjme_jobject SJME_BASIC_TYPE_ID_OBJECT
962 /** Is a pointer for @c sjme_jobject ? */
963 #define SJME_TYPEOF_IS_POINTER_sjme_jobject 1
966 * Throwable type.
968 * @since 2023/07/25
970 typedef sjme_jobject sjme_jthrowable;
972 typedef union sjme_anyData
974 /** Integer. */
975 sjme_jint jint;
977 /** Object. */
978 sjme_jobject jobject;
980 /** Temporary index. */
981 sjme_tempIndex tempIndex;
982 } sjme_anyData;
984 typedef struct sjme_any
986 /** Data type used. */
987 sjme_basicTypeId type;
989 /** Data stored within. */
990 sjme_anyData data;
991 } sjme_any;
994 * Represents the virtual machine state.
996 * @since 2023/07/28
998 typedef struct sjme_nvm_state sjme_nvm_state;
1001 * Frame of execution within a thread.
1003 * @since 2023/07/25
1005 typedef struct sjme_nvm_frame sjme_nvm_frame;
1008 * Exception stack trace mechanism storage.
1010 * @since 2023/12/08
1012 typedef struct sjme_exceptTrace sjme_exceptTrace;
1014 typedef struct sjme_nvm_thread
1016 /** The VM state this thread is in. */
1017 sjme_nvm_state* inState;
1019 /** The wrapper in the front end. */
1020 sjme_frontEnd frontEnd;
1022 /** The thread ID. */
1023 sjme_jint threadId;
1025 /** The top of the stack. */
1026 sjme_nvm_frame* top;
1028 /** The number of frames. */
1029 sjme_jint numFrames;
1031 /** Current exception handler go back. */
1032 sjme_exceptTrace* except;
1033 } sjme_nvm_thread;
1035 typedef struct sjme_static_constValue
1037 /** Integer value. */
1038 sjme_jint jint;
1040 /** Long value. */
1041 sjme_jlong jlong;
1043 /** Float value. */
1044 sjme_jfloat jfloat;
1046 /** Double value. */
1047 sjme_jdouble jdouble;
1049 /** String value. */
1050 sjme_lpcstr jstring;
1052 /** Class name. */
1053 sjme_lpcstr jclass;
1054 } sjme_static_constValue;
1057 * Represents a field type.
1059 * @since 2023/08/10
1061 typedef struct sjme_static_fieldType
1063 /** The hash code for the field type. */
1064 sjme_jint hashCode;
1066 /** The field descriptor. */
1067 sjme_lpcstr descriptor;
1069 /** The basic type. */
1070 sjme_basicTypeId basicType;
1071 } sjme_static_fieldType;
1073 typedef struct sjme_static_classField
1075 /** Field name. */
1076 sjme_lpcstr name;
1078 /** The field type. */
1079 const sjme_static_fieldType* type;
1081 /** Flags. */
1082 sjme_jint flags;
1084 /** The constant value type. */
1085 sjme_basicTypeId valueType;
1087 /** The value. */
1088 sjme_static_constValue value;
1089 } sjme_static_classField;
1091 typedef struct sjme_static_classFields
1093 /** The number of fields. */
1094 sjme_jint count;
1096 /** Fields. */
1097 sjme_static_classField fields[sjme_flexibleArrayCount];
1098 } sjme_static_classFields;
1101 * Type used for method code functions.
1103 * @param currentState The current virtual machine state.
1104 * @param currentThread The current virtual machine thread.
1105 * @return Will return @c SJME_JNI_TRUE if execution completed without throwing
1106 * a @c Throwable object.
1107 * @since 2023/07/25
1109 typedef sjme_jboolean (*sjme_methodCodeFunction)(
1110 struct sjme_nvm_state* currentState,
1111 struct sjme_nvm_thread* currentThread);
1114 * The variable mapping and setup for any given method.
1116 * @since 2023/08/09
1118 typedef struct sjme_static_classCodeLimits
1120 /** The maximum number of @c sjme_basicTypeId local/stack variables. */
1121 const sjme_jubyte maxVariables[SJME_NUM_JAVA_TYPE_IDS];
1122 } sjme_static_classCodeLimits;
1125 * Contains information about method code and how variables should be placed
1126 * on execution and stack handling.
1128 * @since 2023/08/09
1130 typedef struct sjme_static_classCode
1132 /** The variable count and thrown index count used. */
1133 const sjme_static_classCodeLimits* limits;
1135 /** The index where thrown objects are placed. */
1136 sjme_jshort thrownVarIndex;
1138 /** The method code. */
1139 sjme_methodCodeFunction code;
1140 } sjme_static_classCode;
1143 * Represents a standard Java method type, using field descriptors.
1145 * @since 2023/08/10
1147 typedef struct sjme_static_methodType
1149 /** The hash code for the method type. */
1150 sjme_jint hashCode;
1152 /** The descriptor for the method type. */
1153 sjme_lpcstr descriptor;
1155 /** The return type. */
1156 const sjme_static_fieldType* returnType;
1158 /** The number of arguments. */
1159 sjme_jint argCount;
1161 /** The arguments to the method. */
1162 const sjme_static_fieldType* argTypes[sjme_flexibleArrayCount];
1163 } sjme_static_methodType;
1165 typedef struct sjme_static_classMethod
1167 /** Method name. */
1168 sjme_lpcstr name;
1170 /** Flags. */
1171 sjme_jint flags;
1173 /** Name typed. */
1174 const sjme_static_methodType* type;
1176 /** Method code and any pertaining information. */
1177 const sjme_static_classCode* code;
1178 } sjme_static_classMethod;
1180 typedef struct sjme_static_classMethods
1182 /** The number of methods. */
1183 sjme_jint count;
1185 /** Methods. */
1186 sjme_static_classMethod methods[sjme_flexibleArrayCount];
1187 } sjme_static_classMethods;
1189 typedef struct sjme_static_classInterface
1191 sjme_lpcstr interfaceName;
1192 } sjme_static_classInterface;
1194 typedef struct sjme_static_classInterfaces
1196 /** The number of interfaces. */
1197 sjme_jint count;
1199 /** Interfaces. */
1200 sjme_static_classInterface interfaces[sjme_flexibleArrayCount];
1201 } sjme_static_classInterfaces;
1203 typedef struct sjme_static_resource
1205 /** The resource path. */
1206 sjme_lpcstr path;
1208 /** The hash for the path. */
1209 sjme_jint pathHash;
1211 /** The size of the resource. */
1212 sjme_jint size;
1214 /** The resource data. */
1215 const sjme_jbyte data[sjme_flexibleArrayCount];
1216 } sjme_static_resource;
1218 typedef struct sjme_static_linkage_data_classObject
1220 /** The class name. */
1221 sjme_lpcstr className;
1222 } sjme_static_linkage_data_classObject;
1224 typedef struct sjme_static_linkage_data_fieldAccess
1226 /** Is this static? */
1227 sjme_jboolean isStatic;
1229 /** Is this a store? */
1230 sjme_jboolean isStore;
1232 /** The source method name. */
1233 sjme_lpcstr sourceMethodName;
1235 /** The source method type. */
1236 sjme_lpcstr sourceMethodType;
1238 /** The target class. */
1239 sjme_lpcstr targetClass;
1241 /** The target field name. */
1242 sjme_lpcstr targetFieldName;
1244 /** The target field type. */
1245 sjme_lpcstr targetFieldType;
1246 } sjme_static_linkage_data_fieldAccess;
1248 typedef struct sjme_static_linkage_data_invokeSpecial
1250 /** The source method name. */
1251 sjme_lpcstr sourceMethodName;
1253 /** The source method type. */
1254 sjme_lpcstr sourceMethodType;
1256 /** The target class. */
1257 sjme_lpcstr targetClass;
1259 /** The target method name. */
1260 sjme_lpcstr targetMethodName;
1262 /** The target method type. */
1263 sjme_lpcstr targetMethodType;
1264 } sjme_static_linkage_data_invokeSpecial;
1266 typedef struct sjme_static_linkage_data_invokeNormal
1268 /** Is this a static invocation? */
1269 sjme_jboolean isStatic;
1271 /** The source method name. */
1272 sjme_lpcstr sourceMethodName;
1274 /** The source method type. */
1275 sjme_lpcstr sourceMethodType;
1277 /** The target class. */
1278 sjme_lpcstr targetClass;
1280 /** The target method name. */
1281 sjme_lpcstr targetMethodName;
1283 /** The target method type. */
1284 sjme_lpcstr targetMethodType;
1285 } sjme_static_linkage_data_invokeNormal;
1287 typedef struct sjme_static_linkage_data_stringObject
1289 /** The string value. */
1290 sjme_lpcstr string;
1291 } sjme_static_linkage_data_stringObject;
1293 typedef union sjme_static_linkage_data
1295 /** Reference to class object. */
1296 sjme_static_linkage_data_classObject classObject;
1298 /** Field access. */
1299 sjme_static_linkage_data_fieldAccess fieldAccess;
1301 /** Special invocation. */
1302 sjme_static_linkage_data_invokeSpecial invokeSpecial;
1304 /** Normal invocation. */
1305 sjme_static_linkage_data_invokeNormal invokeNormal;
1307 /** String object. */
1308 sjme_static_linkage_data_stringObject stringObject;
1309 } sjme_static_linkage_data;
1312 * Static linkage.
1314 * @since 2023/07/25
1316 typedef struct sjme_static_linkage
1318 /** The type of linkage this is. */
1319 sjme_staticLinkageType type;
1321 /** Linkage data. */
1322 sjme_static_linkage_data data;
1323 } sjme_static_linkage;
1325 typedef struct sjme_static_linkages
1327 /** The number of linkages. */
1328 sjme_jint count;
1330 /** The define linkages. */
1331 sjme_static_linkage linkages[sjme_flexibleArrayCount];
1332 } sjme_static_linkages;
1334 typedef struct sjme_dynamic_linkage_data_classObject
1336 int todo;
1337 } sjme_dynamic_linkage_data_classObject;
1339 typedef struct sjme_dynamic_linkage_data_fieldAccess
1341 int todo;
1342 } sjme_dynamic_linkage_data_fieldAccess;
1344 typedef struct sjme_dynamic_linkage_data_invokeSpecial
1346 int todo;
1347 } sjme_dynamic_linkage_data_invokeSpecial;
1349 typedef struct sjme_dynamic_linkage_data_invokeNormal
1351 int todo;
1352 } sjme_dynamic_linkage_data_invokeNormal;
1354 typedef struct sjme_dynamic_linkage_data_stringObject
1356 int todo;
1357 } sjme_dynamic_linkage_data_stringObject;
1359 typedef union sjme_dynamic_linkage_data
1361 /** Reference to class object. */
1362 sjme_dynamic_linkage_data_classObject classObject;
1364 /** Field access. */
1365 sjme_dynamic_linkage_data_fieldAccess fieldAccess;
1367 /** Special invocation. */
1368 sjme_dynamic_linkage_data_invokeSpecial invokeSpecial;
1370 /** Normal invocation. */
1371 sjme_dynamic_linkage_data_invokeNormal invokeNormal;
1373 /** String object. */
1374 sjme_dynamic_linkage_data_stringObject stringObject;
1375 } sjme_dynamic_linkage_data;
1378 * Dynamic linkage.
1380 * @since 2023/07/25
1382 typedef struct sjme_dynamic_linkage
1384 /** The type of linkage this is. */
1385 sjme_staticLinkageType type;
1387 /** Linkage data. */
1388 sjme_dynamic_linkage_data data;
1389 } sjme_dynamic_linkage;
1392 * Represents the frame of a stack tread.
1394 * @since 2023/11/15
1396 typedef struct sjme_nvm_frameTread
1398 /** The number of items in this tread. */
1399 sjme_jint count;
1401 /** The base index for the stack index. */
1402 sjme_jint stackBaseIndex;
1404 /** The maximum size this tread can be. */
1405 sjme_jint max;
1407 /** Values within the tread. */
1408 union
1410 /** Integer values. */
1411 sjme_jint jints[sjme_flexibleArrayCountUnion];
1413 /** Long values. */
1414 sjme_jlong jlongs[sjme_flexibleArrayCountUnion];
1416 /** Float values. */
1417 sjme_jfloat jfloats[sjme_flexibleArrayCountUnion];
1419 /** Double values. */
1420 sjme_jdouble jdoubles[sjme_flexibleArrayCountUnion];
1422 /** Object references. */
1423 sjme_jobject jobjects[sjme_flexibleArrayCountUnion];
1424 } values;
1425 } sjme_nvm_frameTread;
1428 * Calculates the size of a frame tread for a given type.
1430 * @param type The type to get the size for.
1431 * @param count The number if items to store.
1432 * @return The size in bytes for the tread.
1433 * @since 2023/11/15
1435 #define SJME_SIZEOF_FRAME_TREAD(type, count, baseType) \
1436 (sizeof(sjme_nvm_frameTread) + \
1437 /* Need to handle cases where values could be aligned up... */ \
1438 (offsetof(sjme_nvm_frameTread, values.SJME_TOKEN_PASTE(baseType,s)[0]) - \
1439 offsetof(sjme_nvm_frameTread, values)) + \
1440 (sizeof(type) * (size_t)(count)))
1443 * Calculates the size of a frame tread for a given type via variable.
1445 * @param typeId The type to get the size for.
1446 * @param count The number if items to store.
1447 * @return The size in bytes for the tread.
1448 * @since 2023/11/15
1450 static sjme_inline sjme_attrArtificial size_t SJME_SIZEOF_FRAME_TREAD_VAR(
1451 sjme_javaTypeId typeId, sjme_jint count)
1453 switch (typeId)
1455 case SJME_JAVA_TYPE_ID_INTEGER:
1456 return SJME_SIZEOF_FRAME_TREAD(sjme_jint, count, jint);
1458 case SJME_JAVA_TYPE_ID_LONG:
1459 return SJME_SIZEOF_FRAME_TREAD(sjme_jlong, count, jlong);
1461 case SJME_JAVA_TYPE_ID_FLOAT:
1462 return SJME_SIZEOF_FRAME_TREAD(sjme_jfloat, count, jfloat);
1464 case SJME_JAVA_TYPE_ID_DOUBLE:
1465 return SJME_SIZEOF_FRAME_TREAD(sjme_jdouble, count, jdouble);
1467 case SJME_JAVA_TYPE_ID_OBJECT:
1468 return SJME_SIZEOF_FRAME_TREAD(sjme_jobject, count, jobject);
1471 /* Invalid. */
1472 return 0;
1476 * Represents information on a frame's stack storage.
1478 * @since 2023/11/16
1480 typedef struct sjme_nvm_frameStack
1482 /** The number of items in the stack. */
1483 sjme_jint count;
1485 /** The current limit of this structure. */
1486 sjme_jint limit;
1488 /** The stack order. */
1489 sjme_javaTypeId order[sjme_flexibleArrayCount];
1490 } sjme_nvm_frameStack;
1493 * Calculates the size of a frame stack.
1495 * @param count The number if items to store.
1496 * @return The size in bytes for the tread.
1497 * @since 2023/11/16
1499 #define SJME_SIZEOF_FRAME_STACK(count) \
1500 (sizeof(sjme_nvm_frameStack) + \
1501 (sizeof(sjme_javaTypeId) * (size_t)(count)))
1503 typedef struct sjme_nvm_frameLocalMap
1505 /** The maximum number of locals. */
1506 sjme_jint max;
1508 /** Mapping of a specific variable to a given type index. */
1509 union
1511 sjme_jbyte to[SJME_NUM_JAVA_TYPE_IDS];
1512 } maps[sjme_flexibleArrayCount];
1513 } sjme_nvm_frameLocalMap;
1516 * Calculates the size of the frame local variable map.
1518 * @param count The number of items in the mapping.
1519 * @return The size in bytes of the local mapping.
1520 * @since 2023/11/26
1522 #define SJME_SIZEOF_FRAME_LOCAL_MAP(count) \
1523 (sizeof(sjme_nvm_frameLocalMap) + \
1524 (SJME_SIZEOF_STRUCT_MEMBER(sjme_nvm_frameLocalMap, maps[0]) * (count)))
1526 struct sjme_nvm_frame
1528 /** The thread this frame is in. */
1529 sjme_nvm_thread* inThread;
1531 /** The wrapper in the front end. */
1532 sjme_frontEnd frontEnd;
1534 /** The parent frame. */
1535 sjme_nvm_frame* parent;
1537 /** The frame index in the thread. */
1538 sjme_jint frameIndex;
1540 /** The current program counter. */
1541 sjme_pcAddr pc;
1543 /** Object which is waiting to be thrown for exception handling. */
1544 sjme_jobject waitingThrown;
1546 /** Frame linkage. */
1547 sjme_dynamic_linkage* linkage;
1549 /** Temporary stack. */
1550 sjme_any* tempStack;
1552 /** Reference to this. */
1553 sjme_jobject thisRef;
1555 /** Class reference. */
1556 sjme_jclass classObjectRef;
1558 /** The current stack information. */
1559 sjme_nvm_frameStack* stack;
1561 /** Treads for the stack and locals. */
1562 sjme_nvm_frameTread* treads[SJME_NUM_BASIC_TYPE_IDS];
1564 /** Mapping of local variables to the tread indexes per type. */
1565 const sjme_nvm_frameLocalMap* localMap;
1569 * Contains the payload information.
1571 * @since 2023/07/27
1573 typedef struct sjme_payload_config sjme_payload_config;
1576 * Hook for garbage collection detection and/or cancel capability.
1578 * @param frame The frame this is garbage collecting in.
1579 * @param gcWhat what is being garbage collected?
1580 * @return Returns @c SJME_JNI_TRUE if garbage collection should continue.
1581 * @since 2023/11/17
1583 typedef sjme_jboolean (*sjme_nvm_stateHookGcFunc)(sjme_nvm_frame* frame,
1584 sjme_jobject gcWhat);
1587 * Hooks for alternative function.
1589 * @since 2023/11/17
1591 typedef struct sjme_nvm_stateHooks
1593 /** Garbage collection. */
1594 sjme_nvm_stateHookGcFunc gc;
1595 } sjme_nvm_stateHooks;
1598 * Structure which stores the pooled memory allocator.
1600 * @since 2023/11/18
1602 typedef struct sjme_alloc_pool sjme_alloc_pool;
1605 * Boot parameters for NanoCoat.
1607 * @since 2023/07/27
1609 typedef struct sjme_nvm_bootParam sjme_nvm_bootParam;
1612 * Standard Suite structure.
1614 * @since 2023/12/12
1616 typedef struct sjme_rom_suiteCore sjme_rom_suiteCore;
1619 * Opaque suite structure type.
1621 * @since 2023/12/22
1623 typedef struct sjme_rom_suiteCore* sjme_rom_suite;
1626 * Structure for a single task.
1628 * @since 2023/12/17
1630 typedef struct sjme_nvm_taskCore* sjme_nvm_task;
1633 * Represents the virtual machine state.
1635 * @since 2023/07/28
1637 struct sjme_nvm_state
1639 /** The wrapper in the front end. */
1640 sjme_frontEnd frontEnd;
1642 /** The memory pool to use for allocations. */
1643 sjme_alloc_pool* allocPool;
1645 /** The reserved memory pool. */
1646 sjme_alloc_pool* reservedPool;
1648 /** The copy of the input boot parameters. */
1649 const sjme_nvm_bootParam* bootParamCopy;
1651 /** Hooks for the state. */
1652 const sjme_nvm_stateHooks* hooks;
1654 /* The suite containing all the libraries. */
1655 sjme_rom_suite suite;
1659 * Method initialization start.
1661 * @since 2023/07/25
1663 #define SJME_NANOCOAT_START_CALL ((sjme_pcAddr)-1)
1666 * Method closing end.
1668 * @since 2023/07/25
1670 #define SJME_NANOCOAT_END_CALL ((sjme_pcAddr)-2)
1673 * Error codes.
1675 * @since 2023/11/14
1677 typedef enum sjme_errorCode
1679 /** No error. */
1680 SJME_ERROR_NONE = 1,
1682 /** Generic unknown error. */
1683 SJME_ERROR_UNKNOWN = 0,
1685 /** Generic unknown error. */
1686 SJME_ERROR_UNKNOWN_NEGATIVE = -1,
1688 /** Null arguments. */
1689 SJME_ERROR_NULL_ARGUMENTS = -2,
1691 /** Local variable out of bounds. */
1692 SJME_ERROR_LOCAL_INDEX_INVALID = -3,
1694 /** Stack variable out of bounds. */
1695 SJME_ERROR_STACK_INDEX_INVALID = -4,
1697 /** Stack underflow. */
1698 SJME_ERROR_STACK_UNDERFLOW = -5,
1700 /** Stack overflow. */
1701 SJME_ERROR_STACK_OVERFLOW = -6,
1703 /** Top is not an integer type. */
1704 SJME_ERROR_TOP_NOT_INTEGER = -7,
1706 /** Top is not a long type. */
1707 SJME_ERROR_TOP_NOT_LONG = -8,
1709 /** Top is not a float type. */
1710 SJME_ERROR_TOP_NOT_FLOAT = -9,
1712 /** Top is not a double type. */
1713 SJME_ERROR_TOP_NOT_DOUBLE = -10,
1715 /** Top is not a object type. */
1716 SJME_ERROR_TOP_NOT_OBJECT = -11,
1718 /** Frame is missing stack treads. */
1719 SJME_ERROR_FRAME_MISSING_STACK_TREADS = -12,
1721 /** Invalid read of stack. */
1722 SJME_ERROR_STACK_INVALID_READ = -13,
1724 /** Invalid write of stack. */
1725 SJME_ERROR_STACK_INVALID_WRITE = -14,
1727 /** Invalid read of stack. */
1728 SJME_ERROR_LOCAL_INVALID_READ = -15,
1730 /** Invalid write of stack. */
1731 SJME_ERROR_LOCAL_INVALID_WRITE = -16,
1733 /** Invalid reference pop. */
1734 SJME_ERROR_INVALID_REFERENCE_POP = -17,
1736 /** Invalid reference push. */
1737 SJME_ERROR_INVALID_REFERENCE_PUSH = -18,
1739 /** Failed to garbage collect object. */
1740 SJME_ERROR_COULD_NOT_GC_OBJECT = -19,
1742 /** Object reference count is not zero. */
1743 SJME_ERROR_OBJECT_REFCOUNT_NOT_ZERO = -20,
1745 /** Garbage collection of object cancelled. */
1746 SJME_ERROR_OBJECT_GC_CANCELLED = -21,
1748 /** Out of memory. */
1749 SJME_ERROR_OUT_OF_MEMORY = -22,
1751 /** Pool initialization failed. */
1752 SJME_ERROR_POOL_INIT_FAILED = -23,
1754 /** Invalid argument. */
1755 SJME_ERROR_INVALID_ARGUMENT = -24,
1757 /** Not implemented. */
1758 SJME_ERROR_NOT_IMPLEMENTED = -25,
1760 /** Invalid tread read. */
1761 SJME_ERROR_TREAD_INVALID_READ = -26,
1763 /** Invalid tread write. */
1764 SJME_ERROR_TREAD_INVALID_WRITE = -27,
1766 /** There are no suites available. */
1767 SJME_ERROR_NO_SUITES = -28,
1769 /** Classpath cannot be obtained by both ID and Name. */
1770 SJME_ERROR_CLASS_PATH_BY_BOTH = -29,
1772 /** Illegal state. */
1773 SJME_ERROR_ILLEGAL_STATE = -30,
1775 /** A library was not found. */
1776 SJME_ERROR_LIBRARY_NOT_FOUND = -31,
1778 /** Boot failure. */
1779 SJME_ERROR_BOOT_FAILURE = -32,
1781 /** Generic JNI exception. */
1782 SJME_ERROR_JNI_EXCEPTION = -33,
1784 /** Memory has been corrupted. */
1785 SJME_ERROR_MEMORY_CORRUPTION = -34,
1787 /** Index out of bounds. */
1788 SJME_ERROR_INDEX_OUT_OF_BOUNDS = -35,
1790 /** Unsupported operation. */
1791 SJME_ERROR_UNSUPPORTED_OPERATION = -36,
1793 /** Resource not found. */
1794 SJME_ERROR_RESOURCE_NOT_FOUND = -37,
1796 /** Unexpected end of file. */
1797 SJME_ERROR_UNEXPECTED_EOF = -38,
1799 /** Invalid identifier. */
1800 SJME_ERROR_INVALID_IDENTIFIER = -39,
1802 /** Invalid binary name. */
1803 SJME_ERROR_INVALID_BINARY_NAME = -40,
1805 /** Invalid field type. */
1806 SJME_ERROR_INVALID_FIELD_TYPE = -41,
1808 /** Invalid method type. */
1809 SJME_ERROR_INVALID_METHOD_TYPE = -42,
1811 /** Invalid class name. */
1812 SJME_ERROR_INVALID_CLASS_NAME = -43,
1814 /** Could not load library. */
1815 SJME_ERROR_COULD_NOT_LOAD_LIBRARY = -44,
1817 /** Invalid library symbol. */
1818 SJME_ERROR_INVALID_LIBRARY_SYMBOL = -45,
1820 /** There is no graphics display. */
1821 SJME_ERROR_HEADLESS_DISPLAY = -46,
1823 /** Cannot create something. */
1824 SJME_ERROR_CANNOT_CREATE = -47,
1826 /** Invalid thread state. */
1827 SJME_ERROR_INVALID_THREAD_STATE = -48,
1829 /** Component is already in a container. */
1830 SJME_ERROR_ALREADY_IN_CONTAINER = -49,
1832 /** Not a sub component. */
1833 SJME_ERROR_NOT_SUB_COMPONENT = -50,
1835 /** No such class exists. */
1836 SJME_ERROR_NO_CLASS = -51,
1838 /** No such method exists. */
1839 SJME_ERROR_NO_METHOD = -52,
1841 /** There is no listener. */
1842 SJME_ERROR_NO_LISTENER = -53,
1844 /** Cancel close of window. */
1845 SJME_ERROR_CANCEL_WINDOW_CLOSE = -54,
1847 /** The class cannot be casted. */
1848 SJME_ERROR_CLASS_CAST = -55,
1850 /** The font is not valid. */
1851 SJME_ERROR_INVALID_FONT = -56,
1853 /** There is no Java environment. */
1854 SJME_ERROR_NO_JAVA_ENVIRONMENT = -57,
1856 /** Font has negative height. */
1857 SJME_ERROR_FONT_NEGATIVE_HEIGHT = -58,
1859 /** Could not create native widget. */
1860 SJME_ERROR_NATIVE_WIDGET_CREATE_FAILED = -59,
1862 /** Clock failure. */
1863 SJME_ERROR_NATIVE_SYSTEM_CLOCK_FAILURE = -60,
1865 /** A weak reference it attached. */
1866 SJME_ERROR_WEAK_REFERENCE_ATTACHED = -61,
1868 /** An enqueue has already been set for the weak reference. */
1869 SJME_ERROR_ENQUEUE_ALREADY_SET = -62,
1871 /** Keep the weak reference, do not free it on zero references. */
1872 SJME_ERROR_ENQUEUE_KEEP_WEAK = -63,
1874 /** Not a weak reference. */
1875 SJME_ERROR_NOT_WEAK_REFERENCE = -64,
1877 /** Could not access array natively. */
1878 SJME_ERROR_NATIVE_ARRAY_ACCESS_FAILED = -65,
1880 /** The graphics buffer is not locked. */
1881 SJME_ERROR_BUFFER_NOT_LOCKED = -66,
1883 /** Component is not in this container. */
1884 SJME_ERROR_NOT_IN_CONTAINER = -67,
1886 /** Invalid link. */
1887 SJME_ERROR_INVALID_LINK = -68,
1889 /** We are not the owner of the lock. */
1890 SJME_ERROR_NOT_LOCK_OWNER = -69,
1892 /** Item already has a parent. */
1893 SJME_ERROR_HAS_PARENT = -70,
1895 /** Member already exists. */
1896 SJME_ERROR_MEMBER_EXISTS = -71,
1898 /** The native widget system failed for some reason. */
1899 SJME_ERROR_NATIVE_WIDGET_FAILURE = -72,
1901 /** Scan out of bounds. */
1902 SJME_ERROR_SCAN_OUT_OF_BOUNDS = -73,
1904 /** Native graphics access not yet valid. */
1905 SJME_ERROR_FRAMEBUFFER_NOT_READY = -74,
1907 /** Could not unload native library. */
1908 SJME_ERROR_COULD_NOT_UNLOAD_LIBRARY = -75,
1910 /** Could not enqueue onto the message loop. */
1911 SJME_ERROR_LOOP_ENQUEUE_FAILED = -76,
1913 /** Use fallback. */
1914 SJME_ERROR_USE_FALLBACK = -77,
1916 /** Continue operation. */
1917 SJME_ERROR_CONTINUE = -78,
1919 /** The number of error codes. */
1920 SJME_NUM_ERROR_CODES = -79
1921 } sjme_errorCode;
1924 * Propagates an error code which allows others to run accordingly.
1926 * @param error The current error code.
1927 * @param expression The result from the expression.
1928 * @return If @c expression is an error, that will be returned otherwise
1929 * the value in @c error provided @c error is not an error.
1930 * @since 2024/01/18
1932 sjme_errorCode sjme_error_also(
1933 sjme_errorCode error, sjme_errorCode expression);
1936 * Similar to @c sjme_error_also except this allows multiple error expressions
1937 * to be passed until the final is done via @c sjme_error_alsoVEnd() .
1939 * @param error The current error state.
1940 * @param ... All of the expressions, ends on @c sjme_error_alsoVEnd() .
1941 * @return The resultant error code.
1942 * @since 2024/01/18
1944 sjme_errorCode sjme_error_alsoV(
1945 sjme_errorCode error, ...);
1948 * The end expression for @c sjme_error_alsoV() .
1950 * @return The ending sequence for error codes.
1951 * @since 2024/01/18
1953 sjme_errorCode sjme_error_alsoVEnd(void);
1956 * Is this expression considered an error?
1958 * @param error The expression.
1959 * @since 2023/12/08
1961 sjme_jboolean sjme_error_is(
1962 sjme_errorCode error);
1965 * Determines the default error code to use.
1967 * @param error The error code.
1968 * @return Either @c error or a default error.
1969 * @since 2023/12/29
1971 sjme_errorCode sjme_error_default(
1972 sjme_errorCode error);
1975 * Determines the default error code to use.
1977 * @param error The error code.
1978 * @param otherwise The other error code rather than @c SJME_ERROR_UNKNOWN.
1979 * @return Either @c error or @c otherwise if the former is not valid.
1980 * @since 2023/12/29
1982 sjme_errorCode sjme_error_defaultOr(
1983 sjme_errorCode error, sjme_errorCode otherwise);
1985 /*--------------------------------------------------------------------------*/
1987 /* Anti-C++. */
1988 #ifdef __cplusplus
1989 #ifdef SJME_CXX_SQUIRRELJME_NVM_H
1991 #undef SJME_CXX_SQUIRRELJME_NVM_H
1992 #undef SJME_CXX_IS_EXTERNED
1993 #endif /* #ifdef SJME_CXX_SQUIRRELJME_NVM_H */
1994 #endif /* #ifdef __cplusplus */
1996 #endif /* SQUIRRELJME_NVM_H */