diff --git a/py/builtinimport.c b/py/builtinimport.c index a8f6a81741253b829daa04ea8ba09301043437ee..fd804ee3563105a981d3ab1b0cfab1ede4016818 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -323,7 +323,7 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, const mp_obj_t *args) { vstr_add_str(&path, "__init__.py"); if (mp_import_stat(vstr_str(&path)) != MP_IMPORT_STAT_FILE) { vstr_cut_tail_bytes(&path, sizeof("/__init__.py") - 1); // cut off /__init__.py - printf("Notice: %s is imported as namespace package\n", vstr_str(&path)); + mp_warning("%s is imported as namespace package", vstr_str(&path)); } else { do_load(module_obj, &path); vstr_cut_tail_bytes(&path, sizeof("/__init__.py") - 1); // cut off /__init__.py diff --git a/py/emit.h b/py/emit.h index 927e33ea73f157cc5776a57d44390aa1f9d31d82..f039770a5c68b5795da4ae08e062209170b28c78 100644 --- a/py/emit.h +++ b/py/emit.h @@ -204,4 +204,10 @@ extern const emit_inline_asm_method_table_t emit_inline_thumb_method_table; emit_inline_asm_t *emit_inline_thumb_new(mp_uint_t max_num_labels); void emit_inline_thumb_free(emit_inline_asm_t *emit); +#if MICROPY_WARNINGS +void mp_emitter_warning(pass_kind_t pass, const char *msg); +#else +#define mp_emitter_warning(pass, msg) +#endif + #endif // __MICROPY_INCLUDED_PY_EMIT_H__ diff --git a/py/emitnative.c b/py/emitnative.c index c2fe951be879e9014ead3c21c4b54f76aa10287a..556a977a06c43a4c1826af5376720bae6725094a 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -1636,6 +1636,7 @@ STATIC void emit_native_store_subscr(emit_t *emit) { STATIC void emit_native_delete_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { // TODO implement me! // could support for Python types, just set to None (so GC can reclaim it) + mp_emitter_warning(emit->pass, "Native codegeneration doesn't support deleting local"); } STATIC void emit_native_delete_deref(emit_t *emit, qstr qst, mp_uint_t local_num) { diff --git a/py/mpconfig.h b/py/mpconfig.h index b193051c51d3ee617bd77250a381058abfdf3d7e..bbc791c0b7e9f8b9a308e09ec6ff7ae403bb929f 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -251,6 +251,11 @@ typedef long long mp_longint_impl_t; #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL) #endif +// Whether issue warnings during compiling/execution +#ifndef MICROPY_WARNINGS +#define MICROPY_WARNINGS (0) +#endif + // Float and complex implementation #define MICROPY_FLOAT_IMPL_NONE (0) #define MICROPY_FLOAT_IMPL_FLOAT (1) diff --git a/py/py.mk b/py/py.mk index f54c06cbcfc949109aa1735d7934c4ba3fa588d8..4c4094eb66dc54c07f1bb919db7b2e9530e703f8 100644 --- a/py/py.mk +++ b/py/py.mk @@ -51,6 +51,7 @@ PY_O_BASENAME = \ nativeglue.o \ stackctrl.o \ argcheck.o \ + warning.o \ map.o \ obj.o \ objarray.o \ diff --git a/py/runtime.h b/py/runtime.h index 59d61e708daf9061e922476497da251ac9361d60..711b15f0da2a5de59af59d465287da1c8c54d466 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -126,4 +126,10 @@ extern struct _mp_obj_list_t mp_sys_argv_obj; #define mp_sys_path ((mp_obj_t)&mp_sys_path_obj) #define mp_sys_argv ((mp_obj_t)&mp_sys_argv_obj) +#if MICROPY_WARNINGS +void mp_warning(const char *msg, ...); +#else +#define mp_warning(msg, ...) +#endif + #endif // __MICROPY_INCLUDED_PY_RUNTIME_H__ diff --git a/py/warning.c b/py/warning.c new file mode 100644 index 0000000000000000000000000000000000000000..c7461c0f54d496d1a3481f38a6a80d252b48934f --- /dev/null +++ b/py/warning.c @@ -0,0 +1,54 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2014 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include <stdint.h> +#include <stdarg.h> +#include <stdio.h> + +#include "mpconfig.h" +#include "misc.h" +#include "qstr.h" +#include "obj.h" +#include "compile.h" +#include "scope.h" +#include "emit.h" + +#if MICROPY_WARNINGS + +void mp_warning(const char *msg, ...) { + va_list args; + va_start(args, msg); + printf("Warning: "); + vprintf(msg, args); + printf("\n"); +} + +void mp_emitter_warning(pass_kind_t pass, const char *msg) { + if (pass == MP_PASS_CODE_SIZE) { + mp_warning(msg, NULL); + } +} + +#endif // MICROPY_WARNINGS diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index a895aeab0c1e399abfa4e68459a2d45f863efdd2..fc2a18278f38ec4891c6c79a75c8e6d1ad18ab50 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -74,6 +74,7 @@ // Define to MICROPY_ERROR_REPORTING_DETAILED to get function, etc. // names in exception messages (may require more RAM). #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED) +#define MICROPY_WARNINGS (1) // Define to 1 to use undertested inefficient GC helper implementation // (if more efficient arch-specific one is not available).