Skip to content

Commit

Permalink
Tidy up some configuration options.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dpgeorge committed May 21, 2014
1 parent aa7cf6f commit 58ebde4
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 93 deletions.
8 changes: 4 additions & 4 deletions bare-arm/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

// options to control how Micro Python is built

#define MICROPY_ALLOC_PATH_MAX (512)
#define MICROPY_EMIT_X64 (0)
#define MICROPY_EMIT_THUMB (0)
#define MICROPY_EMIT_INLINE_THUMB (0)
#define MICROPY_MEM_STATS (0)
#define MICROPY_DEBUG_PRINTERS (0)
#define MICROPY_ENABLE_GC (0)
#define MICROPY_ENABLE_REPL_HELPERS (0)
#define MICROPY_ENABLE_LEXER_UNIX (0)
#define MICROPY_HELPER_REPL (0)
#define MICROPY_HELPER_LEXER_UNIX (0)
#define MICROPY_ENABLE_SOURCE_LINE (0)
#define MICROPY_ENABLE_MOD_COLLECTIONS (0)
#define MICROPY_ENABLE_MOD_MATH (0)
Expand All @@ -21,7 +22,6 @@
#define MICROPY_CPYTHON_COMPAT (0)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
#define MICROPY_PATH_MAX (512)

// type definitions for the specific machine

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

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

2 changes: 1 addition & 1 deletion py/builtinimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
DEBUG_printf("Module not yet loaded\n");

uint last = 0;
VSTR_FIXED(path, MICROPY_PATH_MAX)
VSTR_FIXED(path, MICROPY_ALLOC_PATH_MAX)
module_obj = MP_OBJ_NULL;
mp_obj_t top_module_obj = MP_OBJ_NULL;
mp_obj_t outer_module_obj = MP_OBJ_NULL;
Expand Down
4 changes: 2 additions & 2 deletions py/builtintables.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ STATIC const mp_map_elem_t mp_builtin_object_table[] = {
// TODO: For MICROPY_CPYTHON_COMPAT==0 use ValueError to avoid exc proliferation

// Extra builtins as defined by a port
MICROPY_EXTRA_BUILTINS
MICROPY_PORT_BUILTINS
};

