summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2013-06-18 01:36:18 +0100
committerStephen Dolan <mu@netsoc.tcd.ie>2013-06-18 01:36:18 +0100
commitb49d65a276f2c37776db354927130a574cc5e2de (patch)
tree8fa6a4d607a72ba99068117201e1c4225cb7cdfc
parent824ce76cecd11863f6c86cf04e3a56075cbcd30a (diff)
Fold opcode.{c,h} into bytecode.{c,h}
-rw-r--r--Makefile.am8
-rw-r--r--builtin.h11
-rw-r--r--bytecode.c32
-rw-r--r--bytecode.h46
-rw-r--r--compile.c1
-rw-r--r--compile.h6
-rw-r--r--execute.c1
-rw-r--r--jq_parser.h2
-rw-r--r--opcode.c31
-rw-r--r--opcode.h41
10 files changed, 83 insertions, 96 deletions
diff --git a/Makefile.am b/Makefile.am
index c4f79e04..ceeadb1a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,11 +2,11 @@
JQ_INCS = jq_parser.h builtin.h bytecode.h compile.h execute.h \
forkable_stack.h frame_layout.h jv.h jv_alloc.h jv_aux.h jv_dtoa.h \
- jv_file.h jv_parse.h jv_unicode.h locfile.h opcode.h opcode_list.h \
- parser.y jv_utf8_tables.h lexer.l
+ jv_file.h jv_parse.h jv_unicode.h locfile.h opcode_list.h parser.y \
+ jv_utf8_tables.h lexer.l
-JQ_SRC = locfile.c opcode.c bytecode.c compile.c execute.c builtin.c \
- jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c jv_aux.c jv_file.c \
+JQ_SRC = locfile.c bytecode.c compile.c execute.c builtin.c jv.c \
+ jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c jv_aux.c jv_file.c \
jv_alloc.c jq_test.c ${JQ_INCS}
diff --git a/builtin.h b/builtin.h
index fdbce92a..63562635 100644
--- a/builtin.h
+++ b/builtin.h
@@ -1,20 +1,11 @@
#ifndef BUILTIN_H
#define BUILTIN_H
+#include "bytecode.h"
#include "compile.h"
int builtins_bind(block*);
-
-typedef void (*cfunction_ptr)(void);
-
-struct cfunction {
- cfunction_ptr fptr;
- const char* name;
- int nargs;
-};
-
-
jv cfunction_invoke(struct cfunction* function, jv input[]);
diff --git a/bytecode.c b/bytecode.c
index 184cf983..1277fdc1 100644
--- a/bytecode.c
+++ b/bytecode.c
@@ -3,9 +3,39 @@
#include <stdlib.h>
#include "bytecode.h"
-#include "opcode.h"
#include "jv_alloc.h"
+// flags, length
+#define NONE 0, 1
+#define CONSTANT OP_HAS_CONSTANT, 2
+#define VARIABLE (OP_HAS_VARIABLE | OP_HAS_BINDING), 3
+#define BRANCH OP_HAS_BRANCH, 2
+#define CFUNC (OP_HAS_CFUNC | OP_HAS_BINDING), 3
+#define UFUNC (OP_HAS_UFUNC | OP_HAS_BINDING | OP_IS_CALL_PSEUDO), 4
+#define DEFINITION (OP_IS_CALL_PSEUDO | OP_HAS_BINDING), 0
+#define CLOSURE_REF_IMM (OP_IS_CALL_PSEUDO | OP_HAS_BINDING), 2
+
+#define OP(name, imm, in, out) \
+ {name, #name, imm, in, out},
+
+static const struct opcode_description opcode_descriptions[] = {
+#include "opcode_list.h"
+};
+
+static const struct opcode_description invalid_opcode_description = {
+ -1, "#INVALID", 0, 0, 0, 0
+};
+
+
+const struct opcode_description* opcode_describe(opcode op) {
+ if ((int)op >= 0 && (int)op < NUM_OPCODES) {
+ return &opcode_descriptions[op];
+ } else {
+ return &invalid_opcode_description;
+ }
+}
+
+
static int bytecode_operation_length(uint16_t* codeptr) {
int length = opcode_describe(*codeptr)->length;
if (*codeptr == CALL_JQ) {
diff --git a/bytecode.h b/bytecode.h
index 70929c91..ba5fec3a 100644
--- a/bytecode.h
+++ b/bytecode.h
@@ -3,10 +3,52 @@
#include <stdint.h>
#include "jv.h"
-#include "opcode.h"
-#include "builtin.h"
+
+typedef enum {
+#define OP(name, imm, in, out) name,
+#include "opcode_list.h"
+#undef OP
+} opcode;
+
+enum {
+ NUM_OPCODES =
+#define OP(name, imm, in, out) +1
+#include "opcode_list.h"
+#undef OP
+};
+
+enum {
+ OP_HAS_CONSTANT = 2,
+ OP_HAS_VARIABLE = 4,
+ OP_HAS_BRANCH = 8,
+ OP_HAS_CFUNC = 32,
+ OP_HAS_UFUNC = 64,
+ OP_IS_CALL_PSEUDO = 128,
+ OP_HAS_BINDING = 1024,
+};
+struct opcode_description {
+ opcode op;
+ const char* name;
+
+ int flags;
+
+ // length in 16-bit units
+ int length;
+
+ int stack_in, stack_out;
+};
+
+const struct opcode_description* opcode_describe(opcode op);
+
#define MAX_CFUNCTION_ARGS 10
+typedef void (*cfunction_ptr)(void);
+struct cfunction {
+ cfunction_ptr fptr;
+ const char* name;
+ int nargs;
+};
+
struct symbol_table {
struct cfunction* cfunctions;
int ncfunctions;
diff --git a/compile.c b/compile.c
index 4dda1011..248d363e 100644
--- a/compile.c
+++ b/compile.c
@@ -2,7 +2,6 @@
#include <assert.h>
#include <string.h>
#include <stdlib.h>
-#include "opcode.h"
#include "compile.h"
#include "bytecode.h"
#include "locfile.h"
diff --git a/compile.h b/compile.h
index 4ac7168b..531e853e 100644
--- a/compile.h
+++ b/compile.h
@@ -2,13 +2,9 @@
#define COMPILE_H
#include <stdint.h>
#include "jv.h"
-#include "opcode.h"
+#include "bytecode.h"
#include "locfile.h"
-struct bytecode;
-struct symbol_table;
-struct cfunction;
-
struct inst;
typedef struct inst inst;
diff --git a/execute.c b/execute.c
index 3a5512aa..b43ad26a 100644
--- a/execute.c
+++ b/execute.c
@@ -6,7 +6,6 @@
#include "execute.h"
#include "exec_stack.h"
-#include "opcode.h"
#include "bytecode.h"
#include "jv_alloc.h"
diff --git a/jq_parser.h b/jq_parser.h
index 8dc37163..809ace06 100644
--- a/jq_parser.h
+++ b/jq_parser.h
@@ -1,5 +1,7 @@
#ifndef JQ_PARSER_H
#define JQ_PARSER_H
+#include "locfile.h"
+#include "compile.h"
int jq_parse(struct locfile* source, block* answer);
int jq_parse_library(struct locfile* locations, block* answer);
diff --git a/opcode.c b/opcode.c
deleted file mode 100644
index 4e785b8f..00000000
--- a/opcode.c
+++ /dev/null
@@ -1,31 +0,0 @@
-#include "opcode.h"
-
-// flags, length
-#define NONE 0, 1
-#define CONSTANT OP_HAS_CONSTANT, 2
-#define VARIABLE (OP_HAS_VARIABLE | OP_HAS_BINDING), 3
-#define BRANCH OP_HAS_BRANCH, 2
-#define CFUNC (OP_HAS_CFUNC | OP_HAS_BINDING), 3
-#define UFUNC (OP_HAS_UFUNC | OP_HAS_BINDING | OP_IS_CALL_PSEUDO), 4
-#define DEFINITION (OP_IS_CALL_PSEUDO | OP_HAS_BINDING), 0
-#define CLOSURE_REF_IMM (OP_IS_CALL_PSEUDO | OP_HAS_BINDING), 2
-
-#define OP(name, imm, in, out) \
- {name, #name, imm, in, out},
-
-static const struct opcode_description opcode_descriptions[] = {
-#include "opcode_list.h"
-};
-
-static const struct opcode_description invalid_opcode_description = {
- -1, "#INVALID", 0, 0, 0, 0
-};
-
-
-const struct opcode_description* opcode_describe(opcode op) {
- if ((int)op >= 0 && (int)op < NUM_OPCODES) {
- return &opcode_descriptions[op];
- } else {
- return &invalid_opcode_description;
- }
-}
diff --git a/opcode.h b/opcode.h
deleted file mode 100644
index ee956e27..00000000
--- a/opcode.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef OPCODE_H
-#define OPCODE_H
-#include <assert.h>
-
-typedef enum {
-#define OP(name, imm, in, out) name,
-#include "opcode_list.h"
-#undef OP
-} opcode;
-
-enum {
- NUM_OPCODES =
-#define OP(name, imm, in, out) +1
-#include "opcode_list.h"
-#undef OP
-};
-
-enum {
- OP_HAS_CONSTANT = 2,
- OP_HAS_VARIABLE = 4,
- OP_HAS_BRANCH = 8,
- OP_HAS_CFUNC = 32,
- OP_HAS_UFUNC = 64,
- OP_IS_CALL_PSEUDO = 128,
- OP_HAS_BINDING = 1024,
-};
-struct opcode_description {
- opcode op;
- const char* name;
-
- int flags;
-
- // length in 16-bit units
- int length;
-
- int stack_in, stack_out;
-};
-
-const struct opcode_description* opcode_describe(opcode op);
-
-#endif