From 6038363d2facd5c8a79d9c4920ca5b3cf70bef95 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 16 Oct 2023 01:06:49 +0100 Subject: Added functionality to read and write instruction bytecode Uses some bit hacks to quickly check what data type an opcode may have by shifting down to units then casting it to a data_type_t. Not very well tested yet, we'll need to see now. --- src/inst.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/inst.h') diff --git a/src/inst.h b/src/inst.h index 3c77a86..7fed8e1 100644 --- a/src/inst.h +++ b/src/inst.h @@ -13,7 +13,10 @@ #ifndef INST_H #define INST_H +#include + #include "./base.h" +#include "./darr.h" typedef enum { @@ -57,6 +60,13 @@ typedef struct data_t operand; } inst_t; +size_t inst_bytecode_size(inst_t); +void inst_write_bytecode(inst_t, darr_t *); +// Here the dynamic array is a preloaded buffer of bytes, where +// darr.available is the number of overall bytes and used is the +// cursor (where we are in the buffer). +inst_t inst_read_bytecode(darr_t *); + #define INST_BPUSH(BYTE) \ ((inst_t){.opcode = OP_PUSH_BYTE, .operand = DBYTE(BYTE)}) -- cgit v1.2.3-13-gbd6f