├── tests ├── io │ ├── data │ │ ├── file2 │ │ └── file1 │ ├── argv.py │ ├── file_iter.py │ ├── buffered_writer.py.exp │ ├── file_long_read.py │ ├── file_stdio.py │ ├── file_long_read2.py │ ├── write_ext.py.exp │ ├── file_long_read3.py │ ├── file_readinto_len.py.exp │ ├── stringio_with.py │ ├── file_readinto_len.py │ ├── file_readline.py │ ├── file_readinto.py │ └── bytesio_ext.py ├── import │ ├── pkg │ │ ├── __init__.py │ │ └── mod.py │ ├── pkg6 │ │ ├── x │ │ │ ├── y.py │ │ │ └── __init__.py │ │ └── __init__.py │ ├── pkg2 │ │ ├── mod2.py │ │ ├── mod1.py │ │ └── __init__.py │ ├── gen_context2.py │ ├── import1a.py │ ├── import3a.py │ ├── pkg3 │ │ ├── __init__.py │ │ ├── subpkg1 │ │ │ ├── __init__.py │ │ │ └── mod1.py │ │ ├── mod1.py │ │ └── mod2.py │ ├── import_file.py │ ├── import1b.py │ ├── import_pkg6.py │ ├── import2a.py │ ├── import_pkg3.py │ ├── import_pkg4.py │ ├── rel_import_inv.py │ ├── import_pkg5.py │ ├── gen_context.py │ ├── try_module.py │ └── import_pkg1.py ├── pyb │ ├── dac.py.exp │ ├── switch.py.exp │ ├── accel.py.exp │ ├── modstm.py.exp │ ├── irq.py.exp │ ├── extint.py.exp │ ├── timer.py.exp │ ├── halerror.py.exp │ ├── led.py.exp │ ├── adc.py.exp │ ├── i2c_error.py.exp │ ├── servo.py.exp │ ├── pyb1.py.exp │ ├── timer_callback.py.exp │ ├── switch.py │ ├── accel.py │ ├── i2c.py.exp │ ├── dac.py │ ├── pin.py.exp │ ├── spi.py.exp │ ├── halerror.py │ ├── timer.py │ ├── servo.py │ ├── modstm.py │ └── extint.py ├── extmod │ ├── ticks_diff.py.exp │ ├── uctypes_sizeof_native.py.exp │ ├── time_ms_us.py.exp │ ├── ujson_dumps_extra.py.exp │ ├── uctypes_native_float.py.exp │ ├── uctypes_le_float.py.exp │ ├── uctypes_sizeof.py.exp │ ├── uctypes_bytearray.py.exp │ ├── vfs_fat_oldproto.py.exp │ ├── ure_split_empty.py.exp │ ├── machine1.py.exp │ ├── uctypes_ptr_le.py.exp │ ├── uctypes_ptr_native_le.py.exp │ ├── uctypes_array_assign_native_le.py.exp │ ├── uctypes_array_assign_le.py.exp │ ├── ujson_dumps_extra.py │ ├── ujson_dumps_float.py │ ├── machine_pinbase.py.exp │ ├── uzlib_decompio_gz.py.exp │ ├── vfs_fat_fsusermount.py.exp │ ├── machine_pulse.py.exp │ ├── uctypes_le.py.exp │ ├── uctypes_native_le.py.exp │ ├── uzlib_decompio.py.exp │ ├── ujson_loads_float.py │ ├── ubinascii_unhexlify.py │ ├── time_ms_us.py │ ├── ubinascii_hexlify.py │ ├── ujson_load.py │ ├── uctypes_native_float.py │ ├── vfs_fat_fileio.py.exp │ ├── ure_error.py │ ├── uctypes_bytearray.py │ └── uctypes_le_float.py ├── feature_check │ ├── byteorder.py.exp │ ├── complex.py.exp │ ├── native_check.py.exp │ ├── byteorder.py │ ├── repl_emacs_check.py │ ├── complex.py │ ├── native_check.py │ ├── repl_emacs_check.py.exp │ └── README ├── pyboard.py ├── cmdline │ ├── cmd_optimise.py.exp │ ├── repl_basic.py │ ├── cmd_verbose.py │ ├── cmd_optimise.py │ ├── repl_basic.py.exp │ ├── repl_emacs_keys.py │ ├── repl_emacs_keys.py.exp │ └── repl_cont.py ├── inlineasm │ ├── asmblbx.py.exp │ ├── asmfpaddsub.py.exp │ ├── asmfpldrstr.py.exp │ ├── asmfpmuldiv.py.exp │ ├── asmfpsqrt.py.exp │ ├── asmpushpop.py.exp │ ├── asmconst.py.exp │ ├── asmfpcmp.py.exp │ ├── asmit.py.exp │ ├── asmspecialregs.py.exp │ ├── asmbcc.py.exp │ ├── asmargs.py.exp │ ├── asmbitops.py.exp │ ├── asmdiv.py.exp │ ├── asmshift.py.exp │ ├── asmsum.py.exp │ ├── asmrettype.py.exp │ ├── asmpushpop.py │ ├── asmconst.py │ ├── asmspecialregs.py │ ├── asmbitops.py │ ├── asmfpldrstr.py │ ├── asmfpcmp.py │ ├── asmit.py │ ├── asmblbx.py │ ├── asmfpsqrt.py │ ├── asmdiv.py │ ├── asmfpaddsub.py │ └── asmfpmuldiv.py ├── unicode │ ├── data │ │ ├── utf-8_1.txt │ │ └── utf-8_2.txt │ ├── unicode_ord.py │ ├── unicode_iter.py │ ├── unicode_str_modulo.py │ ├── file1.py │ ├── unicode_chr.py │ ├── unicode_str_format.py │ ├── unicode_index.py │ ├── unicode_pos.py │ └── unicode_subscr.py ├── wipy │ ├── reset │ │ ├── reset.py.exp │ │ └── reset.py │ ├── modwipy.py.exp │ ├── sd.py.exp │ ├── wdt.py.exp │ ├── wlan │ │ ├── machine.py.exp │ │ └── server.py.exp │ ├── skipped │ │ └── rtc_irq.py.exp │ ├── pin_irq.py.exp │ └── uart_irq.py.exp ├── basics │ ├── module2.py.exp │ ├── class_emptybases.py │ ├── memoryerror.py.exp │ ├── set_union.py │ ├── async_def.py.exp │ ├── errno1.py.exp │ ├── bytearray_longint.py │ ├── zip.py │ ├── bytes_compare3.py.exp │ ├── fun1.py │ ├── set_add.py │ ├── set_clear.py │ ├── set_discard.py │ ├── lambda1.py │ ├── set_iter.py │ ├── generator2.py │ ├── list_clear.py │ ├── bytes_format_modulo.py.exp │ ├── dict_get.py │ ├── exception_chain.py.exp │ ├── fun_str.py │ ├── list_sum.py │ ├── 0prelim.py │ ├── compare_multi.py │ ├── list_reverse.py │ ├── dict_clear.py │ ├── filter.py │ ├── fun_annotations.py │ ├── bytes_add_endian.py │ ├── async_for.py.exp │ ├── dict_iterator.py │ ├── set_copy.py │ ├── object1.py │ ├── tuple_count.py │ ├── builtin_ellipsis.py │ ├── async_with.py.exp │ ├── dict_copy.py │ ├── list_copy.py │ ├── set_specialmeth.py │ ├── exec1.py │ ├── int_big_pow.py │ ├── int_big_unary.py │ ├── for_return.py │ ├── iter0.py │ ├── list_count.py │ ├── python34.py.exp │ ├── set_update.py │ ├── bytes_gen.py │ ├── string_cr_conversion.py │ ├── string_upperlow.py │ ├── andor.py │ ├── assign1.py │ ├── async_await2.py.exp │ ├── builtin_eval_error.py │ ├── int2.py │ ├── int_big_rshift.py │ ├── memoryerror.py │ ├── builtin_round.py │ ├── dict_specialmeth.py │ ├── fun2.py │ ├── module2.py │ ├── array_construct2.py │ ├── fun3.py │ ├── string_crlf_conversion.py │ ├── list_insert.py │ ├── set_isfooset.py │ ├── set_pop.py │ ├── int_big_cmp.py │ ├── slice_bignum.py │ ├── try1.py │ ├── array_construct_endian.py │ ├── bytes_format_modulo.py │ ├── closure_namedarg.py │ ├── set_isdisjoint.py │ ├── builtin_chr.py │ ├── for2.py │ ├── map.py │ ├── generator_return.py │ ├── bytes_construct_endian.py │ ├── int_divzero.py │ ├── set_intersection.py │ ├── subclass_native4.py │ ├── dict_fromkeys.py │ ├── string_repr.py │ ├── exception_chain.py │ ├── return1.py │ ├── set_symmetric_difference.py │ ├── bytearray_construct_endian.py │ ├── iter_of_iter.py │ ├── closure_defargs.py │ ├── string_escape.py │ ├── builtin_eval.py │ ├── builtin_len1.py │ ├── list_remove.py │ ├── builtin_pow.py │ ├── builtin_slice.py │ ├── builtin_type.py │ ├── closure_manyvars.py │ ├── subclass_native_cmp.py │ ├── class_use_other.py │ ├── getattr.py │ ├── try_as_var.py │ ├── async_await.py.exp │ ├── break.py │ ├── builtin_sum.py │ ├── class_instance_override.py │ ├── subclass_native5.py │ ├── set_unop.py │ ├── while1.py │ ├── frozenset_copy.py │ ├── array_add.py │ ├── gen_yield_from_iter.py │ ├── builtin_bin.py │ ├── builtin_hex.py │ ├── builtin_oct.py │ ├── dict_setdefault.py │ ├── bytes_add.py │ ├── lambda_defargs.py │ ├── builtin_sorted.py │ ├── class_store.py │ ├── while_nest_exc.py │ ├── builtin_id.py │ ├── del_subscr.py │ ├── dict_construct.py │ ├── object_dict.py │ ├── types2.py │ ├── bytes_subscr.py │ ├── gen_yield_from_exc.py │ ├── set1.py │ ├── dict2.py │ ├── is_isnot.py │ ├── attrtuple1.py │ ├── closure1.py │ ├── dict_pop.py │ ├── gen_yield_from_send.py │ ├── module1.py │ ├── try_error.py │ ├── string_mult.py │ ├── try3.py │ ├── async_def.py │ ├── bytes_mult.py │ ├── for3.py │ ├── builtin_override.py │ ├── bytearray_append.py │ ├── dict_update.py │ ├── string_center.py │ ├── builtin_delattr.py │ ├── del_name.py │ ├── setattr1.py │ ├── try_continue.py │ ├── bool1.py │ ├── builtin_dir.py │ ├── closure2.py │ ├── with_break.py │ ├── async_with2.py.exp │ ├── builtin_issubclass.py │ ├── class_call.py │ ├── continue.py │ ├── with_continue.py │ ├── dict_from_iter.py │ ├── fun_name.py │ ├── bytearray_construct.py │ ├── dict_popitem.py │ ├── int_bytes.py │ ├── unboundlocal.py │ ├── class_number.py │ ├── exception1.py │ ├── fun_defargs2.py │ ├── builtin_allany.py │ ├── class_super_object.py │ ├── frozenset_add.py │ ├── bytes_compare2.py │ ├── frozenset1.py │ ├── array_q.py │ ├── bytearray_add.py │ ├── dict_intern.py │ ├── ordereddict_eq.py.exp │ ├── slots_bool_len.py │ ├── decorator.py │ ├── print.py │ ├── try_reraise.py │ ├── subclass_native_specmeth.py │ ├── async_await.py │ ├── builtin_abs.py │ ├── enumerate.py │ ├── fun_calldblstar3.py │ ├── getattr1.py │ ├── fun_calldblstar.py │ ├── int_divmod.py │ ├── class_item.py │ ├── string_startswith.py │ ├── equal_class.py │ ├── gen_yield_from_stopped.py │ ├── subclass_native_buffer.py │ ├── list_mult.py │ ├── subclass_native2_tuple.py │ ├── class_super.py │ ├── except_match_tuple.py │ ├── list_pop.py │ ├── try4.py │ ├── tuple_mult.py │ ├── frozenset_set.py │ ├── gen_yield_from_throw.py │ ├── class_inherit1.py │ ├── fun_kwvarargs.py │ ├── ordereddict1.py │ ├── generator1.py │ ├── generator_args.py │ ├── memoryview_gc.py │ ├── class3.py │ ├── for1.py │ ├── string_endswith.py │ ├── del_deref.py │ ├── errno1.py │ └── int_big_div.py ├── jni │ ├── object.py.exp │ ├── system_out.py.exp │ ├── list.py.exp │ ├── system_out.py │ ├── list.py │ └── object.py ├── micropython │ ├── decorator.py.exp │ ├── emg_exc.py.exp │ ├── viper_import.py.exp │ ├── heap_lock.py.exp │ ├── native_closure.py.exp │ ├── memstats.py.exp │ ├── const_error.py.exp │ ├── opt_level.py.exp │ ├── decorator_error.py.exp │ ├── native_const.py.exp │ ├── viper_cond.py.exp │ ├── viper_subscr.py.exp │ ├── viper_args.py.exp │ ├── const.py.exp │ ├── native_misc.py.exp │ ├── viper_ptr8_load.py.exp │ ├── viper_ptr16_load.py.exp │ ├── const2.py.exp │ ├── heapalloc.py.exp │ ├── viper_ptr32_load.py.exp │ ├── viper_binop_comp_imm.py.exp │ ├── viper_binop_multi_comp.py.exp │ ├── decorator.py │ ├── native_const.py │ ├── viper_addr.py.exp │ ├── viper_ptr16_store.py.exp │ ├── viper_ptr8_store.py.exp │ ├── viper_ptr32_store.py.exp │ ├── viper_binop_comp.py.exp │ ├── viper_misc.py.exp │ ├── viper_binop_comp_imm.py │ ├── viper_import.py │ ├── heap_lock.py │ ├── decorator_error.py │ ├── meminfo.py │ ├── const_error.py │ ├── viper_binop_arith.py.exp │ ├── const.py │ ├── opt_level.py │ └── viper_subscr.py ├── misc │ ├── recursive_data.py.exp │ ├── recursive_iternext.py.exp │ ├── non_compliant_lexer.py.exp │ ├── recursion.py │ ├── recursive_data.py │ └── non_compliant.py.exp ├── pybnative │ ├── while.py.exp │ ├── for.py.exp │ ├── for.py │ └── while.py ├── unix │ ├── ffi_callback.py.exp │ ├── ffi_float2.py.exp │ ├── ffi_float.py.exp │ └── extra_coverage.py ├── float │ ├── int_divzero.py │ ├── list_index.py │ ├── int_power.py │ ├── true_value.py │ ├── bytes_construct.py │ ├── bytearray_construct.py │ ├── array_construct.py │ ├── types.py │ ├── float_array.py │ └── math_fun_bool.py ├── bench │ ├── loop_count-1-range.py │ ├── loop_count-4-while_down_gt.py │ ├── loop_count-5-while_down_ne.py │ ├── loop_count-2-range_iter.py │ ├── loop_count-3-while_up.py │ ├── var-1-constant.py │ ├── bytealloc-1-bytes_n.py │ ├── bytealloc-2-repeat.py │ ├── func_builtin-1-enum_pos.py │ ├── loop_count-5.1-while_down_ne_localvar.py │ ├── var-4-arg.py │ ├── bench.py │ ├── var-2-global.py │ ├── func_builtin-2-enum_kw.py │ ├── var-3-local.py │ ├── from_iter-1-list_bound.py │ ├── from_iter-3-tuple_bound.py │ ├── from_iter-5-bytes_bound.py │ ├── func_args-1.1-pos_1.py │ ├── func_args-3.1-kw_1.py │ ├── from_iter-7-bytearray_bound.py │ ├── func_args-1.2-pos_3.py │ ├── var-5-class-attr.py │ ├── from_iter-2-list_unbound.py │ ├── func_args-3.2-kw_3.py │ ├── from_iter-4-tuple_unbound.py │ ├── from_iter-6-bytes_unbound.py │ ├── func_args-2-pos_default_2_of_3.py │ ├── from_iter-8-bytearray_unbound.py │ ├── funcall-1-inline.py │ ├── var-6-instance-attr.py │ ├── var-8-namedtuple-1st.py │ ├── funcall-2-funcall.py │ ├── var-8.1-namedtuple-5th.py │ ├── bytebuf-3-bytarray_map.py │ ├── bytebuf-1-inplace.py │ ├── var-7-instance-meth.py │ ├── var-6.1-instance-attr-5.py │ ├── arrayop-1-list_inplace.py │ ├── arrayop-3-bytearray_inplace.py │ ├── arrayop-2-list_map.py │ ├── arrayop-4-bytearray_map.py │ └── bytebuf-2-join_map_bytes.py └── stress │ ├── dict_create.py │ ├── dict_copy.py │ └── list_sort.py ├── stmhal ├── .gitignore ├── memory.h ├── hal │ └── f4 │ │ ├── inc │ │ └── stm32f4xx_hal_def.h │ │ └── src │ │ └── stm32f4xx_hal_rcc_ex.c ├── boards │ ├── CERB40 │ │ └── mpconfigboard.mk │ ├── PYBV10 │ │ └── mpconfigboard.mk │ ├── PYBV11 │ │ └── mpconfigboard.mk │ ├── PYBV3 │ │ └── mpconfigboard.mk │ ├── PYBV4 │ │ └── mpconfigboard.mk │ ├── HYDRABUS │ │ └── mpconfigboard.mk │ ├── OLIMEX_E407 │ │ └── mpconfigboard.mk │ ├── PYBLITEV10 │ │ └── mpconfigboard.mk │ ├── STM32F439 │ │ └── mpconfigboard.mk │ ├── STM32F4DISC │ │ └── mpconfigboard.mk │ ├── STM32F7DISC │ │ └── mpconfigboard.mk │ ├── ESPRUINO_PICO │ │ └── mpconfigboard.mk │ ├── NETDUINO_PLUS_2 │ │ ├── mpconfigboard.mk │ │ └── pins.csv │ ├── NUCLEO_F401RE │ │ └── mpconfigboard.mk │ ├── NUCLEO_F411RE │ │ └── mpconfigboard.mk │ ├── STM32F411DISC │ │ └── mpconfigboard.mk │ ├── STM32F429DISC │ │ └── mpconfigboard.mk │ ├── LIMIFROG │ │ └── mpconfigboard.mk │ └── STM32L476DISC │ │ └── mpconfigboard.mk ├── mpconfigport.mk ├── usbd_hid_interface.h └── pybioctl.h ├── bare-arm ├── mphalport.h └── qstrdefsport.h ├── esp8266 ├── user_config.h ├── modules │ ├── upip.py │ ├── upip_utarfile.py │ └── _boot.py ├── espneopixel.h └── ets_alt_task.h ├── mpy-cross ├── .gitignore ├── mphalport.h └── qstrdefsport.h ├── docs ├── sphinx_selective_exclude │ └── __init__.py ├── pyboard │ └── tutorial │ │ ├── img │ │ ├── skin_amp_1.jpg │ │ ├── skin_amp_2.jpg │ │ ├── skin_lcd_1.jpg │ │ ├── skin_lcd_2.jpg │ │ ├── pyboard_servo.jpg │ │ ├── pyboard_usb_micro.jpg │ │ └── fading_leds_breadboard_fritzing.png │ │ └── power_ctrl.rst ├── esp8266 │ └── img │ │ └── adafruit_products_pinoutstop.jpg ├── unix_contents.rst ├── static │ └── customstyle.css ├── templates │ └── layout.html ├── wipy_contents.rst ├── esp8266_contents.rst ├── unix_index.rst ├── pyboard_contents.rst ├── esp8266_index.rst ├── readthedocs │ └── settings │ │ └── local_settings.py ├── wipy_index.rst ├── wipy │ └── tutorial │ │ └── index.rst ├── pyboard_index.rst └── library │ └── uzlib.rst ├── tools ├── .gitattributes ├── .gitignore └── gen-changelog.sh ├── unix ├── scripts │ ├── upip.py │ └── upip_utarfile.py ├── input.h ├── fatfs_port.c └── .gitignore ├── emscripten ├── .gitignore ├── frozentest.mpy ├── mphalport.h ├── qstrdefsport.h ├── frozentest.py ├── README.md └── stdio_core.c ├── examples ├── embedding │ ├── mpconfigport.h │ └── Makefile ├── SDdatalogger │ └── cardreader.py ├── hwapi │ ├── hwconfig_esp8266_esp12.py │ └── hwconfig_z_frdm_k64f.py ├── micropython.py └── unix │ └── machine_bios.py ├── minimal ├── qstrdefsport.h ├── frozentest.mpy ├── mphalport.h └── frozentest.py ├── pic16bit ├── qstrdefsport.h └── unistd.h ├── qemu-arm ├── qstrdefsport.h ├── memory.h └── mphalport.h ├── teensy ├── qstrdefsport.h ├── lexermemzip.h ├── core │ └── Arduino.h ├── servo.h ├── memzip_files │ ├── main.py │ └── boot.py ├── led.h ├── reg.h ├── lexerfrozen.c ├── lcd.c ├── usb.h └── lexerfatfs.c ├── logo ├── logo.jpg ├── 1bit-logo.png ├── trans-logo.png ├── vector-logo-2.png ├── vector-logo-3.png ├── upython-with-micro.jpg ├── upython-with-micro.png └── micropythonpowered-art.png ├── drivers ├── dht │ └── dht.h ├── cc3100 │ └── inc │ │ └── netapp.h ├── README.md ├── cc3000 │ └── inc │ │ ├── inet_pton.h │ │ ├── inet_ntop.h │ │ └── patch_prog.h └── wiznet5k │ └── README.md ├── zephyr ├── Kbuild ├── prj.conf ├── prj.mdef └── modmachine.h ├── windows ├── .gitignore └── mpconfigport.mk ├── cc3200 ├── bootmgr │ ├── relocator │ │ └── relocator.bin │ └── runapp.s └── boards │ ├── LAUNCHXL │ └── pins.csv │ └── WIPY │ └── pins.csv ├── lib ├── README.md ├── embed │ └── abort_.c ├── libm │ └── thumb_vfp_sqrtf.c └── memzip │ ├── import.c │ └── lexermemzip.c ├── extmod ├── modwebsocket.h └── lwip-include │ └── arch │ └── perf.h ├── CONTRIBUTING.md └── .gitmodules /tests/io/data/file2: -------------------------------------------------------------------------------- 1 | 1234 -------------------------------------------------------------------------------- /tests/import/pkg/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /stmhal/.gitignore: -------------------------------------------------------------------------------- 1 | build-*/ 2 | -------------------------------------------------------------------------------- /tests/pyb/dac.py.exp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/pyb/switch.py.exp: -------------------------------------------------------------------------------- 1 | False 2 | -------------------------------------------------------------------------------- /bare-arm/mphalport.h: -------------------------------------------------------------------------------- 1 | // empty file 2 | -------------------------------------------------------------------------------- /esp8266/user_config.h: -------------------------------------------------------------------------------- 1 | // empty 2 | -------------------------------------------------------------------------------- /mpy-cross/.gitignore: -------------------------------------------------------------------------------- 1 | mpy-cross 2 | -------------------------------------------------------------------------------- /tests/extmod/ticks_diff.py.exp: -------------------------------------------------------------------------------- 1 | OK 2 | -------------------------------------------------------------------------------- /tests/feature_check/byteorder.py.exp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/feature_check/complex.py.exp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/pyb/accel.py.exp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/pyboard.py: -------------------------------------------------------------------------------- 1 | ../tools/pyboard.py -------------------------------------------------------------------------------- /docs/sphinx_selective_exclude/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /esp8266/modules/upip.py: -------------------------------------------------------------------------------- 1 | ../../tools/upip.py -------------------------------------------------------------------------------- /mpy-cross/mphalport.h: -------------------------------------------------------------------------------- 1 | // empty file 2 | -------------------------------------------------------------------------------- /tests/cmdline/cmd_optimise.py.exp: -------------------------------------------------------------------------------- 1 | False 2 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_sizeof_native.py.exp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/feature_check/native_check.py.exp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/import/pkg6/x/y.py: -------------------------------------------------------------------------------- 1 | print('y') 2 | -------------------------------------------------------------------------------- /tests/inlineasm/asmblbx.py.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -------------------------------------------------------------------------------- /tests/inlineasm/asmfpaddsub.py.exp: -------------------------------------------------------------------------------- 1 | 90 2 | -------------------------------------------------------------------------------- /tests/inlineasm/asmfpldrstr.py.exp: -------------------------------------------------------------------------------- 1 | 6.0 2 | -------------------------------------------------------------------------------- /tests/inlineasm/asmfpmuldiv.py.exp: -------------------------------------------------------------------------------- 1 | 20 2 | -------------------------------------------------------------------------------- /tests/inlineasm/asmfpsqrt.py.exp: -------------------------------------------------------------------------------- 1 | -160 2 | -------------------------------------------------------------------------------- /tests/inlineasm/asmpushpop.py.exp: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /tests/pyb/modstm.py.exp: -------------------------------------------------------------------------------- 1 | 0x8000 2 | 0x0 3 | -------------------------------------------------------------------------------- /tests/unicode/data/utf-8_1.txt: -------------------------------------------------------------------------------- 1 | Привет 2 | -------------------------------------------------------------------------------- /tests/wipy/reset/reset.py.exp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tools/.gitattributes: -------------------------------------------------------------------------------- 1 | *.tar.gz binary 2 | -------------------------------------------------------------------------------- /unix/scripts/upip.py: -------------------------------------------------------------------------------- 1 | ../../tools/upip.py -------------------------------------------------------------------------------- /emscripten/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | 3 | -------------------------------------------------------------------------------- /tests/basics/module2.py.exp: -------------------------------------------------------------------------------- 1 | AttributeError 2 | -------------------------------------------------------------------------------- /tests/extmod/time_ms_us.py.exp: -------------------------------------------------------------------------------- 1 | True 2 | True 3 | -------------------------------------------------------------------------------- /tests/extmod/ujson_dumps_extra.py.exp: -------------------------------------------------------------------------------- 1 | "1234" 2 | -------------------------------------------------------------------------------- /tests/import/pkg2/mod2.py: -------------------------------------------------------------------------------- 1 | print("in mod2") 2 | -------------------------------------------------------------------------------- /tests/inlineasm/asmconst.py.exp: -------------------------------------------------------------------------------- 1 | 0xfffffff 2 | -------------------------------------------------------------------------------- /tests/jni/object.py.exp: -------------------------------------------------------------------------------- 1 | 42 2 | 42 3 | 42 4 | -------------------------------------------------------------------------------- /tests/jni/system_out.py.exp: -------------------------------------------------------------------------------- 1 | Hello, Java! 2 | -------------------------------------------------------------------------------- /tests/micropython/decorator.py.exp: -------------------------------------------------------------------------------- 1 | bytecode 2 | -------------------------------------------------------------------------------- /tests/pyb/irq.py.exp: -------------------------------------------------------------------------------- 1 | True 2 | True False 3 | -------------------------------------------------------------------------------- /tests/import/pkg2/mod1.py: -------------------------------------------------------------------------------- 1 | from pkg2 import mod2 2 | -------------------------------------------------------------------------------- /tests/inlineasm/asmfpcmp.py.exp: -------------------------------------------------------------------------------- 1 | 2 2 | 6 3 | 8 4 | -------------------------------------------------------------------------------- /tests/inlineasm/asmit.py.exp: -------------------------------------------------------------------------------- 1 | 100 1 2 | 100 200 3 | -------------------------------------------------------------------------------- /tests/inlineasm/asmspecialregs.py.exp: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | -------------------------------------------------------------------------------- /tests/io/argv.py: -------------------------------------------------------------------------------- 1 | import sys 2 | print(sys.argv) 3 | -------------------------------------------------------------------------------- /tests/micropython/emg_exc.py.exp: -------------------------------------------------------------------------------- 1 | ValueError: 2 | -------------------------------------------------------------------------------- /tests/micropython/viper_import.py.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -------------------------------------------------------------------------------- /tests/misc/recursive_data.py.exp: -------------------------------------------------------------------------------- 1 | RuntimeError 2 | -------------------------------------------------------------------------------- /tests/pyb/extint.py.exp: -------------------------------------------------------------------------------- 1 | 0 2 | line: 0 3 | line: 0 4 | -------------------------------------------------------------------------------- /tests/unicode/data/utf-8_2.txt: -------------------------------------------------------------------------------- 1 | aαbβcγdδ 2 | ぁ🙐 3 | -------------------------------------------------------------------------------- /bare-arm/qstrdefsport.h: -------------------------------------------------------------------------------- 1 | // qstrs specific to this port 2 | -------------------------------------------------------------------------------- /examples/embedding/mpconfigport.h: -------------------------------------------------------------------------------- 1 | mpconfigport_minimal.h -------------------------------------------------------------------------------- /minimal/qstrdefsport.h: -------------------------------------------------------------------------------- 1 | // qstrs specific to this port 2 | -------------------------------------------------------------------------------- /pic16bit/qstrdefsport.h: -------------------------------------------------------------------------------- 1 | // qstrs specific to this port 2 | -------------------------------------------------------------------------------- /qemu-arm/qstrdefsport.h: -------------------------------------------------------------------------------- 1 | // qstrs specific to this port 2 | -------------------------------------------------------------------------------- /teensy/qstrdefsport.h: -------------------------------------------------------------------------------- 1 | // qstrs specific to this port 2 | -------------------------------------------------------------------------------- /tests/import/pkg/mod.py: -------------------------------------------------------------------------------- 1 | def foo(): 2 | return 42 3 | -------------------------------------------------------------------------------- /tests/import/pkg2/__init__.py: -------------------------------------------------------------------------------- 1 | from pkg2 import mod1 2 | -------------------------------------------------------------------------------- /tests/inlineasm/asmbcc.py.exp: -------------------------------------------------------------------------------- 1 | 0 2 | 10 3 | 20 4 | 30 5 | -------------------------------------------------------------------------------- /tests/io/data/file1: -------------------------------------------------------------------------------- 1 | longer line1 2 | line2 3 | line3 4 | -------------------------------------------------------------------------------- /tests/micropython/heap_lock.py.exp: -------------------------------------------------------------------------------- 1 | MemoryError 2 | [] 3 | -------------------------------------------------------------------------------- /tests/micropython/native_closure.py.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 9 4 | -------------------------------------------------------------------------------- /tests/pyb/timer.py.exp: -------------------------------------------------------------------------------- 1 | 100 2 | 200 3 | 300 4 | 400 5 | -------------------------------------------------------------------------------- /unix/scripts/upip_utarfile.py: -------------------------------------------------------------------------------- 1 | ../../tools/upip_utarfile.py -------------------------------------------------------------------------------- /esp8266/modules/upip_utarfile.py: -------------------------------------------------------------------------------- 1 | ../../tools/upip_utarfile.py -------------------------------------------------------------------------------- /mpy-cross/qstrdefsport.h: -------------------------------------------------------------------------------- 1 | // qstrs specific to this port 2 | -------------------------------------------------------------------------------- /tests/basics/class_emptybases.py: -------------------------------------------------------------------------------- 1 | class A(): 2 | pass 3 | -------------------------------------------------------------------------------- /tests/basics/memoryerror.py.exp: -------------------------------------------------------------------------------- 1 | MemoryError 2 | 1000 0 999 3 | -------------------------------------------------------------------------------- /tests/basics/set_union.py: -------------------------------------------------------------------------------- 1 | print(sorted({1}.union({2}))) 2 | -------------------------------------------------------------------------------- /tests/import/gen_context2.py: -------------------------------------------------------------------------------- 1 | def call(g): 2 | next(g) 3 | -------------------------------------------------------------------------------- /tests/inlineasm/asmargs.py.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 6 5 | 10 6 | -------------------------------------------------------------------------------- /tests/micropython/memstats.py.exp: -------------------------------------------------------------------------------- 1 | True 2 | True 3 | True 4 | -------------------------------------------------------------------------------- /tests/pyb/halerror.py.exp: -------------------------------------------------------------------------------- 1 | OSError(5,) 2 | OSError(110,) 3 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_native_float.py.exp: -------------------------------------------------------------------------------- 1 | 12.3400 2 | 12.3400 3 | -------------------------------------------------------------------------------- /tests/import/import1a.py: -------------------------------------------------------------------------------- 1 | import import1b 2 | print(import1b.var) 3 | -------------------------------------------------------------------------------- /tests/import/import3a.py: -------------------------------------------------------------------------------- 1 | from import1b import * 2 | print(var) 3 | -------------------------------------------------------------------------------- /tests/import/pkg3/__init__.py: -------------------------------------------------------------------------------- 1 | print("pkg __name__:", __name__) 2 | -------------------------------------------------------------------------------- /tests/import/pkg6/__init__.py: -------------------------------------------------------------------------------- 1 | from .x import * 2 | print('init') 3 | -------------------------------------------------------------------------------- /tests/import/pkg6/x/__init__.py: -------------------------------------------------------------------------------- 1 | from .y import * 2 | print('x') 3 | -------------------------------------------------------------------------------- /tests/micropython/const_error.py.exp: -------------------------------------------------------------------------------- 1 | SyntaxError 2 | SyntaxError 3 | -------------------------------------------------------------------------------- /tests/micropython/opt_level.py.exp: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | True 4 | False 5 | -------------------------------------------------------------------------------- /tests/pyb/led.py.exp: -------------------------------------------------------------------------------- 1 | LED(1) 2 | LED(2) 3 | LED(3) 4 | LED(4) 5 | -------------------------------------------------------------------------------- /tests/pybnative/while.py.exp: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 0 4 | 1 5 | 2 6 | 3 7 | -------------------------------------------------------------------------------- /tests/wipy/modwipy.py.exp: -------------------------------------------------------------------------------- 1 | True 2 | True 3 | True 4 | Exception 5 | -------------------------------------------------------------------------------- /tests/basics/async_def.py.exp: -------------------------------------------------------------------------------- 1 | decorator 2 | foo 3 | StopIteration 4 | -------------------------------------------------------------------------------- /tests/basics/errno1.py.exp: -------------------------------------------------------------------------------- 1 | 2 | [Errno ] EIO 3 | 9999 4 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_le_float.py.exp: -------------------------------------------------------------------------------- 1 | 12.3400 2 | 12.3400 3 | 12.3400 4 | -------------------------------------------------------------------------------- /tests/feature_check/byteorder.py: -------------------------------------------------------------------------------- 1 | import sys 2 | print(sys.byteorder) 3 | -------------------------------------------------------------------------------- /tests/inlineasm/asmbitops.py.exp: -------------------------------------------------------------------------------- 1 | 24 2 | 16 3 | 0xf000000 4 | 0x10000 5 | -------------------------------------------------------------------------------- /tests/jni/list.py.exp: -------------------------------------------------------------------------------- 1 | [] 2 | [one, two] 3 | [one, two] 4 | one two 5 | -------------------------------------------------------------------------------- /tests/micropython/decorator_error.py.exp: -------------------------------------------------------------------------------- 1 | SyntaxError 2 | SyntaxError 3 | -------------------------------------------------------------------------------- /tests/micropython/native_const.py.exp: -------------------------------------------------------------------------------- 1 | 123456789012345678901234567890 2 | -------------------------------------------------------------------------------- /tests/micropython/viper_cond.py.exp: -------------------------------------------------------------------------------- 1 | not x False 2 | x True 3 | y 1 4 | -------------------------------------------------------------------------------- /tests/micropython/viper_subscr.py.exp: -------------------------------------------------------------------------------- 1 | [1, 2, 3] 2 | 1 3 | 2 4 | 3 5 | -------------------------------------------------------------------------------- /tests/pyb/adc.py.exp: -------------------------------------------------------------------------------- 1 | 2 | 50 3 | 25 4 | 30 5 | -------------------------------------------------------------------------------- /tests/basics/bytearray_longint.py: -------------------------------------------------------------------------------- 1 | print(bytearray(2**65 - (2**65 - 1))) 2 | -------------------------------------------------------------------------------- /tests/basics/zip.py: -------------------------------------------------------------------------------- 1 | print(list(zip())) 2 | print(list(zip([1], {2,3}))) 3 | -------------------------------------------------------------------------------- /tests/cmdline/repl_basic.py: -------------------------------------------------------------------------------- 1 | # basic REPL tests 2 | print(1) 3 |  4 | 2 5 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_sizeof.py.exp: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | 4 4 | TypeError 5 | 6 6 | 1 7 | -------------------------------------------------------------------------------- /tests/import/import_file.py: -------------------------------------------------------------------------------- 1 | import import1b 2 | print(import1b.__file__) 3 | -------------------------------------------------------------------------------- /tests/import/pkg3/subpkg1/__init__.py: -------------------------------------------------------------------------------- 1 | print("subpkg1 __name__:", __name__) 2 | -------------------------------------------------------------------------------- /tests/micropython/viper_args.py.exp: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 1 2 4 | 1 2 3 5 | 1 2 3 4 6 | -------------------------------------------------------------------------------- /tests/pybnative/for.py.exp: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 3 5 | 0 6 | 1 7 | 2 8 | 3 9 | -------------------------------------------------------------------------------- /tests/basics/bytes_compare3.py.exp: -------------------------------------------------------------------------------- 1 | ######## 2 | False 3 | ######## 4 | False 5 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_bytearray.py.exp: -------------------------------------------------------------------------------- 1 | bytearray(b'01') 2 | 3 | -------------------------------------------------------------------------------- /tests/extmod/vfs_fat_oldproto.py.exp: -------------------------------------------------------------------------------- 1 | ['file.txt'] 2 | hello! 3 | [] 4 | True 5 | -------------------------------------------------------------------------------- /tests/inlineasm/asmdiv.py.exp: -------------------------------------------------------------------------------- 1 | 411 2 | -411 3 | -411 4 | 411 5 | 411 6 | 2 7 | 1 8 | -------------------------------------------------------------------------------- /logo/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/logo/logo.jpg -------------------------------------------------------------------------------- /tests/basics/fun1.py: -------------------------------------------------------------------------------- 1 | # calling a function 2 | 3 | def f(): 4 | print(1) 5 | f() 6 | -------------------------------------------------------------------------------- /tests/basics/set_add.py: -------------------------------------------------------------------------------- 1 | s = {1, 2, 3, 4} 2 | print(s.add(5)) 3 | print(sorted(s)) 4 | -------------------------------------------------------------------------------- /tests/basics/set_clear.py: -------------------------------------------------------------------------------- 1 | s = {1, 2, 3, 4} 2 | print(s.clear()) 3 | print(list(s)) 4 | -------------------------------------------------------------------------------- /tests/basics/set_discard.py: -------------------------------------------------------------------------------- 1 | s = {1, 2} 2 | print(s.discard(1)) 3 | print(list(s)) 4 | -------------------------------------------------------------------------------- /tests/cmdline/cmd_verbose.py: -------------------------------------------------------------------------------- 1 | # cmdline: -v -v 2 | # test verbose output 3 | print(1) 4 | -------------------------------------------------------------------------------- /tests/extmod/ure_split_empty.py.exp: -------------------------------------------------------------------------------- 1 | ['a b c foobar'] 2 | ['foo'] 3 | ['axbc'] 4 | -------------------------------------------------------------------------------- /tests/import/import1b.py: -------------------------------------------------------------------------------- 1 | var = 123 2 | 3 | def throw(): 4 | raise ValueError 5 | -------------------------------------------------------------------------------- /tests/import/pkg3/mod1.py: -------------------------------------------------------------------------------- 1 | print("mod1 __name__:", __name__) 2 | from . import mod2 3 | -------------------------------------------------------------------------------- /tests/io/file_iter.py: -------------------------------------------------------------------------------- 1 | f = open("io/data/file1") 2 | for l in f: 3 | print(l) 4 | -------------------------------------------------------------------------------- /tests/micropython/const.py.exp: -------------------------------------------------------------------------------- 1 | 123 580 2 | 123 580 3 | 12 46 4 | 1 2 5 | True False 6 | -------------------------------------------------------------------------------- /tests/basics/lambda1.py: -------------------------------------------------------------------------------- 1 | # lambda 2 | 3 | f = lambda x, y: x + 3 * y 4 | print(f(3, 5)) 5 | -------------------------------------------------------------------------------- /tests/basics/set_iter.py: -------------------------------------------------------------------------------- 1 | s = {1, 2, 3, 4} 2 | l = list(s) 3 | l.sort() 4 | print(l) 5 | 6 | -------------------------------------------------------------------------------- /tests/extmod/machine1.py.exp: -------------------------------------------------------------------------------- 1 | <8-bit memory> 2 | ValueError 3 | ValueError 4 | TypeError 5 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_ptr_le.py.exp: -------------------------------------------------------------------------------- 1 | 48 2 | 49 3 | 0x3130 4 | 48 49 5 | 48 49 6 | 0x3130 7 | -------------------------------------------------------------------------------- /tests/import/import_pkg6.py: -------------------------------------------------------------------------------- 1 | # This tests relative imports as used in pkg6 2 | import pkg6 3 | -------------------------------------------------------------------------------- /tests/inlineasm/asmshift.py.exp: -------------------------------------------------------------------------------- 1 | 0x246 2 | 0x800000 3 | 0x91 4 | 0x1 5 | 0x91 6 | -0x1 7 | -------------------------------------------------------------------------------- /tests/micropython/native_misc.py.exp: -------------------------------------------------------------------------------- 1 | 1 [] 2 2 | 1 [] 3 3 | 3 4 | 6 5 | True 6 | False 7 | -------------------------------------------------------------------------------- /tests/micropython/viper_ptr8_load.py.exp: -------------------------------------------------------------------------------- 1 | bytearray(b'1234') 2 | 49 50 3 | 202 4 | 202 5 | -------------------------------------------------------------------------------- /tests/pyb/i2c_error.py.exp: -------------------------------------------------------------------------------- 1 | OSError(5,) 2 | OSError(5,) 3 | OSError(5,) 4 | OSError(5,) 5 | -------------------------------------------------------------------------------- /tests/pyb/servo.py.exp: -------------------------------------------------------------------------------- 1 | 2 | 1500 3 | (630, 2410, 1490, 2460, 2190) 4 | -------------------------------------------------------------------------------- /tests/wipy/sd.py.exp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exception 5 | Exception 6 | Exception 7 | -------------------------------------------------------------------------------- /drivers/dht/dht.h: -------------------------------------------------------------------------------- 1 | #include "py/obj.h" 2 | 3 | MP_DECLARE_CONST_FUN_OBJ_2(dht_readinto_obj); 4 | -------------------------------------------------------------------------------- /logo/1bit-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/logo/1bit-logo.png -------------------------------------------------------------------------------- /logo/trans-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/logo/trans-logo.png -------------------------------------------------------------------------------- /teensy/lexermemzip.h: -------------------------------------------------------------------------------- 1 | mp_lexer_t *mp_lexer_new_from_memzip_file(const char *filename); 2 | 3 | -------------------------------------------------------------------------------- /tests/basics/generator2.py: -------------------------------------------------------------------------------- 1 | gen = (i for i in range(10)) 2 | for i in gen: 3 | print(i) 4 | -------------------------------------------------------------------------------- /tests/basics/list_clear.py: -------------------------------------------------------------------------------- 1 | # tests list.clear 2 | x = [1, 2, 3, 4] 3 | x.clear() 4 | print(x) 5 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_ptr_native_le.py.exp: -------------------------------------------------------------------------------- 1 | 48 2 | 49 3 | 0x3130 4 | 48 49 5 | 48 49 6 | 0x3130 7 | -------------------------------------------------------------------------------- /tests/io/buffered_writer.py.exp: -------------------------------------------------------------------------------- 1 | b'' 2 | b'foobarfo' 3 | b'foobarfoobar' 4 | b'foobarfoobar' 5 | -------------------------------------------------------------------------------- /tests/io/file_long_read.py: -------------------------------------------------------------------------------- 1 | f = open("io/data/file1") 2 | b = f.read(100) 3 | print(len(b)) 4 | -------------------------------------------------------------------------------- /tests/pyb/pyb1.py.exp: -------------------------------------------------------------------------------- 1 | 3 2 | 3 3 | (168000000, 168000000, 42000000, 84000000) 4 | True 5 | 12 6 | -------------------------------------------------------------------------------- /zephyr/Kbuild: -------------------------------------------------------------------------------- 1 | #subdir-ccflags-y += -I$(SOURCE_DIR)/../mylib/include 2 | 3 | obj-y += src/ 4 | -------------------------------------------------------------------------------- /logo/vector-logo-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/logo/vector-logo-2.png -------------------------------------------------------------------------------- /logo/vector-logo-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/logo/vector-logo-3.png -------------------------------------------------------------------------------- /minimal/frozentest.mpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/minimal/frozentest.mpy -------------------------------------------------------------------------------- /qemu-arm/memory.h: -------------------------------------------------------------------------------- 1 | // this is needed for extmod/crypto-algorithms/sha256.c 2 | #include 3 | -------------------------------------------------------------------------------- /stmhal/memory.h: -------------------------------------------------------------------------------- 1 | // this is needed for extmod/crypto-algorithms/sha256.c 2 | #include 3 | -------------------------------------------------------------------------------- /tests/basics/bytes_format_modulo.py.exp: -------------------------------------------------------------------------------- 1 | b'%' 2 | b'=1=' 3 | b'=1=2=' 4 | b'=str=' 5 | b"=b'str'=" 6 | -------------------------------------------------------------------------------- /tests/basics/dict_get.py: -------------------------------------------------------------------------------- 1 | for d in {}, {42:2}: 2 | print(d.get(42)) 3 | print(d.get(42,2)) 4 | -------------------------------------------------------------------------------- /tests/basics/exception_chain.py.exp: -------------------------------------------------------------------------------- 1 | Warning: exception chaining not supported 2 | Caught Exception 3 | -------------------------------------------------------------------------------- /tests/basics/fun_str.py: -------------------------------------------------------------------------------- 1 | # test str of function 2 | 3 | def f(): 4 | pass 5 | print(str(f)[:8]) 6 | -------------------------------------------------------------------------------- /tests/basics/list_sum.py: -------------------------------------------------------------------------------- 1 | # list addition 2 | a = [1,2,3] 3 | b = [4,5,6] 4 | c = a + b 5 | print(c) 6 | -------------------------------------------------------------------------------- /tests/feature_check/repl_emacs_check.py: -------------------------------------------------------------------------------- 1 | # Check for emacs keys in REPL 2 | t = +11 3 | t == 2 4 | -------------------------------------------------------------------------------- /tests/io/file_stdio.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | print(sys.stdin.fileno()) 4 | print(sys.stdout.fileno()) 5 | -------------------------------------------------------------------------------- /tests/micropython/viper_ptr16_load.py.exp: -------------------------------------------------------------------------------- 1 | bytearray(b'1234') 2 | 12849 13363 3 | 26212 4 | 26212 5 | -------------------------------------------------------------------------------- /tests/unicode/unicode_ord.py: -------------------------------------------------------------------------------- 1 | # test builtin ord with unicode characters 2 | 3 | print(ord('α')) 4 | -------------------------------------------------------------------------------- /tests/unix/ffi_callback.py.exp: -------------------------------------------------------------------------------- 1 | org string: bytearray(b'foobar') 2 | qsort'ed: bytearray(b'abfoor') 3 | -------------------------------------------------------------------------------- /teensy/core/Arduino.h: -------------------------------------------------------------------------------- 1 | //#include "WProgram.h" 2 | #include "core_pins.h" 3 | #include "pins_arduino.h" 4 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_array_assign_native_le.py.exp: -------------------------------------------------------------------------------- 1 | 0x11 2 | 0x2233 3 | 0x4455 4 | 0x66778899 5 | True 6 | -------------------------------------------------------------------------------- /tests/import/pkg3/subpkg1/mod1.py: -------------------------------------------------------------------------------- 1 | print("subpkg1.mod1 __name__:", __name__) 2 | from ..mod2 import foo 3 | -------------------------------------------------------------------------------- /tests/io/file_long_read2.py: -------------------------------------------------------------------------------- 1 | f = open("io/data/bigfile1") 2 | b = f.read() 3 | print(len(b)) 4 | print(b) 5 | -------------------------------------------------------------------------------- /tests/io/write_ext.py.exp: -------------------------------------------------------------------------------- 1 | b'fo' 2 | b'fofoo' 3 | b'fofoooob' 4 | b'fofooooboobar' 5 | b'fofooooboobar' 6 | -------------------------------------------------------------------------------- /tests/micropython/const2.py.exp: -------------------------------------------------------------------------------- 1 | 2 | function X 1 3 | class X 1 4 | method X 2 4 4 5 | -------------------------------------------------------------------------------- /tests/misc/recursive_iternext.py.exp: -------------------------------------------------------------------------------- 1 | RuntimeError 2 | RuntimeError 3 | RuntimeError 4 | RuntimeError 5 | -------------------------------------------------------------------------------- /tests/unicode/unicode_iter.py: -------------------------------------------------------------------------------- 1 | for c in "Hello": 2 | print(c) 3 | for c in "Привет": 4 | print(c) 5 | -------------------------------------------------------------------------------- /tests/unix/ffi_float2.py.exp: -------------------------------------------------------------------------------- 1 | 1.772454 2 | 1.000000 3 | 1.000000 4 | 0.886227 5 | 6.000000 6 | 6.000000 7 | -------------------------------------------------------------------------------- /tests/wipy/wdt.py.exp: -------------------------------------------------------------------------------- 1 | Exception 2 | Exception 3 | Exception 4 | 5 | Exception 6 | 7 | 8 | -------------------------------------------------------------------------------- /drivers/cc3100/inc/netapp.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/drivers/cc3100/inc/netapp.h -------------------------------------------------------------------------------- /emscripten/frozentest.mpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/emscripten/frozentest.mpy -------------------------------------------------------------------------------- /logo/upython-with-micro.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/logo/upython-with-micro.jpg -------------------------------------------------------------------------------- /logo/upython-with-micro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/logo/upython-with-micro.png -------------------------------------------------------------------------------- /tests/cmdline/cmd_optimise.py: -------------------------------------------------------------------------------- 1 | # cmdline: -O 2 | # test optimisation output 3 | print(__debug__) 4 | assert 0 5 | -------------------------------------------------------------------------------- /unix/input.h: -------------------------------------------------------------------------------- 1 | char *prompt(char *p); 2 | void prompt_read_history(void); 3 | void prompt_write_history(void); 4 | -------------------------------------------------------------------------------- /esp8266/espneopixel.h: -------------------------------------------------------------------------------- 1 | void esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz); 2 | -------------------------------------------------------------------------------- /tests/basics/0prelim.py: -------------------------------------------------------------------------------- 1 | # all tests need print to work! make sure it does work 2 | 3 | print(1) 4 | print('abc') 5 | -------------------------------------------------------------------------------- /tests/basics/compare_multi.py: -------------------------------------------------------------------------------- 1 | print(1 < 2 < 3) 2 | print(1 < 2 < 3 < 4) 3 | print(1 > 2 < 3) 4 | print(1 < 2 > 3) 5 | -------------------------------------------------------------------------------- /tests/basics/list_reverse.py: -------------------------------------------------------------------------------- 1 | a = [] 2 | for i in range(100): 3 | a.append(i) 4 | a.reverse() 5 | print(a) 6 | -------------------------------------------------------------------------------- /tests/float/int_divzero.py: -------------------------------------------------------------------------------- 1 | try: 2 | 1 / 0 3 | except ZeroDivisionError: 4 | print("ZeroDivisionError") 5 | -------------------------------------------------------------------------------- /tests/io/file_long_read3.py: -------------------------------------------------------------------------------- 1 | f = open("io/data/bigfile1", "rb") 2 | b = f.read(512) 3 | print(len(b)) 4 | print(b) 5 | -------------------------------------------------------------------------------- /tests/wipy/wlan/machine.py.exp: -------------------------------------------------------------------------------- 1 | 2 | True 3 | True 4 | Active 5 | True 6 | True 7 | Exception 8 | -------------------------------------------------------------------------------- /logo/micropythonpowered-art.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/logo/micropythonpowered-art.png -------------------------------------------------------------------------------- /tests/basics/dict_clear.py: -------------------------------------------------------------------------------- 1 | d = {1: 2, 3: 4} 2 | print(len(d)) 3 | d.clear() 4 | print(d) 5 | d[2] = 42 6 | print(d) 7 | -------------------------------------------------------------------------------- /tests/basics/filter.py: -------------------------------------------------------------------------------- 1 | print(list(filter(lambda x: x & 1, range(-3, 4)))) 2 | print(list(filter(None, range(-3, 4)))) 3 | -------------------------------------------------------------------------------- /tests/basics/fun_annotations.py: -------------------------------------------------------------------------------- 1 | def foo(x: int, y: list) -> dict: 2 | return {x: y} 3 | 4 | print(foo(1, [2, 3])) 5 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_array_assign_le.py.exp: -------------------------------------------------------------------------------- 1 | 0x11 2 | 0x2233 3 | 0x4455 4 | 0x66778899 5 | True 6 | 0xaabbccdd 7 | True 8 | -------------------------------------------------------------------------------- /tests/unicode/unicode_str_modulo.py: -------------------------------------------------------------------------------- 1 | # test handling of unicode chars in string % formatting 2 | 3 | print('α' % ()) 4 | -------------------------------------------------------------------------------- /qemu-arm/mphalport.h: -------------------------------------------------------------------------------- 1 | #define mp_hal_stdin_rx_chr() (0) 2 | #define mp_hal_stdout_tx_strn_cooked(s, l) write(1, (s), (l)) 3 | -------------------------------------------------------------------------------- /tests/basics/bytes_add_endian.py: -------------------------------------------------------------------------------- 1 | # test bytes + other 2 | 3 | import array 4 | 5 | print(b"123" + array.array('i', [1])) 6 | -------------------------------------------------------------------------------- /tests/feature_check/complex.py: -------------------------------------------------------------------------------- 1 | try: 2 | complex 3 | print("complex") 4 | except NameError: 5 | print("no") 6 | 7 | -------------------------------------------------------------------------------- /tests/import/import2a.py: -------------------------------------------------------------------------------- 1 | from import1b import var 2 | print(var) 3 | 4 | from import1b import var as var2 5 | print(var2) 6 | -------------------------------------------------------------------------------- /tests/import/import_pkg3.py: -------------------------------------------------------------------------------- 1 | from pkg import mod 2 | 3 | print(mod.foo()) 4 | 5 | import pkg.mod 6 | print(mod is pkg.mod) 7 | -------------------------------------------------------------------------------- /tests/import/import_pkg4.py: -------------------------------------------------------------------------------- 1 | # Testing that "recursive" imports (pkg2/__init__.py imports from pkg2) work 2 | import pkg2 3 | -------------------------------------------------------------------------------- /tests/import/rel_import_inv.py: -------------------------------------------------------------------------------- 1 | try: 2 | from . import foo 3 | except: 4 | print("Invalid relative import caught") 5 | -------------------------------------------------------------------------------- /tests/inlineasm/asmsum.py.exp: -------------------------------------------------------------------------------- 1 | array('l', [100, 200, 300, 400]) 1000 2 | array('b', [10, 20, 30, 40, 50, 60, 70, 80]) 360 3 | -------------------------------------------------------------------------------- /tests/misc/non_compliant_lexer.py.exp: -------------------------------------------------------------------------------- 1 | SyntaxError 2 | SyntaxError 3 | SyntaxError 4 | SyntaxError 5 | NotImplementedError 6 | -------------------------------------------------------------------------------- /tests/pyb/timer_callback.py.exp: -------------------------------------------------------------------------------- 1 | before cb1 2 | cb1 3 | before cb2 4 | cb2 5 | before cb1 6 | cb1 7 | before cb4 8 | cb4 3 9 | -------------------------------------------------------------------------------- /windows/.gitignore: -------------------------------------------------------------------------------- 1 | *.user 2 | *.*sdf 3 | *.suo 4 | *.sln 5 | *.exe 6 | *.pdb 7 | *.ilk 8 | *.filters 9 | /build/* 10 | -------------------------------------------------------------------------------- /examples/SDdatalogger/cardreader.py: -------------------------------------------------------------------------------- 1 | # cardread.py 2 | # This is called when the user enters cardreader mode. It does nothing. 3 | -------------------------------------------------------------------------------- /pic16bit/unistd.h: -------------------------------------------------------------------------------- 1 | // XC16 compiler doesn't seem to have unistd.h file 2 | 3 | #define SEEK_CUR 1 4 | 5 | typedef int ssize_t; 6 | -------------------------------------------------------------------------------- /stmhal/hal/f4/inc/stm32f4xx_hal_def.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/stmhal/hal/f4/inc/stm32f4xx_hal_def.h -------------------------------------------------------------------------------- /tests/basics/async_for.py.exp: -------------------------------------------------------------------------------- 1 | init 2 | aiter 3 | anext 4 | a 5 | anext 6 | b 7 | anext 8 | c 9 | anext 10 | finished 11 | -------------------------------------------------------------------------------- /tests/basics/dict_iterator.py: -------------------------------------------------------------------------------- 1 | d = {1: 2, 3: 4} 2 | els = [] 3 | for i in d: 4 | els.append((i, d[i])) 5 | print(sorted(els)) 6 | -------------------------------------------------------------------------------- /tests/basics/set_copy.py: -------------------------------------------------------------------------------- 1 | s = {1, 2, 3, 4} 2 | t = s.copy() 3 | s.add(5) 4 | t.add(7) 5 | for i in s, t: 6 | print(sorted(i)) 7 | -------------------------------------------------------------------------------- /tests/import/pkg3/mod2.py: -------------------------------------------------------------------------------- 1 | print("mod2 __name__:", __name__) 2 | print("in mod2") 3 | 4 | def foo(): 5 | print("mod2.foo()") 6 | -------------------------------------------------------------------------------- /tests/inlineasm/asmrettype.py.exp: -------------------------------------------------------------------------------- 1 | 1 2 | False True 3 | 0 0x20000000 0x40000000 -0x80000000 4 | 0 0x20000000 0x40000000 0x80000000 5 | -------------------------------------------------------------------------------- /tests/micropython/heapalloc.py.exp: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 0 4 | 0 2 5 | 0 0 6 | 1 7 | 3 8 | 1 9 | 1 2 10 | 1 1 11 | 1 2 3 4 10 12 | -------------------------------------------------------------------------------- /tests/pyb/switch.py: -------------------------------------------------------------------------------- 1 | from pyb import Switch 2 | 3 | sw = Switch() 4 | print(sw()) 5 | sw.callback(print) 6 | sw.callback(None) 7 | -------------------------------------------------------------------------------- /tests/unicode/file1.py: -------------------------------------------------------------------------------- 1 | f = open("unicode/data/utf-8_1.txt", encoding="utf-8") 2 | l = f.readline() 3 | print(l) 4 | print(len(l)) 5 | -------------------------------------------------------------------------------- /tests/unix/ffi_float.py.exp: -------------------------------------------------------------------------------- 1 | 1.230000 2 | 1.230000 3 | 1.772454 4 | 1.000000 5 | 1.000000 6 | 0.886227 7 | 6.000000 8 | 6.000000 9 | -------------------------------------------------------------------------------- /cc3200/bootmgr/relocator/relocator.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/cc3200/bootmgr/relocator/relocator.bin -------------------------------------------------------------------------------- /drivers/README.md: -------------------------------------------------------------------------------- 1 | This directory contains drivers for specific hardware. The drivers are 2 | intended to work across multiple ports. 3 | -------------------------------------------------------------------------------- /esp8266/ets_alt_task.h: -------------------------------------------------------------------------------- 1 | extern int ets_loop_iter_disable; 2 | extern uint32_t system_time_high_word; 3 | 4 | bool ets_loop_iter(void); 5 | -------------------------------------------------------------------------------- /tests/basics/object1.py: -------------------------------------------------------------------------------- 1 | # test builtin object() 2 | 3 | # creation 4 | object() 5 | 6 | # printing 7 | print(repr(object())[:7]) 8 | -------------------------------------------------------------------------------- /tests/basics/tuple_count.py: -------------------------------------------------------------------------------- 1 | a = (1, 2, 3) 2 | a = a + a + a 3 | b = (0, 0, a, 0, a, 0) 4 | print(a.count(2)) 5 | print(b.count(a)) 6 | -------------------------------------------------------------------------------- /tests/micropython/viper_ptr32_load.py.exp: -------------------------------------------------------------------------------- 1 | bytearray(b'\x12\x12\x12\x124444') 2 | 0x12121212 0x34343434 3 | 0x46464646 4 | 0x46464646 5 | -------------------------------------------------------------------------------- /tests/misc/recursion.py: -------------------------------------------------------------------------------- 1 | def foo(): 2 | foo() 3 | 4 | try: 5 | foo() 6 | except RuntimeError: 7 | print("RuntimeError") 8 | -------------------------------------------------------------------------------- /docs/pyboard/tutorial/img/skin_amp_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/docs/pyboard/tutorial/img/skin_amp_1.jpg -------------------------------------------------------------------------------- /docs/pyboard/tutorial/img/skin_amp_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/docs/pyboard/tutorial/img/skin_amp_2.jpg -------------------------------------------------------------------------------- /docs/pyboard/tutorial/img/skin_lcd_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/docs/pyboard/tutorial/img/skin_lcd_1.jpg -------------------------------------------------------------------------------- /docs/pyboard/tutorial/img/skin_lcd_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/docs/pyboard/tutorial/img/skin_lcd_2.jpg -------------------------------------------------------------------------------- /minimal/mphalport.h: -------------------------------------------------------------------------------- 1 | static inline mp_uint_t mp_hal_ticks_ms(void) { return 0; } 2 | static inline void mp_hal_set_interrupt_char(char c) {} 3 | -------------------------------------------------------------------------------- /stmhal/hal/f4/src/stm32f4xx_hal_rcc_ex.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/stmhal/hal/f4/src/stm32f4xx_hal_rcc_ex.c -------------------------------------------------------------------------------- /tests/basics/builtin_ellipsis.py: -------------------------------------------------------------------------------- 1 | # tests that .../Ellipsis exists 2 | 3 | print(...) 4 | print(Ellipsis) 5 | 6 | print(... == Ellipsis) 7 | -------------------------------------------------------------------------------- /tests/feature_check/native_check.py: -------------------------------------------------------------------------------- 1 | # this test for the availability of native emitter 2 | @micropython.native 3 | def f(): 4 | pass 5 | -------------------------------------------------------------------------------- /unix/fatfs_port.c: -------------------------------------------------------------------------------- 1 | #include "lib/fatfs/ff.h" 2 | #include "lib/fatfs/diskio.h" 3 | 4 | DWORD get_fattime(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /docs/pyboard/tutorial/img/pyboard_servo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/docs/pyboard/tutorial/img/pyboard_servo.jpg -------------------------------------------------------------------------------- /emscripten/mphalport.h: -------------------------------------------------------------------------------- 1 | static inline mp_uint_t mp_hal_ticks_ms(void) { return 0; } 2 | static inline void mp_hal_set_interrupt_char(char c) {} 3 | -------------------------------------------------------------------------------- /tests/basics/async_with.py.exp: -------------------------------------------------------------------------------- 1 | enter 2 | body 3 | exit None None 4 | finished 5 | enter 6 | 1 7 | exit error 8 | ValueError 9 | -------------------------------------------------------------------------------- /tests/basics/dict_copy.py: -------------------------------------------------------------------------------- 1 | a = {i: 2*i for i in range(100)} 2 | b = a.copy() 3 | for i in range(100): 4 | print(i, b[i]) 5 | print(len(b)) 6 | -------------------------------------------------------------------------------- /tests/basics/list_copy.py: -------------------------------------------------------------------------------- 1 | # list copy tests 2 | a = [1, 2, []] 3 | b = a.copy() 4 | a[-1].append(1) 5 | a.append(4) 6 | print(a) 7 | print(b) 8 | -------------------------------------------------------------------------------- /tests/basics/set_specialmeth.py: -------------------------------------------------------------------------------- 1 | # set object with special methods 2 | 3 | s = {1, 2} 4 | print(s.__contains__(1)) 5 | print(s.__contains__(3)) 6 | -------------------------------------------------------------------------------- /tests/bench/loop_count-1-range.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in range(num): 5 | pass 6 | 7 | bench.run(test) 8 | -------------------------------------------------------------------------------- /tests/extmod/ujson_dumps_extra.py: -------------------------------------------------------------------------------- 1 | # test uPy ujson behaviour that's not valid in CPy 2 | 3 | import ujson 4 | 5 | print(ujson.dumps(b'1234')) 6 | -------------------------------------------------------------------------------- /tests/extmod/ujson_dumps_float.py: -------------------------------------------------------------------------------- 1 | try: 2 | import ujson as json 3 | except ImportError: 4 | import json 5 | 6 | print(json.dumps(1.2)) 7 | -------------------------------------------------------------------------------- /tests/float/list_index.py: -------------------------------------------------------------------------------- 1 | x = [1, 2] 2 | 3 | print(x[1]) 4 | 5 | try: 6 | print(x[1.0]) 7 | except TypeError: 8 | print("TypeError") 9 | -------------------------------------------------------------------------------- /tests/unicode/unicode_chr.py: -------------------------------------------------------------------------------- 1 | # test builtin chr with unicode characters 2 | 3 | print(chr(945)) 4 | print(chr(0x800)) 5 | print(chr(0x10000)) 6 | -------------------------------------------------------------------------------- /tests/unicode/unicode_str_format.py: -------------------------------------------------------------------------------- 1 | # test handling of unicode chars in format strings 2 | 3 | print('α'.format()) 4 | print('{α}'.format(α=1)) 5 | -------------------------------------------------------------------------------- /tests/wipy/wlan/server.py.exp: -------------------------------------------------------------------------------- 1 | True 2 | True 3 | True 4 | True 5 | True 6 | True 7 | True 8 | Exception 9 | Exception 10 | Exception 11 | -------------------------------------------------------------------------------- /docs/pyboard/tutorial/img/pyboard_usb_micro.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/docs/pyboard/tutorial/img/pyboard_usb_micro.jpg -------------------------------------------------------------------------------- /tests/basics/exec1.py: -------------------------------------------------------------------------------- 1 | print(exec("def foo(): return 42")) 2 | print(foo()) 3 | 4 | d = {} 5 | exec("def bar(): return 84", d) 6 | print(d["bar"]()) 7 | -------------------------------------------------------------------------------- /tests/basics/int_big_pow.py: -------------------------------------------------------------------------------- 1 | # test bignum power 2 | 3 | i = 1 << 65 4 | 5 | print(0 ** i) 6 | print(i ** 0) 7 | print(i ** 1) 8 | print(i ** 2) 9 | -------------------------------------------------------------------------------- /tests/basics/int_big_unary.py: -------------------------------------------------------------------------------- 1 | # test bignum unary operations 2 | 3 | i = 1 << 65 4 | 5 | print(bool(i)) 6 | print(+i) 7 | print(-i) 8 | print(~i) 9 | -------------------------------------------------------------------------------- /tests/bench/loop_count-4-while_down_gt.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | while num > 0: 5 | num -= 1 6 | 7 | bench.run(test) 8 | -------------------------------------------------------------------------------- /tests/bench/loop_count-5-while_down_ne.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | while num != 0: 5 | num -= 1 6 | 7 | bench.run(test) 8 | -------------------------------------------------------------------------------- /tests/extmod/machine_pinbase.py.exp: -------------------------------------------------------------------------------- 1 | __init__ 2 | value: None 3 | 1 4 | value: None 5 | 0 6 | value: None 7 | 1 8 | value: 1 9 | value: 0 10 | -------------------------------------------------------------------------------- /tests/float/int_power.py: -------------------------------------------------------------------------------- 1 | # negative power should produce float 2 | 3 | x = 2 4 | print(x ** -2) 5 | 6 | x = 3 7 | x **= -2 8 | print('%.5f' % x) 9 | -------------------------------------------------------------------------------- /tests/micropython/viper_binop_comp_imm.py.exp: -------------------------------------------------------------------------------- 1 | True False False False 2 | False True False False 3 | False False True False 4 | False False False True 5 | -------------------------------------------------------------------------------- /docs/esp8266/img/adafruit_products_pinoutstop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/docs/esp8266/img/adafruit_products_pinoutstop.jpg -------------------------------------------------------------------------------- /lib/README.md: -------------------------------------------------------------------------------- 1 | This directory contains standard, low-level C libraries with emphasis on 2 | being independent and efficient. They can be used by any port. 3 | -------------------------------------------------------------------------------- /stmhal/boards/CERB40/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F405xx 3 | AF_FILE = boards/stm32f405_af.csv 4 | LD_FILE = boards/stm32f405.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/PYBV10/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F405xx 3 | AF_FILE = boards/stm32f405_af.csv 4 | LD_FILE = boards/stm32f405.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/PYBV11/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F405xx 3 | AF_FILE = boards/stm32f405_af.csv 4 | LD_FILE = boards/stm32f405.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/PYBV3/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F405xx 3 | AF_FILE = boards/stm32f405_af.csv 4 | LD_FILE = boards/stm32f405.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/PYBV4/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F405xx 3 | AF_FILE = boards/stm32f405_af.csv 4 | LD_FILE = boards/stm32f405.ld 5 | -------------------------------------------------------------------------------- /tests/basics/for_return.py: -------------------------------------------------------------------------------- 1 | # test returning from within a for loop 2 | 3 | def f(): 4 | for i in [1, 2, 3]: 5 | return i 6 | 7 | print(f()) 8 | -------------------------------------------------------------------------------- /tests/basics/iter0.py: -------------------------------------------------------------------------------- 1 | # builtin type that is not iterable 2 | try: 3 | for i in 1: 4 | pass 5 | except TypeError: 6 | print('TypeError') 7 | -------------------------------------------------------------------------------- /tests/basics/list_count.py: -------------------------------------------------------------------------------- 1 | # list count tests 2 | a = [1, 2, 3] 3 | a = a + a + a 4 | b = [0, 0, a, 0, a, 0] 5 | print(a.count(2)) 6 | print(b.count(a)) 7 | -------------------------------------------------------------------------------- /tests/basics/python34.py.exp: -------------------------------------------------------------------------------- 1 | None 2 | ['a', 'b'] 3 | ('a', 'b') {'kw_arg': None} 4 | 2 5 | 1 6 | SyntaxError 7 | SyntaxError 8 | 3.4 9 | 3 4 10 | -------------------------------------------------------------------------------- /tests/basics/set_update.py: -------------------------------------------------------------------------------- 1 | s = {1} 2 | s.update() 3 | print(s) 4 | s.update([2]) 5 | print(sorted(s)) 6 | s.update([1,3], [2,2,4]) 7 | print(sorted(s)) 8 | -------------------------------------------------------------------------------- /tests/bench/loop_count-2-range_iter.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num)): 5 | pass 6 | 7 | bench.run(test) 8 | -------------------------------------------------------------------------------- /tests/bench/loop_count-3-while_up.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | i = 0 5 | while i < num: 6 | i += 1 7 | 8 | bench.run(test) 9 | -------------------------------------------------------------------------------- /tests/bench/var-1-constant.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | i = 0 5 | while i < 20000000: 6 | i += 1 7 | 8 | bench.run(test) 9 | -------------------------------------------------------------------------------- /tests/extmod/uzlib_decompio_gz.py.exp: -------------------------------------------------------------------------------- 1 | 16 2 | b'h' 3 | 18 4 | b'el' 5 | b'lo' 6 | 31 7 | b'' 8 | b'' 9 | 31 10 | ValueError 11 | OSError(22,) 12 | -------------------------------------------------------------------------------- /tests/extmod/vfs_fat_fsusermount.py.exp: -------------------------------------------------------------------------------- 1 | can't mkfs 2 | can't mount 3 | True 4 | can't umount 5 | can't umount 6 | EROFS: True 7 | too many devices mounted 8 | -------------------------------------------------------------------------------- /tests/float/true_value.py: -------------------------------------------------------------------------------- 1 | # Test true-ish value handling 2 | 3 | if not 0.0: 4 | print("float 0") 5 | 6 | if not 0+0j: 7 | print("complex 0") 8 | -------------------------------------------------------------------------------- /tests/micropython/viper_binop_multi_comp.py.exp: -------------------------------------------------------------------------------- 1 | 1 == 1 2 | 2 > 1 3 | 2 >= 1 4 | 2 != 1 5 | 1 < 2 6 | 2 > -1 7 | 2 >= -1 8 | 2 != -1 9 | -2 <= 1 10 | -------------------------------------------------------------------------------- /tests/stress/dict_create.py: -------------------------------------------------------------------------------- 1 | # create a large dictionary 2 | 3 | d = {} 4 | x = 1 5 | while x < 1000: 6 | d[x] = x 7 | x += 1 8 | print(d[500]) 9 | -------------------------------------------------------------------------------- /tests/wipy/skipped/rtc_irq.py.exp: -------------------------------------------------------------------------------- 1 | True 2 | True 3 | True 4 | True 5 | True 6 | True 7 | True 8 | True 9 | True 10 | Exception 11 | Exception 12 | -------------------------------------------------------------------------------- /drivers/cc3000/inc/inet_pton.h: -------------------------------------------------------------------------------- 1 | #ifndef __INET_PTON_H 2 | #define __INET_PTON_H 3 | int inet_pton(int, const char *, void *); 4 | #endif /* __INET_PTON_H */ 5 | -------------------------------------------------------------------------------- /emscripten/qstrdefsport.h: -------------------------------------------------------------------------------- 1 | // qstrs specific to this port 2 | Q(file) 3 | Q(mode) 4 | Q(encoding) 5 | Q(r) 6 | Q(buffering) 7 | Q(heap_lock) 8 | Q(heap_unlock) 9 | -------------------------------------------------------------------------------- /stmhal/boards/HYDRABUS/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F405xx 3 | AF_FILE = boards/stm32f405_af.csv 4 | LD_FILE = boards/stm32f405.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/OLIMEX_E407/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F407xx 3 | AF_FILE = boards/stm32f405_af.csv 4 | LD_FILE = boards/stm32f405.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/PYBLITEV10/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F411xE 3 | AF_FILE = boards/stm32f411_af.csv 4 | LD_FILE = boards/stm32f411.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/STM32F439/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F439xx 3 | AF_FILE = boards/stm32f439_af.csv 4 | LD_FILE = boards/stm32f439.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/STM32F4DISC/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F407xx 3 | AF_FILE = boards/stm32f405_af.csv 4 | LD_FILE = boards/stm32f405.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/STM32F7DISC/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f7 2 | CMSIS_MCU = STM32F746xx 3 | AF_FILE = boards/stm32f746_af.csv 4 | LD_FILE = boards/stm32f746.ld 5 | -------------------------------------------------------------------------------- /tests/basics/bytes_gen.py: -------------------------------------------------------------------------------- 1 | # construct a bytes object from a generator 2 | def gen(): 3 | for i in range(4): 4 | yield i 5 | print(bytes(gen())) 6 | -------------------------------------------------------------------------------- /tests/basics/string_cr_conversion.py: -------------------------------------------------------------------------------- 1 | # this file has CR line endings to test lexer's conversion of them to LF # in triple quoted strings print(repr("""abc def""")) -------------------------------------------------------------------------------- /tests/basics/string_upperlow.py: -------------------------------------------------------------------------------- 1 | print("".lower()) 2 | print(" t\tn\nr\rv\vf\f".upper()) 3 | print(" T E S T".lower()) 4 | print("*@a1b2cabc_[]/\\".upper()) 5 | -------------------------------------------------------------------------------- /tests/micropython/decorator.py: -------------------------------------------------------------------------------- 1 | # test micropython-specific decorators 2 | 3 | @micropython.bytecode 4 | def f(): 5 | return 'bytecode' 6 | 7 | print(f()) 8 | -------------------------------------------------------------------------------- /zephyr/prj.conf: -------------------------------------------------------------------------------- 1 | CONFIG_STDOUT_CONSOLE=y 2 | CONFIG_CONSOLE_HANDLER=y 3 | CONFIG_UART_CONSOLE_DEBUG_SERVER_HOOKS=y 4 | CONFIG_NEWLIB_LIBC=y 5 | CONFIG_FLOAT=y 6 | -------------------------------------------------------------------------------- /examples/hwapi/hwconfig_esp8266_esp12.py: -------------------------------------------------------------------------------- 1 | from machine import Pin 2 | 3 | # ESP12 module as used by many boards 4 | # Blue LED on pin 2 5 | LED = Pin(2, Pin.OUT) 6 | -------------------------------------------------------------------------------- /extmod/modwebsocket.h: -------------------------------------------------------------------------------- 1 | #define FRAME_OPCODE_MASK 0x0f 2 | enum { 3 | FRAME_CONT, FRAME_TXT, FRAME_BIN, 4 | FRAME_CLOSE = 0x8, FRAME_PING, FRAME_PONG 5 | }; 6 | -------------------------------------------------------------------------------- /stmhal/boards/ESPRUINO_PICO/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F401xE 3 | AF_FILE = boards/stm32f401_af.csv 4 | LD_FILE = boards/stm32f401xd.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F405xx 3 | AF_FILE = boards/stm32f405_af.csv 4 | LD_FILE = boards/stm32f405.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/NUCLEO_F401RE/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F401xE 3 | AF_FILE = boards/stm32f401_af.csv 4 | LD_FILE = boards/stm32f401xe.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/NUCLEO_F411RE/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F411xE 3 | AF_FILE = boards/stm32f411_af.csv 4 | LD_FILE = boards/stm32f411.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/STM32F411DISC/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F411xE 3 | AF_FILE = boards/stm32f411_af.csv 4 | LD_FILE = boards/stm32f411.ld 5 | -------------------------------------------------------------------------------- /stmhal/boards/STM32F429DISC/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F429xx 3 | AF_FILE = boards/stm32f429_af.csv 4 | LD_FILE = boards/stm32f429.ld 5 | -------------------------------------------------------------------------------- /tests/basics/andor.py: -------------------------------------------------------------------------------- 1 | # test short circuit expressions outside if conditionals 2 | print(() or 1) 3 | print((1,) or 1) 4 | print(() and 1) 5 | print((1,) and 1) 6 | -------------------------------------------------------------------------------- /tests/basics/assign1.py: -------------------------------------------------------------------------------- 1 | # test assignments 2 | 3 | a = 1 4 | print(a) 5 | 6 | a = b = 2 7 | print(a, b) 8 | 9 | a = b = c = 3 10 | print(a, b, c) 11 | 12 | -------------------------------------------------------------------------------- /tests/basics/async_await2.py.exp: -------------------------------------------------------------------------------- 1 | wait value: 1 2 | return from send: message from wait(1) 3 | wait got back: message from main 4 | x = 100 5 | got StopIteration 6 | -------------------------------------------------------------------------------- /tests/basics/builtin_eval_error.py: -------------------------------------------------------------------------------- 1 | # test if eval raises SyntaxError 2 | 3 | try: 4 | print(eval("[1,,]")) 5 | except SyntaxError: 6 | print("SyntaxError") 7 | -------------------------------------------------------------------------------- /tests/basics/int2.py: -------------------------------------------------------------------------------- 1 | # test basic int operations 2 | 3 | # test conversion of bool on RHS of binary op 4 | a = False 5 | print(1 + a) 6 | a = True 7 | print(1 + a) 8 | -------------------------------------------------------------------------------- /tests/bench/bytealloc-1-bytes_n.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num // 1000)): 5 | bytes(10000) 6 | 7 | bench.run(test) 8 | -------------------------------------------------------------------------------- /tests/bench/bytealloc-2-repeat.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num // 1000)): 5 | b"\0" * 10000 6 | 7 | bench.run(test) 8 | -------------------------------------------------------------------------------- /tests/extmod/machine_pulse.py.exp: -------------------------------------------------------------------------------- 1 | value: 1 2 | value: 0 3 | 4 | value: 1 5 | value: 0 6 | value: 1 7 | 8 | OSError 9 | OSError 10 | -------------------------------------------------------------------------------- /tests/basics/int_big_rshift.py: -------------------------------------------------------------------------------- 1 | i = 123456789012345678901234567890 2 | print(i >> 1) 3 | print(i >> 1000) 4 | 5 | # result needs rounding up 6 | print(-(1<<70) >> 80) 7 | -------------------------------------------------------------------------------- /tests/basics/memoryerror.py: -------------------------------------------------------------------------------- 1 | l = list(range(1000)) 2 | try: 3 | 1000000000 * l 4 | except MemoryError: 5 | print('MemoryError') 6 | print(len(l), l[0], l[-1]) 7 | -------------------------------------------------------------------------------- /tests/float/bytes_construct.py: -------------------------------------------------------------------------------- 1 | # test construction of bytearray from array with float type 2 | 3 | from array import array 4 | 5 | print(bytes(array('f', [1, 2.3]))) 6 | -------------------------------------------------------------------------------- /tests/micropython/native_const.py: -------------------------------------------------------------------------------- 1 | # check loading constants 2 | 3 | @micropython.native 4 | def f(): 5 | return 123456789012345678901234567890 6 | 7 | print(f()) 8 | -------------------------------------------------------------------------------- /tests/micropython/viper_addr.py.exp: -------------------------------------------------------------------------------- 1 | 2 | 3 | bytearray(b'0000') 4 | bytearray(b'1111') 5 | bytearray(b'2222') 6 | bytearray(b'2233') 7 | -------------------------------------------------------------------------------- /tests/pyb/accel.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | 3 | accel = pyb.Accel() 4 | print(accel) 5 | accel.x() 6 | accel.y() 7 | accel.z() 8 | accel.tilt() 9 | accel.filtered_xyz() 10 | -------------------------------------------------------------------------------- /tests/bench/func_builtin-1-enum_pos.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num//20)): 5 | enumerate([1, 2], 1) 6 | 7 | bench.run(test) 8 | -------------------------------------------------------------------------------- /tests/feature_check/repl_emacs_check.py.exp: -------------------------------------------------------------------------------- 1 | MicroPython \.\+ version 2 | Use \.\+ 3 | >>> # Check for emacs keys in REPL 4 | >>> t = \.\+ 5 | >>> t == 2 6 | True 7 | >>> 8 | -------------------------------------------------------------------------------- /tests/import/import_pkg5.py: -------------------------------------------------------------------------------- 1 | # This tests relative imports as used in pkg3 2 | import pkg3 3 | import pkg3.mod1 4 | import pkg3.subpkg1.mod1 5 | 6 | pkg3.subpkg1.mod1.foo() 7 | -------------------------------------------------------------------------------- /tests/micropython/viper_ptr16_store.py.exp: -------------------------------------------------------------------------------- 1 | bytearray(b'\x00\x00\x00\x00') 2 | bytearray(b'BB\x00\x00') 3 | bytearray(b'BBCC') 4 | bytearray(b'DDDD') 5 | bytearray(b'EEEE') 6 | -------------------------------------------------------------------------------- /docs/pyboard/tutorial/img/fading_leds_breadboard_fritzing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewelse/micropython/HEAD/docs/pyboard/tutorial/img/fading_leds_breadboard_fritzing.png -------------------------------------------------------------------------------- /examples/hwapi/hwconfig_z_frdm_k64f.py: -------------------------------------------------------------------------------- 1 | from machine import Pin 2 | 3 | # Freescale/NXP FRDM-K64F board 4 | # Blue LED on port B, pin 21 5 | LED = Pin(("GPIO_1", 21), Pin.OUT) 6 | -------------------------------------------------------------------------------- /tests/basics/builtin_round.py: -------------------------------------------------------------------------------- 1 | # test round() with integral values 2 | 3 | tests = [ 4 | False, True, 5 | 0, 1, -1, 10 6 | ] 7 | for t in tests: 8 | print(round(t)) 9 | -------------------------------------------------------------------------------- /tests/basics/dict_specialmeth.py: -------------------------------------------------------------------------------- 1 | # dict object with special methods 2 | 3 | d = {} 4 | d.__setitem__('2', 'two') 5 | print(d.__getitem__('2')) 6 | d.__delitem__('2') 7 | print(d) 8 | -------------------------------------------------------------------------------- /tests/basics/fun2.py: -------------------------------------------------------------------------------- 1 | # calling a function from a function 2 | 3 | def f(x): 4 | print(x + 1) 5 | 6 | def g(x): 7 | f(2 * x) 8 | f(4 * x) 9 | 10 | g(3) 11 | -------------------------------------------------------------------------------- /tests/basics/module2.py: -------------------------------------------------------------------------------- 1 | # uPy behaviour only: builtin modules are read-only 2 | import sys 3 | try: 4 | sys.x = 1 5 | except AttributeError: 6 | print("AttributeError") 7 | -------------------------------------------------------------------------------- /tests/bench/loop_count-5.1-while_down_ne_localvar.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | zero = 0 5 | while num != zero: 6 | num -= 1 7 | 8 | bench.run(test) 9 | -------------------------------------------------------------------------------- /tests/bench/var-4-arg.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | 4 | def test(num): 5 | i = 0 6 | while i < num: 7 | i += 1 8 | 9 | bench.run(lambda n:test(20000000)) 10 | -------------------------------------------------------------------------------- /tests/cmdline/repl_basic.py.exp: -------------------------------------------------------------------------------- 1 | MicroPython \.\+ version 2 | Use \.\+ 3 | >>> # basic REPL tests 4 | >>> print(1) 5 | 1 6 | >>> print(1) 7 | 1 8 | >>> 2 9 | 2 10 | >>> 11 | -------------------------------------------------------------------------------- /tests/float/bytearray_construct.py: -------------------------------------------------------------------------------- 1 | # test construction of bytearray from array with float type 2 | 3 | from array import array 4 | 5 | print(bytearray(array('f', [1, 2.3]))) 6 | -------------------------------------------------------------------------------- /tests/import/gen_context.py: -------------------------------------------------------------------------------- 1 | import gen_context2 2 | 3 | GLOBAL = "GLOBAL" 4 | 5 | def gen(): 6 | print(GLOBAL) 7 | yield 1 8 | 9 | gen_context2.call(gen()) 10 | -------------------------------------------------------------------------------- /tests/io/file_readinto_len.py.exp: -------------------------------------------------------------------------------- 1 | 8 2 | bytearray(b'longer l\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') 3 | 4 4 | bytearray(b'long') 5 | -------------------------------------------------------------------------------- /tests/micropython/viper_ptr8_store.py.exp: -------------------------------------------------------------------------------- 1 | bytearray(b'\x00\x00\x00\x00') 2 | bytearray(b')\x00\x00\x00') 3 | bytearray(b')*\x00\x00') 4 | bytearray(b'++++') 5 | bytearray(b',,,,') 6 | -------------------------------------------------------------------------------- /tests/pyb/i2c.py.exp: -------------------------------------------------------------------------------- 1 | ValueError -1 2 | ValueError 0 3 | I2C 1 4 | I2C 2 5 | ValueError 3 6 | I2C X 7 | I2C Y 8 | ValueError Z 9 | [] 10 | [76] 11 | True 12 | b'\x01' 13 | -------------------------------------------------------------------------------- /zephyr/prj.mdef: -------------------------------------------------------------------------------- 1 | % Application : MicroPython 2 | 3 | % TASK NAME PRIO ENTRY STACK GROUPS 4 | % ================================== 5 | TASK MAIN 7 main 4096 [EXE] 6 | -------------------------------------------------------------------------------- /drivers/cc3000/inc/inet_ntop.h: -------------------------------------------------------------------------------- 1 | #ifndef __INET_NTOP_H 2 | #define __INET_NTOP_H 3 | char *inet_ntop(int af, const void *addr, char *buf, size_t size); 4 | #endif /* __INET_NTOP_H */ 5 | -------------------------------------------------------------------------------- /stmhal/boards/LIMIFROG/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = l4 2 | CMSIS_MCU = STM32L476xx 3 | AF_FILE = boards/stm32l476_af.csv 4 | LD_FILE = boards/stm32l476xe.ld 5 | TEXT_ADDR = 0x08004000 6 | -------------------------------------------------------------------------------- /tests/basics/array_construct2.py: -------------------------------------------------------------------------------- 1 | from array import array 2 | 3 | # construct from something with unknown length (requires generators) 4 | print(array('i', (i for i in range(10)))) 5 | -------------------------------------------------------------------------------- /tests/basics/fun3.py: -------------------------------------------------------------------------------- 1 | # function with large number of arguments 2 | 3 | def fun(a, b, c, d, e, f, g): 4 | return a + b + c * d + e * f * g 5 | 6 | print(fun(1, 2, 3, 4, 5, 6, 7)) 7 | -------------------------------------------------------------------------------- /tests/basics/string_crlf_conversion.py: -------------------------------------------------------------------------------- 1 | # this file has CRLF line endings to test lexer's conversion of them to LF 2 | # in triple quoted strings 3 | print(repr("""abc 4 | def""")) 5 | -------------------------------------------------------------------------------- /tests/bench/bench.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | 4 | ITERS = 20000000 5 | 6 | def run(f): 7 | t = time.time() 8 | f(ITERS) 9 | t = time.time() - t 10 | print(t) 11 | -------------------------------------------------------------------------------- /tests/bench/var-2-global.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | ITERS = 20000000 4 | 5 | def test(num): 6 | i = 0 7 | while i < ITERS: 8 | i += 1 9 | 10 | bench.run(test) 11 | -------------------------------------------------------------------------------- /tests/inlineasm/asmpushpop.py: -------------------------------------------------------------------------------- 1 | @micropython.asm_thumb 2 | def f(r0, r1, r2): 3 | push({r0}) 4 | push({r1, r2}) 5 | pop({r0}) 6 | pop({r1, r2}) 7 | 8 | print(f(0, 1, 2)) 9 | -------------------------------------------------------------------------------- /tests/stress/dict_copy.py: -------------------------------------------------------------------------------- 1 | # copying a large dictionary 2 | 3 | a = {i:2*i for i in range(1000)} 4 | b = a.copy() 5 | for i in range(1000): 6 | print(i, b[i]) 7 | print(len(b)) 8 | -------------------------------------------------------------------------------- /stmhal/boards/STM32L476DISC/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = l4 2 | CMSIS_MCU = STM32L476xx 3 | AF_FILE = boards/stm32l476_af.csv 4 | LD_FILE = boards/stm32l476xg.ld 5 | TEXT_ADDR = 0x08004000 6 | -------------------------------------------------------------------------------- /tests/basics/list_insert.py: -------------------------------------------------------------------------------- 1 | a = [1, 2, 3] 2 | a.insert(1, 42) 3 | print(a) 4 | a.insert(-1, -1) 5 | print(a) 6 | a.insert(99, 99) 7 | print(a) 8 | a.insert(-99, -99) 9 | print(a) 10 | -------------------------------------------------------------------------------- /tests/bench/func_builtin-2-enum_kw.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num//20)): 5 | enumerate(iterable=[1, 2], start=1) 6 | 7 | bench.run(test) 8 | -------------------------------------------------------------------------------- /tests/bench/var-3-local.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | 4 | def test(num): 5 | ITERS = 20000000 6 | i = 0 7 | while i < ITERS: 8 | i += 1 9 | 10 | bench.run(test) 11 | -------------------------------------------------------------------------------- /tests/stress/list_sort.py: -------------------------------------------------------------------------------- 1 | # test large list sorting (should not stack overflow) 2 | l = list(range(2000)) 3 | l.sort() 4 | print(l[0], l[-1]) 5 | l.sort(reverse=True) 6 | print(l[0], l[-1]) 7 | -------------------------------------------------------------------------------- /examples/micropython.py: -------------------------------------------------------------------------------- 1 | # micropython module placeholder for CPython 2 | 3 | # Dummy function decorators 4 | 5 | def nodecor(x): 6 | return x 7 | 8 | bytecode = native = viper = nodecor 9 | -------------------------------------------------------------------------------- /tests/basics/set_isfooset.py: -------------------------------------------------------------------------------- 1 | sets = [set(), {1}, {1, 2, 3}, {3, 4, 5}, {5, 6, 7}] 2 | for i in sets: 3 | for j in sets: 4 | print(i.issubset(j)) 5 | print(i.issuperset(j)) 6 | -------------------------------------------------------------------------------- /tests/basics/set_pop.py: -------------------------------------------------------------------------------- 1 | s = {1} 2 | print(s.pop()) 3 | try: 4 | print(s.pop(), "!!!") 5 | except KeyError: 6 | pass 7 | else: 8 | print("Failed to raise KeyError") 9 | 10 | -------------------------------------------------------------------------------- /tests/bench/from_iter-1-list_bound.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num//10000)): 5 | l = [0] * 1000 6 | l2 = list(l) 7 | 8 | bench.run(test) 9 | -------------------------------------------------------------------------------- /docs/unix_contents.rst: -------------------------------------------------------------------------------- 1 | MicroPython documentation contents 2 | ================================== 3 | 4 | .. toctree:: 5 | 6 | library/index.rst 7 | reference/index.rst 8 | license.rst 9 | -------------------------------------------------------------------------------- /stmhal/mpconfigport.mk: -------------------------------------------------------------------------------- 1 | # Enable/disable extra modules 2 | 3 | # wiznet5k module for ethernet support 4 | MICROPY_PY_WIZNET5K ?= 0 5 | 6 | # cc3k module for wifi support 7 | MICROPY_PY_CC3K ?= 0 8 | -------------------------------------------------------------------------------- /teensy/servo.h: -------------------------------------------------------------------------------- 1 | void servo_init(void); 2 | 3 | extern const mp_obj_type_t pyb_servo_type; 4 | 5 | MP_DECLARE_CONST_FUN_OBJ_2(pyb_servo_set_obj); 6 | MP_DECLARE_CONST_FUN_OBJ_2(pyb_pwm_set_obj); 7 | 8 | -------------------------------------------------------------------------------- /tests/basics/int_big_cmp.py: -------------------------------------------------------------------------------- 1 | # test bignum comparisons 2 | 3 | i = 1 << 65 4 | 5 | print(i == 0) 6 | print(i != 0) 7 | print(i < 0) 8 | print(i > 0) 9 | print(i <= 0) 10 | print(i >= 0) 11 | -------------------------------------------------------------------------------- /tests/basics/slice_bignum.py: -------------------------------------------------------------------------------- 1 | # test slicing when arguments are bignums 2 | 3 | print(list(range(10))[(1<<66)>>65:]) 4 | print(list(range(10))[:(1<<66)>>65]) 5 | print(list(range(10))[::(1<<66)>>65]) 6 | -------------------------------------------------------------------------------- /tests/basics/try1.py: -------------------------------------------------------------------------------- 1 | # basic exceptions 2 | x = 1 3 | try: 4 | x.a() 5 | except: 6 | print(x) 7 | 8 | try: 9 | raise IndexError 10 | except IndexError: 11 | print("caught") 12 | -------------------------------------------------------------------------------- /tests/bench/from_iter-3-tuple_bound.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num//10000)): 5 | l = [0] * 1000 6 | l2 = tuple(l) 7 | 8 | bench.run(test) 9 | -------------------------------------------------------------------------------- /tests/bench/from_iter-5-bytes_bound.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num//10000)): 5 | l = [0] * 1000 6 | l2 = bytes(l) 7 | 8 | bench.run(test) 9 | -------------------------------------------------------------------------------- /tests/bench/func_args-1.1-pos_1.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def func(a): 4 | pass 5 | 6 | def test(num): 7 | for i in iter(range(num)): 8 | func(i) 9 | 10 | bench.run(test) 11 | -------------------------------------------------------------------------------- /tests/bench/func_args-3.1-kw_1.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def func(a): 4 | pass 5 | 6 | def test(num): 7 | for i in iter(range(num)): 8 | func(a=i) 9 | 10 | bench.run(test) 11 | -------------------------------------------------------------------------------- /tests/basics/array_construct_endian.py: -------------------------------------------------------------------------------- 1 | # test construction of array.array from different objects 2 | 3 | from array import array 4 | 5 | # raw copy from bytes, bytearray 6 | print(array('h', b'12')) 7 | -------------------------------------------------------------------------------- /tests/basics/bytes_format_modulo.py: -------------------------------------------------------------------------------- 1 | # This test requires CPython3.5 2 | print(b"%%" % ()) 3 | print(b"=%d=" % 1) 4 | print(b"=%d=%d=" % (1, 2)) 5 | 6 | print(b"=%s=" % b"str") 7 | print(b"=%r=" % b"str") 8 | -------------------------------------------------------------------------------- /tests/basics/closure_namedarg.py: -------------------------------------------------------------------------------- 1 | # test passing named arg to closed-over function 2 | 3 | def f(): 4 | x = 1 5 | def g(z): 6 | print(x, z) 7 | return g 8 | 9 | f()(z=42) 10 | -------------------------------------------------------------------------------- /tests/basics/set_isdisjoint.py: -------------------------------------------------------------------------------- 1 | s = {1, 2, 3, 4} 2 | print(s.isdisjoint({1})) 3 | print(s.isdisjoint([2])) 4 | print(s.isdisjoint([])) 5 | print(s.isdisjoint({7,8,9,10})) 6 | print(s.isdisjoint([7,8,9,1])) 7 | -------------------------------------------------------------------------------- /tests/bench/from_iter-7-bytearray_bound.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num//10000)): 5 | l = [0] * 1000 6 | l2 = bytearray(l) 7 | 8 | bench.run(test) 9 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_le.py.exp: -------------------------------------------------------------------------------- 1 | 0x3130 2 | 48 49 3 | TypeError 4 | arr: 48 49 5 | arr of struct: 48 49 6 | IndexError 7 | bf: 48 49 8 | bf 4bit: 3 1 3 0 9 | bytearray(b'21') 10 | bytearray(b'2Q') 11 | -------------------------------------------------------------------------------- /extmod/lwip-include/arch/perf.h: -------------------------------------------------------------------------------- 1 | #ifndef __PERF_H__ 2 | #define __PERF_H__ 3 | 4 | #define PERF_START /* null definition */ 5 | #define PERF_STOP(x) /* null definition */ 6 | 7 | #endif /* __PERF_H__ */ 8 | -------------------------------------------------------------------------------- /lib/embed/abort_.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | NORETURN void abort_(void); 4 | 5 | NORETURN void abort_(void) { 6 | nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "abort() called")); 7 | } 8 | -------------------------------------------------------------------------------- /tests/basics/builtin_chr.py: -------------------------------------------------------------------------------- 1 | # test builtin chr (whether or not we support unicode) 2 | 3 | print(chr(65)) 4 | 5 | try: 6 | chr(0x110000) 7 | except ValueError: 8 | print("ValueError") 9 | 10 | -------------------------------------------------------------------------------- /tests/basics/for2.py: -------------------------------------------------------------------------------- 1 | i = 'init' 2 | for i in range(0): 3 | pass 4 | print(i) # should not have been modified 5 | 6 | for i in range(10): 7 | pass 8 | print(i) # should be last successful value of loop 9 | -------------------------------------------------------------------------------- /tests/basics/map.py: -------------------------------------------------------------------------------- 1 | print(list(map(lambda x: x & 1, range(-3, 4)))) 2 | print(list(map(abs, range(-3, 4)))) 3 | print(list(map(set, [[i] for i in range(-3, 4)]))) 4 | print(list(map(pow, range(4), range(4)))) 5 | -------------------------------------------------------------------------------- /tests/bench/func_args-1.2-pos_3.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def func(a, b, c): 4 | pass 5 | 6 | def test(num): 7 | for i in iter(range(num)): 8 | func(i, i, i) 9 | 10 | bench.run(test) 11 | -------------------------------------------------------------------------------- /tests/bench/var-5-class-attr.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | class Foo: 4 | num = 20000000 5 | 6 | def test(num): 7 | i = 0 8 | while i < Foo.num: 9 | i += 1 10 | 11 | bench.run(test) 12 | -------------------------------------------------------------------------------- /tests/float/array_construct.py: -------------------------------------------------------------------------------- 1 | # test construction of array from array with float type 2 | 3 | from array import array 4 | 5 | print(array('f', array('h', [1, 2]))) 6 | print(array('d', array('f', [1, 2]))) 7 | -------------------------------------------------------------------------------- /tests/inlineasm/asmconst.py: -------------------------------------------------------------------------------- 1 | # test constants in assembler 2 | 3 | @micropython.asm_thumb 4 | def c1(): 5 | movwt(r0, 0xffffffff) 6 | movwt(r1, 0xf0000000) 7 | sub(r0, r0, r1) 8 | print(hex(c1())) 9 | -------------------------------------------------------------------------------- /tests/micropython/viper_ptr32_store.py.exp: -------------------------------------------------------------------------------- 1 | bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') 2 | bytearray(b'BBBB\x00\x00\x00\x00') 3 | bytearray(b'BBBBCCCC') 4 | bytearray(b'DDDDDDDD') 5 | bytearray(b'EEEEEEEE') 6 | -------------------------------------------------------------------------------- /tests/basics/generator_return.py: -------------------------------------------------------------------------------- 1 | def gen(): 2 | yield 1 3 | return 42 4 | 5 | g = gen() 6 | print(next(g)) 7 | try: 8 | print(next(g)) 9 | except StopIteration as e: 10 | print(repr(e)) 11 | -------------------------------------------------------------------------------- /tests/bench/from_iter-2-list_unbound.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num//10000)): 5 | l = [0] * 1000 6 | l2 = list(map(lambda x: x, l)) 7 | 8 | bench.run(test) 9 | -------------------------------------------------------------------------------- /tests/bench/func_args-3.2-kw_3.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def func(a, b, c): 4 | pass 5 | 6 | def test(num): 7 | for i in iter(range(num)): 8 | func(c=i, b=i, a=i) 9 | 10 | bench.run(test) 11 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_native_le.py.exp: -------------------------------------------------------------------------------- 1 | 0x3130 2 | 48 49 3 | TypeError 4 | arr: 48 49 5 | arr of struct: 48 49 6 | IndexError 7 | bf: 48 49 8 | bf 4bit: 3 1 3 0 9 | bytearray(b'21') 10 | bytearray(b'2Q') 11 | -------------------------------------------------------------------------------- /tests/jni/system_out.py: -------------------------------------------------------------------------------- 1 | import sys 2 | try: 3 | import jni 4 | System = jni.cls("java/lang/System") 5 | except: 6 | print("SKIP") 7 | sys.exit() 8 | 9 | System.out.println("Hello, Java!") 10 | -------------------------------------------------------------------------------- /tests/unicode/unicode_index.py: -------------------------------------------------------------------------------- 1 | print("Привет".find("т")) 2 | print("Привет".find("П")) 3 | print("Привет".rfind("т")) 4 | print("Привет".rfind("П")) 5 | print("Привет".index("т")) 6 | print("Привет".index("П")) 7 | -------------------------------------------------------------------------------- /tests/unicode/unicode_pos.py: -------------------------------------------------------------------------------- 1 | # str methods with explicit start/end pos 2 | print("Привет".startswith("П")) 3 | print("Привет".startswith("р", 1)) 4 | print("абвба".find("а", 1)) 5 | print("абвба".find("а", 1, -1)) 6 | -------------------------------------------------------------------------------- /tests/basics/bytes_construct_endian.py: -------------------------------------------------------------------------------- 1 | # test construction of bytes from different objects 2 | 3 | from array import array 4 | 5 | # arrays 6 | print(bytes(array('h', [1, 2]))) 7 | print(bytes(array('I', [1, 2]))) 8 | -------------------------------------------------------------------------------- /tests/basics/int_divzero.py: -------------------------------------------------------------------------------- 1 | try: 2 | 1 // 0 3 | except ZeroDivisionError: 4 | print("ZeroDivisionError") 5 | 6 | try: 7 | 1 % 0 8 | except ZeroDivisionError: 9 | print("ZeroDivisionError") 10 | -------------------------------------------------------------------------------- /tests/basics/set_intersection.py: -------------------------------------------------------------------------------- 1 | s = {1, 2, 3, 4} 2 | print(sorted(s)) 3 | print(sorted(s.intersection({1, 3}))) 4 | print(sorted(s.intersection([3, 4]))) 5 | 6 | print(s.intersection_update([1])) 7 | print(sorted(s)) 8 | -------------------------------------------------------------------------------- /tests/basics/subclass_native4.py: -------------------------------------------------------------------------------- 1 | # Test calling non-special method inherited from native type 2 | 3 | class mylist(list): 4 | pass 5 | 6 | l = mylist([1, 2, 3]) 7 | print(l) 8 | l.append(10) 9 | print(l) 10 | -------------------------------------------------------------------------------- /tests/bench/from_iter-4-tuple_unbound.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num//10000)): 5 | l = [0] * 1000 6 | l2 = tuple(map(lambda x: x, l)) 7 | 8 | bench.run(test) 9 | -------------------------------------------------------------------------------- /tests/bench/from_iter-6-bytes_unbound.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num//10000)): 5 | l = [0] * 1000 6 | l2 = bytes(map(lambda x: x, l)) 7 | 8 | bench.run(test) 9 | -------------------------------------------------------------------------------- /tests/bench/func_args-2-pos_default_2_of_3.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def func(a, b=1, c=2): 4 | pass 5 | 6 | def test(num): 7 | for i in iter(range(num)): 8 | func(i) 9 | 10 | bench.run(test) 11 | -------------------------------------------------------------------------------- /tests/cmdline/repl_emacs_keys.py: -------------------------------------------------------------------------------- 1 | # REPL tests of GNU-ish readline navigation 2 | # history buffer navigation 3 | 1 4 | 2 5 | 3 6 |  7 |  8 | # input line motion 9 | t = 12 10 | 'boofar fbar' 11 | -------------------------------------------------------------------------------- /emscripten/frozentest.py: -------------------------------------------------------------------------------- 1 | print('uPy') 2 | print('a long string that is not interned') 3 | print('a string that has unicode αβγ chars') 4 | print(b'bytes 1234\x01') 5 | print(123456789) 6 | for i in range(4): 7 | print(i) 8 | -------------------------------------------------------------------------------- /minimal/frozentest.py: -------------------------------------------------------------------------------- 1 | print('uPy') 2 | print('a long string that is not interned') 3 | print('a string that has unicode αβγ chars') 4 | print(b'bytes 1234\x01') 5 | print(123456789) 6 | for i in range(4): 7 | print(i) 8 | -------------------------------------------------------------------------------- /tests/basics/dict_fromkeys.py: -------------------------------------------------------------------------------- 1 | d = dict.fromkeys([1, 2, 3, 4]) 2 | l = list(d.keys()) 3 | l.sort() 4 | print(l) 5 | 6 | d = dict.fromkeys([1, 2, 3, 4], 42) 7 | l = list(d.values()) 8 | l.sort() 9 | print(l) 10 | 11 | -------------------------------------------------------------------------------- /tests/basics/string_repr.py: -------------------------------------------------------------------------------- 1 | # anything above 0xa0 is printed as Unicode by CPython 2 | # the abobe is CPython implementation detail, stick to ASCII 3 | for c in range(0x80): 4 | print("0x%02x: %s" % (c, repr(chr(c)))) 5 | -------------------------------------------------------------------------------- /tests/bench/from_iter-8-bytearray_unbound.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | def test(num): 4 | for i in iter(range(num//10000)): 5 | l = [0] * 1000 6 | l2 = bytearray(map(lambda x: x, l)) 7 | 8 | bench.run(test) 9 | -------------------------------------------------------------------------------- /tests/io/stringio_with.py: -------------------------------------------------------------------------------- 1 | try: 2 | import uio as io 3 | except ImportError: 4 | import io 5 | 6 | # test __enter__/__exit__ 7 | with io.StringIO() as b: 8 | b.write("foo") 9 | print(b.getvalue()) 10 | -------------------------------------------------------------------------------- /tests/micropython/viper_binop_comp.py.exp: -------------------------------------------------------------------------------- 1 | 1 == 1 2 | 1 <= 1 3 | 1 >= 1 4 | 2 > 1 5 | 2 >= 1 6 | 2 != 1 7 | 1 < 2 8 | 1 <= 2 9 | 1 != 2 10 | 2 > -1 11 | 2 >= -1 12 | 2 != -1 13 | -2 < 1 14 | -2 <= 1 15 | -2 != 1 16 | -------------------------------------------------------------------------------- /tests/micropython/viper_misc.py.exp: -------------------------------------------------------------------------------- 1 | 6 2 | 3 3 | 0 4 | Ellipsis 5 | 6 6 | 7 7 | 20 8 | True 9 | 49994955 10 | 1 1 11 | 1 3 12 | (0, 1, False, True) 13 | (1, 3) 14 | [1, 3] 15 | [1, 3] 16 | OSError(1,) 17 | 1 18 | 1 19 | -------------------------------------------------------------------------------- /tests/basics/exception_chain.py: -------------------------------------------------------------------------------- 1 | # Exception chaining is not supported, but check that basic 2 | # exception works as expected. 3 | try: 4 | raise Exception from None 5 | except Exception: 6 | print("Caught Exception") 7 | -------------------------------------------------------------------------------- /tests/basics/return1.py: -------------------------------------------------------------------------------- 1 | # test return statement 2 | 3 | def f(): 4 | return 5 | print(f()) 6 | 7 | def g(): 8 | return 1 9 | print(g()) 10 | 11 | def f(x): 12 | return 1 if x else 2 13 | print(f(0), f(1)) 14 | -------------------------------------------------------------------------------- /tests/basics/set_symmetric_difference.py: -------------------------------------------------------------------------------- 1 | print(sorted({1,2}.symmetric_difference({2,3}))) 2 | print(sorted({1,2}.symmetric_difference([2,3]))) 3 | s = {1,2} 4 | print(s.symmetric_difference_update({2,3})) 5 | print(sorted(s)) 6 | -------------------------------------------------------------------------------- /tests/wipy/pin_irq.py.exp: -------------------------------------------------------------------------------- 1 | True 2 | True 3 | True 4 | True 5 | True 6 | True 7 | True 8 | True 9 | True 10 | True 11 | True 12 | True 13 | True 14 | Awake 15 | True 16 | Awake 17 | Exception 18 | Exception 19 | Exception 20 | -------------------------------------------------------------------------------- /tools/.gitignore: -------------------------------------------------------------------------------- 1 | tinytest/.gitignore 2 | tinytest/.travis.yml 3 | tinytest/Makefile 4 | tinytest/Makefile.arm-cortex-m3-qemu 5 | tinytest/Makefile.avr 6 | tinytest/TODO 7 | tinytest/portable_demo.c 8 | tinytest/tinytest_demo.c 9 | -------------------------------------------------------------------------------- /tests/basics/bytearray_construct_endian.py: -------------------------------------------------------------------------------- 1 | # test construction of bytearray from different objects 2 | 3 | from array import array 4 | 5 | # arrays 6 | print(bytearray(array('h', [1, 2]))) 7 | print(bytearray(array('I', [1, 2]))) 8 | -------------------------------------------------------------------------------- /tests/basics/iter_of_iter.py: -------------------------------------------------------------------------------- 1 | i = iter(iter((1, 2, 3))) 2 | print(list(i)) 3 | i = iter(iter([1, 2, 3])) 4 | print(list(i)) 5 | i = iter(iter({1:2, 3:4, 5:6})) 6 | print(sorted(i)) 7 | i = iter(iter({1, 2, 3})) 8 | print(sorted(i)) 9 | -------------------------------------------------------------------------------- /tests/pyb/dac.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | 3 | dac = pyb.DAC(1) 4 | print(dac) 5 | dac.noise(100) 6 | dac.triangle(100) 7 | dac.write(0) 8 | dac.write_timed(bytearray(10), 100, mode=pyb.DAC.NORMAL) 9 | pyb.delay(20) 10 | dac.write(0) 11 | -------------------------------------------------------------------------------- /unix/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | build-fast 3 | build-minimal 4 | build-coverage 5 | build-nanbox 6 | micropython 7 | micropython_fast 8 | micropython_minimal 9 | micropython_coverage 10 | micropython_nanbox 11 | *.py 12 | *.gcov 13 | -------------------------------------------------------------------------------- /tests/basics/closure_defargs.py: -------------------------------------------------------------------------------- 1 | # test closure with default args 2 | 3 | def f(): 4 | a = 1 5 | def bar(b = 10, c = 20): 6 | print(a + b + c) 7 | bar() 8 | bar(2) 9 | bar(2, 3) 10 | 11 | print(f()) 12 | -------------------------------------------------------------------------------- /tests/basics/string_escape.py: -------------------------------------------------------------------------------- 1 | a = "a\1b" 2 | print(len(a)) 3 | print(ord(a[1])) 4 | print(len("a\123b")) 5 | a = "a\12345b" 6 | print(len(a)) 7 | print(ord(a[1])) 8 | 9 | a = "a\xffb" 10 | print(len(a)) 11 | print(ord(a[1])) 12 | -------------------------------------------------------------------------------- /tests/pyb/pin.py.exp: -------------------------------------------------------------------------------- 1 | Pin(Pin.cpu.A0, mode=Pin.IN) 2 | A0 3 | 0 4 | 0 5 | Pin(Pin.cpu.A0, mode=Pin.IN, pull=Pin.PULL_UP) 6 | 1 7 | Pin(Pin.cpu.A0, mode=Pin.IN, pull=Pin.PULL_DOWN) 8 | 0 9 | 0 10 | 1 11 | 0 12 | 1 13 | 0 14 | 1 15 | -------------------------------------------------------------------------------- /drivers/wiznet5k/README.md: -------------------------------------------------------------------------------- 1 | This is the driver for the WIZnet5x00 series of Ethernet controllers. 2 | 3 | Adapted for Micro Python. 4 | 5 | Original source: https://github.com/Wiznet/W5500_EVB/tree/master/ioLibrary 6 | Taken on: 30 August 2014 7 | -------------------------------------------------------------------------------- /teensy/memzip_files/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | 3 | print("Executing main.py") 4 | 5 | led = pyb.LED(1) 6 | 7 | led.on() 8 | pyb.delay(100) 9 | led.off() 10 | pyb.delay(100) 11 | led.on() 12 | pyb.delay(100) 13 | led.off() 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/basics/builtin_eval.py: -------------------------------------------------------------------------------- 1 | # builtin eval 2 | 3 | eval('1 + 2') 4 | eval('1 + 2\n') 5 | eval('1 + 2\n\n#comment\n') 6 | 7 | x = 4 8 | eval('x') 9 | 10 | eval('lambda x: x + 10')(-5) 11 | 12 | y = 6 13 | eval('lambda: y * 2')() 14 | -------------------------------------------------------------------------------- /tests/basics/builtin_len1.py: -------------------------------------------------------------------------------- 1 | # builtin len 2 | 3 | print(len(())) 4 | print(len((1,))) 5 | print(len((1, 2))) 6 | 7 | print(len([])) 8 | x = [1, 2, 3] 9 | print(len(x)) 10 | 11 | f = len 12 | print(f({})) 13 | print(f({1:2, 3:4})) 14 | -------------------------------------------------------------------------------- /tests/basics/list_remove.py: -------------------------------------------------------------------------------- 1 | a = [1, 2, 3] 2 | print(a.remove(2)) 3 | print(a) 4 | try: 5 | a.remove(2) 6 | except ValueError: 7 | print("Raised ValueError") 8 | else: 9 | raise AssertionError("Did not raise ValueError") 10 | -------------------------------------------------------------------------------- /tests/inlineasm/asmspecialregs.py: -------------------------------------------------------------------------------- 1 | @micropython.asm_thumb 2 | def getIPSR(): 3 | mrs(r0, IPSR) 4 | 5 | @micropython.asm_thumb 6 | def getBASEPRI(): 7 | mrs(r0, BASEPRI) 8 | 9 | print(getBASEPRI()) 10 | print(getIPSR()) 11 | 12 | -------------------------------------------------------------------------------- /teensy/led.h: -------------------------------------------------------------------------------- 1 | typedef enum { 2 | PYB_LED_BUILTIN = 1, 3 | } pyb_led_t; 4 | 5 | void led_init(void); 6 | void led_state(pyb_led_t led, int state); 7 | void led_toggle(pyb_led_t led); 8 | 9 | extern const mp_obj_type_t pyb_led_type; 10 | -------------------------------------------------------------------------------- /tests/basics/builtin_pow.py: -------------------------------------------------------------------------------- 1 | # test builtin pow() with integral values 2 | 3 | # 2 arg version 4 | print(pow(0, 1)) 5 | print(pow(1, 0)) 6 | print(pow(-2, 3)) 7 | print(pow(3, 8)) 8 | 9 | # 3 arg version 10 | print(pow(3, 4, 7)) 11 | 12 | -------------------------------------------------------------------------------- /tests/basics/builtin_slice.py: -------------------------------------------------------------------------------- 1 | # test builtin slice 2 | 3 | # print slice 4 | class A: 5 | def __getitem__(self, idx): 6 | print(idx) 7 | return idx 8 | s = A()[1:2:3] 9 | 10 | # check type 11 | print(type(s) is slice) 12 | -------------------------------------------------------------------------------- /tests/basics/builtin_type.py: -------------------------------------------------------------------------------- 1 | # test builtin type 2 | 3 | print(type(int)) 4 | 5 | try: 6 | type() 7 | except TypeError: 8 | print('TypeError') 9 | 10 | try: 11 | type(1, 2) 12 | except TypeError: 13 | print('TypeError') 14 | -------------------------------------------------------------------------------- /tests/basics/closure_manyvars.py: -------------------------------------------------------------------------------- 1 | # test closure with lots of closed over variables 2 | 3 | def f(): 4 | a, b, c, d, e, f, g, h = [i for i in range(8)] 5 | def x(): 6 | print(a, b, c, d, e, f, g, h) 7 | x() 8 | 9 | f() 10 | -------------------------------------------------------------------------------- /tests/basics/subclass_native_cmp.py: -------------------------------------------------------------------------------- 1 | # Test calling non-special method inherited from native type 2 | 3 | class mytuple(tuple): 4 | pass 5 | 6 | t = mytuple((1, 2, 3)) 7 | print(t) 8 | print(t == (1, 2, 3)) 9 | print((1, 2, 3) == t) 10 | -------------------------------------------------------------------------------- /tests/extmod/uzlib_decompio.py.exp: -------------------------------------------------------------------------------- 1 | 0 2 | b'h' 3 | 2 4 | b'el' 5 | b'lo' 6 | 7 7 | b'' 8 | b'' 9 | 7 10 | b'0000000000' 11 | b'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' 12 | OSError(22,) 13 | -------------------------------------------------------------------------------- /tests/micropython/viper_binop_comp_imm.py: -------------------------------------------------------------------------------- 1 | # comparisons with immediate boundary values 2 | @micropython.viper 3 | def f(a: int): 4 | print(a == -1, a == -255, a == -256, a == -257) 5 | 6 | f(-1) 7 | f(-255) 8 | f(-256) 9 | f(-257) 10 | -------------------------------------------------------------------------------- /tests/basics/class_use_other.py: -------------------------------------------------------------------------------- 1 | # check that we can use an instance of B in a method of A 2 | 3 | class A: 4 | def store(a, b): 5 | a.value = b 6 | 7 | class B: 8 | pass 9 | 10 | b = B() 11 | A.store(b, 1) 12 | print(b.value) 13 | -------------------------------------------------------------------------------- /tests/basics/getattr.py: -------------------------------------------------------------------------------- 1 | # test __getattr__ 2 | 3 | class A: 4 | def __init__(self, d): 5 | self.d = d 6 | 7 | def __getattr__(self, attr): 8 | return self.d[attr] 9 | 10 | a = A({'a':1, 'b':2}) 11 | print(a.a, a.b) 12 | -------------------------------------------------------------------------------- /tests/basics/try_as_var.py: -------------------------------------------------------------------------------- 1 | try: 2 | raise ValueError(534) 3 | except ValueError as e: 4 | print(repr(e)) 5 | 6 | # Var bound in except block is automatically deleted 7 | try: 8 | e 9 | except NameError: 10 | print("NameError") 11 | -------------------------------------------------------------------------------- /docs/static/customstyle.css: -------------------------------------------------------------------------------- 1 | /* custom CSS for MicroPython docs 2 | */ 3 | 4 | .admonition-difference-to-cpython { 5 | border: 1px solid black; 6 | } 7 | 8 | .admonition-difference-to-cpython .admonition-title { 9 | margin: 4px; 10 | } 11 | -------------------------------------------------------------------------------- /examples/embedding/Makefile: -------------------------------------------------------------------------------- 1 | MPTOP = ../.. 2 | CFLAGS = -std=c99 -I. -I$(MPTOP) -DNO_QSTR 3 | LDFLAGS = -L. 4 | 5 | hello-embed: hello-embed.o -lmicropython 6 | 7 | -lmicropython: 8 | $(MAKE) -f $(MPTOP)/examples/embedding/Makefile.upylib MPTOP=$(MPTOP) 9 | -------------------------------------------------------------------------------- /tests/basics/async_await.py.exp: -------------------------------------------------------------------------------- 1 | 4 2 | 3 3 | 2 4 | 1 5 | 0 6 | 0 7 | 1 8 | 0 9 | 0 10 | 2 11 | 1 12 | 0 13 | 0 14 | 1 15 | 0 16 | 0 17 | 3 18 | 2 19 | 1 20 | 0 21 | 0 22 | 1 23 | 0 24 | 0 25 | 2 26 | 1 27 | 0 28 | 0 29 | 1 30 | 0 31 | 0 32 | finished 33 | -------------------------------------------------------------------------------- /tests/basics/break.py: -------------------------------------------------------------------------------- 1 | while True: 2 | break 3 | 4 | for i in range(4): 5 | print('one', i) 6 | if i > 2: 7 | break 8 | print('two', i) 9 | 10 | for i in [1, 2, 3, 4]: 11 | if i == 3: 12 | break 13 | print(i) 14 | -------------------------------------------------------------------------------- /tests/basics/builtin_sum.py: -------------------------------------------------------------------------------- 1 | # test builtin "sum" 2 | 3 | tests = ( 4 | (), 5 | [], 6 | [0], 7 | [1], 8 | [0, 1, 2], 9 | range(10), 10 | ) 11 | 12 | for test in tests: 13 | print(sum(test)) 14 | print(sum(test, -2)) 15 | -------------------------------------------------------------------------------- /tests/basics/class_instance_override.py: -------------------------------------------------------------------------------- 1 | # test that we can override a class method with an instance method 2 | 3 | class A: 4 | def foo(self): 5 | return 1 6 | 7 | a = A() 8 | print(a.foo()) 9 | a.foo = lambda:2 10 | print(a.foo()) 11 | -------------------------------------------------------------------------------- /tests/basics/subclass_native5.py: -------------------------------------------------------------------------------- 1 | # Subclass from 2 bases explicitly subclasses from object 2 | 3 | class Base1(object): 4 | pass 5 | 6 | class Base2(object): 7 | pass 8 | 9 | class Sub(Base1, Base2): 10 | pass 11 | 12 | o = Sub() 13 | -------------------------------------------------------------------------------- /tests/micropython/viper_import.py: -------------------------------------------------------------------------------- 1 | # test import within viper function 2 | 3 | @micropython.viper 4 | def f(): 5 | import micropython 6 | print(micropython.const(1)) 7 | 8 | from micropython import const 9 | print(const(2)) 10 | f() 11 | -------------------------------------------------------------------------------- /tests/basics/set_unop.py: -------------------------------------------------------------------------------- 1 | # test set unary operations 2 | 3 | print(bool(set())) 4 | print(bool(set('abc'))) 5 | 6 | print(len(set())) 7 | print(len(set('abc'))) 8 | 9 | try: 10 | hash(set('abc')) 11 | except TypeError: 12 | print('TypeError') 13 | -------------------------------------------------------------------------------- /tests/basics/while1.py: -------------------------------------------------------------------------------- 1 | # basic while loop 2 | 3 | x = 0 4 | while x < 2: 5 | y = 0 6 | while y < 2: 7 | z = 0 8 | while z < 2: 9 | z = z + 1 10 | print(x, y, z) 11 | y = y + 1 12 | x = x + 1 13 | -------------------------------------------------------------------------------- /tests/bench/funcall-1-inline.py: -------------------------------------------------------------------------------- 1 | # Function call overhead test 2 | # Establish a baseline for performing a trivial operation inline 3 | import bench 4 | 5 | def test(num): 6 | for i in iter(range(num)): 7 | a = i + 1 8 | 9 | bench.run(test) 10 | -------------------------------------------------------------------------------- /tests/pybnative/for.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | 3 | @micropython.native 4 | def f1(n): 5 | for i in range(n): 6 | print(i) 7 | 8 | f1(4) 9 | 10 | @micropython.native 11 | def f2(r): 12 | for i in r: 13 | print(i) 14 | 15 | f2(range(4)) 16 | -------------------------------------------------------------------------------- /teensy/reg.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | const char *name; 3 | mp_uint_t offset; 4 | } reg_t; 5 | 6 | #define REG_ENTRY(st, name) { #name, offsetof(st, name) } 7 | 8 | mp_obj_t reg_cmd(void *base, reg_t *reg, mp_uint_t num_reg, uint n_args, const mp_obj_t *args); 9 | -------------------------------------------------------------------------------- /tests/basics/frozenset_copy.py: -------------------------------------------------------------------------------- 1 | try: 2 | frozenset 3 | except NameError: 4 | print("SKIP") 5 | import sys 6 | sys.exit() 7 | 8 | s = frozenset({1, 2, 3, 4}) 9 | t = s.copy() 10 | print(type(t)) 11 | for i in s, t: 12 | print(sorted(i)) 13 | -------------------------------------------------------------------------------- /tests/basics/array_add.py: -------------------------------------------------------------------------------- 1 | # test array + array 2 | import array 3 | 4 | a1 = array.array('I', [1]) 5 | a2 = array.array('I', [2]) 6 | print(a1 + a2) 7 | 8 | a1 += array.array('I', [3, 4]) 9 | print(a1) 10 | 11 | a1.extend(array.array('I', [5])) 12 | print(a1) 13 | -------------------------------------------------------------------------------- /tests/basics/gen_yield_from_iter.py: -------------------------------------------------------------------------------- 1 | def gen(): 2 | yield from (1, 2, 3) 3 | 4 | def gen2(): 5 | yield from gen() 6 | 7 | def gen3(): 8 | yield from (4, 5) 9 | yield 6 10 | 11 | print(list(gen())) 12 | print(list(gen2())) 13 | print(list(gen3())) 14 | -------------------------------------------------------------------------------- /tests/bench/var-6-instance-attr.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | class Foo: 4 | 5 | def __init__(self): 6 | self.num = 20000000 7 | 8 | def test(num): 9 | o = Foo() 10 | i = 0 11 | while i < o.num: 12 | i += 1 13 | 14 | bench.run(test) 15 | -------------------------------------------------------------------------------- /teensy/lexerfrozen.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "py/lexer.h" 4 | 5 | mp_import_stat_t mp_import_stat(const char *path) { 6 | return MP_IMPORT_STAT_NO_EXIST; 7 | } 8 | 9 | mp_lexer_t *mp_lexer_new_from_file(const char *filename) { 10 | return NULL; 11 | } 12 | -------------------------------------------------------------------------------- /tests/basics/builtin_bin.py: -------------------------------------------------------------------------------- 1 | # test builtin bin function 2 | 3 | print(bin(1)) 4 | print(bin(-1)) 5 | print(bin(15)) 6 | print(bin(-15)) 7 | 8 | print(bin(12345)) 9 | print(bin(0b10101)) 10 | 11 | print(bin(12345678901234567890)) 12 | print(bin(0b10101010101010101010)) 13 | -------------------------------------------------------------------------------- /tests/basics/builtin_hex.py: -------------------------------------------------------------------------------- 1 | # test builtin hex function 2 | 3 | print(hex(1)) 4 | print(hex(-1)) 5 | print(hex(15)) 6 | print(hex(-15)) 7 | 8 | print(hex(12345)) 9 | print(hex(0x12345)) 10 | 11 | print(hex(12345678901234567890)) 12 | print(hex(0x12345678901234567890)) 13 | -------------------------------------------------------------------------------- /tests/basics/builtin_oct.py: -------------------------------------------------------------------------------- 1 | # test builtin oct function 2 | 3 | print(oct(1)) 4 | print(oct(-1)) 5 | print(oct(15)) 6 | print(oct(-15)) 7 | 8 | print(oct(12345)) 9 | print(oct(0o12345)) 10 | 11 | print(oct(12345678901234567890)) 12 | print(oct(0o12345670123456701234)) 13 | -------------------------------------------------------------------------------- /tests/basics/dict_setdefault.py: -------------------------------------------------------------------------------- 1 | d = {} 2 | print(d.setdefault(1)) 3 | print(d.setdefault(1)) 4 | print(d.setdefault(5, 42)) 5 | print(d.setdefault(5, 1)) 6 | print(d[1]) 7 | print(d[5]) 8 | d.pop(5) 9 | print(d.setdefault(5, 1)) 10 | print(d[1]) 11 | print(d[5]) 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/bench/var-8-namedtuple-1st.py: -------------------------------------------------------------------------------- 1 | import bench 2 | from ucollections import namedtuple 3 | 4 | T = namedtuple("Tup", ["num", "bar"]) 5 | 6 | def test(num): 7 | t = T(20000000, 0) 8 | i = 0 9 | while i < t.num: 10 | i += 1 11 | 12 | bench.run(test) 13 | -------------------------------------------------------------------------------- /tests/inlineasm/asmbitops.py: -------------------------------------------------------------------------------- 1 | @micropython.asm_thumb 2 | def clz(r0): 3 | clz(r0, r0) 4 | 5 | print(clz(0xf0)) 6 | print(clz(0x8000)) 7 | 8 | @micropython.asm_thumb 9 | def rbit(r0): 10 | rbit(r0, r0) 11 | 12 | print(hex(rbit(0xf0))) 13 | print(hex(rbit(0x8000))) 14 | -------------------------------------------------------------------------------- /tests/misc/recursive_data.py: -------------------------------------------------------------------------------- 1 | # This tests that printing recursive data structure doesn't lead to segfault. 2 | import uio as io 3 | 4 | l = [1, 2, 3, None] 5 | l[-1] = l 6 | try: 7 | print(l, file=io.StringIO()) 8 | except RuntimeError: 9 | print("RuntimeError") 10 | -------------------------------------------------------------------------------- /tests/basics/bytes_add.py: -------------------------------------------------------------------------------- 1 | # test bytes + other 2 | 3 | print(b"123" + b"456") 4 | print(b"123" + bytearray(2)) 5 | 6 | import array 7 | 8 | # should be byteorder-neutral 9 | print(b"123" + array.array('h', [0x1515])) 10 | 11 | print(b"\x01\x02" + array.array('b', [1, 2])) 12 | -------------------------------------------------------------------------------- /tests/basics/lambda_defargs.py: -------------------------------------------------------------------------------- 1 | # test default args with lambda 2 | 3 | f = lambda x=1: x 4 | print(f(), f(2), f(x=3)) 5 | 6 | y = 'y' 7 | f = lambda x=y: x 8 | print(f()) 9 | 10 | f = lambda x, y=[]: (x, y) 11 | f(0)[1].append(1) 12 | print(f(1), f(x=2), f(3, 4), f(4, y=5)) 13 | -------------------------------------------------------------------------------- /docs/templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | {% set css_files = css_files + ["_static/customstyle.css"] %} 3 | 4 | {# we change the master_doc variable so that links to the index 5 | page are to index.html instead of _index.html #} 6 | {% set master_doc = "index" %} 7 | -------------------------------------------------------------------------------- /docs/wipy_contents.rst: -------------------------------------------------------------------------------- 1 | MicroPython documentation contents 2 | ================================== 3 | 4 | .. toctree:: 5 | 6 | wipy/quickref.rst 7 | wipy/general.rst 8 | wipy/tutorial/index.rst 9 | library/index.rst 10 | reference/index.rst 11 | license.rst 12 | -------------------------------------------------------------------------------- /tests/basics/builtin_sorted.py: -------------------------------------------------------------------------------- 1 | # test builtin sorted 2 | 3 | print(sorted(set(range(100)))) 4 | print(sorted(set(range(100)), key=lambda x: x + 100*(x % 2))) 5 | 6 | # need to use keyword argument 7 | try: 8 | sorted([], None) 9 | except TypeError: 10 | print("TypeError") 11 | -------------------------------------------------------------------------------- /tests/basics/class_store.py: -------------------------------------------------------------------------------- 1 | # store to class vs instance 2 | 3 | class C: 4 | pass 5 | 6 | c = C() 7 | c.x = 1 8 | print(c.x) 9 | C.x = 2 10 | C.y = 3 11 | print(c.x, c.y) 12 | print(C.x, C.y) 13 | print(C().x, C().y) 14 | c = C() 15 | print(c.x) 16 | c.x = 4 17 | print(c.x) 18 | -------------------------------------------------------------------------------- /tests/basics/while_nest_exc.py: -------------------------------------------------------------------------------- 1 | # test nested whiles within a try-except 2 | 3 | while 1: 4 | print(1) 5 | try: 6 | print(2) 7 | while 1: 8 | print(3) 9 | break 10 | except: 11 | print(4) 12 | print(5) 13 | break 14 | -------------------------------------------------------------------------------- /tests/io/file_readinto_len.py: -------------------------------------------------------------------------------- 1 | b = bytearray(30) 2 | f = open("io/data/file1", "rb") 3 | # 2nd arg (length to read) is extension to CPython 4 | print(f.readinto(b, 8)) 5 | print(b) 6 | 7 | b = bytearray(4) 8 | f = open("io/data/file1", "rb") 9 | print(f.readinto(b, 8)) 10 | print(b) 11 | -------------------------------------------------------------------------------- /teensy/lcd.c: -------------------------------------------------------------------------------- 1 | #include "py/obj.h" 2 | #include "../stmhal/lcd.h" 3 | 4 | void lcd_init(void) { 5 | } 6 | 7 | void lcd_print_str(const char *str) { 8 | (void)str; 9 | } 10 | 11 | void lcd_print_strn(const char *str, unsigned int len) { 12 | (void)str; 13 | (void)len; 14 | } 15 | -------------------------------------------------------------------------------- /tests/basics/builtin_id.py: -------------------------------------------------------------------------------- 1 | print(id(1) == id(2)) 2 | print(id(None) == id(None)) 3 | # This can't be true per Python semantics, just CPython implementation detail 4 | #print(id([]) == id([])) 5 | 6 | l = [1, 2] 7 | print(id(l) == id(l)) 8 | 9 | f = lambda:None 10 | print(id(f) == id(f)) 11 | -------------------------------------------------------------------------------- /tests/basics/del_subscr.py: -------------------------------------------------------------------------------- 1 | l = [1, 2, 3] 2 | print(l) 3 | del l[0] 4 | print(l) 5 | del l[-1] 6 | print(l) 7 | 8 | d = {1:2, 3:4, 5:6} 9 | del d[1] 10 | del d[3] 11 | print(d) 12 | del d[5] 13 | print(d) 14 | 15 | # delete nested subscr 16 | d = {0:{0:0}} 17 | del d[0][0] 18 | print(d) 19 | -------------------------------------------------------------------------------- /tests/basics/dict_construct.py: -------------------------------------------------------------------------------- 1 | # dict constructor 2 | 3 | d = dict() 4 | print(d) 5 | 6 | d = dict({1:2}) 7 | print(d) 8 | 9 | d = dict(a=1) 10 | print(d) 11 | 12 | d = dict({1:2}, a=3) 13 | print(d[1], d['a']) 14 | 15 | d = dict([(1, 2)], a=3, b=4) 16 | print(d[1], d['a'], d['b']) 17 | -------------------------------------------------------------------------------- /tests/micropython/heap_lock.py: -------------------------------------------------------------------------------- 1 | # check that heap_lock/heap_unlock work as expected 2 | 3 | import micropython 4 | 5 | micropython.heap_lock() 6 | 7 | try: 8 | print([]) 9 | except MemoryError: 10 | print('MemoryError') 11 | 12 | micropython.heap_unlock() 13 | 14 | print([]) 15 | -------------------------------------------------------------------------------- /docs/esp8266_contents.rst: -------------------------------------------------------------------------------- 1 | MicroPython documentation contents 2 | ================================== 3 | 4 | .. toctree:: 5 | 6 | esp8266/quickref.rst 7 | esp8266/general.rst 8 | esp8266/tutorial/index.rst 9 | library/index.rst 10 | reference/index.rst 11 | license.rst 12 | -------------------------------------------------------------------------------- /stmhal/usbd_hid_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | */ 4 | 5 | #include "usbd_cdc_msc_hid.h" 6 | 7 | extern const USBD_HID_ItfTypeDef USBD_HID_fops; 8 | 9 | int USBD_HID_Rx(uint8_t *buf, uint32_t len, uint32_t timeout); 10 | -------------------------------------------------------------------------------- /tests/basics/object_dict.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | class Foo: 4 | 5 | def __init__(self): 6 | self.a = 1 7 | self.b = "bar" 8 | 9 | o = Foo() 10 | if not hasattr(o, "__dict__"): 11 | print("SKIP") 12 | sys.exit() 13 | 14 | print(o.__dict__ == {'a': 1, 'b': 'bar'}) 15 | -------------------------------------------------------------------------------- /tests/basics/types2.py: -------------------------------------------------------------------------------- 1 | # Types are hashable 2 | print(hash(type) != 0) 3 | print(hash(int) != 0) 4 | print(hash(list) != 0) 5 | class Foo: pass 6 | print(hash(Foo) != 0) 7 | 8 | print(int == int) 9 | print(int != list) 10 | 11 | d = {} 12 | d[int] = list 13 | d[list] = int 14 | print(len(d)) 15 | -------------------------------------------------------------------------------- /tests/bench/funcall-2-funcall.py: -------------------------------------------------------------------------------- 1 | # Function call overhead test 2 | # Perform the same trivial operation as global function call 3 | import bench 4 | 5 | def f(x): 6 | return x + 1 7 | 8 | def test(num): 9 | for i in iter(range(num)): 10 | a = f(i) 11 | 12 | bench.run(test) 13 | -------------------------------------------------------------------------------- /tests/basics/bytes_subscr.py: -------------------------------------------------------------------------------- 1 | # test [...] of bytes 2 | 3 | print(b'123'[0]) 4 | print(b'123'[1]) 5 | print(b'123'[-1]) 6 | 7 | try: 8 | b'123'[1] = 4 9 | except TypeError: 10 | print('TypeError') 11 | 12 | try: 13 | del b'123'[1] 14 | except TypeError: 15 | print('TypeError') 16 | -------------------------------------------------------------------------------- /tests/basics/gen_yield_from_exc.py: -------------------------------------------------------------------------------- 1 | def gen(): 2 | yield 1 3 | yield 2 4 | raise ValueError 5 | 6 | def gen2(): 7 | try: 8 | print((yield from gen())) 9 | except ValueError: 10 | print("caught ValueError from downstream") 11 | 12 | g = gen2() 13 | print(list(g)) 14 | -------------------------------------------------------------------------------- /tests/basics/set1.py: -------------------------------------------------------------------------------- 1 | # basic sets 2 | 3 | s = {1} 4 | print(s) 5 | 6 | s = {3, 4, 3, 1} 7 | print(sorted(s)) 8 | 9 | # expression in constructor 10 | s = {1 + len(s)} 11 | print(s) 12 | 13 | # Sets are not hashable 14 | try: 15 | {s: 1} 16 | except TypeError: 17 | print("TypeError") 18 | -------------------------------------------------------------------------------- /tests/jni/list.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import jni 3 | try: 4 | ArrayList = jni.cls("java/util/ArrayList") 5 | except: 6 | print("SKIP") 7 | sys.exit() 8 | 9 | l = ArrayList() 10 | print(l) 11 | l.add("one") 12 | l.add("two") 13 | 14 | print(l.toString()) 15 | print(l) 16 | print(l[0], l[1]) 17 | -------------------------------------------------------------------------------- /stmhal/pybioctl.h: -------------------------------------------------------------------------------- 1 | #define MP_IOCTL_POLL (0x100 | 1) 2 | 3 | // These values are compatible with Linux, which are in turn 4 | // compatible with iBCS2 spec. 5 | #define MP_IOCTL_POLL_RD (0x0001) 6 | #define MP_IOCTL_POLL_WR (0x0004) 7 | #define MP_IOCTL_POLL_ERR (0x0008) 8 | #define MP_IOCTL_POLL_HUP (0x0010) 9 | -------------------------------------------------------------------------------- /teensy/usb.h: -------------------------------------------------------------------------------- 1 | bool usb_vcp_is_connected(void); 2 | bool usb_vcp_is_enabled(void); 3 | int usb_vcp_rx_num(void); 4 | int usb_vcp_recv_byte(uint8_t *ptr); 5 | void usb_vcp_send_str(const char* str); 6 | void usb_vcp_send_strn(const char* str, int len); 7 | void usb_vcp_send_strn_cooked(const char *str, int len); 8 | -------------------------------------------------------------------------------- /tests/basics/dict2.py: -------------------------------------------------------------------------------- 1 | # using strings as keys in dict 2 | 3 | d = {'1': 1, '2': 2} 4 | print(d['1'], d['2']) 5 | 6 | d['3'] = 3 7 | print(d['1'], d['2'], d['3']) 8 | 9 | d['2'] = 222 10 | print(d['1'], d['2'], d['3']) 11 | 12 | d2 = dict(d) 13 | print('2' in d2) 14 | print(id(d) != id(d2), d == d2) 15 | -------------------------------------------------------------------------------- /tests/basics/is_isnot.py: -------------------------------------------------------------------------------- 1 | print(1 is 1) 2 | print(1 is 2) 3 | print(1 is not 1) 4 | print(1 is not 2) 5 | 6 | 7 | print([1, 2] is [1, 2]) 8 | a = [1, 2] 9 | b = a 10 | print(b is a) 11 | 12 | # TODO: strings require special "is" handling, postponed 13 | # until qstr refactor. 14 | #print("a" is "a") 15 | -------------------------------------------------------------------------------- /tests/feature_check/README: -------------------------------------------------------------------------------- 1 | This directory doesn't contain real tests, but code snippets to detect 2 | various interpreter features, which can't be/inconvenient to detecte by 3 | other means. Scripts here are executed by run-tests at the beginning of 4 | testsuite to decide what other test groups to run/exclude. 5 | -------------------------------------------------------------------------------- /tests/inlineasm/asmfpldrstr.py: -------------------------------------------------------------------------------- 1 | import array 2 | @micropython.asm_thumb # test vldr, vstr 3 | def arrayadd(r0): 4 | vldr(s0, [r0, 0]) 5 | vldr(s1, [r0, 4]) 6 | vadd(s2, s0, s1) 7 | vstr(s2, [r0, 8]) 8 | 9 | z = array.array("f", [2, 4, 10]) 10 | arrayadd(z) 11 | print(z[2]) 12 | 13 | -------------------------------------------------------------------------------- /cc3200/boards/LAUNCHXL/pins.csv: -------------------------------------------------------------------------------- 1 | P12,58 2 | P13,4 3 | P14,3 4 | P15,61 5 | P16,59 6 | P17,5 7 | P18,62 8 | P19,1 9 | P110,2 10 | P33,57 11 | P34,60 12 | P37,63 13 | P38,53 14 | P39,64 15 | P310,50 16 | P49,16 17 | P410,17 18 | P22,18 19 | P23,8 20 | P24,45 21 | P26,7 22 | P27,6 23 | P28,21 24 | P29,55 25 | P210,15 -------------------------------------------------------------------------------- /esp8266/modules/_boot.py: -------------------------------------------------------------------------------- 1 | import gc 2 | gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4) 3 | import uos 4 | from flashbdev import bdev 5 | 6 | try: 7 | if bdev: 8 | vfs = uos.VfsFat(bdev, "") 9 | except OSError: 10 | import inisetup 11 | vfs = inisetup.setup() 12 | 13 | gc.collect() 14 | -------------------------------------------------------------------------------- /tests/basics/attrtuple1.py: -------------------------------------------------------------------------------- 1 | # test attrtuple 2 | # we can't test this type directly so we use sys.implementation object 3 | 4 | import sys 5 | t = sys.implementation 6 | 7 | # test printing of attrtuple 8 | print(str(t).find("version=") > 0) 9 | 10 | # test read attr 11 | print(isinstance(t.name, str)) 12 | -------------------------------------------------------------------------------- /tests/basics/closure1.py: -------------------------------------------------------------------------------- 1 | # closures 2 | 3 | def f(x): 4 | y = 2 * x 5 | def g(z): 6 | return y + z 7 | return g 8 | 9 | print(f(1)(1)) 10 | 11 | x = f(2) 12 | y = f(3) 13 | print(x(1), x(2), x(3)) 14 | print(y(1), y(2), y(3)) 15 | print(x(1), x(2), x(3)) 16 | print(y(1), y(2), y(3)) 17 | -------------------------------------------------------------------------------- /tests/basics/dict_pop.py: -------------------------------------------------------------------------------- 1 | d = {1: 2, 3: 4} 2 | print(d.pop(3), d) 3 | print(d) 4 | print(d.pop(1, 42), d) 5 | print(d.pop(1, 42), d) 6 | print(d.pop(1, None), d) 7 | try: 8 | print(d.pop(1), "!!!",) 9 | except KeyError: 10 | print("Raised KeyError") 11 | else: 12 | print("Did not rise KeyError!") 13 | -------------------------------------------------------------------------------- /tests/basics/gen_yield_from_send.py: -------------------------------------------------------------------------------- 1 | def gen(): 2 | print("sent:", (yield 1)) 3 | yield 2 4 | 5 | def gen2(): 6 | print((yield from gen())) 7 | 8 | g = gen2() 9 | next(g) 10 | print("yielded:", g.send("val")) 11 | try: 12 | next(g) 13 | except StopIteration: 14 | print("StopIteration") 15 | -------------------------------------------------------------------------------- /tests/basics/module1.py: -------------------------------------------------------------------------------- 1 | # test behaviour of module objects 2 | 3 | # this module should always exist 4 | import __main__ 5 | 6 | # print module 7 | print(repr(__main__).startswith(" 4 | 5 | float sqrtf(float x) { 6 | asm volatile ( 7 | "vsqrt.f32 %[r], %[x]\n" 8 | : [r] "=t" (x) 9 | : [x] "t" (x)); 10 | return x; 11 | } 12 | -------------------------------------------------------------------------------- /tests/basics/try_error.py: -------------------------------------------------------------------------------- 1 | # test bad exception match 2 | 3 | try: 4 | try: 5 | a 6 | except 1: 7 | pass 8 | except TypeError: 9 | print("TypeError") 10 | 11 | try: 12 | try: 13 | a 14 | except (1,): 15 | pass 16 | except TypeError: 17 | print("TypeError") 18 | -------------------------------------------------------------------------------- /tests/bench/bytebuf-3-bytarray_map.py: -------------------------------------------------------------------------------- 1 | # Doing some operation on bytearray 2 | # No joins, but still map(). 3 | import bench 4 | 5 | def test(num): 6 | for i in iter(range(num//10000)): 7 | ba = bytearray(b"\0" * 1000) 8 | ba2 = bytearray(map(lambda x: x + 1, ba)) 9 | 10 | bench.run(test) 11 | -------------------------------------------------------------------------------- /tests/pyb/spi.py.exp: -------------------------------------------------------------------------------- 1 | ValueError -1 2 | ValueError 0 3 | SPI 1 4 | SPI 2 5 | ValueError 3 6 | SPI X 7 | SPI Y 8 | ValueError Z 9 | SPI(1) 10 | SPI(1, SPI.MASTER, baudrate=328125, prescaler=256, polarity=1, phase=0, bits=8) 11 | SPI(1, SPI.SLAVE, polarity=1, phase=1, bits=8) 12 | OSError 13 | b'\xff' 14 | b'\xff' 15 | -------------------------------------------------------------------------------- /tools/gen-changelog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "MicroPython change log" 4 | 5 | for t in $(git tag | grep -v v1.0-rc1 | sort -rV); do 6 | echo '' 7 | echo '========' 8 | echo '' 9 | git show -s --format=%cD `git rev-list $t --max-count=1` 10 | echo '' 11 | git tag -l $t -n9999 12 | done 13 | -------------------------------------------------------------------------------- /tests/basics/string_mult.py: -------------------------------------------------------------------------------- 1 | # basic multiplication 2 | print('0' * 5) 3 | 4 | # check negative, 0, positive; lhs and rhs multiplication 5 | for i in (-4, -2, 0, 2, 4): 6 | print(i * '12') 7 | print('12' * i) 8 | 9 | # check that we don't modify existing object 10 | a = '123' 11 | c = a * 3 12 | print(a, c) 13 | -------------------------------------------------------------------------------- /tests/basics/try3.py: -------------------------------------------------------------------------------- 1 | # nested exceptions 2 | 3 | def f(): 4 | try: 5 | foo() 6 | except: 7 | print("except 1") 8 | try: 9 | baz() 10 | except: 11 | print("except 2") 12 | bar() 13 | 14 | try: 15 | f() 16 | except: 17 | print("f except") 18 | -------------------------------------------------------------------------------- /tests/basics/async_def.py: -------------------------------------------------------------------------------- 1 | # test async def 2 | 3 | def dec(f): 4 | print('decorator') 5 | return f 6 | 7 | # test definition with a decorator 8 | @dec 9 | async def foo(): 10 | print('foo') 11 | 12 | coro = foo() 13 | try: 14 | coro.send(None) 15 | except StopIteration: 16 | print('StopIteration') 17 | -------------------------------------------------------------------------------- /tests/basics/bytes_mult.py: -------------------------------------------------------------------------------- 1 | # basic multiplication 2 | print(b'0' * 5) 3 | 4 | # check negative, 0, positive; lhs and rhs multiplication 5 | for i in (-4, -2, 0, 2, 4): 6 | print(i * b'12') 7 | print(b'12' * i) 8 | 9 | # check that we don't modify existing object 10 | a = b'123' 11 | c = a * 3 12 | print(a, c) 13 | -------------------------------------------------------------------------------- /tests/basics/for3.py: -------------------------------------------------------------------------------- 1 | # test assigning to iterator within the loop 2 | for i in range(2): 3 | print(i) 4 | i = 2 5 | 6 | # test assigning to range parameter within the loop 7 | # (since we optimise for loops, this needs checking, currently it fails) 8 | n = 2 9 | for i in range(n): 10 | print(i) 11 | n = 0 12 | -------------------------------------------------------------------------------- /tests/extmod/ujson_loads_float.py: -------------------------------------------------------------------------------- 1 | try: 2 | import ujson as json 3 | except: 4 | import json 5 | 6 | def my_print(o): 7 | print('%.3f' % o) 8 | 9 | my_print(json.loads('1.2')) 10 | my_print(json.loads('1e2')) 11 | my_print(json.loads('-2.3')) 12 | my_print(json.loads('-2e3')) 13 | my_print(json.loads('-2e-3')) 14 | -------------------------------------------------------------------------------- /tests/pyb/halerror.py: -------------------------------------------------------------------------------- 1 | # test hal errors 2 | 3 | import pyb 4 | 5 | i2c = pyb.I2C(2, pyb.I2C.MASTER) 6 | try: 7 | i2c.recv(1, 1) 8 | except OSError as e: 9 | print(repr(e)) 10 | 11 | can = pyb.CAN(1, pyb.CAN.NORMAL) 12 | try: 13 | can.send('1', 1, timeout=50) 14 | except OSError as e: 15 | print(repr(e)) 16 | -------------------------------------------------------------------------------- /tests/basics/builtin_override.py: -------------------------------------------------------------------------------- 1 | # test overriding builtins 2 | 3 | import builtins 4 | 5 | # override generic builtin 6 | builtins.abs = lambda x: x + 1 7 | print(abs(1)) 8 | 9 | # __build_class__ is handled in a special way 10 | builtins.__build_class__ = lambda x, y: ('class', y) 11 | class A: 12 | pass 13 | print(A) 14 | -------------------------------------------------------------------------------- /tests/basics/bytearray_append.py: -------------------------------------------------------------------------------- 1 | # test bytearray.append method 2 | 3 | a = bytearray(4) 4 | print(a) 5 | 6 | # append should append a single byte 7 | a.append(2) 8 | print(a) 9 | 10 | # a should not be modified if append fails 11 | try: 12 | a.append(None) 13 | except TypeError: 14 | print('TypeError') 15 | print(a) 16 | -------------------------------------------------------------------------------- /tests/basics/dict_update.py: -------------------------------------------------------------------------------- 1 | d = {1:2, 3:4} 2 | print(len(d)) 3 | d.update(["ab"]) 4 | print(d[1]) 5 | print(d[3]) 6 | print(d["a"]) 7 | print(len(d)) 8 | d.update([(1,4)]) 9 | print(d[1]) 10 | print(len(d)) 11 | 12 | # using keywords 13 | d.update(a=5) 14 | print(d['a']) 15 | d.update([(1,5)], b=6) 16 | print(d[1], d['b']) 17 | -------------------------------------------------------------------------------- /tests/basics/string_center.py: -------------------------------------------------------------------------------- 1 | try: 2 | str.center 3 | except: 4 | import sys 5 | print("SKIP") 6 | sys.exit() 7 | 8 | print("foo".center(0)) 9 | print("foo".center(1)) 10 | print("foo".center(3)) 11 | print("foo".center(4)) 12 | print("foo".center(5)) 13 | print("foo".center(6)) 14 | print("foo".center(20)) 15 | -------------------------------------------------------------------------------- /tests/bench/bytebuf-1-inplace.py: -------------------------------------------------------------------------------- 1 | # Doing some operation on bytearray 2 | # Inplace - the most memory efficient way 3 | import bench 4 | 5 | def test(num): 6 | for i in iter(range(num//10000)): 7 | ba = bytearray(b"\0" * 1000) 8 | for i in range(len(ba)): 9 | ba[i] += 1 10 | 11 | bench.run(test) 12 | -------------------------------------------------------------------------------- /tests/bench/var-7-instance-meth.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | class Foo: 4 | 5 | def __init__(self): 6 | self._num = 20000000 7 | 8 | def num(self): 9 | return self._num 10 | 11 | def test(num): 12 | o = Foo() 13 | i = 0 14 | while i < o.num(): 15 | i += 1 16 | 17 | bench.run(test) 18 | -------------------------------------------------------------------------------- /docs/unix_index.rst: -------------------------------------------------------------------------------- 1 | MicroPython documentation and references 2 | ======================================== 3 | 4 | .. toctree:: 5 | 6 | library/index.rst 7 | license.rst 8 | unix_contents.rst 9 | 10 | Indices and tables 11 | ================== 12 | 13 | * :ref:`genindex` 14 | * :ref:`modindex` 15 | * :ref:`search` 16 | -------------------------------------------------------------------------------- /tests/basics/builtin_delattr.py: -------------------------------------------------------------------------------- 1 | # test builtin delattr 2 | 3 | class A: pass 4 | a = A() 5 | a.x = 1 6 | print(a.x) 7 | 8 | delattr(a, 'x') 9 | 10 | try: 11 | a.x 12 | except AttributeError: 13 | print('AttributeError') 14 | 15 | try: 16 | delattr(a, 'x') 17 | except AttributeError: 18 | print('AttributeError') 19 | -------------------------------------------------------------------------------- /tests/basics/del_name.py: -------------------------------------------------------------------------------- 1 | # del name 2 | 3 | x = 1 4 | print(x) 5 | del x 6 | try: 7 | print(x) 8 | except NameError: 9 | print("NameError") 10 | try: 11 | del x 12 | except: # NameError: 13 | # FIXME uPy returns KeyError for this 14 | print("NameError") 15 | 16 | class C: 17 | def f(): 18 | pass 19 | -------------------------------------------------------------------------------- /tests/basics/setattr1.py: -------------------------------------------------------------------------------- 1 | class A: 2 | 3 | var = 132 4 | 5 | def __init__(self): 6 | self.var2 = 34 7 | 8 | 9 | a = A() 10 | setattr(a, "var", 123) 11 | setattr(a, "var2", 56) 12 | print(a.var) 13 | print(a.var2) 14 | 15 | try: 16 | setattr(a, b'var3', 1) 17 | except TypeError: 18 | print('TypeError') 19 | -------------------------------------------------------------------------------- /tests/basics/try_continue.py: -------------------------------------------------------------------------------- 1 | # test continue within exception handler 2 | 3 | def f(): 4 | lst = [1, 2, 3] 5 | for x in lst: 6 | print('a', x) 7 | try: 8 | if x == 2: 9 | raise Exception 10 | except Exception: 11 | continue 12 | print('b', x) 13 | f() 14 | -------------------------------------------------------------------------------- /tests/extmod/ubinascii_unhexlify.py: -------------------------------------------------------------------------------- 1 | try: 2 | import ubinascii as binascii 3 | except ImportError: 4 | import binascii 5 | 6 | print(binascii.unhexlify(b'0001020304050607')) 7 | print(binascii.unhexlify(b'08090a0b0c0d0e0f')) 8 | print(binascii.unhexlify(b'7f80ff')) 9 | print(binascii.unhexlify(b'313233344142434461626364')) 10 | -------------------------------------------------------------------------------- /tests/pyb/timer.py: -------------------------------------------------------------------------------- 1 | # check basic functionality of the timer class 2 | 3 | import pyb 4 | from pyb import Timer 5 | 6 | tim = Timer(4) 7 | tim = Timer(4, prescaler=100, period=200) 8 | print(tim.prescaler()) 9 | print(tim.period()) 10 | tim.prescaler(300) 11 | print(tim.prescaler()) 12 | tim.period(400) 13 | print(tim.period()) 14 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | When reporting an issue and especially submitting a pull request, please 2 | make sure that you are acquainted with Contributor Guidelines: 3 | 4 | https://github.com/micropython/micropython/wiki/ContributorGuidelines 5 | 6 | and Code Conventions: 7 | 8 | https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md 9 | -------------------------------------------------------------------------------- /docs/pyboard_contents.rst: -------------------------------------------------------------------------------- 1 | MicroPython documentation contents 2 | ================================== 3 | 4 | .. toctree:: 5 | 6 | pyboard/quickref.rst 7 | pyboard/general.rst 8 | pyboard/tutorial/index.rst 9 | library/index.rst 10 | reference/index.rst 11 | pyboard/hardware/index.rst 12 | license.rst 13 | 14 | -------------------------------------------------------------------------------- /tests/basics/bool1.py: -------------------------------------------------------------------------------- 1 | # tests for bool objects 2 | 3 | # basic logic 4 | print(not False) 5 | print(not True) 6 | print(False and True) 7 | print(False or True) 8 | 9 | # unary operators 10 | print(+True) 11 | print(-True) 12 | 13 | # unsupported unary op 14 | try: 15 | len(False) 16 | except TypeError: 17 | print('TypeError') 18 | -------------------------------------------------------------------------------- /tests/basics/builtin_dir.py: -------------------------------------------------------------------------------- 1 | # test builtin dir 2 | 3 | # dir of locals 4 | print('__name__' in dir()) 5 | 6 | # dir of module 7 | import sys 8 | print('platform' in dir(sys)) 9 | 10 | class Foo: 11 | def __init__(self): 12 | self.x = 1 13 | foo = Foo() 14 | print('__init__' in dir(foo)) 15 | print('x' in dir(foo)) 16 | 17 | -------------------------------------------------------------------------------- /tests/basics/closure2.py: -------------------------------------------------------------------------------- 1 | # closures; closing over an argument 2 | 3 | def f(x): 4 | y = 2 * x 5 | def g(z): 6 | return x + y + z 7 | return g 8 | 9 | print(f(1)(1)) 10 | 11 | x = f(2) 12 | y = f(3) 13 | print(x(1), x(2), x(3)) 14 | print(y(1), y(2), y(3)) 15 | print(x(1), x(2), x(3)) 16 | print(y(1), y(2), y(3)) 17 | -------------------------------------------------------------------------------- /tests/basics/with_break.py: -------------------------------------------------------------------------------- 1 | class CtxMgr: 2 | 3 | def __enter__(self): 4 | print("__enter__") 5 | return self 6 | 7 | def __exit__(self, a, b, c): 8 | print("__exit__", repr(a), repr(b)) 9 | 10 | for i in range(5): 11 | print(i) 12 | with CtxMgr(): 13 | if i == 3: 14 | break 15 | -------------------------------------------------------------------------------- /cc3200/boards/WIPY/pins.csv: -------------------------------------------------------------------------------- 1 | L2,GP2 2 | L3,GP1 3 | L4,GP23 4 | L5,GP24 5 | L6,GP11 6 | L7,GP12 7 | L8,GP13 8 | L9,GP14 9 | L10,GP15 10 | L11,GP16 11 | L12,GP17 12 | L13,GP22 13 | L14,GP28 14 | R4,GP10 15 | R5,GP9 16 | R6,GP8 17 | R7,GP7 18 | R8,GP6 19 | R9,GP30 20 | R10,GP31 21 | R11,GP3 22 | R12,GP0 23 | R13,GP4 24 | R14,GP5 25 | HBL,GP25 26 | -------------------------------------------------------------------------------- /tests/basics/async_with2.py.exp: -------------------------------------------------------------------------------- 1 | enter 2 | f start: 10 3 | coro yielded: 11 4 | coro yielded: 12 5 | f returned: 13 6 | body start 7 | f start: 30 8 | coro yielded: 31 9 | coro yielded: 32 10 | body f returned: 33 11 | body end 12 | exit None None 13 | f start: 20 14 | coro yielded: 21 15 | coro yielded: 22 16 | f returned: 23 17 | finished 18 | -------------------------------------------------------------------------------- /tests/basics/builtin_issubclass.py: -------------------------------------------------------------------------------- 1 | # test builtin issubclass 2 | 3 | class A: 4 | pass 5 | 6 | print(issubclass(A, A)) 7 | print(issubclass(A, (A,))) 8 | 9 | try: 10 | issubclass(A, 1) 11 | except TypeError: 12 | print('TypeError') 13 | 14 | try: 15 | issubclass('a', 1) 16 | except TypeError: 17 | print('TypeError') 18 | -------------------------------------------------------------------------------- /tests/basics/class_call.py: -------------------------------------------------------------------------------- 1 | class C1: 2 | def __call__(self, val): 3 | print('call', val) 4 | return 'item' 5 | 6 | class C2: 7 | 8 | def __getattr__(self, k): 9 | pass 10 | 11 | c1 = C1() 12 | print(c1(1)) 13 | 14 | c2 = C2() 15 | try: 16 | print(c2(1)) 17 | except TypeError: 18 | print("TypeError") 19 | -------------------------------------------------------------------------------- /tests/basics/continue.py: -------------------------------------------------------------------------------- 1 | for i in range(4): 2 | print('one', i) 3 | if i > 2: 4 | continue 5 | print('two', i) 6 | 7 | for i in range(4): 8 | print('one', i) 9 | if i < 2: 10 | continue 11 | print('two', i) 12 | 13 | for i in [1, 2, 3, 4]: 14 | if i == 3: 15 | continue 16 | print(i) 17 | -------------------------------------------------------------------------------- /tests/basics/with_continue.py: -------------------------------------------------------------------------------- 1 | class CtxMgr: 2 | 3 | def __enter__(self): 4 | print("__enter__") 5 | return self 6 | 7 | def __exit__(self, a, b, c): 8 | print("__exit__", repr(a), repr(b)) 9 | 10 | for i in range(5): 11 | print(i) 12 | with CtxMgr(): 13 | if i == 3: 14 | continue 15 | -------------------------------------------------------------------------------- /tests/cmdline/repl_emacs_keys.py.exp: -------------------------------------------------------------------------------- 1 | MicroPython \.\+ version 2 | Use \.\+ 3 | >>> # REPL tests of GNU-ish readline navigation 4 | >>> # history buffer navigation 5 | >>> 1 6 | 1 7 | >>> 2 8 | 2 9 | >>> 3 10 | 3 11 | >>> 321 12 | 1 13 | >>> 1323 14 | 3 15 | >>> # input line motion 16 | >>> t = 121 17 | >>> \.\+ 18 | 'foobar' 19 | >>> 20 | -------------------------------------------------------------------------------- /tests/float/types.py: -------------------------------------------------------------------------------- 1 | # float types 2 | 3 | print(float) 4 | print(complex) 5 | 6 | print(type(float()) == float) 7 | print(type(complex()) == complex) 8 | 9 | print(type(0.0) == float) 10 | print(type(1j) == complex) 11 | 12 | # hashing float types 13 | 14 | d = dict() 15 | d[float] = complex 16 | d[complex] = float 17 | print(len(d)) 18 | -------------------------------------------------------------------------------- /tests/inlineasm/asmfpcmp.py: -------------------------------------------------------------------------------- 1 | @micropython.asm_thumb # test vcmp, vmrs 2 | def f(r0, r1): 3 | vmov(s0, r0) 4 | vcvt_f32_s32(s0, s0) 5 | vmov(s1, r1) 6 | vcvt_f32_s32(s1, s1) 7 | vcmp(s1, s0) 8 | vmrs(r0, FPSCR) 9 | mov(r1, 28) 10 | lsr(r0, r1) 11 | 12 | print(f(0,1)) 13 | print(f(1,1)) 14 | print(f(1,0)) 15 | -------------------------------------------------------------------------------- /tests/io/file_readline.py: -------------------------------------------------------------------------------- 1 | f = open("io/data/file1") 2 | print(f.readline()) 3 | print(f.readline(3)) 4 | print(f.readline(4)) 5 | print(f.readline(5)) 6 | print(f.readline()) 7 | 8 | # readline() on writable file 9 | f = open('io/data/file1', 'ab') 10 | try: 11 | f.readline() 12 | except OSError: 13 | print('OSError') 14 | f.close() 15 | -------------------------------------------------------------------------------- /tests/pyb/servo.py: -------------------------------------------------------------------------------- 1 | from pyb import Servo 2 | 3 | servo = Servo(1) 4 | print(servo) 5 | 6 | servo.angle(0) 7 | servo.angle(10, 100) 8 | 9 | servo.speed(-10) 10 | servo.speed(10, 100) 11 | 12 | servo.pulse_width(1500) 13 | print(servo.pulse_width()) 14 | 15 | servo.calibration(630, 2410, 1490, 2460, 2190) 16 | print(servo.calibration()) 17 | -------------------------------------------------------------------------------- /tests/basics/dict_from_iter.py: -------------------------------------------------------------------------------- 1 | print(dict([(1, "foo")])) 2 | d = dict([("foo", "foo2"), ("bar", "baz")]) 3 | print(sorted(d.keys())) 4 | print(sorted(d.values())) 5 | 6 | try: 7 | dict(((1,),)) 8 | except ValueError: 9 | print("ValueError") 10 | 11 | try: 12 | dict(((1, 2, 3),)) 13 | except ValueError: 14 | print("ValueError") 15 | -------------------------------------------------------------------------------- /tests/basics/fun_name.py: -------------------------------------------------------------------------------- 1 | def Fun(): 2 | pass 3 | 4 | class A: 5 | def __init__(self): 6 | pass 7 | def Fun(self): 8 | pass 9 | 10 | try: 11 | print(Fun.__name__) 12 | print(A.__init__.__name__) 13 | print(A.Fun.__name__) 14 | print(A().Fun.__name__) 15 | except AttributeError: 16 | print('SKIP') 17 | -------------------------------------------------------------------------------- /tests/extmod/time_ms_us.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import utime 3 | try: 4 | utime.sleep_ms 5 | except AttributeError: 6 | print("SKIP") 7 | sys.exit() 8 | 9 | utime.sleep_ms(1) 10 | utime.sleep_us(1) 11 | print(utime.ticks_diff(utime.ticks_ms(), utime.ticks_ms()) <= 1) 12 | print(utime.ticks_diff(utime.ticks_us(), utime.ticks_us()) <= 500) 13 | -------------------------------------------------------------------------------- /tests/extmod/ubinascii_hexlify.py: -------------------------------------------------------------------------------- 1 | try: 2 | import ubinascii as binascii 3 | except ImportError: 4 | import binascii 5 | 6 | print(binascii.hexlify(b'\x00\x01\x02\x03\x04\x05\x06\x07')) 7 | print(binascii.hexlify(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f')) 8 | print(binascii.hexlify(b'\x7f\x80\xff')) 9 | print(binascii.hexlify(b'1234ABCDabcd')) 10 | -------------------------------------------------------------------------------- /tests/inlineasm/asmit.py: -------------------------------------------------------------------------------- 1 | # test it instruction 2 | 3 | @micropython.asm_thumb 4 | def f(r0, r1): 5 | cmp(r0, r1) 6 | it(eq) 7 | mov(r0, 100) 8 | print(f(0, 0), f(1, 2)) 9 | 10 | @micropython.asm_thumb 11 | def g(r0, r1): 12 | cmp(r0, r1) 13 | ite(eq) 14 | mov(r0, 100) 15 | mov(r0, 200) 16 | print(g(0, 0), g(0, 1)) 17 | -------------------------------------------------------------------------------- /tests/basics/bytearray_construct.py: -------------------------------------------------------------------------------- 1 | # test construction of bytearray from different objects 2 | 3 | from array import array 4 | 5 | # bytes, tuple, list 6 | print(bytearray(b'123')) 7 | print(bytearray((1, 2))) 8 | print(bytearray([1, 2])) 9 | 10 | # arrays 11 | print(bytearray(array('b', [1, 2]))) 12 | print(bytearray(array('h', [0x101, 0x202]))) 13 | -------------------------------------------------------------------------------- /tests/basics/dict_popitem.py: -------------------------------------------------------------------------------- 1 | els = [] 2 | d = {1:2,3:4} 3 | a = d.popitem() 4 | print(len(d)) 5 | els.append(a) 6 | a = d.popitem() 7 | print(len(d)) 8 | els.append(a) 9 | try: 10 | print(d.popitem(), "!!!",) 11 | except KeyError: 12 | print("Raised KeyError") 13 | else: 14 | print("Did not raise KeyError") 15 | print(sorted(els)) 16 | 17 | -------------------------------------------------------------------------------- /tests/basics/int_bytes.py: -------------------------------------------------------------------------------- 1 | print((10).to_bytes(1, "little")) 2 | print((111111).to_bytes(4, "little")) 3 | print((100).to_bytes(10, "little")) 4 | print((2**64).to_bytes(9, "little")) 5 | print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) 6 | print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little")) 7 | print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) 8 | -------------------------------------------------------------------------------- /tests/basics/unboundlocal.py: -------------------------------------------------------------------------------- 1 | # locals referenced before assignment 2 | 3 | def f1(): 4 | print(x) 5 | x = 1 6 | 7 | def f2(): 8 | for i in range(0): 9 | print(i) 10 | print(i) 11 | 12 | def check(f): 13 | try: 14 | f() 15 | except NameError: 16 | print("NameError") 17 | 18 | check(f1) 19 | check(f2) 20 | -------------------------------------------------------------------------------- /tests/extmod/ujson_load.py: -------------------------------------------------------------------------------- 1 | try: 2 | from uio import StringIO 3 | import ujson as json 4 | except: 5 | from io import StringIO 6 | import json 7 | 8 | print(json.load(StringIO('null'))) 9 | print(json.load(StringIO('"abc\\u0064e"'))) 10 | print(json.load(StringIO('[false, true, 1, -2]'))) 11 | print(json.load(StringIO('{"a":true}'))) 12 | -------------------------------------------------------------------------------- /tests/basics/class_number.py: -------------------------------------------------------------------------------- 1 | # test class with __add__ and __sub__ methods 2 | 3 | class C: 4 | def __init__(self, value): 5 | self.value = value 6 | 7 | def __add__(self, rhs): 8 | print(self.value, '+', rhs) 9 | 10 | def __sub__(self, rhs): 11 | print(self.value, '-', rhs) 12 | 13 | c = C(0) 14 | c + 1 15 | c - 2 16 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_native_float.py: -------------------------------------------------------------------------------- 1 | import uctypes 2 | 3 | desc = { 4 | "f32": uctypes.FLOAT32 | 0, 5 | "f64": uctypes.FLOAT64 | 0, 6 | } 7 | 8 | data = bytearray(8) 9 | 10 | S = uctypes.struct(uctypes.addressof(data), desc, uctypes.NATIVE) 11 | 12 | S.f32 = 12.34 13 | print('%.4f' % S.f32) 14 | 15 | S.f64 = 12.34 16 | print('%.4f' % S.f64) 17 | -------------------------------------------------------------------------------- /tests/extmod/vfs_fat_fileio.py.exp: -------------------------------------------------------------------------------- 1 | 2 | True 3 | True 4 | True 5 | True 6 | hello!world! 7 | 12 8 | h 9 | e 10 | True 11 | d 12 | True 13 | True 14 | True 15 | True 16 | True 17 | b'data in file' 18 | True 19 | ['sub_file.txt', 'file.txt'] 20 | ['foo_file.txt', 'foo_dir', 'moved-to-root.txt'] 21 | ['moved-to-root.txt'] 22 | ENOSPC: True 23 | -------------------------------------------------------------------------------- /tests/io/file_readinto.py: -------------------------------------------------------------------------------- 1 | b = bytearray(30) 2 | f = open("io/data/file1", "rb") 3 | print(f.readinto(b)) 4 | print(b) 5 | f = open("io/data/file2", "rb") 6 | print(f.readinto(b)) 7 | print(b) 8 | 9 | # readinto() on writable file 10 | f = open('io/data/file1', 'ab') 11 | try: 12 | f.readinto(bytearray(4)) 13 | except OSError: 14 | print('OSError') 15 | -------------------------------------------------------------------------------- /tests/micropython/decorator_error.py: -------------------------------------------------------------------------------- 1 | # test syntax errors for uPy-specific decorators 2 | 3 | def test_syntax(code): 4 | try: 5 | exec(code) 6 | except SyntaxError: 7 | print("SyntaxError") 8 | 9 | # invalid micropython decorators 10 | test_syntax("@micropython.a\ndef f(): pass") 11 | test_syntax("@micropython.a.b\ndef f(): pass") 12 | -------------------------------------------------------------------------------- /tests/wipy/uart_irq.py.exp: -------------------------------------------------------------------------------- 1 | True 2 | True 3 | True 4 | True 5 | True 6 | True 7 | True 8 | True 9 | True 10 | True 11 | True 12 | True 13 | True 14 | True 15 | True 16 | True 17 | True 18 | True 19 | True 20 | True 21 | True 22 | True 23 | True 24 | True 25 | True 26 | True 27 | True 28 | True 29 | True 30 | True 31 | Exception 32 | Exception 33 | Exception 34 | -------------------------------------------------------------------------------- /tests/basics/exception1.py: -------------------------------------------------------------------------------- 1 | print(repr(IndexError())) 2 | print(str(IndexError())) 3 | 4 | print(repr(IndexError("foo"))) 5 | print(str(IndexError("foo"))) 6 | 7 | a = IndexError(1, "test", [100, 200]) 8 | print(repr(a)) 9 | print(str(a)) 10 | print(a.args) 11 | 12 | s = StopIteration() 13 | print(s.value) 14 | s = StopIteration(1, 2, 3) 15 | print(s.value) 16 | -------------------------------------------------------------------------------- /tests/micropython/meminfo.py: -------------------------------------------------------------------------------- 1 | # tests meminfo functions in micropython module 2 | 3 | import micropython 4 | 5 | # these functions are not always available 6 | if not hasattr(micropython, 'mem_info'): 7 | print('SKIP') 8 | else: 9 | micropython.mem_info() 10 | micropython.mem_info(1) 11 | micropython.qstr_info() 12 | micropython.qstr_info(1) 13 | -------------------------------------------------------------------------------- /docs/esp8266_index.rst: -------------------------------------------------------------------------------- 1 | MicroPython documentation and references 2 | ======================================== 3 | 4 | .. toctree:: 5 | 6 | esp8266/quickref.rst 7 | library/index.rst 8 | license.rst 9 | esp8266_contents.rst 10 | 11 | Indices and tables 12 | ================== 13 | 14 | * :ref:`genindex` 15 | * :ref:`modindex` 16 | * :ref:`search` 17 | -------------------------------------------------------------------------------- /teensy/lexerfatfs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "misc.h" 5 | #include "mpconfig.h" 6 | #include "qstr.h" 7 | #include "lexer.h" 8 | typedef int FIL; 9 | #include "../stmhal/lexerfatfs.h" 10 | 11 | mp_lexer_t *mp_lexer_new_from_file(const char *filename) { 12 | printf("import not implemented\n"); 13 | return NULL; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/basics/fun_defargs2.py: -------------------------------------------------------------------------------- 1 | # overriding default arguments 2 | 3 | def foo(a, b=3): 4 | print(a, b) 5 | 6 | # override with positional 7 | foo(1, 333) 8 | 9 | # override with keyword 10 | foo(1, b=333) 11 | 12 | # override with keyword 13 | foo(a=2, b=333) 14 | 15 | def foo2(a=1, b=2): 16 | print(a, b) 17 | 18 | # default and keyword 19 | foo2(b='two') 20 | -------------------------------------------------------------------------------- /tests/basics/builtin_allany.py: -------------------------------------------------------------------------------- 1 | # test builtin "all" and "any" 2 | 3 | tests = ( 4 | (), 5 | [], 6 | [False], 7 | [True], 8 | [False, True], 9 | [True, False], 10 | [False, False], 11 | [True, True], 12 | range(10), 13 | ) 14 | 15 | for test in tests: 16 | print(all(test)) 17 | 18 | for test in tests: 19 | print(any(test)) 20 | -------------------------------------------------------------------------------- /tests/basics/class_super_object.py: -------------------------------------------------------------------------------- 1 | # Calling object.__init__() via super().__init__ 2 | 3 | class Test(object): 4 | def __init__(self): 5 | super().__init__() 6 | print("Test.__init__") 7 | 8 | t = Test() 9 | 10 | class Test2: 11 | def __init__(self): 12 | super().__init__() 13 | print("Test2.__init__") 14 | 15 | t = Test2() 16 | -------------------------------------------------------------------------------- /tests/basics/frozenset_add.py: -------------------------------------------------------------------------------- 1 | try: 2 | frozenset 3 | except NameError: 4 | print("SKIP") 5 | import sys 6 | sys.exit() 7 | 8 | s = frozenset({1, 2, 3, 4}) 9 | try: 10 | print(s.add(5)) 11 | except AttributeError: 12 | print("AttributeError") 13 | 14 | try: 15 | print(s.update([5])) 16 | except AttributeError: 17 | print("AttributeError") 18 | -------------------------------------------------------------------------------- /tests/bench/var-6.1-instance-attr-5.py: -------------------------------------------------------------------------------- 1 | import bench 2 | 3 | class Foo: 4 | 5 | def __init__(self): 6 | self.num1 = 0 7 | self.num2 = 0 8 | self.num3 = 0 9 | self.num4 = 0 10 | self.num = 20000000 11 | 12 | def test(num): 13 | o = Foo() 14 | i = 0 15 | while i < o.num: 16 | i += 1 17 | 18 | bench.run(test) 19 | -------------------------------------------------------------------------------- /tests/jni/object.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import jni 3 | try: 4 | Integer = jni.cls("java/lang/Integer") 5 | except: 6 | print("SKIP") 7 | sys.exit() 8 | 9 | # Create object 10 | i = Integer(42) 11 | print(i) 12 | # Call object method 13 | print(i.hashCode()) 14 | # Pass object to another method 15 | System = jni.cls("java/lang/System") 16 | System.out.println(i) 17 | -------------------------------------------------------------------------------- /windows/mpconfigport.mk: -------------------------------------------------------------------------------- 1 | # Enable/disable modules and 3rd-party libs to be included in interpreter 2 | 3 | # Build 32-bit binaries on a 64-bit host 4 | MICROPY_FORCE_32BIT = 0 5 | 6 | # Linking with GNU readline causes binary to be licensed under GPL 7 | MICROPY_USE_READLINE = 1 8 | 9 | # ffi module requires libffi (libffi-dev Debian package) 10 | MICROPY_PY_FFI = 0 11 | -------------------------------------------------------------------------------- /tests/basics/bytes_compare2.py: -------------------------------------------------------------------------------- 1 | print(b"1" == 1) 2 | print(b"123" == bytearray(b"123")) 3 | print(b'123' < bytearray(b"124")) 4 | print(b'123' > bytearray(b"122")) 5 | print(bytearray(b"23") in b"1234") 6 | 7 | import array 8 | 9 | print(array.array('b', [1, 2]) in b'\x01\x02\x03') 10 | # CPython gives False here 11 | #print(b"\x01\x02\x03" == array.array("B", [1, 2, 3])) 12 | -------------------------------------------------------------------------------- /tests/basics/frozenset1.py: -------------------------------------------------------------------------------- 1 | # basic sets 2 | 3 | try: 4 | frozenset 5 | except NameError: 6 | print("SKIP") 7 | import sys 8 | sys.exit() 9 | 10 | s = frozenset() 11 | print(s) 12 | 13 | s = frozenset({1}) 14 | print(s) 15 | 16 | s = frozenset({3, 4, 3, 1}) 17 | print(sorted(s)) 18 | 19 | # frozensets are hashable unlike sets 20 | print({frozenset("1"): 2}) 21 | -------------------------------------------------------------------------------- /emscripten/README.md: -------------------------------------------------------------------------------- 1 | # MicroPython on Emscripten 2 | 3 | Follow the instructions for getting started with Emscripten [here](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). 4 | 5 | Then you can run 6 | 7 | ```bash 8 | source ./emsdk_env.sh 9 | cd {micropython directory}/emscripten 10 | make EMSCRIPTEN=1 -j 11 | node build/firmware.js 12 | ``` 13 | 14 | -------------------------------------------------------------------------------- /examples/unix/machine_bios.py: -------------------------------------------------------------------------------- 1 | # This example shows how to access Video BIOS memory area via machine.mem 2 | # It requires root privilege and x86 legacy harfware (which has mentioned 3 | # Video BIOS at all). 4 | # It is expected to print 0xaa55, which is a signature at the start of 5 | # Video BIOS. 6 | 7 | import umachine as machine 8 | 9 | print(hex(machine.mem16[0xc0000])) 10 | -------------------------------------------------------------------------------- /tests/basics/array_q.py: -------------------------------------------------------------------------------- 1 | # test array('q') and array('Q') 2 | 3 | from array import array 4 | 5 | print(array('q')) 6 | print(array('Q')) 7 | 8 | print(array('q', [0])) 9 | print(array('Q', [0])) 10 | 11 | print(array('q', [-2**63, -1, 0, 1, 2, 2**63-1])) 12 | print(array('Q', [0, 1, 2, 2**64-1])) 13 | 14 | print(bytes(array('q', [-1]))) 15 | print(bytes(array('Q', [2**64-1]))) 16 | -------------------------------------------------------------------------------- /tests/basics/bytearray_add.py: -------------------------------------------------------------------------------- 1 | # test bytearray + bytearray 2 | 3 | b = bytearray(2) 4 | b[0] = 1 5 | b[1] = 2 6 | print(b + bytearray(2)) 7 | 8 | # inplace add 9 | b += bytearray(3) 10 | print(b) 11 | 12 | # extend 13 | b.extend(bytearray(4)) 14 | print(b) 15 | 16 | # this inplace add tests the code when the buffer doesn't need to be increased 17 | b = bytearray() 18 | b += b'' 19 | -------------------------------------------------------------------------------- /tests/unix/extra_coverage.py: -------------------------------------------------------------------------------- 1 | try: 2 | extra_coverage 3 | except NameError: 4 | print("SKIP") 5 | import sys 6 | sys.exit() 7 | 8 | data = extra_coverage() 9 | 10 | # test hashing of str/bytes that have an invalid hash 11 | print(data) 12 | print(hash(data[0])) 13 | print(hash(data[1])) 14 | print(hash(bytes(data[0], 'utf8'))) 15 | print(hash(str(data[1], 'utf8'))) 16 | -------------------------------------------------------------------------------- /emscripten/stdio_core.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stdio.h" 3 | #include "py/mpconfig.h" 4 | 5 | // Receive single character 6 | int mp_hal_stdin_rx_chr(void) { 7 | unsigned char c = fgetc(stdin); 8 | return c; 9 | } 10 | 11 | // Send string of given length 12 | void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { 13 | fwrite(str, len, 1, stdout); 14 | } 15 | -------------------------------------------------------------------------------- /tests/basics/dict_intern.py: -------------------------------------------------------------------------------- 1 | # check that interned strings are compared against non-interned strings 2 | 3 | di = {"key1": "value"} 4 | 5 | # lookup interned string 6 | k = "key1" 7 | print(k in di) 8 | 9 | # lookup non-interned string 10 | k2 = "key" + "1" 11 | print(k == k2) 12 | print(k2 in di) 13 | 14 | # lookup non-interned string 15 | print("".join(['k', 'e', 'y', '1']) in di) 16 | -------------------------------------------------------------------------------- /tests/basics/ordereddict_eq.py.exp: -------------------------------------------------------------------------------- 1 | OrderedDict({'a': 1, 'b': 2}) 2 | OrderedDict({'a': 1, 'b': 2}) 3 | True 4 | OrderedDict({'a': 1, 'b': 2}) 5 | OrderedDict({'b': 2, 'a': 1}) 6 | False 7 | OrderedDict({'a': 1, 'b': 2}) 8 | OrderedDict({'a': 1, 'b': 2}) 9 | True 10 | OrderedDict({'b': 2}) 11 | OrderedDict({'b': 2}) 12 | True 13 | OrderedDict({}) 14 | OrderedDict({'a': 1}) 15 | False 16 | -------------------------------------------------------------------------------- /tests/basics/slots_bool_len.py: -------------------------------------------------------------------------------- 1 | class A: 2 | def __bool__(self): 3 | print('__bool__') 4 | return True 5 | def __len__(self): 6 | print('__len__') 7 | return 1 8 | 9 | class B: 10 | def __len__(self): 11 | print('__len__') 12 | return 0 13 | 14 | print(bool(A())) 15 | print(len(A())) 16 | print(bool(B())) 17 | print(len(B())) 18 | -------------------------------------------------------------------------------- /tests/import/try_module.py: -------------------------------------------------------------------------------- 1 | # Regression test for #290 - throwing exception in another module led to 2 | # its namespace stick and namespace of current module not coming back. 3 | import import1b 4 | 5 | def func1(): 6 | print('func1') 7 | 8 | def func2(): 9 | try: 10 | import1b.throw() 11 | except ValueError: 12 | pass 13 | func1() 14 | 15 | func2() 16 | -------------------------------------------------------------------------------- /tests/basics/decorator.py: -------------------------------------------------------------------------------- 1 | # test decorators 2 | 3 | def dec(f): 4 | print('dec') 5 | return f 6 | 7 | def dec_arg(x): 8 | print(x) 9 | return lambda f:f 10 | 11 | # plain decorator 12 | @dec 13 | def f(): 14 | pass 15 | 16 | # decorator with arg 17 | @dec_arg('dec_arg') 18 | def g(): 19 | pass 20 | 21 | # decorator of class 22 | @dec 23 | class A: 24 | pass 25 | -------------------------------------------------------------------------------- /tests/basics/print.py: -------------------------------------------------------------------------------- 1 | # test builtin print function 2 | 3 | print() 4 | print(None) 5 | print('') 6 | print(1) 7 | print(1, 2) 8 | 9 | print(sep='') 10 | print(sep='x') 11 | print(end='') 12 | print(end='x\n') 13 | print(1, sep='') 14 | print(1, end='') 15 | print(1, sep='', end='') 16 | print(1, 2, sep='') 17 | print(1, 2, end='') 18 | print(1, 2, sep='', end='') 19 | 20 | print([{1:2}]) 21 | -------------------------------------------------------------------------------- /tests/basics/try_reraise.py: -------------------------------------------------------------------------------- 1 | # Reraising last exception with raise w/o args 2 | 3 | def f(): 4 | try: 5 | raise ValueError("val", 3) 6 | except: 7 | raise 8 | 9 | try: 10 | f() 11 | except ValueError as e: 12 | print(repr(e)) 13 | 14 | 15 | # Can reraise only in except block 16 | try: 17 | raise 18 | except RuntimeError: 19 | print("RuntimeError") 20 | -------------------------------------------------------------------------------- /tests/inlineasm/asmblbx.py: -------------------------------------------------------------------------------- 1 | # test bl and bx instructions 2 | 3 | @micropython.asm_thumb 4 | def f(r0): 5 | # jump over the internal functions 6 | b(entry) 7 | 8 | label(func1) 9 | add(r0, 2) 10 | bx(lr) 11 | 12 | label(func2) 13 | sub(r0, 1) 14 | bx(lr) 15 | 16 | label(entry) 17 | bl(func1) 18 | bl(func2) 19 | 20 | print(f(0)) 21 | print(f(1)) 22 | -------------------------------------------------------------------------------- /docs/readthedocs/settings/local_settings.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # Directory that the project lives in, aka ../.. 4 | SITE_ROOT = '/'.join(os.path.dirname(__file__).split('/')[0:-2]) 5 | 6 | TEMPLATE_DIRS = ( 7 | "%s/templates/" % SITE_ROOT, # Your custom template directory, before the RTD one to override it. 8 | "%s/readthedocs/templates/" % SITE_ROOT, # Default RTD template dir 9 | ) 10 | -------------------------------------------------------------------------------- /drivers/cc3000/inc/patch_prog.h: -------------------------------------------------------------------------------- 1 | #ifndef __CC3000_PATCH_PROG_H__ 2 | #define __CC3000_PATCH_PROG_H__ 3 | extern unsigned short fw_length; 4 | extern const unsigned char fw_patch[]; 5 | 6 | extern unsigned short drv_length; 7 | extern const unsigned char wlan_drv_patch[]; 8 | extern const unsigned char cRMdefaultParams[128]; 9 | 10 | void patch_prog_start(); 11 | #endif //__CC3000_PATCH_PROG_H__ 12 | -------------------------------------------------------------------------------- /tests/basics/subclass_native_specmeth.py: -------------------------------------------------------------------------------- 1 | # Test calling non-special method inherited from native type 2 | 3 | class mylist(list): 4 | pass 5 | 6 | l = mylist([1, 2, 3]) 7 | print(l) 8 | print([e for e in l]) 9 | 10 | 11 | class mylist2(list): 12 | 13 | def __iter__(self): 14 | return iter([10, 20, 30]) 15 | 16 | l = mylist2([1, 2, 3]) 17 | print(l) 18 | print([e for e in l]) 19 | -------------------------------------------------------------------------------- /tests/inlineasm/asmfpsqrt.py: -------------------------------------------------------------------------------- 1 | # test vsqrt, vneg 2 | @micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1) 3 | def sqrt_test(r0, r1): 4 | vmov(s1, r0) 5 | vcvt_f32_s32(s1, s1) 6 | vsqrt(s1, s1) 7 | vmov(s2, r1) 8 | vcvt_f32_s32(s2, s2) 9 | vmul(s0, s1, s2) 10 | vneg(s7, s0) 11 | vcvt_s32_f32(s31, s7) 12 | vmov(r0, s31) 13 | 14 | print(sqrt_test(256, 10)) 15 | 16 | -------------------------------------------------------------------------------- /teensy/memzip_files/boot.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | print("Executing boot.py") 3 | 4 | def pins(): 5 | for pin_name in dir(pyb.Pin.board): 6 | pin = pyb.Pin(pin_name) 7 | print('{:10s} {:s}'.format(pin_name, str(pin))) 8 | 9 | def af(): 10 | for pin_name in dir(pyb.Pin.board): 11 | pin = pyb.Pin(pin_name) 12 | print('{:10s} {:s}'.format(pin_name, str(pin.af_list()))) 13 | -------------------------------------------------------------------------------- /tests/basics/async_await.py: -------------------------------------------------------------------------------- 1 | # test basic await expression 2 | # adapted from PEP0492 3 | 4 | async def abinary(n): 5 | print(n) 6 | if n <= 0: 7 | return 1 8 | l = await abinary(n - 1) 9 | r = await abinary(n - 1) 10 | return l + 1 + r 11 | 12 | o = abinary(4) 13 | try: 14 | while True: 15 | o.send(None) 16 | except StopIteration: 17 | print('finished') 18 | -------------------------------------------------------------------------------- /tests/basics/builtin_abs.py: -------------------------------------------------------------------------------- 1 | # test builtin abs 2 | 3 | print(abs(False)) 4 | print(abs(True)) 5 | print(abs(1)) 6 | print(abs(-1)) 7 | 8 | # bignum 9 | print(abs(123456789012345678901234567890)) 10 | print(abs(-123456789012345678901234567890)) 11 | 12 | # edge cases for 32 and 64 bit archs (small int overflow when negating) 13 | print(abs(-0x3fffffff - 1)) 14 | print(abs(-0x3fffffffffffffff - 1)) 15 | -------------------------------------------------------------------------------- /tests/basics/enumerate.py: -------------------------------------------------------------------------------- 1 | print(list(enumerate([]))) 2 | print(list(enumerate([1, 2, 3]))) 3 | print(list(enumerate([1, 2, 3], 5))) 4 | print(list(enumerate([1, 2, 3], -5))) 5 | print(list(enumerate(range(100)))) 6 | 7 | # specifying args with keywords 8 | print(list(enumerate([1, 2, 3], start=1))) 9 | print(list(enumerate(iterable=[1, 2, 3]))) 10 | print(list(enumerate(iterable=[1, 2, 3], start=1))) 11 | -------------------------------------------------------------------------------- /tests/basics/fun_calldblstar3.py: -------------------------------------------------------------------------------- 1 | # test passing a user-defined mapping as the argument to ** 2 | 3 | def foo(**kw): 4 | print(sorted(kw.items())) 5 | 6 | class Mapping: 7 | def keys(self): 8 | return ['a', 'b', 'c'] 9 | 10 | def __getitem__(self, key): 11 | if key == 'a': 12 | return 1 13 | else: 14 | return 2 15 | 16 | foo(**Mapping()) 17 | -------------------------------------------------------------------------------- /tests/bench/arrayop-1-list_inplace.py: -------------------------------------------------------------------------------- 1 | # Array operation 2 | # Type: list, inplace operation using for. What's good about this 3 | # method is that it doesn't require any extra memory allocation. 4 | import bench 5 | 6 | def test(num): 7 | for i in iter(range(num//10000)): 8 | arr = [0] * 1000 9 | for i in range(len(arr)): 10 | arr[i] += 1 11 | 12 | bench.run(test) 13 | -------------------------------------------------------------------------------- /tests/import/import_pkg1.py: -------------------------------------------------------------------------------- 1 | import pkg.mod 2 | 3 | print(pkg.__name__) 4 | print(pkg.mod.__name__) 5 | print(pkg.mod.foo()) 6 | 7 | # Import 2nd time, must be same module objects 8 | pkg_ = __import__("pkg.mod") 9 | print(pkg_ is not pkg.mod) 10 | print(pkg_ is pkg) 11 | print(pkg_.mod is pkg.mod) 12 | 13 | # import using "as" 14 | import pkg.mod as mm 15 | print(mm is pkg.mod) 16 | print(mm.foo()) 17 | -------------------------------------------------------------------------------- /tests/inlineasm/asmdiv.py: -------------------------------------------------------------------------------- 1 | @micropython.asm_thumb 2 | def sdiv(r0, r1): 3 | sdiv(r0, r0, r1) 4 | 5 | @micropython.asm_thumb 6 | def udiv(r0, r1): 7 | udiv(r0, r0, r1) 8 | 9 | print(sdiv(1234, 3)) 10 | print(sdiv(-1234, 3)) 11 | print(sdiv(1234, -3)) 12 | print(sdiv(-1234, -3)) 13 | 14 | print(udiv(1234, 3)) 15 | print(udiv(0xffffffff, 0x7fffffff)) 16 | print(udiv(0xffffffff, 0xffffffff)) 17 | -------------------------------------------------------------------------------- /tests/inlineasm/asmfpaddsub.py: -------------------------------------------------------------------------------- 1 | @micropython.asm_thumb # r0 = r0+r1-r2 2 | def add_sub(r0, r1, r2): 3 | vmov(s0, r0) 4 | vcvt_f32_s32(s0, s0) 5 | vmov(s1, r1) 6 | vcvt_f32_s32(s1, s1) 7 | vmov(s2, r2) 8 | vcvt_f32_s32(s2, s2) 9 | vadd(s0, s0, s1) 10 | vsub(s0, s0, s2) 11 | vcvt_s32_f32(s31, s0) 12 | vmov(r0, s31) 13 | 14 | print(add_sub(100, 20, 30)) 15 | 16 | -------------------------------------------------------------------------------- /tests/inlineasm/asmfpmuldiv.py: -------------------------------------------------------------------------------- 1 | @micropython.asm_thumb # r0 = (int)(r0*r1/r2) 2 | def muldiv(r0, r1, r2): 3 | vmov(s0, r0) 4 | vcvt_f32_s32(s0, s0) 5 | vmov(s1, r1) 6 | vcvt_f32_s32(s1, s1) 7 | vmov(s2, r2) 8 | vcvt_f32_s32(s2, s2) 9 | vmul(s7, s0, s1) 10 | vdiv(s8, s7, s2) 11 | vcvt_s32_f32(s31, s8) 12 | vmov(r0, s31) 13 | 14 | print(muldiv(100, 10, 50)) 15 | 16 | -------------------------------------------------------------------------------- /tests/basics/getattr1.py: -------------------------------------------------------------------------------- 1 | class A: 2 | 3 | var = 132 4 | 5 | def __init__(self): 6 | self.var2 = 34 7 | 8 | def meth(self, i): 9 | return 42 + i 10 | 11 | 12 | a = A() 13 | print(getattr(a, "var")) 14 | print(getattr(a, "var2")) 15 | print(getattr(a, "meth")(5)) 16 | print(getattr(a, "_none_such", 123)) 17 | print(getattr(list, "foo", 456)) 18 | print(getattr(a, "va" + "r2")) 19 | -------------------------------------------------------------------------------- /tests/float/float_array.py: -------------------------------------------------------------------------------- 1 | from array import array 2 | 3 | def test(a): 4 | print(a) 5 | a.append(1.2) 6 | print(len(a), '%.3f' % a[0]) 7 | a.append(1) 8 | a.append(False) 9 | print(len(a), '%.3f %.3f' % (a[1], a[2])) 10 | a[-1] = 3.45 11 | print('%.3f' % a[-1]) 12 | 13 | test(array('f')) 14 | test(array('d')) 15 | 16 | print('{:.4f}'.format(array('f', b'\xcc\xcc\xcc=')[0])) 17 | -------------------------------------------------------------------------------- /docs/wipy_index.rst: -------------------------------------------------------------------------------- 1 | MicroPython documentation and references 2 | ======================================== 3 | 4 | .. toctree:: 5 | 6 | wipy/quickref.rst 7 | wipy/general.rst 8 | wipy/tutorial/index.rst 9 | library/index.rst 10 | license.rst 11 | wipy_contents.rst 12 | 13 | Indices and tables 14 | ================== 15 | 16 | * :ref:`genindex` 17 | * :ref:`modindex` 18 | * :ref:`search` 19 | -------------------------------------------------------------------------------- /stmhal/boards/NETDUINO_PLUS_2/pins.csv: -------------------------------------------------------------------------------- 1 | D0,PC7 2 | D1,PC6 3 | D2,PA3 4 | D3,PA2 5 | D4,PB12 6 | D5,PB8 7 | D6,PB9 8 | D7,PA1 9 | D8,PA0 10 | D9,PA6 11 | D10,PB10 12 | D11,PB15 13 | D12,PB14 14 | D13,PB13 15 | SDA,PB6 16 | SCL,PB7 17 | A0,PC0 18 | A1,PC1 19 | A2,PC2 20 | A3,PC3 21 | A4,PC4 22 | A5,PC5 23 | LED,PA10 24 | SW,PB11 25 | PWR_LED,PC13 26 | PWR_SD,PB1 27 | PWR_HDR,PB2 28 | PWR_ETH,PC15 29 | RST_ETH,PD2 30 | 31 | -------------------------------------------------------------------------------- /tests/basics/fun_calldblstar.py: -------------------------------------------------------------------------------- 1 | # test calling a function with keywords given by **dict 2 | 3 | def f(a, b): 4 | print(a, b) 5 | 6 | f(1, **{'b':2}) 7 | f(1, **{'b':val for val in range(1)}) 8 | 9 | # test calling a method with keywords given by **dict 10 | 11 | class A: 12 | def f(self, a, b): 13 | print(a, b) 14 | 15 | a = A() 16 | a.f(1, **{'b':2}) 17 | a.f(1, **{'b':val for val in range(1)}) 18 | -------------------------------------------------------------------------------- /tests/basics/int_divmod.py: -------------------------------------------------------------------------------- 1 | # test integer floor division and modulo 2 | 3 | # test all combination of +/-/0 cases 4 | for i in range(-2, 3): 5 | for j in range(-4, 5): 6 | if j != 0: 7 | print(i, j, i // j, i % j, divmod(i, j)) 8 | 9 | # this tests bignum modulo 10 | a = 987654321987987987987987987987 11 | b = 19 12 | print(a % b) 13 | print(a % -b) 14 | print(-a % b) 15 | print(-a % -b) 16 | -------------------------------------------------------------------------------- /tests/micropython/const_error.py: -------------------------------------------------------------------------------- 1 | # make sure syntax error works correctly for bad const definition 2 | 3 | from micropython import const 4 | 5 | def test_syntax(code): 6 | try: 7 | exec(code) 8 | except SyntaxError: 9 | print("SyntaxError") 10 | 11 | # argument not a constant 12 | test_syntax("a = const(x)") 13 | 14 | # redefined constant 15 | test_syntax("A = const(1); A = const(2)") 16 | -------------------------------------------------------------------------------- /docs/wipy/tutorial/index.rst: -------------------------------------------------------------------------------- 1 | .. _wipy_tutorial_index: 2 | 3 | WiPy tutorials and examples 4 | =========================== 5 | 6 | Before starting, make sure that you are running the latest firmware, 7 | for instructions see :ref:`OTA How-To `. 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :numbered: 12 | 13 | intro.rst 14 | repl.rst 15 | blynk.rst 16 | wlan.rst 17 | reset.rst 18 | -------------------------------------------------------------------------------- /lib/memzip/import.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "py/lexer.h" 4 | #include "memzip.h" 5 | 6 | mp_import_stat_t mp_import_stat(const char *path) { 7 | MEMZIP_FILE_INFO info; 8 | 9 | if (memzip_stat(path, &info) != MZ_OK) { 10 | return MP_IMPORT_STAT_NO_EXIST; 11 | } 12 | 13 | if (info.is_dir) { 14 | return MP_IMPORT_STAT_DIR; 15 | } 16 | return MP_IMPORT_STAT_FILE; 17 | } 18 | -------------------------------------------------------------------------------- /tests/bench/arrayop-3-bytearray_inplace.py: -------------------------------------------------------------------------------- 1 | # Array operation 2 | # Type: bytearray, inplace operation using for. What's good about this 3 | # method is that it doesn't require any extra memory allocation. 4 | import bench 5 | 6 | def test(num): 7 | for i in iter(range(num//10000)): 8 | arr = bytearray(b"\0" * 1000) 9 | for i in range(len(arr)): 10 | arr[i] += 1 11 | 12 | bench.run(test) 13 | -------------------------------------------------------------------------------- /tests/pyb/modstm.py: -------------------------------------------------------------------------------- 1 | # test stm module 2 | 3 | import stm 4 | import pyb 5 | 6 | # test storing a full 32-bit number 7 | # turn on then off the A15(=yellow) LED 8 | BSRR = 0x18 9 | stm.mem32[stm.GPIOA + BSRR] = 0x00008000 10 | pyb.delay(100) 11 | print(hex(stm.mem32[stm.GPIOA + stm.GPIO_ODR] & 0x00008000)) 12 | stm.mem32[stm.GPIOA + BSRR] = 0x80000000 13 | print(hex(stm.mem32[stm.GPIOA + stm.GPIO_ODR] & 0x00008000)) 14 | -------------------------------------------------------------------------------- /tests/basics/class_item.py: -------------------------------------------------------------------------------- 1 | # test class with __getitem__, __setitem__, __delitem__ methods 2 | 3 | class C: 4 | def __getitem__(self, item): 5 | print('get', item) 6 | return 'item' 7 | 8 | def __setitem__(self, item, value): 9 | print('set', item, value) 10 | 11 | def __delitem__(self, item): 12 | print('del', item) 13 | 14 | c = C() 15 | print(c[1]) 16 | c[1] = 2 17 | del c[3] 18 | -------------------------------------------------------------------------------- /tests/basics/string_startswith.py: -------------------------------------------------------------------------------- 1 | print("foobar".startswith("foo")) 2 | print("foobar".startswith("Foo")) 3 | print("foobar".startswith("foo1")) 4 | print("foobar".startswith("foobar")) 5 | print("foobar".startswith("")) 6 | 7 | print("1foobar".startswith("foo", 1)) 8 | print("1foo".startswith("foo", 1)) 9 | print("1foo".startswith("1foo", 1)) 10 | print("1fo".startswith("foo", 1)) 11 | print("1fo".startswith("foo", 10)) 12 | -------------------------------------------------------------------------------- /docs/pyboard/tutorial/power_ctrl.rst: -------------------------------------------------------------------------------- 1 | Power control 2 | ============= 3 | 4 | :meth:`pyb.wfi` is used to reduce power consumption while waiting for an 5 | event such as an interrupt. You would use it in the following situation:: 6 | 7 | while True: 8 | do_some_processing() 9 | pyb.wfi() 10 | 11 | Control the frequency using :meth:`pyb.freq`:: 12 | 13 | pyb.freq(30000000) # set CPU frequency to 30MHz 14 | -------------------------------------------------------------------------------- /tests/basics/equal_class.py: -------------------------------------------------------------------------------- 1 | # test equality for classes/instances to other types 2 | 3 | class A: 4 | pass 5 | 6 | class B: 7 | pass 8 | 9 | class C(A): 10 | pass 11 | 12 | print(A == None) 13 | print(None == A) 14 | 15 | print(A == A) 16 | print(A() == A) 17 | print(A() == A()) 18 | 19 | print(A == B) 20 | print(A() == B) 21 | print(A() == B()) 22 | 23 | print(A == C) 24 | print(A() == C) 25 | print(A() == C()) 26 | -------------------------------------------------------------------------------- /tests/basics/gen_yield_from_stopped.py: -------------------------------------------------------------------------------- 1 | # Yielding from stopped generator is ok and results in None 2 | 3 | def gen(): 4 | return 1 5 | # This yield is just to make this a generator 6 | yield 7 | 8 | f = gen() 9 | 10 | def run(): 11 | print((yield from f)) 12 | print((yield from f)) 13 | print((yield from f)) 14 | 15 | try: 16 | next(run()) 17 | except StopIteration: 18 | print("StopIteration") 19 | -------------------------------------------------------------------------------- /tests/basics/subclass_native_buffer.py: -------------------------------------------------------------------------------- 1 | # test when we subclass a type with the buffer protocol 2 | 3 | class my_bytes(bytes): 4 | pass 5 | 6 | b1 = my_bytes([0, 1]) 7 | b2 = my_bytes([2, 3]) 8 | b3 = bytes([4, 5]) 9 | 10 | # addition will use the buffer protocol on the RHS 11 | print(b1 + b2) 12 | print(b1 + b3) 13 | print(b3 + b1) 14 | 15 | # bytearray construction will use the buffer protocol 16 | print(bytearray(b1)) 17 | -------------------------------------------------------------------------------- /tests/bench/arrayop-2-list_map.py: -------------------------------------------------------------------------------- 1 | # Array operation 2 | # Type: list, map() call. This method requires allocation of 3 | # the same amount of memory as original array (to hold result 4 | # array). On the other hand, input array stays intact. 5 | import bench 6 | 7 | def test(num): 8 | for i in iter(range(num//10000)): 9 | arr = [0] * 1000 10 | arr2 = list(map(lambda x: x + 1, arr)) 11 | 12 | bench.run(test) 13 | -------------------------------------------------------------------------------- /tests/micropython/viper_binop_arith.py.exp: -------------------------------------------------------------------------------- 1 | 3 2 | 3 3 | 45 4 | 45 5 | 1 6 | 1 7 | -45 8 | -45 9 | -1 10 | 1 11 | 39 12 | -39 13 | -3 14 | 3 15 | -39 16 | 39 17 | 0 18 | 0 19 | -1 20 | -1 21 | 2 22 | 2 23 | 24 24 | 24 25 | -12 26 | -12 27 | 54 28 | 54 29 | 1 30 | 8 31 | 1073741824 32 | 43008 33 | -43008 34 | 1 35 | 0 36 | 10 37 | -11 38 | 0 0 39 | 1 1 40 | 48 48 41 | 6 6 42 | 1 1 43 | 3 3 44 | -41 -41 45 | 1 1 46 | 3 3 47 | -45 -45 48 | -------------------------------------------------------------------------------- /tests/basics/list_mult.py: -------------------------------------------------------------------------------- 1 | # basic multiplication 2 | print([0] * 5) 3 | 4 | # check negative, 0, positive; lhs and rhs multiplication 5 | for i in (-4, -2, 0, 2, 4): 6 | print(i * [1, 2]) 7 | print([1, 2] * i) 8 | 9 | # check that we don't modify existing list 10 | a = [1, 2, 3] 11 | c = a * 3 12 | print(a, c) 13 | 14 | # unsupported type on RHS 15 | try: 16 | [] * None 17 | except TypeError: 18 | print('TypeError') 19 | -------------------------------------------------------------------------------- /tests/basics/subclass_native2_tuple.py: -------------------------------------------------------------------------------- 1 | class Base1: 2 | def __init__(self, *args): 3 | print("Base1.__init__", args) 4 | 5 | class Ctuple1(Base1, tuple): 6 | pass 7 | 8 | a = Ctuple1() 9 | print(len(a)) 10 | a = Ctuple1([1, 2, 3]) 11 | print(len(a)) 12 | 13 | print("---") 14 | 15 | class Ctuple2(tuple, Base1): 16 | pass 17 | 18 | a = Ctuple2() 19 | print(len(a)) 20 | a = Ctuple2([1, 2, 3]) 21 | print(len(a)) 22 | -------------------------------------------------------------------------------- /tests/wipy/reset/reset.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Reset script for the cc3200 boards 3 | This is needed to force the board to reboot 4 | with the default WLAN AP settings 5 | ''' 6 | 7 | from machine import WDT 8 | import time 9 | import os 10 | 11 | mch = os.uname().machine 12 | if not 'LaunchPad' in mch and not 'WiPy' in mch: 13 | raise Exception('Board not supported!') 14 | 15 | wdt = WDT(timeout=1000) 16 | print(wdt) 17 | time.sleep_ms(900) 18 | -------------------------------------------------------------------------------- /lib/memzip/lexermemzip.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "py/lexer.h" 4 | #include "memzip.h" 5 | 6 | mp_lexer_t *mp_lexer_new_from_file(const char *filename) 7 | { 8 | void *data; 9 | size_t len; 10 | 11 | if (memzip_locate(filename, &data, &len) != MZ_OK) { 12 | return NULL; 13 | } 14 | 15 | return mp_lexer_new_from_str_len(qstr_from_str(filename), (const char *)data, (mp_uint_t)len, 0); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/basics/class_super.py: -------------------------------------------------------------------------------- 1 | class Base: 2 | 3 | def __init__(self): 4 | self.a = 1 5 | 6 | def meth(self): 7 | print("in Base meth", self.a) 8 | 9 | class Sub(Base): 10 | 11 | def meth(self): 12 | print("in Sub meth") 13 | return super().meth() 14 | 15 | a = Sub() 16 | a.meth() 17 | 18 | # printing super 19 | class A: 20 | def p(self): 21 | print(str(super())[:18]) 22 | A().p() 23 | -------------------------------------------------------------------------------- /tests/basics/except_match_tuple.py: -------------------------------------------------------------------------------- 1 | # test exception matching against a tuple 2 | 3 | try: 4 | fail 5 | except (Exception,): 6 | print('except 1') 7 | 8 | try: 9 | fail 10 | except (Exception, Exception): 11 | print('except 2') 12 | 13 | try: 14 | fail 15 | except (TypeError, NameError): 16 | print('except 3') 17 | 18 | try: 19 | fail 20 | except (TypeError, ValueError, Exception): 21 | print('except 4') 22 | -------------------------------------------------------------------------------- /tests/basics/list_pop.py: -------------------------------------------------------------------------------- 1 | # list poppin' 2 | a = [1, 2, 3] 3 | print(a.pop()) 4 | print(a.pop()) 5 | print(a.pop()) 6 | try: 7 | print(a.pop()) 8 | except IndexError: 9 | print("IndexError raised") 10 | else: 11 | raise AssertionError("No IndexError raised") 12 | 13 | # popping such that list storage shrinks (tests implementation detail of uPy) 14 | l = list(range(20)) 15 | for i in range(len(l)): 16 | l.pop() 17 | print(l) 18 | -------------------------------------------------------------------------------- /tests/basics/try4.py: -------------------------------------------------------------------------------- 1 | # triple nested exceptions 2 | 3 | def f(): 4 | try: 5 | foo() 6 | except: 7 | print("except 1") 8 | try: 9 | bar() 10 | except: 11 | print("except 2") 12 | try: 13 | baz() 14 | except: 15 | print("except 3") 16 | bak() 17 | 18 | try: 19 | f() 20 | except: 21 | print("f except") 22 | -------------------------------------------------------------------------------- /tests/basics/tuple_mult.py: -------------------------------------------------------------------------------- 1 | # basic multiplication 2 | print((0,) * 5) 3 | 4 | # check negative, 0, positive; lhs and rhs multiplication 5 | for i in (-4, -2, 0, 2, 4): 6 | print(i * (1, 2)) 7 | print((1, 2) * i) 8 | 9 | # check that we don't modify existing tuple 10 | a = (1, 2, 3) 11 | c = a * 3 12 | print(a, c) 13 | 14 | # unsupported type on RHS 15 | try: 16 | () * None 17 | except TypeError: 18 | print('TypeError') 19 | -------------------------------------------------------------------------------- /tests/micropython/const.py: -------------------------------------------------------------------------------- 1 | # test constant optimisation 2 | 3 | from micropython import const 4 | 5 | X = const(123) 6 | Y = const(X + 456) 7 | 8 | print(X, Y + 1) 9 | 10 | def f(): 11 | print(X, Y + 1) 12 | 13 | f() 14 | 15 | _X = const(12) 16 | _Y = const(_X + 34) 17 | 18 | print(_X, _Y) 19 | 20 | class A: 21 | Z = const(1) 22 | _Z = const(2) 23 | print(Z, _Z) 24 | 25 | print(hasattr(A, 'Z'), hasattr(A, '_Z')) 26 | -------------------------------------------------------------------------------- /tests/micropython/opt_level.py: -------------------------------------------------------------------------------- 1 | import micropython as micropython 2 | 3 | # check we can get and set the level 4 | micropython.opt_level(0) 5 | print(micropython.opt_level()) 6 | micropython.opt_level(1) 7 | print(micropython.opt_level()) 8 | 9 | # check that the optimisation levels actually differ 10 | micropython.opt_level(0) 11 | exec('print(__debug__)') 12 | micropython.opt_level(1) 13 | exec('print(__debug__)') 14 | exec('assert 0') 15 | -------------------------------------------------------------------------------- /tests/pyb/extint.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | 3 | # test basic functionality 4 | ext = pyb.ExtInt('X1', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l:print('line:', l)) 5 | ext.disable() 6 | ext.enable() 7 | print(ext.line()) 8 | ext.swint() 9 | 10 | # test swint while disabled, then again after re-enabled 11 | ext.disable() 12 | ext.swint() 13 | ext.enable() 14 | ext.swint() 15 | 16 | # disable now that the test is finished 17 | ext.disable() 18 | -------------------------------------------------------------------------------- /cc3200/bootmgr/runapp.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .cpu cortex-m4 3 | .thumb 4 | .text 5 | .align 2 6 | 7 | @ void bootmgr_run_app(_u32 base) 8 | .global bootmgr_run_app 9 | .thumb 10 | .thumb_func 11 | .type bootmgr_run_app, %function 12 | bootmgr_run_app: 13 | @ set the SP 14 | ldr sp, [r0] 15 | add r0, r0, #4 16 | 17 | @ jump to the entry code 18 | ldr r1, [r0] 19 | bx r1 20 | -------------------------------------------------------------------------------- /tests/basics/frozenset_set.py: -------------------------------------------------------------------------------- 1 | try: 2 | frozenset 3 | except NameError: 4 | print("SKIP") 5 | import sys 6 | sys.exit() 7 | 8 | # Examples from https://docs.python.org/3/library/stdtypes.html#set 9 | # "Instances of set are compared to instances of frozenset based on their 10 | # members. For example:" 11 | print(set('abc') == frozenset('abc')) 12 | # This doesn't work in uPy 13 | #print(set('abc') in set([frozenset('abc')])) 14 | -------------------------------------------------------------------------------- /tests/basics/gen_yield_from_throw.py: -------------------------------------------------------------------------------- 1 | def gen(): 2 | try: 3 | yield 1 4 | except ValueError: 5 | print("got ValueError from upstream!") 6 | yield "str1" 7 | raise TypeError 8 | 9 | def gen2(): 10 | print((yield from gen())) 11 | 12 | g = gen2() 13 | print(next(g)) 14 | print(g.throw(ValueError)) 15 | try: 16 | print(next(g)) 17 | except TypeError: 18 | print("got TypeError from downstream!") 19 | 20 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/axtls"] 2 | path = lib/axtls 3 | url = https://github.com/pfalcon/axtls 4 | branch = micropython 5 | [submodule "lib/libffi"] 6 | path = lib/libffi 7 | url = https://github.com/atgreen/libffi 8 | [submodule "lib/lwip"] 9 | path = lib/lwip 10 | url = http://git.savannah.gnu.org/r/lwip.git 11 | [submodule "lib/berkeley-db-1.xx"] 12 | path = lib/berkeley-db-1.xx 13 | url = https://github.com/pfalcon/berkeley-db-1.xx 14 | -------------------------------------------------------------------------------- /tests/basics/class_inherit1.py: -------------------------------------------------------------------------------- 1 | class A: 2 | def __init__(self, x): 3 | print('A init', x) 4 | self.x = x 5 | 6 | def f(self): 7 | print(self.x, self.y) 8 | 9 | class B(A): 10 | def __init__(self, x, y): 11 | A.__init__(self, x) 12 | print('B init', x, y) 13 | self.y = y 14 | 15 | def g(self): 16 | print(self.x, self.y) 17 | 18 | A(1) 19 | b = B(1, 2) 20 | b.f() 21 | b.g() 22 | -------------------------------------------------------------------------------- /tests/basics/fun_kwvarargs.py: -------------------------------------------------------------------------------- 1 | def f1(**kwargs): 2 | print(kwargs) 3 | 4 | f1() 5 | f1(a=1) 6 | 7 | def f2(a, **kwargs): 8 | print(a, kwargs) 9 | 10 | f2(1) 11 | f2(1, b=2) 12 | 13 | def f3(a, *vargs, **kwargs): 14 | print(a, vargs, kwargs) 15 | 16 | f3(1) 17 | f3(1, 2) 18 | f3(1, b=2) 19 | f3(1, 2, b=3) 20 | 21 | def f4(*vargs, **kwargs): 22 | print(vargs, kwargs) 23 | f4(*(1, 2)) 24 | f4(kw_arg=3) 25 | f4(*(1, 2), kw_arg=3) 26 | -------------------------------------------------------------------------------- /tests/basics/ordereddict1.py: -------------------------------------------------------------------------------- 1 | try: 2 | from collections import OrderedDict 3 | except ImportError: 4 | try: 5 | from ucollections import OrderedDict 6 | except ImportError: 7 | print("SKIP") 8 | import sys 9 | sys.exit() 10 | 11 | d = OrderedDict([(10, 20), ("b", 100), (1, 2)]) 12 | print(list(d.keys())) 13 | print(list(d.values())) 14 | del d["b"] 15 | print(list(d.keys())) 16 | print(list(d.values())) 17 | -------------------------------------------------------------------------------- /tests/extmod/ure_error.py: -------------------------------------------------------------------------------- 1 | # test errors in regex 2 | 3 | try: 4 | import ure as re 5 | except: 6 | import re 7 | 8 | def test_re(r): 9 | try: 10 | re.compile(r) 11 | print("OK") 12 | except: # uPy and CPy use different errors, so just ignore the type 13 | print("Error") 14 | 15 | test_re(r'?') 16 | test_re(r'*') 17 | test_re(r'+') 18 | test_re(r')') 19 | test_re(r'[') 20 | test_re(r'([') 21 | test_re(r'([)') 22 | -------------------------------------------------------------------------------- /tests/misc/non_compliant.py.exp: -------------------------------------------------------------------------------- 1 | SyntaxError 2 | AttributeError 3 | TypeError 4 | NotImplementedError 5 | NotImplementedError 6 | True 7 | True 8 | TypeError, ValueError 9 | NotImplementedError 10 | NotImplementedError 11 | NotImplementedError 12 | NotImplementedError 13 | NotImplementedError 14 | NotImplementedError 15 | NotImplementedError 16 | NotImplementedError 17 | NotImplementedError 18 | NotImplementedError 19 | b'\x01\x02' 20 | b'\x01\x00' 21 | -------------------------------------------------------------------------------- /tests/basics/generator1.py: -------------------------------------------------------------------------------- 1 | def f(x): 2 | print('a') 3 | y = x 4 | print('b') 5 | while y > 0: 6 | print('c') 7 | y -= 1 8 | print('d') 9 | yield y 10 | print('e') 11 | print('f') 12 | return None 13 | 14 | for val in f(3): 15 | print(val) 16 | 17 | #gen = f(3) 18 | #print(gen) 19 | #print(gen.__next__()) 20 | #print(gen.__next__()) 21 | #print(gen.__next__()) 22 | #print(gen.__next__()) 23 | -------------------------------------------------------------------------------- /tests/basics/generator_args.py: -------------------------------------------------------------------------------- 1 | # Handling of "complicated" arg forms to generators 2 | # https://github.com/micropython/micropython/issues/397 3 | def gen(v=5): 4 | for i in range(v): 5 | yield i 6 | 7 | print(list(gen())) 8 | print(list(gen(v=10))) 9 | 10 | 11 | def g(*args, **kwargs): 12 | for i in args: 13 | yield i 14 | for k, v in kwargs.items(): 15 | yield (k, v) 16 | 17 | print(list(g(1, 2, 3, foo="bar"))) 18 | -------------------------------------------------------------------------------- /tests/basics/memoryview_gc.py: -------------------------------------------------------------------------------- 1 | # test memoryview retains pointer to original object/buffer 2 | 3 | b = bytearray(10) 4 | m = memoryview(b)[1:] 5 | for i in range(len(m)): 6 | m[i] = i 7 | 8 | # reclaim b, but hopefully not the buffer 9 | b = None 10 | import gc 11 | gc.collect() 12 | 13 | # allocate lots of memory 14 | for i in range(100000): 15 | [42, 42, 42, 42] 16 | 17 | # check that the memoryview is still what we want 18 | print(list(m)) 19 | -------------------------------------------------------------------------------- /tests/bench/arrayop-4-bytearray_map.py: -------------------------------------------------------------------------------- 1 | # Array operation 2 | # Type: list, map() call. This method requires allocation of 3 | # the same amount of memory as original array (to hold result 4 | # array). On the other hand, input array stays intact. 5 | import bench 6 | 7 | def test(num): 8 | for i in iter(range(num//10000)): 9 | arr = bytearray(b"\0" * 1000) 10 | arr2 = bytearray(map(lambda x: x + 1, arr)) 11 | 12 | bench.run(test) 13 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_bytearray.py: -------------------------------------------------------------------------------- 1 | import uctypes 2 | 3 | desc = { 4 | "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2), 5 | "arr2": (uctypes.ARRAY | 2, uctypes.INT8 | 2), 6 | } 7 | 8 | data = bytearray(b"01234567") 9 | 10 | S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN) 11 | 12 | # Arrays of UINT8 are accessed as bytearrays 13 | print(S.arr) 14 | # But not INT8, because value range is different 15 | print(type(S.arr2)) 16 | -------------------------------------------------------------------------------- /tests/basics/class3.py: -------------------------------------------------------------------------------- 1 | # inheritance 2 | 3 | class A: 4 | def a(): 5 | print('A.a() called') 6 | 7 | class B(A): 8 | pass 9 | 10 | print(type(A)) 11 | print(type(B)) 12 | 13 | print(issubclass(A, A)) 14 | print(issubclass(A, B)) 15 | print(issubclass(B, A)) 16 | print(issubclass(B, B)) 17 | 18 | print(isinstance(A(), A)) 19 | print(isinstance(A(), B)) 20 | print(isinstance(B(), A)) 21 | print(isinstance(B(), B)) 22 | 23 | A.a() 24 | B.a() 25 | -------------------------------------------------------------------------------- /tests/basics/for1.py: -------------------------------------------------------------------------------- 1 | # basic for loop 2 | 3 | def f(): 4 | for x in range(2): 5 | for y in range(2): 6 | for z in range(2): 7 | print(x, y, z) 8 | 9 | f() 10 | 11 | # range with negative step 12 | for i in range(3, -1, -1): 13 | print(i) 14 | 15 | a = -1 16 | # range with non-constant step - we optimize constant steps, so this 17 | # will be executed differently 18 | for i in range(3, -1, a): 19 | print(i) 20 | -------------------------------------------------------------------------------- /tests/basics/string_endswith.py: -------------------------------------------------------------------------------- 1 | print("foobar".endswith("bar")) 2 | print("foobar".endswith("baR")) 3 | print("foobar".endswith("bar1")) 4 | print("foobar".endswith("foobar")) 5 | print("foobar".endswith("")) 6 | print("foobar".endswith("foobarbaz")) 7 | 8 | #print("1foobar".startswith("foo", 1)) 9 | #print("1foo".startswith("foo", 1)) 10 | #print("1foo".startswith("1foo", 1)) 11 | #print("1fo".startswith("foo", 1)) 12 | #print("1fo".startswith("foo", 10)) 13 | -------------------------------------------------------------------------------- /tests/extmod/uctypes_le_float.py: -------------------------------------------------------------------------------- 1 | import uctypes 2 | 3 | desc = { 4 | "f32": uctypes.FLOAT32 | 0, 5 | "f64": uctypes.FLOAT64 | 0, 6 | "uf64": uctypes.FLOAT64 | 2, # unaligned 7 | } 8 | 9 | data = bytearray(10) 10 | 11 | S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN) 12 | 13 | S.f32 = 12.34 14 | print('%.4f' % S.f32) 15 | 16 | S.f64 = 12.34 17 | print('%.4f' % S.f64) 18 | 19 | S.uf64 = 12.34 20 | print('%.4f' % S.uf64) 21 | -------------------------------------------------------------------------------- /tests/micropython/viper_subscr.py: -------------------------------------------------------------------------------- 1 | # test standard Python subscr using viper types 2 | 3 | @micropython.viper 4 | def get(dest, i:int): 5 | i += 1 6 | return dest[i] 7 | 8 | @micropython.viper 9 | def set(dest, i:int, val:int): 10 | i += 1 11 | dest[i] = val + 1 12 | 13 | ar = [i for i in range(3)] 14 | 15 | for i in range(len(ar)): 16 | set(ar, i - 1, i) 17 | print(ar) 18 | 19 | for i in range(len(ar)): 20 | print(get(ar, i - 1)) 21 | -------------------------------------------------------------------------------- /docs/pyboard_index.rst: -------------------------------------------------------------------------------- 1 | MicroPython documentation and references 2 | ======================================== 3 | 4 | .. toctree:: 5 | 6 | pyboard/quickref.rst 7 | pyboard/general.rst 8 | pyboard/tutorial/index.rst 9 | library/index.rst 10 | pyboard/hardware/index.rst 11 | license.rst 12 | pyboard_contents.rst 13 | 14 | Indices and tables 15 | ================== 16 | 17 | * :ref:`genindex` 18 | * :ref:`modindex` 19 | * :ref:`search` 20 | -------------------------------------------------------------------------------- /tests/bench/bytebuf-2-join_map_bytes.py: -------------------------------------------------------------------------------- 1 | # Doing some operation on bytearray 2 | # Pretty weird way - map bytearray thru function, but make sure that 3 | # function return bytes of size 1, then join them together. Surely, 4 | # this is slowest way to do it. 5 | import bench 6 | 7 | def test(num): 8 | for i in iter(range(num//10000)): 9 | ba = bytearray(b"\0" * 1000) 10 | ba2 = b''.join(map(lambda x:bytes([x + 1]), ba)) 11 | 12 | bench.run(test) 13 | -------------------------------------------------------------------------------- /tests/unicode/unicode_subscr.py: -------------------------------------------------------------------------------- 1 | a = '¢пр' 2 | 3 | print(a[0], a[0:1]) 4 | print(a[1], a[1:2]) 5 | print(a[2], a[2:3]) 6 | try: 7 | print(a[3]) 8 | except IndexError: 9 | print("IndexError") 10 | print(a[3:4]) 11 | 12 | print(a[-1]) 13 | print(a[-2], a[-2:-1]) 14 | print(a[-3], a[-3:-2]) 15 | try: 16 | print(a[-4]) 17 | except IndexError: 18 | print("IndexError") 19 | print(a[-4:-3]) 20 | 21 | print(a[0:2]) 22 | print(a[1:3]) 23 | print(a[2:4]) 24 | -------------------------------------------------------------------------------- /docs/library/uzlib.rst: -------------------------------------------------------------------------------- 1 | :mod:`uzlib` -- zlib decompression 2 | ================================== 3 | 4 | .. module:: uzlib 5 | :synopsis: zlib decompression 6 | 7 | This modules allows to decompress binary data compressed with DEFLATE 8 | algorithm (commonly used in zlib library and gzip archiver). Compression 9 | is not yet implemented. 10 | 11 | Functions 12 | --------- 13 | 14 | .. function:: decompress(data) 15 | 16 | Return decompressed data as bytes. 17 | -------------------------------------------------------------------------------- /tests/basics/del_deref.py: -------------------------------------------------------------------------------- 1 | def f(): 2 | x = 1 3 | y = 2 4 | def g(): 5 | nonlocal x 6 | print(y) 7 | try: 8 | print(x) 9 | except NameError: 10 | print("NameError") 11 | def h(): 12 | nonlocal x 13 | print(y) 14 | try: 15 | del x 16 | except NameError: 17 | print("NameError") 18 | print(x, y) 19 | del x 20 | g() 21 | h() 22 | f() 23 | -------------------------------------------------------------------------------- /tests/basics/errno1.py: -------------------------------------------------------------------------------- 1 | # test errno's and uerrno module 2 | 3 | try: 4 | import uerrno 5 | except ImportError: 6 | print("SKIP") 7 | import sys 8 | sys.exit() 9 | 10 | # check that constants exist and are integers 11 | print(type(uerrno.EIO)) 12 | 13 | # check that errors are rendered in a nice way 14 | msg = str(OSError(uerrno.EIO)) 15 | print(msg[:7], msg[-5:]) 16 | 17 | # check that unknown errno is still rendered 18 | print(str(OSError(9999))) 19 | -------------------------------------------------------------------------------- /tests/basics/int_big_div.py: -------------------------------------------------------------------------------- 1 | for lhs in (1000000000000000000000000, 10000000000100000000000000, 10012003400000000000000007, 12349083434598210349871029923874109871234789): 2 | for rhs in range(1, 555): 3 | print(lhs // rhs) 4 | 5 | # these check an edge case on 64-bit machines where two mpz limbs 6 | # are used and the most significant one has the MSB set 7 | x = 0x8000000000000000 8 | print((x + 1) // x) 9 | x = 0x86c60128feff5330 10 | print((x + 1) // x) 11 | -------------------------------------------------------------------------------- /tests/cmdline/repl_cont.py: -------------------------------------------------------------------------------- 1 | # check REPL allows to continue input 2 | 1 \ 3 | + 2 4 | '"' 5 | "'" 6 | '\'' 7 | "\"" 8 | '\'(' 9 | "\"(" 10 | print("\"(") 11 | print('\'(') 12 | print("\'(") 13 | print('\"(') 14 | 'abc' 15 | "abc" 16 | '''abc 17 | def''' 18 | """ABC 19 | DEF""" 20 | print( 21 | 1 + 2) 22 | l = [1, 23 | 2] 24 | print(l) 25 | d = {1:'one', 26 | 2:'two'} 27 | print(d[2]) 28 | def f(x): 29 | print(x) 30 |  31 | f(3) 32 | if1=1 33 | if1 = 2 34 | print(if1) 35 | -------------------------------------------------------------------------------- /tests/float/math_fun_bool.py: -------------------------------------------------------------------------------- 1 | # Test the bool functions from math 2 | 3 | try: 4 | from math import isfinite, isnan, isinf 5 | except ImportError: 6 | print("SKIP") 7 | import sys 8 | sys.exit() 9 | 10 | test_values = [1, 0, -1, 1.0, 0.0, -1.0, float('NaN'), float('Inf'), 11 | -float('NaN'), -float('Inf')] 12 | 13 | functions = [isfinite, isnan, isinf] 14 | 15 | for val in test_values: 16 | for f in functions: 17 | print(f(val)) 18 | -------------------------------------------------------------------------------- /tests/io/bytesio_ext.py: -------------------------------------------------------------------------------- 1 | # Extended stream operations on io.BytesIO 2 | try: 3 | import uio as io 4 | except ImportError: 5 | import io 6 | 7 | a = io.BytesIO() 8 | print(a.seek(8)) 9 | a.write(b"123") 10 | print(a.getvalue()) 11 | 12 | print(a.seek(0, 1)) 13 | 14 | print(a.seek(-1, 2)) 15 | a.write(b"0") 16 | print(a.getvalue()) 17 | 18 | a.flush() 19 | print(a.getvalue()) 20 | 21 | a.seek(0) 22 | arr = bytearray(10) 23 | print(a.readinto(arr)) 24 | print(arr) 25 | -------------------------------------------------------------------------------- /zephyr/modmachine.h: -------------------------------------------------------------------------------- 1 | #ifndef __MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H__ 2 | #define __MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H__ 3 | 4 | #include "py/obj.h" 5 | 6 | extern const mp_obj_type_t machine_pin_type; 7 | 8 | MP_DECLARE_CONST_FUN_OBJ_0(machine_info_obj); 9 | 10 | typedef struct _machine_pin_obj_t { 11 | mp_obj_base_t base; 12 | struct device *port; 13 | uint32_t pin; 14 | } machine_pin_obj_t; 15 | 16 | #endif // __MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H__ 17 | --------------------------------------------------------------------------------