1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
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 // -------------------------------------------------------------------------*/
11 * Bytecode Execution Support.
16 #ifndef SQUIRRELJME_BYTECODE_H
17 #define SQUIRRELJME_BYTECODE_H
23 #ifndef SJME_CXX_IS_EXTERNED
24 #define SJME_CXX_IS_EXTERNED
25 #define SJME_CXX_SQUIRRELJME_BYTECODE_H
27 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
28 #endif /* #ifdef __cplusplus */
30 /*--------------------------------------------------------------------------*/
33 * Enumeration for byte code instructions.
37 typedef enum sjme_byteCode_instruction
40 SJME_BYTECODE_INSTRUCTION_NOP
= 0,
43 SJME_BYTECODE_INSTRUCTION_ACONST_NULL
= 1,
46 SJME_BYTECODE_INSTRUCTION_ICONST_M1
= 2,
49 SJME_BYTECODE_INSTRUCTION_ICONST_0
= 3,
52 SJME_BYTECODE_INSTRUCTION_ICONST_1
= 4,
55 SJME_BYTECODE_INSTRUCTION_ICONST_2
= 5,
58 SJME_BYTECODE_INSTRUCTION_ICONST_3
= 6,
61 SJME_BYTECODE_INSTRUCTION_ICONST_4
= 7,
64 SJME_BYTECODE_INSTRUCTION_ICONST_5
= 8,
67 SJME_BYTECODE_INSTRUCTION_LCONST_0
= 9,
70 SJME_BYTECODE_INSTRUCTION_LCONST_1
= 10,
73 SJME_BYTECODE_INSTRUCTION_FCONST_0
= 11,
76 SJME_BYTECODE_INSTRUCTION_FCONST_1
= 12,
79 SJME_BYTECODE_INSTRUCTION_FCONST_2
= 13,
82 SJME_BYTECODE_INSTRUCTION_DCONST_0
= 14,
85 SJME_BYTECODE_INSTRUCTION_DCONST_1
= 15,
88 SJME_BYTECODE_INSTRUCTION_BIPUSH
= 16,
91 SJME_BYTECODE_INSTRUCTION_SIPUSH
= 17,
94 SJME_BYTECODE_INSTRUCTION_LDC
= 18,
97 SJME_BYTECODE_INSTRUCTION_LDC_W
= 19,
100 SJME_BYTECODE_INSTRUCTION_LDC2_W
= 20,
103 SJME_BYTECODE_INSTRUCTION_ILOAD
= 21,
106 SJME_BYTECODE_INSTRUCTION_LLOAD
= 22,
109 SJME_BYTECODE_INSTRUCTION_FLOAD
= 23,
112 SJME_BYTECODE_INSTRUCTION_DLOAD
= 24,
115 SJME_BYTECODE_INSTRUCTION_ALOAD
= 25,
118 SJME_BYTECODE_INSTRUCTION_ILOAD_0
= 26,
121 SJME_BYTECODE_INSTRUCTION_ILOAD_1
= 27,
124 SJME_BYTECODE_INSTRUCTION_ILOAD_2
= 28,
127 SJME_BYTECODE_INSTRUCTION_ILOAD_3
= 29,
130 SJME_BYTECODE_INSTRUCTION_LLOAD_0
= 30,
133 SJME_BYTECODE_INSTRUCTION_LLOAD_1
= 31,
136 SJME_BYTECODE_INSTRUCTION_LLOAD_2
= 32,
139 SJME_BYTECODE_INSTRUCTION_LLOAD_3
= 33,
142 SJME_BYTECODE_INSTRUCTION_FLOAD_0
= 34,
145 SJME_BYTECODE_INSTRUCTION_FLOAD_1
= 35,
148 SJME_BYTECODE_INSTRUCTION_FLOAD_2
= 36,
151 SJME_BYTECODE_INSTRUCTION_FLOAD_3
= 37,
154 SJME_BYTECODE_INSTRUCTION_DLOAD_0
= 38,
157 SJME_BYTECODE_INSTRUCTION_DLOAD_1
= 39,
160 SJME_BYTECODE_INSTRUCTION_DLOAD_2
= 40,
163 SJME_BYTECODE_INSTRUCTION_DLOAD_3
= 41,
166 SJME_BYTECODE_INSTRUCTION_ALOAD_0
= 42,
169 SJME_BYTECODE_INSTRUCTION_ALOAD_1
= 43,
172 SJME_BYTECODE_INSTRUCTION_ALOAD_2
= 44,
175 SJME_BYTECODE_INSTRUCTION_ALOAD_3
= 45,
178 SJME_BYTECODE_INSTRUCTION_IALOAD
= 46,
181 SJME_BYTECODE_INSTRUCTION_LALOAD
= 47,
184 SJME_BYTECODE_INSTRUCTION_FALOAD
= 48,
187 SJME_BYTECODE_INSTRUCTION_DALOAD
= 49,
190 SJME_BYTECODE_INSTRUCTION_AALOAD
= 50,
193 SJME_BYTECODE_INSTRUCTION_BALOAD
= 51,
196 SJME_BYTECODE_INSTRUCTION_CALOAD
= 52,
199 SJME_BYTECODE_INSTRUCTION_SALOAD
= 53,
202 SJME_BYTECODE_INSTRUCTION_ISTORE
= 54,
205 SJME_BYTECODE_INSTRUCTION_LSTORE
= 55,
208 SJME_BYTECODE_INSTRUCTION_FSTORE
= 56,
211 SJME_BYTECODE_INSTRUCTION_DSTORE
= 57,
214 SJME_BYTECODE_INSTRUCTION_ASTORE
= 58,
217 SJME_BYTECODE_INSTRUCTION_ISTORE_0
= 59,
220 SJME_BYTECODE_INSTRUCTION_ISTORE_1
= 60,
223 SJME_BYTECODE_INSTRUCTION_ISTORE_2
= 61,
226 SJME_BYTECODE_INSTRUCTION_ISTORE_3
= 62,
229 SJME_BYTECODE_INSTRUCTION_LSTORE_0
= 63,
232 SJME_BYTECODE_INSTRUCTION_LSTORE_1
= 64,
235 SJME_BYTECODE_INSTRUCTION_LSTORE_2
= 65,
238 SJME_BYTECODE_INSTRUCTION_LSTORE_3
= 66,
241 SJME_BYTECODE_INSTRUCTION_FSTORE_0
= 67,
244 SJME_BYTECODE_INSTRUCTION_FSTORE_1
= 68,
247 SJME_BYTECODE_INSTRUCTION_FSTORE_2
= 69,
250 SJME_BYTECODE_INSTRUCTION_FSTORE_3
= 70,
253 SJME_BYTECODE_INSTRUCTION_DSTORE_0
= 71,
256 SJME_BYTECODE_INSTRUCTION_DSTORE_1
= 72,
259 SJME_BYTECODE_INSTRUCTION_DSTORE_2
= 73,
262 SJME_BYTECODE_INSTRUCTION_DSTORE_3
= 74,
265 SJME_BYTECODE_INSTRUCTION_ASTORE_0
= 75,
268 SJME_BYTECODE_INSTRUCTION_ASTORE_1
= 76,
271 SJME_BYTECODE_INSTRUCTION_ASTORE_2
= 77,
274 SJME_BYTECODE_INSTRUCTION_ASTORE_3
= 78,
277 SJME_BYTECODE_INSTRUCTION_IASTORE
= 79,
280 SJME_BYTECODE_INSTRUCTION_LASTORE
= 80,
283 SJME_BYTECODE_INSTRUCTION_FASTORE
= 81,
286 SJME_BYTECODE_INSTRUCTION_DASTORE
= 82,
289 SJME_BYTECODE_INSTRUCTION_AASTORE
= 83,
292 SJME_BYTECODE_INSTRUCTION_BASTORE
= 84,
295 SJME_BYTECODE_INSTRUCTION_CASTORE
= 85,
298 SJME_BYTECODE_INSTRUCTION_SASTORE
= 86,
301 SJME_BYTECODE_INSTRUCTION_POP
= 87,
304 SJME_BYTECODE_INSTRUCTION_POP2
= 88,
307 SJME_BYTECODE_INSTRUCTION_DUP
= 89,
310 SJME_BYTECODE_INSTRUCTION_DUP_X1
= 90,
313 SJME_BYTECODE_INSTRUCTION_DUP_X2
= 91,
316 SJME_BYTECODE_INSTRUCTION_DUP2
= 92,
319 SJME_BYTECODE_INSTRUCTION_DUP2_X1
= 93,
322 SJME_BYTECODE_INSTRUCTION_DUP2_X2
= 94,
325 SJME_BYTECODE_INSTRUCTION_SWAP
= 95,
328 SJME_BYTECODE_INSTRUCTION_IADD
= 96,
331 SJME_BYTECODE_INSTRUCTION_LADD
= 97,
334 SJME_BYTECODE_INSTRUCTION_FADD
= 98,
337 SJME_BYTECODE_INSTRUCTION_DADD
= 99,
340 SJME_BYTECODE_INSTRUCTION_ISUB
= 100,
343 SJME_BYTECODE_INSTRUCTION_LSUB
= 101,
346 SJME_BYTECODE_INSTRUCTION_FSUB
= 102,
349 SJME_BYTECODE_INSTRUCTION_DSUB
= 103,
352 SJME_BYTECODE_INSTRUCTION_IMUL
= 104,
355 SJME_BYTECODE_INSTRUCTION_LMUL
= 105,
358 SJME_BYTECODE_INSTRUCTION_FMUL
= 106,
361 SJME_BYTECODE_INSTRUCTION_DMUL
= 107,
364 SJME_BYTECODE_INSTRUCTION_IDIV
= 108,
367 SJME_BYTECODE_INSTRUCTION_LDIV
= 109,
370 SJME_BYTECODE_INSTRUCTION_FDIV
= 110,
373 SJME_BYTECODE_INSTRUCTION_DDIV
= 111,
376 SJME_BYTECODE_INSTRUCTION_IREM
= 112,
379 SJME_BYTECODE_INSTRUCTION_LREM
= 113,
382 SJME_BYTECODE_INSTRUCTION_FREM
= 114,
385 SJME_BYTECODE_INSTRUCTION_DREM
= 115,
388 SJME_BYTECODE_INSTRUCTION_INEG
= 116,
391 SJME_BYTECODE_INSTRUCTION_LNEG
= 117,
394 SJME_BYTECODE_INSTRUCTION_FNEG
= 118,
397 SJME_BYTECODE_INSTRUCTION_DNEG
= 119,
400 SJME_BYTECODE_INSTRUCTION_ISHL
= 120,
403 SJME_BYTECODE_INSTRUCTION_LSHL
= 121,
406 SJME_BYTECODE_INSTRUCTION_ISHR
= 122,
409 SJME_BYTECODE_INSTRUCTION_LSHR
= 123,
412 SJME_BYTECODE_INSTRUCTION_IUSHR
= 124,
415 SJME_BYTECODE_INSTRUCTION_LUSHR
= 125,
418 SJME_BYTECODE_INSTRUCTION_IAND
= 126,
421 SJME_BYTECODE_INSTRUCTION_LAND
= 127,
424 SJME_BYTECODE_INSTRUCTION_IOR
= 128,
427 SJME_BYTECODE_INSTRUCTION_LOR
= 129,
430 SJME_BYTECODE_INSTRUCTION_IXOR
= 130,
433 SJME_BYTECODE_INSTRUCTION_LXOR
= 131,
436 SJME_BYTECODE_INSTRUCTION_IINC
= 132,
439 SJME_BYTECODE_INSTRUCTION_I2L
= 133,
442 SJME_BYTECODE_INSTRUCTION_I2F
= 134,
445 SJME_BYTECODE_INSTRUCTION_I2D
= 135,
448 SJME_BYTECODE_INSTRUCTION_L2I
= 136,
451 SJME_BYTECODE_INSTRUCTION_L2F
= 137,
454 SJME_BYTECODE_INSTRUCTION_L2D
= 138,
457 SJME_BYTECODE_INSTRUCTION_F2I
= 139,
460 SJME_BYTECODE_INSTRUCTION_F2L
= 140,
463 SJME_BYTECODE_INSTRUCTION_F2D
= 141,
466 SJME_BYTECODE_INSTRUCTION_D2I
= 142,
469 SJME_BYTECODE_INSTRUCTION_D2L
= 143,
472 SJME_BYTECODE_INSTRUCTION_D2F
= 144,
475 SJME_BYTECODE_INSTRUCTION_I2B
= 145,
478 SJME_BYTECODE_INSTRUCTION_I2C
= 146,
481 SJME_BYTECODE_INSTRUCTION_I2S
= 147,
484 SJME_BYTECODE_INSTRUCTION_LCMP
= 148,
487 SJME_BYTECODE_INSTRUCTION_FCMPL
= 149,
490 SJME_BYTECODE_INSTRUCTION_FCMPG
= 150,
493 SJME_BYTECODE_INSTRUCTION_DCMPL
= 151,
496 SJME_BYTECODE_INSTRUCTION_DCMPG
= 152,
499 SJME_BYTECODE_INSTRUCTION_IFEQ
= 153,
502 SJME_BYTECODE_INSTRUCTION_IFNE
= 154,
505 SJME_BYTECODE_INSTRUCTION_IFLT
= 155,
508 SJME_BYTECODE_INSTRUCTION_IFGE
= 156,
511 SJME_BYTECODE_INSTRUCTION_IFGT
= 157,
514 SJME_BYTECODE_INSTRUCTION_IFLE
= 158,
517 SJME_BYTECODE_INSTRUCTION_IF_ICMPEQ
= 159,
520 SJME_BYTECODE_INSTRUCTION_IF_ICMPNE
= 160,
523 SJME_BYTECODE_INSTRUCTION_IF_ICMPLT
= 161,
526 SJME_BYTECODE_INSTRUCTION_IF_ICMPGE
= 162,
529 SJME_BYTECODE_INSTRUCTION_IF_ICMPGT
= 163,
532 SJME_BYTECODE_INSTRUCTION_IF_ICMPLE
= 164,
535 SJME_BYTECODE_INSTRUCTION_IF_ACMPEQ
= 165,
538 SJME_BYTECODE_INSTRUCTION_IF_ACMPNE
= 166,
541 SJME_BYTECODE_INSTRUCTION_GOTO
= 167,
544 SJME_BYTECODE_INSTRUCTION_JSR
= 168,
547 SJME_BYTECODE_INSTRUCTION_RET
= 169,
550 SJME_BYTECODE_INSTRUCTION_TABLESWITCH
= 170,
553 SJME_BYTECODE_INSTRUCTION_LOOKUPSWITCH
= 171,
556 SJME_BYTECODE_INSTRUCTION_IRETURN
= 172,
559 SJME_BYTECODE_INSTRUCTION_LRETURN
= 173,
562 SJME_BYTECODE_INSTRUCTION_FRETURN
= 174,
565 SJME_BYTECODE_INSTRUCTION_DRETURN
= 175,
568 SJME_BYTECODE_INSTRUCTION_ARETURN
= 176,
571 SJME_BYTECODE_INSTRUCTION_RETURN
= 177,
574 SJME_BYTECODE_INSTRUCTION_GETSTATIC
= 178,
577 SJME_BYTECODE_INSTRUCTION_PUTSTATIC
= 179,
580 SJME_BYTECODE_INSTRUCTION_GETFIELD
= 180,
583 SJME_BYTECODE_INSTRUCTION_PUTFIELD
= 181,
585 /** INVOKEVIRTUAL. */
586 SJME_BYTECODE_INSTRUCTION_INVOKEVIRTUAL
= 182,
588 /** INVOKESPECIAL. */
589 SJME_BYTECODE_INSTRUCTION_INVOKESPECIAL
= 183,
592 SJME_BYTECODE_INSTRUCTION_INVOKESTATIC
= 184,
594 /** INVOKEINTERFACE. */
595 SJME_BYTECODE_INSTRUCTION_INVOKEINTERFACE
= 185,
597 /** INVOKEDYNAMIC. */
598 SJME_BYTECODE_INSTRUCTION_INVOKEDYNAMIC
= 186,
601 SJME_BYTECODE_INSTRUCTION_NEW
= 187,
604 SJME_BYTECODE_INSTRUCTION_NEWARRAY
= 188,
607 SJME_BYTECODE_INSTRUCTION_ANEWARRAY
= 189,
610 SJME_BYTECODE_INSTRUCTION_ARRAYLENGTH
= 190,
613 SJME_BYTECODE_INSTRUCTION_ATHROW
= 191,
616 SJME_BYTECODE_INSTRUCTION_CHECKCAST
= 192,
619 SJME_BYTECODE_INSTRUCTION_INSTANCEOF
= 193,
622 SJME_BYTECODE_INSTRUCTION_MONITORENTER
= 194,
625 SJME_BYTECODE_INSTRUCTION_MONITOREXIT
= 195,
628 SJME_BYTECODE_INSTRUCTION_WIDE
= 196,
630 /** MULTIANEWARRAY. */
631 SJME_BYTECODE_INSTRUCTION_MULTIANEWARRAY
= 197,
634 SJME_BYTECODE_INSTRUCTION_IFNULL
= 198,
637 SJME_BYTECODE_INSTRUCTION_IFNONNULL
= 199,
640 SJME_BYTECODE_INSTRUCTION_GOTO_W
= 200,
643 SJME_BYTECODE_INSTRUCTION_JSR_W
= 201,
646 SJME_BYTECODE_INSTRUCTION_BREAKPOINT
= 202,
649 SJME_BYTECODE_INSTRUCTION_IMPDEP1
= 254,
652 SJME_BYTECODE_INSTRUCTION_IMPDEP2
= 255,
655 SJME_BYTECODE_INSTRUCTION_WIDE_ALOAD
=
656 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
657 SJME_BYTECODE_INSTRUCTION_ALOAD
,
660 SJME_BYTECODE_INSTRUCTION_WIDE_ILOAD
=
661 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
662 SJME_BYTECODE_INSTRUCTION_ILOAD
,
665 SJME_BYTECODE_INSTRUCTION_WIDE_LLOAD
=
666 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
667 SJME_BYTECODE_INSTRUCTION_LLOAD
,
670 SJME_BYTECODE_INSTRUCTION_WIDE_FLOAD
=
671 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
672 SJME_BYTECODE_INSTRUCTION_FLOAD
,
675 SJME_BYTECODE_INSTRUCTION_WIDE_DLOAD
=
676 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
677 SJME_BYTECODE_INSTRUCTION_DLOAD
,
680 SJME_BYTECODE_INSTRUCTION_WIDE_ASTORE
=
681 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
682 SJME_BYTECODE_INSTRUCTION_ASTORE
,
685 SJME_BYTECODE_INSTRUCTION_WIDE_ISTORE
=
686 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
687 SJME_BYTECODE_INSTRUCTION_ISTORE
,
690 SJME_BYTECODE_INSTRUCTION_WIDE_LSTORE
=
691 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
692 SJME_BYTECODE_INSTRUCTION_LSTORE
,
695 SJME_BYTECODE_INSTRUCTION_WIDE_FSTORE
=
696 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
697 SJME_BYTECODE_INSTRUCTION_FSTORE
,
700 SJME_BYTECODE_INSTRUCTION_WIDE_DSTORE
=
701 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
702 SJME_BYTECODE_INSTRUCTION_DSTORE
,
705 SJME_BYTECODE_INSTRUCTION_WIDE_IINC
=
706 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
707 SJME_BYTECODE_INSTRUCTION_IINC
,
708 } sjme_byteCode_instruction
;
711 * Function type for byte code execution.
713 * @param frame The frame to execute under.
714 * @return Returns @c SJME_JNI_TRUE on success.
717 typedef sjme_jboolean (*sjme_byteCode_function
)(sjme_nvm_frame
* frame
);
720 * Contains a mapping of a byte code instruction to an actual operation.
724 typedef struct sjme_byteCode_functionMap
726 /** The instruction this maps. */
727 sjme_byteCode_instruction instruction
;
729 /** The function to execute. */
730 sjme_byteCode_function function
;
731 } sjme_byteCode_functionMap
;
734 * Maps a specific bytecode to the mapping for later execution.
736 * @param inInstruction The instruction to map.
737 * @param outMapping The output mapping.
738 * @return Returns @c SJME_JNI_TRUE if the instruction is valid and mappable.
741 sjme_errorCode
sjme_byteCode_map(
742 sjme_attrInValue sjme_byteCode_instruction inInstruction
,
743 sjme_attrOutNotNull
const sjme_byteCode_functionMap
** outMapping
);
745 /*--------------------------------------------------------------------------*/
749 #ifdef SJME_CXX_SQUIRRELJME_BYTECODE_H
751 #undef SJME_CXX_SQUIRRELJME_BYTECODE_H
752 #undef SJME_CXX_IS_EXTERNED
753 #endif /* #ifdef SJME_CXX_SQUIRRELJME_BYTECODE_H */
754 #endif /* #ifdef __cplusplus */
756 #endif /* SQUIRRELJME_BYTECODE_H */