bytecode.h
This file
Path
src/bytecode.h
96 lines · 1.7 KiB · C
Last changed by
builtin.c: typecheck builtin cfunctions in function_listEmanuele Torrebefore adoption0b82b38
History of this fileTake it
The walk stopped after 200 commits: lines older than 19453a6 point at it.
ci.yml: use sysctl -n hw.logicalcpu instead of nproc on macosEmanuele Torrebefore adoption19453a6
lines 1–4why, one step back1#ifndef BYTECODE_H2#define BYTECODE_H3#include <stdint.h>4builtin.c: typecheck builtin cfunctions in function_listEmanuele Torrebefore adoption0b82b38
line 5why, one step back5#include "jq.h"ci.yml: use sysctl -n hw.logicalcpu instead of nproc on macosEmanuele Torrebefore adoption19453a6
lines 6–46why, one step back67typedef enum {8#define OP(name, imm, in, out) name,9#include "opcode_list.h"10#undef OP11} opcode;1213enum {14 NUM_OPCODES =15#define OP(name, imm, in, out) +116#include "opcode_list.h"17#undef OP18};1920enum {21 OP_HAS_CONSTANT = 2,22 OP_HAS_VARIABLE = 4,23 OP_HAS_BRANCH = 8,24 OP_HAS_CFUNC = 32,25 OP_HAS_UFUNC = 64,26 OP_IS_CALL_PSEUDO = 128,27 OP_HAS_BINDING = 1024,28 // NOTE: Not actually part of any op -- a pseudo-op flag for special29 // handling of `break`.30 OP_BIND_WILDCARD = 2048,31};32struct opcode_description {33 opcode op;34 const char* name;3536 int flags;3738 // length in 16-bit units39 int length;4041 int stack_in, stack_out;42};4344const struct opcode_description* opcode_describe(opcode op);4546builtin.c: typecheck builtin cfunctions in function_listEmanuele Torrebefore adoption0b82b38
line 47why, one step back47#define MAX_CFUNCTION_ARGS 4ci.yml: use sysctl -n hw.logicalcpu instead of nproc on macosEmanuele Torrebefore adoption19453a6
line 48why, one step back48struct cfunction {builtin.c: typecheck builtin cfunctions in function_listEmanuele Torrebefore adoption0b82b38
lines 49–54why, one step back49 union {50 jv (*a1)(jq_state *, jv);51 jv (*a2)(jq_state *, jv, jv);52 jv (*a3)(jq_state *, jv, jv, jv);53 jv (*a4)(jq_state *, jv, jv, jv, jv);54 } fptr;ci.yml: use sysctl -n hw.logicalcpu instead of nproc on macosEmanuele Torrebefore adoption19453a6
lines 55–96why, one step back55 const char* name;56 int nargs;57};5859struct symbol_table {60 struct cfunction* cfunctions;61 int ncfunctions;62 jv cfunc_names;63};6465// The bytecode format matters in:66// execute.c - interpreter67// compile.c - compiler68// bytecode.c - disassembler6970#define ARG_NEWCLOSURE 0x10007172struct bytecode {73 uint16_t* code;74 int codelen;7576 int nlocals;77 int nclosures;7879 jv constants; // JSON array of constants80 struct symbol_table* globals;8182 struct bytecode** subfunctions;83 int nsubfunctions;8485 struct bytecode* parent;8687 jv debuginfo;88};8990void dump_disassembly(int, struct bytecode* code);91void dump_operation(struct bytecode* bc, uint16_t* op);9293int bytecode_operation_length(uint16_t* codeptr);94void bytecode_free(struct bytecode* bc);9596#endif