const mp_obj_dict_t mp_builtin_object_dict_obj = {
Expand Down Expand Up @@ -183,7 +183,7 @@ STATIC const mp_map_elem_t mp_builtin_module_table[] = {
#endif

// extra builtin modules as defined by a port
MICROPY_EXTRA_BUILTIN_MODULES
MICROPY_PORT_BUILTIN_MODULES
};

const mp_obj_dict_t mp_builtin_module_dict_obj = {
Expand Down
6 changes: 3 additions & 3 deletions py/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, const cha

STATIC const mp_map_elem_t mp_constants_table[] = {
// Extra constants as defined by a port
MICROPY_EXTRA_CONSTANTS
MICROPY_PORT_CONSTANTS
};

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

// fold some parse nodes before folding their arguments
switch (MP_PARSE_NODE_STRUCT_KIND(pns)) {
#if MICROPY_ENABLE_CONST
#if MICROPY_COMP_CONST
case PN_expr_stmt:
if (!MP_PARSE_NODE_IS_NULL(pns->nodes[1])) {
mp_parse_node_struct_t *pns1 = (mp_parse_node_struct_t*)pns->nodes[1];
Expand Down
6 changes: 3 additions & 3 deletions py/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ STATIC void next_char(mp_lexer_t *lex) {
void indent_push(mp_lexer_t *lex, uint indent) {
if (lex->num_indent_level >= lex->alloc_indent_level) {
// TODO use m_renew_maybe and somehow indicate an error if it fails... probably by using MP_TOKEN_MEMORY_ERROR
lex->indent_level = m_renew(uint16_t, lex->indent_level, lex->alloc_indent_level, lex->alloc_indent_level + MP_ALLOC_LEXEL_INDENT_INC);
lex->alloc_indent_level += MP_ALLOC_LEXEL_INDENT_INC;
lex->indent_level = m_renew(uint16_t, lex->indent_level, lex->alloc_indent_level, lex->alloc_indent_level + MICROPY_ALLOC_LEXEL_INDENT_INC);
lex->alloc_indent_level += MICROPY_ALLOC_LEXEL_INDENT_INC;
}
lex->indent_level[lex->num_indent_level++] = indent;
}
Expand Down Expand Up @@ -731,7 +731,7 @@ mp_lexer_t *mp_lexer_new(qstr src_name, void *stream_data, mp_lexer_stream_next_
lex->column = 1;
lex->emit_dent = 0;
lex->nested_bracket_level = 0;
lex->alloc_indent_level = MP_ALLOC_LEXER_INDENT_INIT;
lex->alloc_indent_level = MICROPY_ALLOC_LEXER_INDENT_INIT;
lex->num_indent_level = 1;
lex->indent_level = m_new_maybe(uint16_t, lex->alloc_indent_level);
vstr_init(&lex->vstr, 32);
Expand Down
4 changes: 2 additions & 2 deletions py/lexerunix.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "misc.h"
#include "mpconfig.h"

#if MICROPY_ENABLE_LEXER_UNIX
#if MICROPY_HELPER_LEXER_UNIX

#include <stdio.h>
#include <unistd.h>
Expand Down Expand Up @@ -81,4 +81,4 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
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);
}

#endif // MICROPY_ENABLE_LEXER_UNIX
#endif // MICROPY_HELPER_LEXER_UNIX
84 changes: 45 additions & 39 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,49 @@
/* Memory allocation policy */

// Initial amount for lexer indentation level
#ifndef MP_ALLOC_LEXER_INDENT_INIT
#define MP_ALLOC_LEXER_INDENT_INIT (10)
#ifndef MICROPY_ALLOC_LEXER_INDENT_INIT
#define MICROPY_ALLOC_LEXER_INDENT_INIT (10)
#endif

// Increment for lexer indentation level
#ifndef MP_ALLOC_LEXEL_INDENT_INC
#define MP_ALLOC_LEXEL_INDENT_INC (8)
#ifndef MICROPY_ALLOC_LEXEL_INDENT_INC
#define MICROPY_ALLOC_LEXEL_INDENT_INC (8)
#endif

// Initial amount for parse rule stack
#ifndef MP_ALLOC_PARSE_RULE_INIT
#define MP_ALLOC_PARSE_RULE_INIT (64)
#ifndef MICROPY_ALLOC_PARSE_RULE_INIT
#define MICROPY_ALLOC_PARSE_RULE_INIT (64)
#endif

// Increment for parse rule stack
#ifndef MP_ALLOC_PARSE_RULE_INC
#define MP_ALLOC_PARSE_RULE_INC (16)
#ifndef MICROPY_ALLOC_PARSE_RULE_INC
#define MICROPY_ALLOC_PARSE_RULE_INC (16)
#endif

// Initial amount for parse result stack
#ifndef MP_ALLOC_PARSE_RESULT_INIT
#define MP_ALLOC_PARSE_RESULT_INIT (32)
#ifndef MICROPY_ALLOC_PARSE_RESULT_INIT
#define MICROPY_ALLOC_PARSE_RESULT_INIT (32)
#endif

// Increment for parse result stack
#ifndef MP_ALLOC_PARSE_RESULT_INC
#define MP_ALLOC_PARSE_RESULT_INC (16)
#ifndef MICROPY_ALLOC_PARSE_RESULT_INC
#define MICROPY_ALLOC_PARSE_RESULT_INC (16)
#endif

// Initial amount for ids in a scope
#ifndef MP_ALLOC_SCOPE_ID_INIT
#define MP_ALLOC_SCOPE_ID_INIT (4)
#ifndef MICROPY_ALLOC_SCOPE_ID_INIT
#define MICROPY_ALLOC_SCOPE_ID_INIT (4)
#endif

// Increment for ids in a scope
#ifndef MP_ALLOC_SCOPE_ID_INC
#define MP_ALLOC_SCOPE_ID_INC (6)
#ifndef MICROPY_ALLOC_SCOPE_ID_INC
#define MICROPY_ALLOC_SCOPE_ID_INC (6)
#endif

// Maximum length of a path in the filesystem
// So we can allocate a buffer on the stack for path manipulation in import
#ifndef MICROPY_ALLOC_PATH_MAX
#define MICROPY_ALLOC_PATH_MAX (512)
#endif

/*****************************************************************************/
Expand All @@ -100,6 +106,14 @@
#define MICROPY_EMIT_INLINE_THUMB (0)
#endif

/*****************************************************************************/
/* Compiler configuration */

// Whether to enable constant optimisation; id = const(value)
#ifndef MICROPY_COMP_CONST
#define MICROPY_COMP_CONST (1)
#endif

/*****************************************************************************/
/* Internal debugging stuff */

Expand All @@ -119,11 +133,6 @@
/*****************************************************************************/
/* Fine control over Python features */

// Whether to enable constant optimisation; id = const(value)
#ifndef MICROPY_ENABLE_CONST
#define MICROPY_ENABLE_CONST (1)
#endif

// Whether to include the garbage collector
#ifndef MICROPY_ENABLE_GC
#define MICROPY_ENABLE_GC (0)
Expand All @@ -135,13 +144,13 @@
#endif

// Whether to include REPL helper function
#ifndef MICROPY_ENABLE_REPL_HELPERS
#define MICROPY_ENABLE_REPL_HELPERS (0)
#ifndef MICROPY_HELPER_REPL
#define MICROPY_HELPER_REPL (0)
#endif

// Whether to include lexer helper function for unix
#ifndef MICROPY_ENABLE_LEXER_UNIX
#define MICROPY_ENABLE_LEXER_UNIX (0)
#ifndef MICROPY_HELPER_LEXER_UNIX
#define MICROPY_HELPER_LEXER_UNIX (0)
#endif

// Long int implementation
Expand Down Expand Up @@ -277,36 +286,33 @@ typedef double mp_float_t;
#define MICROPY_CPYTHON_COMPAT (1)
#endif

// Maximum length of a path in the filesystem
// So we can allocate a buffer on the stack for path manipulation in import
#ifndef MICROPY_PATH_MAX
#define MICROPY_PATH_MAX (512)
#endif

// Whether POSIX-semantics non-blocking streams are supported
#ifndef MICROPY_STREAMS_NON_BLOCK
#define MICROPY_STREAMS_NON_BLOCK (0)
#endif

// Whether to use computed gotos in the VM, or a switch
// Computed gotos are roughly 10% faster, and increase VM code size by a little
#ifndef MICROPY_USE_COMPUTED_GOTO
#define MICROPY_USE_COMPUTED_GOTO (0)
#ifndef MICROPY_OPT_COMPUTED_GOTO
#define MICROPY_OPT_COMPUTED_GOTO (0)
#endif

/*****************************************************************************/
/* Hooks for a port to add builtins */

// Additional builtin function definitions - see builtintables.c:builtin_object_table for format.
#ifndef MICROPY_EXTRA_BUILTINS
#define MICROPY_EXTRA_BUILTINS
#ifndef MICROPY_PORT_BUILTINS
#define MICROPY_PORT_BUILTINS
#endif

// Additional builtin module definitions - see builtintables.c:builtin_module_table for format.
#ifndef MICROPY_EXTRA_BUILTIN_MODULES
#define MICROPY_EXTRA_BUILTIN_MODULES
#ifndef MICROPY_PORT_BUILTIN_MODULES
#define MICROPY_PORT_BUILTIN_MODULES
#endif

// Additional constant definitions for the compiler - see compile.c:mp_constants_table.
#ifndef MICROPY_EXTRA_CONSTANTS
#define MICROPY_EXTRA_CONSTANTS
#ifndef MICROPY_PORT_CONSTANTS
#define MICROPY_PORT_CONSTANTS
#endif

/*****************************************************************************/
Expand Down
12 changes: 6 additions & 6 deletions py/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ STATIC void push_rule(parser_t *parser, int src_line, const rule_t *rule, int ar
return;
}
if (parser->rule_stack_top >= parser->rule_stack_alloc) {
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);
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);
if (rs == NULL) {
memory_error(parser);
return;
}
parser->rule_stack = rs;
parser->rule_stack_alloc += MP_ALLOC_PARSE_RULE_INC;
parser->rule_stack_alloc += MICROPY_ALLOC_PARSE_RULE_INC;
}
rule_stack_t *rs = &parser->rule_stack[parser->rule_stack_top++];
rs->src_line = src_line;
Expand Down Expand Up @@ -263,13 +263,13 @@ STATIC void push_result_node(parser_t *parser, mp_parse_node_t pn) {
return;
}
if (parser->result_stack_top >= parser->result_stack_alloc) {
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);
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);
if (pn == NULL) {
memory_error(parser);
return;
}
parser->result_stack = pn;
parser->result_stack_alloc += MP_ALLOC_PARSE_RESULT_INC;
parser->result_stack_alloc += MICROPY_ALLOC_PARSE_RESULT_INC;
}
parser->result_stack[parser->result_stack_top++] = pn;
}
Expand Down Expand Up @@ -350,11 +350,11 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, mp_p

