Skip to content

Commit 74b9a8e

Browse files
committed
add examples and license
1 parent 80c2dda commit 74b9a8e

File tree

4 files changed

+232
-0
lines changed

4 files changed

+232
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.c
22
*.h
33
__pycache__
4+
!modexample.c

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Pavol Rusnak
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,25 @@ micropython-extmod-generator
22
============================
33

44
Generator for Micropython external modules written in C
5+
6+
Usage
7+
-----
8+
9+
```
10+
generate [module]
11+
```
12+
13+
Program will look for file named `module.py` and generate `modmodule.c`.
14+
15+
If an argument is not provided, the default `example` will be used.
16+
17+
Example
18+
-------
19+
20+
* input: [example.py](example.py)
21+
* output: [modexample.c](modexample.c)
22+
23+
License
24+
-------
25+
26+
Licensed under MIT License.

modexample.c

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Pavol Rusnak
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <stdio.h>
28+
#include <assert.h>
29+
#include <string.h>
30+
31+
#include "py/nlr.h"
32+
#include "py/runtime.h"
33+
#include "py/binary.h"
34+
35+
STATIC mp_obj_t mod_example_func_a(void) {
36+
// TODO
37+
return mp_const_none;
38+
}
39+
MP_DEFINE_CONST_FUN_OBJ_0(mod_example_func_a_obj, mod_example_func_a);
40+
41+
STATIC mp_obj_t mod_example_func_b(mp_obj_t arg1) {
42+
// TODO
43+
return mp_const_none;
44+
}
45+
MP_DEFINE_CONST_FUN_OBJ_1(mod_example_func_b_obj, mod_example_func_b);
46+
47+
STATIC mp_obj_t mod_example_func_c(mp_obj_t arg1, mp_obj_t arg2) {
48+
// TODO
49+
return mp_const_none;
50+
}
51+
MP_DEFINE_CONST_FUN_OBJ_2(mod_example_func_c_obj, mod_example_func_c);
52+
53+
STATIC mp_obj_t mod_example_func_d(mp_obj_t arg1, mp_obj_t arg2, mp_obj_t arg3) {
54+
// TODO
55+
return mp_const_none;
56+
}
57+
MP_DEFINE_CONST_FUN_OBJ_3(mod_example_func_d_obj, mod_example_func_d);
58+
59+
STATIC mp_obj_t mod_example_func_e(size_t n_args, const mp_obj_t *args) {
60+
// TODO
61+
return mp_const_none;
62+
}
63+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_func_e_obj, 4, 4, mod_example_func_e);
64+
65+
STATIC mp_obj_t mod_example_func_f(size_t n_args, const mp_obj_t *args) {
66+
// TODO
67+
return mp_const_none;
68+
}
69+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_func_f_obj, 5, 5, mod_example_func_f);
70+
71+
STATIC mp_obj_t mod_example_func_g(size_t n_args, const mp_obj_t *args) {
72+
// TODO
73+
return mp_const_none;
74+
}
75+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_func_g_obj, 2, 4, mod_example_func_g);
76+
77+
STATIC mp_obj_t mod_example_func_h(size_t n_args, const mp_obj_t *args) {
78+
// TODO
79+
return mp_const_none;
80+
}
81+
MP_DEFINE_CONST_FUN_OBJ_VAR(mod_example_func_h_obj, 3, mod_example_func_h);
82+
83+
STATIC mp_obj_t mod_example_func_i(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
84+
// TODO
85+
return mp_const_none;
86+
}
87+
MP_DEFINE_CONST_FUN_OBJ_KW(mod_example_func_i_obj, 2, mod_example_func_i);
88+
89+
STATIC mp_obj_t mod_example_Klass_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
90+
// TODO
91+
return mp_const_none;
92+
}
93+
94+
STATIC mp_obj_t mod_example_Klass_func_a(mp_obj_t self) {
95+
// TODO
96+
return mp_const_none;
97+
}
98+
MP_DEFINE_CONST_FUN_OBJ_1(mod_example_Klass_func_a_obj, mod_example_Klass_func_a);
99+
100+
STATIC mp_obj_t mod_example_Klass_func_b(mp_obj_t self, mp_obj_t arg1) {
101+
// TODO
102+
return mp_const_none;
103+
}
104+
MP_DEFINE_CONST_FUN_OBJ_2(mod_example_Klass_func_b_obj, mod_example_Klass_func_b);
105+
106+
STATIC mp_obj_t mod_example_Klass_func_c(mp_obj_t self, mp_obj_t arg1, mp_obj_t arg2) {
107+
// TODO
108+
return mp_const_none;
109+
}
110+
MP_DEFINE_CONST_FUN_OBJ_3(mod_example_Klass_func_c_obj, mod_example_Klass_func_c);
111+
112+
STATIC mp_obj_t mod_example_Klass_func_d(size_t n_args, const mp_obj_t *args) {
113+
// TODO
114+
return mp_const_none;
115+
}
116+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_Klass_func_d_obj, 4, 4, mod_example_Klass_func_d);
117+
118+
STATIC mp_obj_t mod_example_Klass_func_e(size_t n_args, const mp_obj_t *args) {
119+
// TODO
120+
return mp_const_none;
121+
}
122+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_Klass_func_e_obj, 5, 5, mod_example_Klass_func_e);
123+
124+
STATIC mp_obj_t mod_example_Klass_func_f(size_t n_args, const mp_obj_t *args) {
125+
// TODO
126+
return mp_const_none;
127+
}
128+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_Klass_func_f_obj, 6, 6, mod_example_Klass_func_f);
129+
130+
STATIC mp_obj_t mod_example_Klass_func_g(size_t n_args, const mp_obj_t *args) {
131+
// TODO
132+
return mp_const_none;
133+
}
134+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_Klass_func_g_obj, 3, 5, mod_example_Klass_func_g);
135+
136+
STATIC mp_obj_t mod_example_Klass_func_h(size_t n_args, const mp_obj_t *args) {
137+
// TODO
138+
return mp_const_none;
139+
}
140+
MP_DEFINE_CONST_FUN_OBJ_VAR(mod_example_Klass_func_h_obj, 4, mod_example_Klass_func_h);
141+
142+
STATIC mp_obj_t mod_example_Klass_func_i(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
143+
// TODO
144+
return mp_const_none;
145+
}
146+
MP_DEFINE_CONST_FUN_OBJ_KW(mod_example_Klass_func_i_obj, 3, mod_example_Klass_func_i);
147+
148+
STATIC const mp_rom_map_elem_t mod_example_Klass_locals_dict_table[] = {
149+
{ MP_ROM_QSTR(MP_QSTR_func_a), MP_ROM_PTR(&mod_example_Klass_func_a_obj) },
150+
{ MP_ROM_QSTR(MP_QSTR_func_b), MP_ROM_PTR(&mod_example_Klass_func_b_obj) },
151+
{ MP_ROM_QSTR(MP_QSTR_func_c), MP_ROM_PTR(&mod_example_Klass_func_c_obj) },
152+
{ MP_ROM_QSTR(MP_QSTR_func_d), MP_ROM_PTR(&mod_example_Klass_func_d_obj) },
153+
{ MP_ROM_QSTR(MP_QSTR_func_e), MP_ROM_PTR(&mod_example_Klass_func_e_obj) },
154+
{ MP_ROM_QSTR(MP_QSTR_func_f), MP_ROM_PTR(&mod_example_Klass_func_f_obj) },
155+
{ MP_ROM_QSTR(MP_QSTR_func_g), MP_ROM_PTR(&mod_example_Klass_func_g_obj) },
156+
{ MP_ROM_QSTR(MP_QSTR_func_h), MP_ROM_PTR(&mod_example_Klass_func_h_obj) },
157+
{ MP_ROM_QSTR(MP_QSTR_func_i), MP_ROM_PTR(&mod_example_Klass_func_i_obj) },
158+
};
159+
STATIC MP_DEFINE_CONST_DICT(mod_example_Klass_locals_dict, mod_example_Klass_locals_dict_table);
160+
161+
STATIC const mp_obj_type_t mod_example_Klass_type = {
162+
{ &mp_type_type },
163+
.name = MP_QSTR_Klass,
164+
.make_new = mod_example_Klass_make_new,
165+
.locals_dict = (void*)&mod_example_Klass_locals_dict,
166+
};
167+
168+
STATIC const mp_rom_map_elem_t mp_module_example_globals_table[] = {
169+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example) },
170+
{ MP_ROM_QSTR(MP_QSTR_func_a), MP_ROM_PTR(&mod_example_func_a_obj) },
171+
{ MP_ROM_QSTR(MP_QSTR_func_b), MP_ROM_PTR(&mod_example_func_b_obj) },
172+
{ MP_ROM_QSTR(MP_QSTR_func_c), MP_ROM_PTR(&mod_example_func_c_obj) },
173+
{ MP_ROM_QSTR(MP_QSTR_func_d), MP_ROM_PTR(&mod_example_func_d_obj) },
174+
{ MP_ROM_QSTR(MP_QSTR_func_e), MP_ROM_PTR(&mod_example_func_e_obj) },
175+
{ MP_ROM_QSTR(MP_QSTR_func_f), MP_ROM_PTR(&mod_example_func_f_obj) },
176+
{ MP_ROM_QSTR(MP_QSTR_func_g), MP_ROM_PTR(&mod_example_func_g_obj) },
177+
{ MP_ROM_QSTR(MP_QSTR_func_h), MP_ROM_PTR(&mod_example_func_h_obj) },
178+
{ MP_ROM_QSTR(MP_QSTR_func_i), MP_ROM_PTR(&mod_example_func_i_obj) },
179+
{ MP_ROM_QSTR(MP_QSTR_Klass), MP_ROM_PTR(&mod_example_Klass_type) },
180+
};
181+
182+
STATIC MP_DEFINE_CONST_DICT(mp_module_example_globals, mp_module_example_globals_table);
183+
184+
const mp_obj_module_t mp_module_example = {
185+
.base = { &mp_type_module },
186+
.name = MP_QSTR_example,
187+
.globals = (mp_obj_dict_t*)&mp_module_example_globals,
188+
};

0 commit comments

Comments
 (0)