1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00
stedolan-jq/bytecode.h

53 lines
997 B
C
Raw Normal View History

2012-08-16 01:00:30 +01:00
#ifndef BYTECODE_H
#define BYTECODE_H
#include <stdint.h>
#include "jv.h"
2012-08-16 01:00:30 +01:00
#include "opcode.h"
typedef void (*cfunction_ptr)(jv input[], jv output[]);
2012-08-16 01:00:30 +01:00
struct cfunction {
cfunction_ptr fptr;
const char* name;
opcode callop;
};
#define MAX_CFUNCTION_ARGS 10
struct symbol_table {
struct cfunction* cfunctions;
int ncfunctions;
};
2012-08-21 18:14:13 +01:00
// The bytecode format matters in:
// execute.c - interpreter
// compile.c - compiler
// bytecode.c - disassembler
#define ARG_NEWCLOSURE 0x1000
2012-08-16 01:00:30 +01:00
struct bytecode {
uint16_t* code;
int codelen;
2012-08-21 12:35:36 +01:00
int nlocals;
int nclosures;
jv constants; // JSON array of constants
2012-08-16 01:00:30 +01:00
struct symbol_table* globals;
2012-08-21 12:35:36 +01:00
2012-08-21 18:14:13 +01:00
struct bytecode** subfunctions;
2012-08-21 12:35:36 +01:00
int nsubfunctions;
2012-08-21 18:14:13 +01:00
struct bytecode* parent;
2012-08-16 01:00:30 +01:00
};
2012-08-21 18:14:13 +01:00
void dump_disassembly(int, struct bytecode* code);
void dump_code(int, struct bytecode* code);
2012-08-16 01:00:30 +01:00
void dump_operation(struct bytecode* bc, uint16_t* op);
2012-08-21 12:35:36 +01:00
void symbol_table_free(struct symbol_table* syms);
void bytecode_free(struct bytecode* bc);
2012-08-16 01:00:30 +01:00
#endif