File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,10 +34,11 @@ def conway_go(num_frames):
3434 for i in range (num_frames ):
3535 conway_step () # do 1 iteration
3636 lcd .show () # update the LCD
37+ pyb .delay (300 )
3738
3839# PC testing
3940import lcd
4041import pyb
4142lcd = lcd .LCD (128 , 32 )
4243conway_rand ()
43- conway_go (100 )
44+ conway_go (1000 )
Original file line number Diff line number Diff line change 1+ try :
2+ import micropython
3+ except :
4+ pass
5+
6+
17def mandelbrot ():
28 # returns True if c, complex, is in the Mandelbrot set
39 @micropython .native
Original file line number Diff line number Diff line change 1+ # micropython module placeholder for CPython
2+
3+ # Dummy function decorators
4+
5+ def nodecor (x ):
6+ return x
7+
8+ byte_code = native = viper = nodecor
Original file line number Diff line number Diff line change 1- # pyboard testing functions for PC
1+ # pyboard testing functions for CPython
2+ import time
3+
24
35def delay (n ):
4- pass
6+ time . sleep ( float ( n ) / 1000 )
57
68rand_seed = 1
79def rand ():
Original file line number Diff line number Diff line change @@ -85,6 +85,14 @@ typedef long long mp_longint_impl_t;
8585#define MICROPY_ENABLE_SLICE (1)
8686#endif
8787
88+ // Enable features which improve CPython compatibility
89+ // but may lead to more code size/memory usage.
90+ // TODO: Originally intended as generic category to not
91+ // add bunch of once-off options. May need refactoring later
92+ #ifndef MICROPY_CPYTHON_COMPAT
93+ #define MICROPY_CPYTHON_COMPAT (1)
94+ #endif
95+
8896/*****************************************************************************/
8997/* Miscellaneous settings */
9098
Original file line number Diff line number Diff line change @@ -143,6 +143,13 @@ void rt_init(void) {
143143 mp_map_add_qstr (& map_builtins , MP_QSTR_sum , (mp_obj_t )& mp_builtin_sum_obj );
144144 mp_map_add_qstr (& map_builtins , MP_QSTR_str , (mp_obj_t )& mp_builtin_str_obj );
145145
146+ #if MICROPY_CPYTHON_COMPAT
147+ // Add (empty) micropython module, so it was possible to "import micropython",
148+ // which can be a placeholder module on CPython.
149+ mp_obj_t m = mp_obj_new_module (qstr_from_str_static ("micropython" ));
150+ rt_store_name (qstr_from_str_static ("micropython" ), m );
151+ #endif
152+
146153 next_unique_code_id = 1 ; // 0 indicates "no code"
147154 unique_codes_alloc = 0 ;
148155 unique_codes = NULL ;
You can’t perform that action at this time.
0 commit comments