moka/lib/prog.h

42 lines
731 B
C

#ifndef MK_PROG_H
#define MK_PROG_H
#include "commons.h"
#include "vec.h"
#include "value.h"
#define OPCODE_KIND(G) \
G(OP_PUSH), \
G(OP_LOCAL_LOAD), \
G(OP_GLOBAL_LOAD), \
G(OP_CALL)
MK_ENUM_H(OpcodeKind, OPCODE_KIND);
struct instruction
{
OpcodeKind opcode;
ssize_t param;
};
struct prog
{
struct vec instructions;
struct vec values;
size_t stack_addr;
};
void prog_init(struct prog* self);
void prog_free(struct prog* self);
size_t prog_add_instruction(struct prog* self,
OpcodeKind opcode,
ssize_t param);
size_t prog_add_new_value(struct prog* self,
struct value* value);
void prog_dump(struct prog* self);
#endif