runtime: add definitions for bshell vm bytecode
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
#include "opcode.h"
|
||||||
|
|
||||||
|
#include <fx/int.h>
|
||||||
|
|
||||||
|
#define OPCODE_MAX 0xFF
|
||||||
|
#define ARG_MAX 0xFFFFFF
|
||||||
|
|
||||||
|
bshell_instruction bshell_instruction_encode(
|
||||||
|
enum bshell_opcode opcode,
|
||||||
|
uint32_t arg)
|
||||||
|
{
|
||||||
|
if (opcode > OPCODE_MAX) {
|
||||||
|
return BSHELL_INSTRUCTION_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fx_u32_htob((opcode & OPCODE_MAX) | (arg & ARG_MAX) << 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bshell_instruction_decode(
|
||||||
|
bshell_instruction instr,
|
||||||
|
enum bshell_opcode *out_opcode,
|
||||||
|
uint32_t *out_arg)
|
||||||
|
{
|
||||||
|
instr = fx_u32_btoh(instr);
|
||||||
|
*out_opcode = (instr & OPCODE_MAX);
|
||||||
|
*out_arg = ((instr >> 8) & ARG_MAX);
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
#ifndef RUNTIME_OPCODE_H_
|
||||||
|
#define RUNTIME_OPCODE_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define BSHELL_INSTRUCTION_INVALID 0xFFFFFFFF
|
||||||
|
|
||||||
|
typedef uint32_t bshell_instruction;
|
||||||
|
|
||||||
|
enum bshell_opcode {
|
||||||
|
OPCODE_NOP = 0,
|
||||||
|
OPCODE_LDC_INT,
|
||||||
|
OPCODE_LDC_STR,
|
||||||
|
OPCODE_LDGLOBAL,
|
||||||
|
OPCODE_LDLOCAL,
|
||||||
|
OPCODE_LDBLOCK,
|
||||||
|
OPCODE_LDENV,
|
||||||
|
OPCODE_LDSTATIC,
|
||||||
|
OPCODE_LDARG,
|
||||||
|
OPCODE_LDPROP,
|
||||||
|
OPCODE_LDELEM,
|
||||||
|
OPCODE_LDELEM_C,
|
||||||
|
OPCODE_STLOCAL,
|
||||||
|
OPCODE_STPROP,
|
||||||
|
OPCODE_STELEM,
|
||||||
|
OPCODE_LDCMD,
|
||||||
|
OPCODE_PEXEC,
|
||||||
|
OPCODE_CALL,
|
||||||
|
OPCODE_MK_STR,
|
||||||
|
OPCODE_MK_ARRAY,
|
||||||
|
OPCODE_MK_HTAB,
|
||||||
|
OPCODE_POP,
|
||||||
|
OPCODE_ADD,
|
||||||
|
OPCODE_SUB,
|
||||||
|
OPCODE_MUL,
|
||||||
|
OPCODE_DIV,
|
||||||
|
OPCODE_ADD_IP,
|
||||||
|
OPCODE_MOD,
|
||||||
|
OPCODE_INC,
|
||||||
|
OPCODE_DEC,
|
||||||
|
OPCODE_SHL,
|
||||||
|
OPCODE_SHR,
|
||||||
|
OPCODE_BAND,
|
||||||
|
OPCODE_BOR,
|
||||||
|
OPCODE_BXOR,
|
||||||
|
OPCODE_BNOT,
|
||||||
|
OPCODE_CMP_NULL,
|
||||||
|
OPCODE_CMP_EQ,
|
||||||
|
OPCODE_CMP_NE,
|
||||||
|
OPCODE_CMP_LT,
|
||||||
|
OPCODE_CMP_GT,
|
||||||
|
OPCODE_CMP_LE,
|
||||||
|
OPCODE_CMP_GE,
|
||||||
|
OPCODE_LAND,
|
||||||
|
OPCODE_LOR,
|
||||||
|
OPCODE_LXOR,
|
||||||
|
OPCODE_LNOT,
|
||||||
|
OPCODE_BR,
|
||||||
|
OPCODE_BR_TRUE,
|
||||||
|
OPCODE_RANGE,
|
||||||
|
OPCODE_MATCH,
|
||||||
|
OPCODE_REPLACE,
|
||||||
|
OPCODE_LIKE,
|
||||||
|
OPCODE_IN,
|
||||||
|
OPCODE_FMT,
|
||||||
|
OPCODE_CONTAINS,
|
||||||
|
OPCODE_SPLIT,
|
||||||
|
OPCODE_JOIN,
|
||||||
|
OPCODE_IS,
|
||||||
|
OPCODE_AS,
|
||||||
|
};
|
||||||
|
|
||||||
|
extern bshell_instruction bshell_instruction_encode(
|
||||||
|
enum bshell_opcode opcode,
|
||||||
|
uint32_t arg);
|
||||||
|
extern void bshell_instruction_decode(
|
||||||
|
bshell_instruction instr,
|
||||||
|
enum bshell_opcode *out_opcode,
|
||||||
|
uint32_t *out_arg);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user