py: Move constant folding from compiler to parser.

It makes much more sense to do constant folding in the parser while the
parse tree is being built.  This eliminates the need to create parse
nodes that will just be folded away.  The code is slightly simpler and a
bit smaller as well.

Constant folding now has a configuration option,
MICROPY_COMP_CONST_FOLDING, which is enabled by default.
This commit is contained in:
Damien George
2015-10-08 14:58:15 +01:00
parent 91fc075a33
commit 64f2b213bb
3 changed files with 286 additions and 264 deletions

View File

@@ -215,6 +215,11 @@
/*****************************************************************************/
/* Compiler configuration */
// Whether to enable constant folding; eg 1+2 rewritten as 3
#ifndef MICROPY_COMP_CONST_FOLDING
#define MICROPY_COMP_CONST_FOLDING (1)
#endif
// Whether to enable lookup of constants in modules; eg module.CONST
#ifndef MICROPY_COMP_MODULE_CONST
#define MICROPY_COMP_MODULE_CONST (0)