8000 Tidy up some configuration options. · errordeveloper/micropython@58ebde4 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 58ebde4

Browse files
committed
Tidy up some configuration options.
MP_ALLOC_* -> MICROPY_ALLOC_* MICROPY_PATH_MAX -> MICROPY_ALLOC_PATH_MAX MICROPY_ENABLE_REPL_HELPERS -> MICROPY_HELPER_REPL MICROPY_ENABLE_LEXER_UNIX -> MICROPY_HELPER_LEXER_UNIX MICROPY_EXTRA_* -> MICROPY_PORT_* See issue micropython#35.
1 parent aa7cf6f commit 58ebde4

File tree

18 files changed

+99
-93
lines changed

18 files changed

+99
-93
lines changed

bare-arm/mpconfigport.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
// options to control how Micro Python is built
44

5+
#define MICROPY_ALLOC_PATH_MAX (512)
56
#define MICROPY_EMIT_X64 (0)
67
#define MICROPY_EMIT_THUMB (0)
78
#define MICROPY_EMIT_INLINE_THUMB (0)
89
#define MICROPY_MEM_STATS (0)
910
#define MICROPY_DEBUG_PRINTERS (0)
1011
#define MICROPY_ENABLE_GC (0)
11-
#define MICROPY_ENABLE_REPL_HELPERS (0)
12-
#define MICROPY_ENABLE_LEXER_UNIX (0)
12+
#define MICROPY_HELPER_REPL (0)
13+
#define MICROPY_HELPER_LEXER_UNIX (0)
1314
#define MICROPY_ENABLE_SOURCE_LINE (0)
1415
#define MICROPY_ENABLE_MOD_COLLECTIONS (0)
1516
#define MICROPY_ENABLE_MOD_MATH (0)
@@ -21,7 +22,6 @@
2122
#define MICROPY_CPYTHON_COMPAT (0)
2223
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
2324
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
24-
#define MICROPY_PATH_MAX (512)
2525

2626
// type definitions for the specific machine
2727

@@ -37,6 +37,6 @@ typedef const void *machine_const_ptr_t; // must be of pointer size
3737

3838
// extra built in names to add to the global namespace
3939
extern const struct _mp_obj_fun_native_t mp_builtin_open_obj;
40-
#define MICROPY_EXTRA_BUILTINS \
40+
#define MICROPY_PORT_BUILTINS \
4141
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
4242

py/builtinimport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
278278
DEBUG_printf("Module not yet loaded\n");
279279

280280
uint last = 0;
281-
VSTR_FIXED(path, MICROPY_PATH_MAX)
281+
VSTR_FIXED(path, MICROPY_ALLOC_PATH_MAX)
282282
module_obj = MP_OBJ_NULL;
283283
mp_obj_t top_module_obj = MP_OBJ_NULL;
284284
mp_obj_t outer_module_obj = MP_OBJ_NULL;

py/builtintables.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ STATIC const mp_map_elem_t mp_builtin_object_table[] = {
140140
// TODO: For MICROPY_CPYTHON_COMPAT==0 use ValueError to avoid exc proliferation
141141

142142
// Extra builtins as defined by a port
143-
MICROPY_EXTRA_BUILTINS
143+
MICROPY_PORT_BUILTINS
144144
};
145145

