diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-05-05 22:37:46 +0100 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-05-05 22:59:53 +0100 |
commit | 47e015e9468ce109c0fb28562d2b768ba29d2de3 (patch) | |
tree | f83083835a0a12cf23731507f0b38a011271bb3d | |
parent | ab1a97472c91a755c2138417db2fe977c263f536 (diff) |
Make a few constant globals actually const.
This means the .data and .bss sections are empty, a good thing
in a shared library (see #98).
-rw-r--r-- | builtin.c | 10 | ||||
-rw-r--r-- | compile.c | 8 | ||||
-rw-r--r-- | compile.h | 3 | ||||
-rw-r--r-- | jv_parse.c | 4 | ||||
-rw-r--r-- | jv_print.c | 4 |
5 files changed, 13 insertions, 16 deletions
@@ -1,6 +1,5 @@ #include <string.h> #include "builtin.h" -#include "bytecode.h" #include "compile.h" #include "parser.h" #include "locfile.h" @@ -469,7 +468,7 @@ static jv f_error(jv input, jv msg) { return jv_invalid_with_msg(msg); } -static struct cfunction function_list[] = { +static const struct cfunction function_list[] = { {(cfunction_ptr)f_plus, "_plus", 3}, {(cfunction_ptr)f_negate, "_negate", 1}, {(cfunction_ptr)f_minus, "_minus", 3}, @@ -501,9 +500,6 @@ static struct cfunction function_list[] = { {(cfunction_ptr)f_format, "format", 2}, }; -static struct symbol_table cbuiltins = - {function_list, sizeof(function_list)/sizeof(function_list[0])}; - struct bytecoded_builtin { const char* name; block code; }; static block bind_bytecoded_builtins(block b) { block builtins = gen_noop(); @@ -537,7 +533,7 @@ static block bind_bytecoded_builtins(block b) { return block_bind(builtins, b, OP_IS_CALL_PSEUDO); } -static const char* jq_builtins[] = { +static const char* const jq_builtins[] = { "def map(f): [.[] | f];", "def select(f): if f then . else empty end;", "def sort_by(f): _sort_by_impl(map([f]));", @@ -564,5 +560,5 @@ block builtins_bind(block b) { locfile_free(&src); } b = bind_bytecoded_builtins(b); - return gen_cbinding(&cbuiltins, b); + return gen_cbinding(function_list, sizeof(function_list)/sizeof(function_list[0]), b); } @@ -30,7 +30,7 @@ struct inst { uint16_t intval; struct inst* target; jv constant; - struct cfunction* cfunc; + const struct cfunction* cfunc; } imm; location source; @@ -377,10 +377,10 @@ block gen_cond(block cond, block iftrue, block iffalse) { BLOCK(gen_op_simple(POP), iffalse))); } -block gen_cbinding(struct symbol_table* t, block code) { - for (int cfunc=0; cfunc<t->ncfunctions; cfunc++) { +block gen_cbinding(const struct cfunction* cfunctions, int ncfunctions, block code) { + for (int cfunc=0; cfunc<ncfunctions; cfunc++) { inst* i = inst_new(CLOSURE_CREATE_C); - i->imm.cfunc = &t->cfunctions[cfunc]; + i->imm.cfunc = &cfunctions[cfunc]; i->symbol = strdup(i->imm.cfunc->name); code = block_bind(inst_block(i), code, OP_IS_CALL_PSEUDO); } @@ -7,6 +7,7 @@ struct bytecode; struct symbol_table; +struct cfunction; struct inst; typedef struct inst inst; @@ -41,7 +42,7 @@ block gen_or(block a, block b); block gen_cond(block cond, block iftrue, block iffalse); -block gen_cbinding(struct symbol_table* functions, block b); +block gen_cbinding(const struct cfunction* functions, int nfunctions, block b); void block_append(block* b, block b2); block block_join(block a, block b); @@ -283,7 +283,7 @@ static chclass classify(char c) { } -static presult OK = "output produced"; +static const presult OK = "output produced"; static int check_done(struct jv_parser* p, jv* out) { if (p->stackpos == 0 && jv_is_valid(p->next)) { @@ -341,7 +341,7 @@ static pfunc scan(struct jv_parser* p, char ch, jv* out) { return answer; } -static unsigned char UTF8_BOM[] = {0xEF,0xBB,0xBF}; +static const unsigned char UTF8_BOM[] = {0xEF,0xBB,0xBF}; void jv_parser_set_buf(struct jv_parser* p, const char* buf, int length, int is_partial) { assert((p->curr_buf == 0 || p->curr_buf_pos == p->curr_buf_length) @@ -12,10 +12,10 @@ // Colour table. See http://en.wikipedia.org/wiki/ANSI_escape_code#Colors // for how to choose these. -static jv_kind colour_kinds[] = +static const jv_kind colour_kinds[] = {JV_KIND_NULL, JV_KIND_FALSE, JV_KIND_TRUE, JV_KIND_NUMBER, JV_KIND_STRING, JV_KIND_ARRAY, JV_KIND_OBJECT}; -static const char* colours[] = +static const char* const colours[] = {COL("30;1"), COL("0"), COL("0"), COL("0"), COL("32"), COL("37"), COL("37")}; #define FIELD_COLOUR COL("34;1") |