parser.had_memory_error = false;

parser.rule_stack_alloc = MP_ALLOC_PARSE_RULE_INIT;
parser.rule_stack_alloc = MICROPY_ALLOC_PARSE_RULE_INIT;
parser.rule_stack_top = 0;
parser.rule_stack = m_new_maybe(rule_stack_t, parser.rule_stack_alloc);

parser.result_stack_alloc = MP_ALLOC_PARSE_RESULT_INIT;
parser.result_stack_alloc = MICROPY_ALLOC_PARSE_RESULT_INIT;
parser.result_stack_top = 0;
parser.result_stack = m_new_maybe(mp_parse_node_t, parser.result_stack_alloc);

Expand Down
4 changes: 2 additions & 2 deletions py/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "mpconfig.h"
#include "repl.h"

#if MICROPY_ENABLE_REPL_HELPERS
#if MICROPY_HELPER_REPL

bool str_startswith_word(const char *str, const char *head) {
int i;
Expand Down Expand Up @@ -107,4 +107,4 @@ bool mp_repl_continue_with_input(const char *input) {
return false;
}

#endif // MICROPY_ENABLE_REPL_HELPERS
#endif // MICROPY_HELPER_REPL
2 changes: 1 addition & 1 deletion py/repl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
* THE SOFTWARE.
*/

#if MICROPY_ENABLE_REPL_HELPERS
#if MICROPY_HELPER_REPL
bool mp_repl_continue_with_input(const char *input);
#endif
6 changes: 3 additions & 3 deletions py/scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, qstr source_file, uint
}
scope->raw_code = mp_emit_glue_new_raw_code();
scope->emit_options = emit_options;
scope->id_info_alloc = MP_ALLOC_SCOPE_ID_INIT;
scope->id_info_alloc = MICROPY_ALLOC_SCOPE_ID_INIT;
scope->id_info = m_new(id_info_t, scope->id_info_alloc);