146146
const mp_obj_dict_t mp_builtin_object_dict_obj = {
@@ -183,7 +183,7 @@ STATIC const mp_map_elem_t mp_builtin_module_table[] = {
183183
#endif
184184

185185
// extra builtin modules as defined by a port
186-
MICROPY_EXTRA_BUILTIN_MODULES
186+
MICROPY_PORT_BUILTIN_MODULES
187187
};
188188

189189
const mp_obj_dict_t mp_builtin_module_dict_obj = {

py/compile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, const cha
104104

105105
STATIC const mp_map_elem_t mp_constants_table[] = {
106106
// Extra constants as defined by a port
107-
MICROPY_EXTRA_CONSTANTS
107+
MICROPY_PORT_CONSTANTS
108108
};
109109

110110
STATIC const mp_map_t mp_constants_map = {
@@ -119,7 +119,7 @@ STATIC const mp_map_t mp_constants_map = {
119119
STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_map_t *consts) {
120120
if (0) {
121121
// dummy
122-
#if MICROPY_ENABLE_CONST
122+
#if MICROPY_COMP_CONST
123123
} else if (MP_PARSE_NODE_IS_ID(pn)) {
124124
// lookup identifier in table of dynamic constants
125125
qstr qst = MP_PARSE_NODE_LEAF_ARG(pn);
@@ -133,7 +133,7 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m
133133

134134
// fold some parse nodes before folding their arguments
135135
switch (MP_PARSE_NODE_STRUCT_KIND(pns)) {
136-
#if MICROPY_ENABLE_CONST
136+
#if MICROPY_COMP_CONST
137137
case PN_expr_stmt:
138138
if (!MP_PARSE_NODE_IS_NULL(pns->nodes[1])) {
139139
mp_parse_node_struct_t *pns1 = (mp_parse_node_struct_t*)pns->nodes[1];

py/lexer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ STATIC void next_char(mp_lexer_t *lex) {
218218
void indent_push(mp_lexer_t *lex, uint indent) {
219219
if (lex->num_indent_level >= lex->alloc_indent_level) {
220220
// TODO use m_renew_maybe and somehow indicate an error if it fails... probably by using MP_TOKEN_MEMORY_ERROR
221-
lex->indent_level = m_renew(uint16_t, lex->indent_level, lex->alloc_indent_level, lex->alloc_indent_level + MP_ALLOC_LEXEL_INDENT_INC);
222-
lex->alloc_indent_level += MP_ALLOC_LEXEL_INDENT_INC;
221+
lex->indent_level = m_renew(uint16_t, lex->indent_level, lex->alloc_indent_level, lex->alloc_indent_level + MICROPY_ALLOC_LEXEL_INDENT_INC);
222+
lex->alloc_indent_level += MICROPY_ALLOC_LEXEL_INDENT_INC;
223223
}
224224
lex->indent_level[lex->num_indent_level++] = indent;
225225
}
@@ -731,7 +731,7 @@ mp_lexer_t *mp_lexer_new(qstr src_name, void *stream_data, mp_lexer_stream_next_
731731
lex->column = 1;
732732
lex->emit_dent = 0;
733733
lex->nested_bracket_level = 0;
734-
lex->alloc_indent_level = MP_ALLOC_LEXER_INDENT_INIT;
734+
lex->alloc_indent_level = MICROPY_ALLOC_LEXER_INDENT_INIT;
735735
lex->num_indent_level = 1;
736736
lex->indent_level = m_new_maybe(uint16_t, lex->alloc_indent_level);
737737
vstr_init(&lex->vstr, 32);

py/lexerunix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "misc.h"
2828
#include "mpconfig.h"
2929

30-
#if MICROPY_ENABLE_LEXER_UNIX
30+
#if MICROPY_HELPER_LEXER_UNIX
3131

3232
#include <stdio.h>
3333
#include <unistd.h>
@@ -81,4 +81,4 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
8181
return mp_lexer_new(qstr_from_str(filename), fb, (mp_lexer_stream_next_char_t)file_buf_next_char, (mp_lexer_stream_close_t)file_buf_close);
8282
}
8383

84-
#endif // MICROPY_ENABLE_LEXER_UNIX
84+
#endif // MICROPY_HELPER_LEXER_UNIX

py/mpconfig.h

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,49 @@
3737
/* Memory allocation policy */
3838

3939
// Initial amount for lexer indentation level
40-
#ifndef MP_ALLOC_LEXER_INDENT_INIT
41-
#define MP_ALLOC_LEXER_INDENT_INIT (10)
40+
#ifndef MICROPY_ALLOC_LEXER_INDENT_INIT
41+
#define MICROPY_ALLOC_LEXER_INDENT_INIT (10)
4242
#endif
4343

4444
// Increment for lexer indentation level
45-
#ifndef MP_ALLOC_LEXEL_INDENT_INC
46-
#define MP_ALLOC_LEXEL_INDENT_INC (8)
45+
#ifndef MICROPY_ALLOC_LEXEL_INDENT_INC
46+
#define MICROPY_ALLOC_LEXEL_INDENT_INC (8)
4747
#endif
4848

4949
// Initial amount for parse rule stack
50-
#ifndef MP_ALLOC_PARSE_RULE_INIT
51-
#define MP_ALLOC_PARSE_RULE_INIT (64)
50+
#ifndef MICROPY_ALLOC_PARSE_RULE_INIT
51+
#define MICROPY_ALLOC_PARSE_RULE_INIT (64)
5252
#endif
5353

5454
// Increment for parse rule stack
55-
#ifndef MP_ALLOC_PARSE_RULE_INC
56-
#define MP_ALLOC_PARSE_RULE_INC (16)
55+
#ifndef MICROPY_ALLOC_PARSE_RULE_INC
56+
#define MICROPY_ALLOC_PARSE_RULE_INC (16)
5757
#endif
5858

5959
// Initial amount for parse result stack
60-
#ifndef MP_ALLOC_PARSE_RESULT_INIT
61-
#define MP_ALLOC_PARSE_RESULT_INIT (32)
60+
#ifndef MICROPY_ALLOC_PARSE_RESULT_INIT
61+
#define MICROPY_ALLOC_PARSE_RESULT_INIT (32)
6262
#endif
6363

6464
// Increment for parse result stack
65-
#ifndef MP_ALLOC_PARSE_RESULT_INC
66-
#define MP_ALLOC_PARSE_RESULT_INC (16)
65+
#ifndef MICROPY_ALLOC_PARSE_RESULT_IN 1241 C
66+
#define MICROPY_ALLOC_PARSE_RESULT_INC (16)
6767
#endif
6868

6969
// Initial amount for ids in a scope
70-
#ifndef MP_ALLOC_SCOPE_ID_INIT
71-
#define MP_ALLOC_SCOPE_ID_INIT (4)
70+
#ifndef MICROPY_ALLOC_SCOPE_ID_INIT
71+
#define MICROPY_ALLOC_SCOPE_ID_INIT (4)
7272
#endif
7373

7474
// Increment for ids in a scope
75-
#ifndef MP_ALLOC_SCOPE_ID_INC
76-
#define MP_ALLOC_SCOPE_ID_INC (6)
75+
#ifndef MICROPY_ALLOC_SCOPE_ID_INC
76+
#define MICROPY_ALLOC_SCOPE_ID_INC (6)
77+
#endif
78+
79+
// Maximum length of a path in the filesystem
80+
// So we can allocate a buffer on the stack for path manipulation in import
81+
#ifndef MICROPY_ALLOC_PATH_MAX
82+
#define MICROPY_ALLOC_PATH_MAX (512)
7783
#endif
7884

7985
/*****************************************************************************/
@@ -100,6 +106,14 @@
100106
#define MICROPY_EMIT_INLINE_THUMB (0)
101107
#endif
102108

109+
/*****************************************************************************/
110+
/* Compiler configuration */
111+
112+
// Whether to enable constant optimisation; id = const(value)
113+
#ifndef MICROPY_COMP_CONST
114+
#define MICROPY_COMP_CONST (1)
115+
#endif
116+
103117
/*****************************************************************************/
104118
/* Internal debugging stuff */
105119

@@ -119,11 +133,6 @@
119133
/*****************************************************************************/
120134
/* Fine control over Python features */
121135

122-
// Whether to enable constant optimisation; id = const(value)
123-
#ifndef MICROPY_ENABLE_CONST
124-
#define MICROPY_ENABLE_CONST (1)
125-
#endif
126-
127136
// Whether to include the garbage collector
128137
#ifndef MICROPY_ENABLE_GC
129138
#define MICROPY_ENABLE_GC (0)
@@ -135,13 +144,13 @@
135144
#endif
136145

137146
// Whether to include REPL helper function
138-
#ifndef MICROPY_ENABLE_REPL_HELPERS
139-
#define MICROPY_ENABLE_REPL_HELPERS (0)
147+
#ifndef MICROPY_HELPER_REPL
148+
#define MICROPY_HELPER_REPL (0)
140149
#endif
141150

142151
// Whether to include lexer helper function for unix
143-
#ifndef MICROPY_ENABLE_LEXER_UNIX
144-
#define MICROPY_ENABLE_LEXER_UNIX (0)
152+
#ifndef MICROPY_HELPER_LEXER_UNIX
153+
#define MICROPY_HELPER_LEXER_UNIX (0)
145154
#endif
146155

147156
// Long int implementation
@@ -277,36 +286,33 @@ typedef double mp_float_t;
277286
#define MICROPY_CPYTHON_COMPAT (1)
278287
#endif
279288

280-
// Maximum length of a path in the filesystem
281-
// So we can allocate a buffer on the stack for path manipulation in import
282-
#ifndef MICROPY_PATH_MAX
283-
#define MICROPY_PATH_MAX (512)
284-
#endif
285-
286289
// Whether POSIX-semantics non-blocking streams are supported
287290
#ifndef MICROPY_STREAMS_NON_BLOCK
288291
#define MICROPY_STREAMS_NON_BLOCK (0)
289292
#endif
290293

291294
// Whether to use computed gotos in the VM, or a switch
292295
// Computed gotos are roughly 10% faster, and increase VM code size by a little
293-
#ifndef MICROPY_USE_COMPUTED_GOTO
294-
#define MICROPY_USE_COMPUTED_GOTO (0)
296+
#ifndef MICROPY_OPT_COMPUTED_GOTO
297+
#define MICROPY_OPT_COMPUTED_GOTO (0)
295298
#endif
296299

300+
/*****************************************************************************/
301+
/* Hooks for a port to add builtins */
302+
297303
// Additional builtin function definitions - see builtintables.c:builtin_object_table for format.
298-
#ifndef MICROPY_EXTRA_BUILTINS
299-
#define MICROPY_EXTRA_BUILTINS
304+
#ifndef MICROPY_PORT_BUILTINS
305+
#define MICROPY_PORT_BUILTINS
300306
#endif
301307

302308
// Additional builtin module definitions - see builtintables.c:builtin_module_table for format.
303-
#ifndef MICROPY_EXTRA_BUILTIN_MODULES
304-
#define MICROPY_EXTRA_BUILTIN_MODULES
309+
#ifndef MICROPY_PORT_BUILTIN_MODULES
310+
#define MICROPY_PORT_BUILTIN_MODULES
305311
#endif
306312

307313
// Additional constant definitions for the compiler - see compile.c:mp_constants_table.
308-
#ifndef MICROPY_EXTRA_CONSTANTS
309-
#define MICROPY_EXTRA_CONSTANTS
314+
#ifndef MICROPY_PORT_CONSTANTS
315+
#define MICROPY_PORT_CONSTANTS
310316
#endif
311317

312318
/*****************************************************************************/

py/parse.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ STATIC void push_rule(parser_t *parser, int src_line, const rule_t *rule, int ar
134134
return;
135135
}
136136
if (parser->rule_stack_top >= parser->rule_stack_alloc) {
137-
rule_stack_t *rs = m_renew_maybe(rule_stack_t, parser->rule_stack, parser->rule_stack_alloc, parser->rule_stack_alloc + MP_ALLOC_PARSE_RULE_INC);
137+
rule_stack_t *rs = m_renew_maybe(rule_stack_t, parser->rule_stack, parser->rule_stack_alloc, parser->rule_stack_alloc + MICROPY_ALLOC_PARSE_RULE_INC);
138138
if (rs == NULL) {
139139
memory_error(parser);
140140
return;
141141
}
142142
parser->rule_stack = rs;
143-
parser->rule_stack_alloc += MP_ALLOC_PARSE_RULE_INC;
143+
parser->rule_stack_alloc += MICROPY_ALLOC_PARSE_RULE_INC;
144144
}
145145
rule_stack_t *rs = &parser->rule_stack[parser->rule_stack_top++];
146146
rs->src_line = src_line;
@@ -263,13 +263,13 @@ STATIC void push_result_node(parser_t *parser, mp_parse_node_t pn) {
263263
return;
264264
}
265265
if (parser->result_stack_top >= parser->result_stack_alloc) {
266-
mp_parse_node_t *pn = m_renew_maybe(mp_parse_node_t, parser->result_stack, parser->result_stack_alloc, parser->result_stack_alloc + MP_ALLOC_PARSE_RESULT_INC);
266+
mp_parse_node_t *pn = m_renew_maybe(mp_parse_node_t, parser->result_stack, parser->result_stack_alloc, parser->result_stack_alloc + MICROPY_ALLOC_PARSE_RESULT_INC);
267267
if (pn == NULL) {
268268
memory_error(parser);
269269
return;
270270
}
271271
parser->result_stack = pn;
272-
parser->result_stack_alloc += MP_ALLOC_PARSE_RESULT_INC;
272+
parser->result_stack_alloc += MICROPY_ALLOC_PARSE_RESULT_INC;
273273
}
274274
parser->result_stack[parser->result_stack_top++] = pn;
275275
}
@@ -350,11 +350,11 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, mp_p
350350

351351
parser.had_memory_error = false;
352352

353-
parser.rule_stack_alloc = MP_ALLOC_PARSE_RULE_INIT;
353+
parser.rule_stack_alloc = MICROPY_ALLOC_PARSE_RULE_INIT;
354354
parser.rule_stack_top = 0;
355355
parser.rule_stack = m_new_maybe(rule_stack_t, parser.rule_stack_alloc);
356356

357-
parser.result_stack_alloc = MP_ALLOC_PARSE_RESULT_INIT;
357+
parser.result_stack_alloc = MICROPY_ALLOC_PARSE_RESULT_INIT;
358358
parser.result_stack_top = 0;
359359
parser.result_stack = m_new_maybe(mp_parse_node_t, parser.result_stack_alloc);
360360

py/repl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "mpconfig.h"
2929
#include "repl.h"
3030

31-
#if MICROPY_ENABLE_REPL_HELPERS
31+
#if MICROPY_HELPER_REPL
3232

3333
bool str_startswith_word(const char *str, const char *head) {
3434
int i;
@@ -107,4 +107,4 @@ bool mp_repl_continue_with_input(const char *input) {
107107
return false;
108108
}
109109

110-
#endif // MICROPY_ENABLE_REPL_HELPERS
110+
#endif // MICROPY_HELPER_REPL

py/repl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#if MICROPY_ENABLE_REPL_HELPERS
27+
#if MICROPY_HELPER_REPL
2828
bool mp_repl_continue_with_input(const char *input);
2929
#endif

0 commit comments

Comments
 (0)
0