Find file
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (38 sloc) 997 Bytes
#ifndef BYTECODE_H
#define BYTECODE_H
#include <stdint.h>
#include "jv.h"
#include "opcode.h"
typedef void (*cfunction_ptr)(jv input[], jv output[]);
struct cfunction {
cfunction_ptr fptr;
const char* name;
opcode callop;
struct symbol_table {
struct cfunction* cfunctions;
int ncfunctions;
// The bytecode format matters in:
// execute.c - interpreter
// compile.c - compiler
// bytecode.c - disassembler
#define ARG_NEWCLOSURE 0x1000
struct bytecode {
uint16_t* code;
int codelen;
int nlocals;
int nclosures;
jv constants; // JSON array of constants
struct symbol_table* globals;
struct bytecode** subfunctions;
int nsubfunctions;
struct bytecode* parent;
void dump_disassembly(int, struct bytecode* code);
void dump_code(int, struct bytecode* code);
void dump_operation(struct bytecode* bc, uint16_t* op);
void symbol_table_free(struct symbol_table* syms);
void bytecode_free(struct bytecode* bc);