return scope;
Expand All @@ -92,8 +92,8 @@ id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added) {

// make sure we have enough memory
if (scope->id_info_len >= scope->id_info_alloc) {
scope->id_info = m_renew(id_info_t, scope->id_info, scope->id_info_alloc, scope->id_info_alloc + MP_ALLOC_SCOPE_ID_INC);
scope->id_info_alloc += MP_ALLOC_SCOPE_ID_INC;
scope->id_info = m_renew(id_info_t, scope->id_info, scope->id_info_alloc, scope->id_info_alloc + MICROPY_ALLOC_SCOPE_ID_INC);
scope->id_info_alloc += MICROPY_ALLOC_SCOPE_ID_INC;
}

// add new id to end of array of all ids; this seems to match CPython
Expand Down
6 changes: 3 additions & 3 deletions py/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ mp_vm_return_kind_t mp_execute_bytecode2(const byte *code_info, const byte **ip_
mp_obj_t *fastn, mp_obj_t **sp_in_out,
mp_exc_stack_t *exc_stack, mp_exc_stack_t **exc_sp_in_out,
volatile mp_obj_t inject_exc) {
#if MICROPY_USE_COMPUTED_GOTO
#if MICROPY_OPT_COMPUTED_GOTO
#include "vmentrytable.h"
#define DISPATCH() do { \
TRACE(ip); \
Expand Down Expand Up @@ -276,7 +276,7 @@ mp_vm_return_kind_t mp_execute_bytecode2(const byte *code_info, const byte **ip_
// loop to execute byte code
for (;;) {
dispatch_loop:
#if MICROPY_USE_COMPUTED_GOTO
#if MICROPY_OPT_COMPUTED_GOTO
DISPATCH();
#else
TRACE(ip);
Expand Down Expand Up @@ -982,7 +982,7 @@ mp_vm_return_kind_t mp_execute_bytecode2(const byte *code_info, const byte **ip_
fastn[0] = obj1;
return MP_VM_RETURN_EXCEPTION;

#if !MICROPY_USE_COMPUTED_GOTO
#if !MICROPY_OPT_COMPUTED_GOTO
} // switch
#endif
} // for loop
Expand Down
Loading

0 comments on commit 58ebde4

Please sign in to comment.