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
19 #include "sjme/error.h"
20 #include "sjme/nvm/nvm.h"
24 #ifndef SJME_CXX_IS_EXTERNED
25 #define SJME_CXX_IS_EXTERNED
26 #define SJME_CXX_SQUIRRELJME_BYTECODE_H
28 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
29 #endif /* #ifdef __cplusplus */
31 /*--------------------------------------------------------------------------*/
34 * Enumeration for byte code instructions.
38 typedef enum sjme_byteCode_instruction
41 SJME_BYTECODE_INSTRUCTION_NOP
= 0,
44 SJME_BYTECODE_INSTRUCTION_ACONST_NULL
= 1,
47 SJME_BYTECODE_INSTRUCTION_ICONST_M1
= 2,
50 SJME_BYTECODE_INSTRUCTION_ICONST_0
= 3,
53 SJME_BYTECODE_INSTRUCTION_ICONST_1
= 4,
56 SJME_BYTECODE_INSTRUCTION_ICONST_2
= 5,
59 SJME_BYTECODE_INSTRUCTION_ICONST_3
= 6,
62 SJME_BYTECODE_INSTRUCTION_ICONST_4
= 7,
65 SJME_BYTECODE_INSTRUCTION_ICONST_5
= 8,
68 SJME_BYTECODE_INSTRUCTION_LCONST_0
= 9,
71 SJME_BYTECODE_INSTRUCTION_LCONST_1
= 10,
74 SJME_BYTECODE_INSTRUCTION_FCONST_0
= 11,
77 SJME_BYTECODE_INSTRUCTION_FCONST_1
= 12,
80 SJME_BYTECODE_INSTRUCTION_FCONST_2
= 13,
83 SJME_BYTECODE_INSTRUCTION_DCONST_0
= 14,
86 SJME_BYTECODE_INSTRUCTION_DCONST_1
= 15,
89 SJME_BYTECODE_INSTRUCTION_BIPUSH
= 16,
92 SJME_BYTECODE_INSTRUCTION_SIPUSH
= 17,
95 SJME_BYTECODE_INSTRUCTION_LDC
= 18,
98 SJME_BYTECODE_INSTRUCTION_LDC_W
= 19,
101 SJME_BYTECODE_INSTRUCTION_LDC2_W
= 20,
104 SJME_BYTECODE_INSTRUCTION_ILOAD
= 21,
107 SJME_BYTECODE_INSTRUCTION_LLOAD
= 22,
110 SJME_BYTECODE_INSTRUCTION_FLOAD
= 23,
113 SJME_BYTECODE_INSTRUCTION_DLOAD
= 24,
116 SJME_BYTECODE_INSTRUCTION_ALOAD
= 25,
119 SJME_BYTECODE_INSTRUCTION_ILOAD_0
= 26,
122 SJME_BYTECODE_INSTRUCTION_ILOAD_1
= 27,
125 SJME_BYTECODE_INSTRUCTION_ILOAD_2
= 28,
128 SJME_BYTECODE_INSTRUCTION_ILOAD_3
= 29,
131 SJME_BYTECODE_INSTRUCTION_LLOAD_0
= 30,
134 SJME_BYTECODE_INSTRUCTION_LLOAD_1
= 31,
137 SJME_BYTECODE_INSTRUCTION_LLOAD_2
= 32,
140 SJME_BYTECODE_INSTRUCTION_LLOAD_3
= 33,
143 SJME_BYTECODE_INSTRUCTION_FLOAD_0
= 34,
146 SJME_BYTECODE_INSTRUCTION_FLOAD_1
= 35,
149 SJME_BYTECODE_INSTRUCTION_FLOAD_2
= 36,
152 SJME_BYTECODE_INSTRUCTION_FLOAD_3
= 37,
155 SJME_BYTECODE_INSTRUCTION_DLOAD_0
= 38,
158 SJME_BYTECODE_INSTRUCTION_DLOAD_1
= 39,
161 SJME_BYTECODE_INSTRUCTION_DLOAD_2
= 40,
164 SJME_BYTECODE_INSTRUCTION_DLOAD_3
= 41,
167 SJME_BYTECODE_INSTRUCTION_ALOAD_0
= 42,
170 SJME_BYTECODE_INSTRUCTION_ALOAD_1
= 43,
173 SJME_BYTECODE_INSTRUCTION_ALOAD_2
= 44,
176 SJME_BYTECODE_INSTRUCTION_ALOAD_3
= 45,
179 SJME_BYTECODE_INSTRUCTION_IALOAD
= 46,
182 SJME_BYTECODE_INSTRUCTION_LALOAD
= 47,
185 SJME_BYTECODE_INSTRUCTION_FALOAD
= 48,
188 SJME_BYTECODE_INSTRUCTION_DALOAD
= 49,
191 SJME_BYTECODE_INSTRUCTION_AALOAD
= 50,
194 SJME_BYTECODE_INSTRUCTION_BALOAD
= 51,
197 SJME_BYTECODE_INSTRUCTION_CALOAD
= 52,
200 SJME_BYTECODE_INSTRUCTION_SALOAD
= 53,
203 SJME_BYTECODE_INSTRUCTION_ISTORE
= 54,
206 SJME_BYTECODE_INSTRUCTION_LSTORE
= 55,
209 SJME_BYTECODE_INSTRUCTION_FSTORE
= 56,
212 SJME_BYTECODE_INSTRUCTION_DSTORE
= 57,
215 SJME_BYTECODE_INSTRUCTION_ASTORE
= 58,
218 SJME_BYTECODE_INSTRUCTION_ISTORE_0
= 59,
221 SJME_BYTECODE_INSTRUCTION_ISTORE_1
= 60,
224 SJME_BYTECODE_INSTRUCTION_ISTORE_2
= 61,
227 SJME_BYTECODE_INSTRUCTION_ISTORE_3
= 62,
230 SJME_BYTECODE_INSTRUCTION_LSTORE_0
= 63,
233 SJME_BYTECODE_INSTRUCTION_LSTORE_1
= 64,
236 SJME_BYTECODE_INSTRUCTION_LSTORE_2
= 65,
239 SJME_BYTECODE_INSTRUCTION_LSTORE_3
= 66,
242 SJME_BYTECODE_INSTRUCTION_FSTORE_0
= 67,
245 SJME_BYTECODE_INSTRUCTION_FSTORE_1
= 68,
248 SJME_BYTECODE_INSTRUCTION_FSTORE_2
= 69,
251 SJME_BYTECODE_INSTRUCTION_FSTORE_3
= 70,
254 SJME_BYTECODE_INSTRUCTION_DSTORE_0
= 71,
257 SJME_BYTECODE_INSTRUCTION_DSTORE_1
= 72,
260 SJME_BYTECODE_INSTRUCTION_DSTORE_2
= 73,
263 SJME_BYTECODE_INSTRUCTION_DSTORE_3
= 74,
266 SJME_BYTECODE_INSTRUCTION_ASTORE_0
= 75,
269 SJME_BYTECODE_INSTRUCTION_ASTORE_1
= 76,
272 SJME_BYTECODE_INSTRUCTION_ASTORE_2
= 77,
275 SJME_BYTECODE_INSTRUCTION_ASTORE_3
= 78,
278 SJME_BYTECODE_INSTRUCTION_IASTORE
= 79,
281 SJME_BYTECODE_INSTRUCTION_LASTORE
= 80,
284 SJME_BYTECODE_INSTRUCTION_FASTORE
= 81,
287 SJME_BYTECODE_INSTRUCTION_DASTORE
= 82,
290 SJME_BYTECODE_INSTRUCTION_AASTORE
= 83,
293 SJME_BYTECODE_INSTRUCTION_BASTORE
= 84,
296 SJME_BYTECODE_INSTRUCTION_CASTORE
= 85,
299 SJME_BYTECODE_INSTRUCTION_SASTORE
= 86,
302 SJME_BYTECODE_INSTRUCTION_POP
= 87,
305 SJME_BYTECODE_INSTRUCTION_POP2
= 88,
308 SJME_BYTECODE_INSTRUCTION_DUP
= 89,
311 SJME_BYTECODE_INSTRUCTION_DUP_X1
= 90,
314 SJME_BYTECODE_INSTRUCTION_DUP_X2
= 91,
317 SJME_BYTECODE_INSTRUCTION_DUP2
= 92,
320 SJME_BYTECODE_INSTRUCTION_DUP2_X1
= 93,
323 SJME_BYTECODE_INSTRUCTION_DUP2_X2
= 94,
326 SJME_BYTECODE_INSTRUCTION_SWAP
= 95,
329 SJME_BYTECODE_INSTRUCTION_IADD
= 96,
332 SJME_BYTECODE_INSTRUCTION_LADD
= 97,
335 SJME_BYTECODE_INSTRUCTION_FADD
= 98,
338 SJME_BYTECODE_INSTRUCTION_DADD
= 99,
341 SJME_BYTECODE_INSTRUCTION_ISUB
= 100,
344 SJME_BYTECODE_INSTRUCTION_LSUB
= 101,
347 SJME_BYTECODE_INSTRUCTION_FSUB
= 102,
350 SJME_BYTECODE_INSTRUCTION_DSUB
= 103,
353 SJME_BYTECODE_INSTRUCTION_IMUL
= 104,
356 SJME_BYTECODE_INSTRUCTION_LMUL
= 105,
359 SJME_BYTECODE_INSTRUCTION_FMUL
= 106,
362 SJME_BYTECODE_INSTRUCTION_DMUL
= 107,
365 SJME_BYTECODE_INSTRUCTION_IDIV
= 108,
368 SJME_BYTECODE_INSTRUCTION_LDIV
= 109,
371 SJME_BYTECODE_INSTRUCTION_FDIV
= 110,
374 SJME_BYTECODE_INSTRUCTION_DDIV
= 111,
377 SJME_BYTECODE_INSTRUCTION_IREM
= 112,
380 SJME_BYTECODE_INSTRUCTION_LREM
= 113,
383 SJME_BYTECODE_INSTRUCTION_FREM
= 114,
386 SJME_BYTECODE_INSTRUCTION_DREM
= 115,
389 SJME_BYTECODE_INSTRUCTION_INEG
= 116,
392 SJME_BYTECODE_INSTRUCTION_LNEG
= 117,
395 SJME_BYTECODE_INSTRUCTION_FNEG
= 118,
398 SJME_BYTECODE_INSTRUCTION_DNEG
= 119,
401 SJME_BYTECODE_INSTRUCTION_ISHL
= 120,
404 SJME_BYTECODE_INSTRUCTION_LSHL
= 121,
407 SJME_BYTECODE_INSTRUCTION_ISHR
= 122,
410 SJME_BYTECODE_INSTRUCTION_LSHR
= 123,
413 SJME_BYTECODE_INSTRUCTION_IUSHR
= 124,
416 SJME_BYTECODE_INSTRUCTION_LUSHR
= 125,
419 SJME_BYTECODE_INSTRUCTION_IAND
= 126,
422 SJME_BYTECODE_INSTRUCTION_LAND
= 127,
425 SJME_BYTECODE_INSTRUCTION_IOR
= 128,
428 SJME_BYTECODE_INSTRUCTION_LOR
= 129,
431 SJME_BYTECODE_INSTRUCTION_IXOR
= 130,
434 SJME_BYTECODE_INSTRUCTION_LXOR
= 131,
437 SJME_BYTECODE_INSTRUCTION_IINC
= 132,
440 SJME_BYTECODE_INSTRUCTION_I2L
= 133,
443 SJME_BYTECODE_INSTRUCTION_I2F
= 134,
446 SJME_BYTECODE_INSTRUCTION_I2D
= 135,
449 SJME_BYTECODE_INSTRUCTION_L2I
= 136,
452 SJME_BYTECODE_INSTRUCTION_L2F
= 137,
455 SJME_BYTECODE_INSTRUCTION_L2D
= 138,
458 SJME_BYTECODE_INSTRUCTION_F2I
= 139,
461 SJME_BYTECODE_INSTRUCTION_F2L
= 140,
464 SJME_BYTECODE_INSTRUCTION_F2D
= 141,
467 SJME_BYTECODE_INSTRUCTION_D2I
= 142,
470 SJME_BYTECODE_INSTRUCTION_D2L
= 143,
473 SJME_BYTECODE_INSTRUCTION_D2F
= 144,
476 SJME_BYTECODE_INSTRUCTION_I2B
= 145,
479 SJME_BYTECODE_INSTRUCTION_I2C
= 146,
482 SJME_BYTECODE_INSTRUCTION_I2S
= 147,
485 SJME_BYTECODE_INSTRUCTION_LCMP
= 148,
488 SJME_BYTECODE_INSTRUCTION_FCMPL
= 149,
491 SJME_BYTECODE_INSTRUCTION_FCMPG
= 150,
494 SJME_BYTECODE_INSTRUCTION_DCMPL
= 151,
497 SJME_BYTECODE_INSTRUCTION_DCMPG
= 152,
500 SJME_BYTECODE_INSTRUCTION_IFEQ
= 153,
503 SJME_BYTECODE_INSTRUCTION_IFNE
= 154,
506 SJME_BYTECODE_INSTRUCTION_IFLT
= 155,
509 SJME_BYTECODE_INSTRUCTION_IFGE
= 156,
512 SJME_BYTECODE_INSTRUCTION_IFGT
= 157,
515 SJME_BYTECODE_INSTRUCTION_IFLE
= 158,
518 SJME_BYTECODE_INSTRUCTION_IF_ICMPEQ
= 159,
521 SJME_BYTECODE_INSTRUCTION_IF_ICMPNE
= 160,
524 SJME_BYTECODE_INSTRUCTION_IF_ICMPLT
= 161,
527 SJME_BYTECODE_INSTRUCTION_IF_ICMPGE
= 162,
530 SJME_BYTECODE_INSTRUCTION_IF_ICMPGT
= 163,
533 SJME_BYTECODE_INSTRUCTION_IF_ICMPLE
= 164,
536 SJME_BYTECODE_INSTRUCTION_IF_ACMPEQ
= 165,
539 SJME_BYTECODE_INSTRUCTION_IF_ACMPNE
= 166,
542 SJME_BYTECODE_INSTRUCTION_GOTO
= 167,
545 SJME_BYTECODE_INSTRUCTION_JSR
= 168,
548 SJME_BYTECODE_INSTRUCTION_RET
= 169,
551 SJME_BYTECODE_INSTRUCTION_TABLESWITCH
= 170,
554 SJME_BYTECODE_INSTRUCTION_LOOKUPSWITCH
= 171,
557 SJME_BYTECODE_INSTRUCTION_IRETURN
= 172,
560 SJME_BYTECODE_INSTRUCTION_LRETURN
= 173,
563 SJME_BYTECODE_INSTRUCTION_FRETURN
= 174,
566 SJME_BYTECODE_INSTRUCTION_DRETURN
= 175,
569 SJME_BYTECODE_INSTRUCTION_ARETURN
= 176,
572 SJME_BYTECODE_INSTRUCTION_RETURN
= 177,
575 SJME_BYTECODE_INSTRUCTION_GETSTATIC
= 178,
578 SJME_BYTECODE_INSTRUCTION_PUTSTATIC
= 179,
581 SJME_BYTECODE_INSTRUCTION_GETFIELD
= 180,
584 SJME_BYTECODE_INSTRUCTION_PUTFIELD
= 181,
586 /** INVOKEVIRTUAL. */
587 SJME_BYTECODE_INSTRUCTION_INVOKEVIRTUAL
= 182,
589 /** INVOKESPECIAL. */
590 SJME_BYTECODE_INSTRUCTION_INVOKESPECIAL
= 183,
593 SJME_BYTECODE_INSTRUCTION_INVOKESTATIC
= 184,
595 /** INVOKEINTERFACE. */
596 SJME_BYTECODE_INSTRUCTION_INVOKEINTERFACE
= 185,
598 /** INVOKEDYNAMIC. */
599 SJME_BYTECODE_INSTRUCTION_INVOKEDYNAMIC
= 186,
602 SJME_BYTECODE_INSTRUCTION_NEW
= 187,
605 SJME_BYTECODE_INSTRUCTION_NEWARRAY
= 188,
608 SJME_BYTECODE_INSTRUCTION_ANEWARRAY
= 189,
611 SJME_BYTECODE_INSTRUCTION_ARRAYLENGTH
= 190,
614 SJME_BYTECODE_INSTRUCTION_ATHROW
= 191,
617 SJME_BYTECODE_INSTRUCTION_CHECKCAST
= 192,
620 SJME_BYTECODE_INSTRUCTION_INSTANCEOF
= 193,
623 SJME_BYTECODE_INSTRUCTION_MONITORENTER
= 194,
626 SJME_BYTECODE_INSTRUCTION_MONITOREXIT
= 195,
629 SJME_BYTECODE_INSTRUCTION_WIDE
= 196,
631 /** MULTIANEWARRAY. */
632 SJME_BYTECODE_INSTRUCTION_MULTIANEWARRAY
= 197,
635 SJME_BYTECODE_INSTRUCTION_IFNULL
= 198,
638 SJME_BYTECODE_INSTRUCTION_IFNONNULL
= 199,
641 SJME_BYTECODE_INSTRUCTION_GOTO_W
= 200,
644 SJME_BYTECODE_INSTRUCTION_JSR_W
= 201,
647 SJME_BYTECODE_INSTRUCTION_BREAKPOINT
= 202,
650 SJME_BYTECODE_INSTRUCTION_IMPDEP1
= 254,
653 SJME_BYTECODE_INSTRUCTION_IMPDEP2
= 255,
656 SJME_BYTECODE_INSTRUCTION_WIDE_ALOAD
=
657 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
658 SJME_BYTECODE_INSTRUCTION_ALOAD
,
661 SJME_BYTECODE_INSTRUCTION_WIDE_ILOAD
=
662 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
663 SJME_BYTECODE_INSTRUCTION_ILOAD
,
666 SJME_BYTECODE_INSTRUCTION_WIDE_LLOAD
=
667 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
668 SJME_BYTECODE_INSTRUCTION_LLOAD
,
671 SJME_BYTECODE_INSTRUCTION_WIDE_FLOAD
=
672 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
673 SJME_BYTECODE_INSTRUCTION_FLOAD
,
676 SJME_BYTECODE_INSTRUCTION_WIDE_DLOAD
=
677 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
678 SJME_BYTECODE_INSTRUCTION_DLOAD
,
681 SJME_BYTECODE_INSTRUCTION_WIDE_ASTORE
=
682 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
683 SJME_BYTECODE_INSTRUCTION_ASTORE
,
686 SJME_BYTECODE_INSTRUCTION_WIDE_ISTORE
=
687 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
688 SJME_BYTECODE_INSTRUCTION_ISTORE
,
691 SJME_BYTECODE_INSTRUCTION_WIDE_LSTORE
=
692 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
693 SJME_BYTECODE_INSTRUCTION_LSTORE
,
696 SJME_BYTECODE_INSTRUCTION_WIDE_FSTORE
=
697 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
698 SJME_BYTECODE_INSTRUCTION_FSTORE
,
701 SJME_BYTECODE_INSTRUCTION_WIDE_DSTORE
=
702 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
703 SJME_BYTECODE_INSTRUCTION_DSTORE
,
706 SJME_BYTECODE_INSTRUCTION_WIDE_IINC
=
707 (SJME_BYTECODE_INSTRUCTION_WIDE
<< 8) |
708 SJME_BYTECODE_INSTRUCTION_IINC
,
709 } sjme_byteCode_instruction
;
712 * Function type for byte code execution.
714 * @param frame The frame to execute under.
715 * @return Returns @c SJME_JNI_TRUE on success.
718 typedef sjme_jboolean (*sjme_byteCode_function
)(sjme_nvm_frame frame
);
721 * Contains a mapping of a byte code instruction to an actual operation.
725 typedef struct sjme_byteCode_functionMap
727 /** The instruction this maps. */
728 sjme_byteCode_instruction instruction
;
730 /** The function to execute. */
731 sjme_byteCode_function function
;
732 } sjme_byteCode_functionMap
;
735 * Maps a specific bytecode to the mapping for later execution.
737 * @param inInstruction The instruction to map.
738 * @param outMapping The output mapping.
739 * @return Returns @c SJME_JNI_TRUE if the instruction is valid and mappable.
742 sjme_errorCode
sjme_byteCode_map(
743 sjme_attrInValue sjme_byteCode_instruction inInstruction
,
744 sjme_attrOutNotNull
const sjme_byteCode_functionMap
** outMapping
);
746 /*--------------------------------------------------------------------------*/
750 #ifdef SJME_CXX_SQUIRRELJME_BYTECODE_H
752 #undef SJME_CXX_SQUIRRELJME_BYTECODE_H
753 #undef SJME_CXX_IS_EXTERNED
754 #endif /* #ifdef SJME_CXX_SQUIRRELJME_BYTECODE_H */
755 #endif /* #ifdef __cplusplus */
757 #endif /* SQUIRRELJME_BYTECODE_H */