Skip to content

Commit df4b4f3

Browse files
committed
Make grammar rules const so the go in .text section.
1 parent 4d7adce commit df4b4f3

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

py/parse.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ enum {
5555
#define opt_tok(t) (RULE_ARG_OPT_TOK | PY_TOKEN_##t)
5656
#define opt_rule(r) (RULE_ARG_OPT_RULE | RULE_##r)
5757
#ifdef USE_RULE_NAME
58-
#define DEF_RULE(rule, comp, kind, arg...) static rule_t rule_##rule = { RULE_##rule, kind, #rule, { arg } };
58+
#define DEF_RULE(rule, comp, kind, arg...) static const rule_t rule_##rule = { RULE_##rule, kind, #rule, { arg } };
5959
#else
60-
#define DEF_RULE(rule, comp, kind, arg...) static rule_t rule_##rule = { RULE_##rule, kind, { arg } };
60+
#define DEF_RULE(rule, comp, kind, arg...) static const rule_t rule_##rule = { RULE_##rule, kind, { arg } };
6161
#endif
6262
#include "grammar.h"
6363
#undef or
@@ -71,7 +71,7 @@ enum {
7171
#undef one_or_more
7272
#undef DEF_RULE
7373

74-
static rule_t *rules[] = {
74+
static const rule_t *rules[] = {
7575
NULL,
7676
#define DEF_RULE(rule, comp, kind, arg...) &rule_##rule,
7777
#include "grammar.h"
@@ -92,7 +92,7 @@ typedef struct _parser_t {
9292
py_parse_node_t *result_stack;
9393
} parser_t;
9494

95-
static void push_rule(parser_t *parser, rule_t *rule, int arg_i) {
95+
static void push_rule(parser_t *parser, const rule_t *rule, int arg_i) {
9696
if (parser->rule_stack_top >= parser->rule_stack_alloc) {
9797
parser->rule_stack_alloc *= 2;
9898
parser->rule_stack = m_renew(rule_stack_t, parser->rule_stack, parser->rule_stack_alloc);
@@ -109,7 +109,7 @@ static void push_rule_from_arg(parser_t *parser, uint arg) {
109109
push_rule(parser, rules[rule_id], 0);
110110
}
111111

112-
static void pop_rule(parser_t *parser, rule_t **rule, uint *arg_i) {
112+
static void pop_rule(parser_t *parser, const rule_t **rule, uint *arg_i) {
113113
parser->rule_stack_top -= 1;
114114
*rule = rules[parser->rule_stack[parser->rule_stack_top].rule_id];
115115
*arg_i = parser->rule_stack[parser->rule_stack_top].arg_i;
@@ -243,7 +243,7 @@ static void push_result_token(parser_t *parser, const py_lexer_t *lex) {
243243
push_result_node(parser, pn);
244244
}
245245

246-
static void push_result_rule(parser_t *parser, rule_t *rule, int num_args) {
246+
static void push_result_rule(parser_t *parser, const rule_t *rule, int num_args) {
247247
py_parse_node_struct_t *pn = parse_node_new_struct(rule->rule_id, num_args);
248248
for (int i = num_args; i > 0; i--) {
249249
pn->nodes[i - 1] = pop_result(parser);
@@ -270,7 +270,7 @@ py_parse_node_t py_parse(py_lexer_t *lex, py_parse_input_kind_t input_kind) {
270270

271271
uint n, i;
272272
bool backtrack = false;
273-
rule_t *rule;
273+
const rule_t *rule;
274274
py_token_kind_t tok_kind;
275275
bool emit_rule;
276276
bool had_trailing_sep;

py/runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ py_obj_t rt_iternext(py_obj_t o_in) {
15461546
}
15471547
}
15481548

1549-
const void *const rt_fun_table[RT_F_NUMBER_OF] = {
1549+
void *const rt_fun_table[RT_F_NUMBER_OF] = {
15501550
rt_load_const_str,
15511551
rt_load_name,
15521552
rt_load_global,

py/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ typedef enum {
7676
RT_F_NUMBER_OF,
7777
} rt_fun_kind_t;
7878

79-
extern const void *const rt_fun_table[RT_F_NUMBER_OF];
79+
extern void *const rt_fun_table[RT_F_NUMBER_OF];
8080

8181
typedef machine_ptr_t py_obj_t; // must be of pointer size
8282
typedef py_obj_t (*py_fun_0_t)();

0 commit comments

Comments
 (0)