Files
bshell/bshell.runtime/runtime/opcode.c
T
wash edfb3e24a3 bshell: re-organise build into three separate components
bshell: the front-end binary
bshell.runtime: contains the parser, compiler, and classes needed to run bshell scripts
bshell.core: contains the builtin commandlets and aliases
2026-05-25 10:33:29 +01:00

27 lines
594 B
C

#include <bshell/runtime/opcode.h>
#include <fx/int.h>
#define BSHELL_OPCODE_MAX 0xFF
#define ARG_MAX 0xFFFFFF
bshell_instruction bshell_instruction_encode(
enum bshell_opcode opcode,
uint32_t arg)
{
if (opcode > BSHELL_OPCODE_MAX) {
return BSHELL_INSTRUCTION_INVALID;
}
return fx_u32_htob((opcode & BSHELL_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 & BSHELL_OPCODE_MAX);
*out_arg = ((instr >> 8) & ARG_MAX);
}