diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-09-18 22:17:13 +0100 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-09-18 22:17:13 +0100 |
commit | 20e45f363c91ef4a305eff5709212f1b2fb43523 (patch) | |
tree | 5fad025d47663b801d15a7cb805562cf6264a044 /execute.c | |
parent | 46af5238ce3e9327e0268d18373d07f67eed58b8 (diff) |
Separate the tests and the main program.
Diffstat (limited to 'execute.c')
-rw-r--r-- | execute.c | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -3,6 +3,8 @@ #include <stdlib.h> #include <stdint.h> +#include "execute.h" + #include "opcode.h" #include "bytecode.h" #include "compile.h" @@ -10,8 +12,10 @@ #include "forkable_stack.h" #include "frame_layout.h" +#include "locfile.h" #include "jv.h" - +#include "parser.h" +#include "builtin.h" typedef struct { jv value; @@ -500,3 +504,22 @@ void jq_teardown() { pathbuf = 0; pathsize = 0; } + +struct bytecode* jq_compile(const char* str) { + struct locfile locations; + locfile_init(&locations, str, strlen(str)); + block program; + struct bytecode* bc = 0; + int nerrors = jq_parse(&locations, &program); + if (nerrors == 0) { + block_append(&program, block_join(gen_op_simple(YIELD), gen_op_simple(BACKTRACK))); + program = builtins_bind(program); + nerrors = block_compile(program, &locations, &bc); + block_free(program); + } + if (nerrors) { + fprintf(stderr, "%d compile %s\n", nerrors, nerrors > 1 ? "errors" : "error"); + } + locfile_free(&locations); + return bc; +} |