-
Notifications
You must be signed in to change notification settings - Fork 2
/
micropython_.py
89 lines (82 loc) · 2.82 KB
/
micropython_.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
Generate `pyi` from corresponding `rst` docs.
"""
import rst
from rst2pyi import RST2PyI
__author__ = rst.__author__
__copyright__ = rst.__copyright__
__license__ = rst.__license__
__version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver
def micropython(shed: RST2PyI) -> None:
shed.module(
name="micropython",
old="access and control MicroPython internals",
post_doc=f'''
from typing import TypeVar, overload, Callable, Any, Final
_T: Final = TypeVar('_T')
_F: Final = TypeVar("_F", bound=Callable[..., Any])
def native(func: _F) -> _F:
"""
This causes the MicroPython compiler to emit unoptimised native CPU opcodes
rather than bytecode (normal) or optimised opcodes (viper) and is an optimisation,
for more information see
https://docs.micropython.org/en/latest/reference/speed_python.html#the-native-code-emitter.
"""
def viper(func: _F) -> _F:
"""
This causes the MicroPython compiler to emit optimised native CPU opcodes based on special typehints
rather than bytecode (normal) or unoptimised opcodes (native) and is an optimisation,
for more information see
https://docs.micropython.org/en/latest/reference/speed_python.html#the-viper-code-emitter.
"""
''',
end="Functions",
)
shed.consume_minuses_underline_line(and_preceding_lines=True)
shed.def_(
old=r".. function:: const(expr)", new="def const(expr: _T, /) -> _T", indent=0,
)
shed.def_(
old=r".. function:: opt_level([level])",
new=["def opt_level() -> int", "def opt_level(level: int, /) -> None"],
indent=0,
)
shed.def_(
old=r".. function:: alloc_emergency_exception_buf(size)",
new="def alloc_emergency_exception_buf(size: int, /) -> None",
indent=0,
)
shed.def_(
old=r".. function:: mem_info([verbose])",
new=["def mem_info() -> None", "def mem_info(verbose: Any, /) -> None"],
indent=0,
)
shed.def_(
old=r".. function:: qstr_info([verbose])",
new=["def qstr_info() -> None", "def qstr_info(verbose: bool, /) -> None"],
indent=0,
)
shed.def_(
old=r".. function:: stack_use()", new="def stack_use() -> int", indent=0,
)
cmd = r".. function:: "
kbd = cmd + r"kbd_intr(chr)"
shed.defs_with_common_description(
cmd=cmd,
old2new={
r"heap_lock()": "def heap_lock() -> None",
r"heap_unlock()": "def heap_unlock() -> None",
r"heap_locked()": "def heap_locked() -> bool",
},
end=kbd,
indent=0,
)
shed.def_(
old=kbd, new="def kbd_intr(chr: int) -> None", indent=0,
)
shed.def_(
old=r".. function:: schedule(func, arg)",
new="def schedule(func: Callable[[_T], None], arg: _T, /) -> None",
indent=0,
)
shed.write()