]> granicus.if.org Git - jq/commitdiff
Fold opcode.{c,h} into bytecode.{c,h}
authorStephen Dolan <mu@netsoc.tcd.ie>
Tue, 18 Jun 2013 00:36:18 +0000 (01:36 +0100)
committerStephen Dolan <mu@netsoc.tcd.ie>
Tue, 18 Jun 2013 00:36:18 +0000 (01:36 +0100)
Makefile.am
builtin.h
bytecode.c
bytecode.h
compile.c
compile.h
execute.c
jq_parser.h
opcode.c [deleted file]
opcode.h [deleted file]

index c4f79e0403eada57149e94263576034ed7ea18eb..ceeadb1a7397abd3129e9401d664fdad3a27ae30 100644 (file)
@@ -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}
 
 
index fdbce92a06d3625ef46d90a163c26d9443b96f04..6356263501ab98aa64a3375237174fd3b23df70f 100644 (file)
--- 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[]);
 
 
index 184cf983caec800e9e1e58e38b63a1977a00144f..1277fdc101fff51961c148c00318c9fc32bdbee9 100644 (file)
@@ -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) {
index 70929c9141f0fc1f09d6de7e891b33ccd83e37d2..ba5fec3a5f6e3e529d7a7217eb16e584868e05c9 100644 (file)
@@ -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;
index 4dda10110db288a02edd53728cf99aac08d9c4fc..248d363e8eece0a555a48413255451471e3d637b 100644 (file)
--- 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"
index 4ac7168b8065c31b10214b67cfcdc50db1037b98..531e853e0e3cd27b9216c94b36f45346f36c4c5a 100644 (file)
--- 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;
 
index 3a5512aab9ff12d1929eb2ea2fd12b1aa00e80f4..b43ad26a1bddfe06d4c29515655a7286c132e4b7 100644 (file)
--- 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"
index 8dc3716315355f301bb76c439078a85851c4d5df..809ace06ed4c8436ff74985e5a41774b106837a1 100644 (file)
@@ -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 (file)
index 4e785b8..0000000
--- 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 (file)
index ee956e2..0000000
--- 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