1
0
Fork 0
undar-lang-old/src/opcodes.h

57 lines
2.6 KiB
C

#ifndef ZRE_OPCODES_H
#define ZRE_OPCODES_H
#include "common.h"
typedef union {
int32_t i; /* Integers */
float f; /* Float */
uint32_t u; /* Unsigned integers */
char c[4]; /* 4 Byte char array for string packing */
} Word;
typedef enum {
OP_HALT, /* terminate execution */
OP_ADD_INT, /* dest = src1 + src2 */
OP_SUB_INT, /* dest = src1 - src2 */
OP_MUL_INT, /* dest = src1 * src2 */
OP_DIV_INT, /* dest = src1 / src2 */
OP_JEQ_INT, /* jump to address dest if src1 as int == src2 as int */
OP_JGT_INT, /* jump to address dest if src1 as int > src2 as int*/
OP_JLT_INT, /* jump to address dest if src1 as int < src2 as int */
OP_JLE_INT, /* jump to address dest if src1 as int <= src2 as int */
OP_JGE_INT, /* jump to address dest if src1 as int >= src2 as int*/
OP_INT_TO_REAL, /* dest = src1 as f32 */
OP_ADD_UINT, /* dest = src1 + src2 */
OP_SUB_UINT, /* dest = src1 - src2 */
OP_MUL_UINT, /* dest = src1 * src2 */
OP_DIV_UINT, /* dest = src1 / src2 */
OP_JEQ_UINT, /* jump to address dest if src1 as int == src2 as uint */
OP_JGT_UINT, /* jump to address dest if src1 as int > src2 as uint*/
OP_JLT_UINT, /* jump to address dest if src1 as int < src2 as uint */
OP_JLE_UINT, /* jump to address dest if src1 as int <= src2 as uint */
OP_JGE_UINT, /* jump to address dest if src1 as int >= src2 as uint*/
OP_UINT_TO_REAL, /* dest = src1 as f32 */
OP_ADD_REAL, /* dest = src1 + src2 */
OP_SUB_REAL, /* dest = src1 - src2 */
OP_MUL_REAL, /* dest = src1 * src2 */
OP_DIV_REAL, /* dest = src1 / src2 */
OP_JEQ_REAL, /* jump to address dest if src1 as real == src2 as real */
OP_JGE_REAL, /* jump to address dest if src1 as real >= src2 as real */
OP_JGT_REAL, /* jump to address dest if src1 as real > src2 as real */
OP_JLT_REAL, /* jump to address dest if src1 as real < src2 as real */
OP_JLE_REAL, /* jump to address dest if src1 as real <= src2 as real */
OP_REAL_TO_INT, /* dest = src1 as int */
OP_REAL_TO_UINT, /* dest = src1 as uint */
OP_MOV, /* dest = src1 */
OP_JMP, /* jump to address src1 unconditionally */
OP_INT_TO_STRING, /* dest = src1 as str */
OP_UINT_TO_STRING, /* dest = src1 as str */
OP_REAL_TO_STRING, /* dest = src1 as str */
OP_READ_STRING, /* dest = read as str */
OP_PRINT_STRING, /* write src1 to stdout */
OP_CMP_STRING, /* dest = (str == src2) as bool */
} Opcode;
#endif