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.
This commit is contained in:
10
src/inst.h
10
src/inst.h
@@ -13,7 +13,10 @@
|
||||
#ifndef INST_H
|
||||
#define INST_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#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)})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user