Skip to content

Commit 104aa26

Browse files
Colin Hogbenpfalcon
authored andcommitted
cc3200, stmhal, teensy: Use pyhelp_print_obj function.
Update the help() implementations in the cc3200, stmhal and teensy ports to use the pyhelp_print_obj function.
1 parent 2b46da2 commit 104aa26

6 files changed

Lines changed: 9 additions & 106 deletions

File tree

cc3200/application.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ APP_LIB_SRC_C = $(addprefix lib/,\
152152
netutils/netutils.c \
153153
timeutils/timeutils.c \
154154
utils/pyexec.c \
155+
utils/pyhelp.c \
155156
utils/printf.c \
156157
)
157158

cc3200/misc/help.c

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,20 @@
2727

2828
#include <stdio.h>
2929

30-
#include "py/mpconfig.h"
31-
#include "py/obj.h"
30+
#include "lib/utils/pyhelp.h"
3231

3332
STATIC const char help_text[] = "Welcome to MicroPython!\n"
3433
"For online help please visit http://micropython.org/help/.\n"
3534
"For further help on a specific object, type help(obj)\n";
3635

37-
STATIC void pyb_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) {
38-
printf(" ");
39-
mp_obj_print(name_o, PRINT_STR);
40-
printf(" -- ");
41-
mp_obj_print(value, PRINT_STR);
42-
printf("\n");
43-
}
44-
4536
STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) {
4637
if (n_args == 0) {
4738
// print a general help message
4839
printf("%s", help_text);
4940
}
5041
else {
5142
// try to print something sensible about the given object
52-
printf("object ");
53-
mp_obj_print(args[0], PRINT_STR);
54-
printf(" is of type %s\n", mp_obj_get_type_str(args[0]));
55-
56-
mp_map_t *map = NULL;
57-
if (MP_OBJ_IS_TYPE(args[0], &mp_type_module)) {
58-
map = mp_obj_dict_get_map(mp_obj_module_get_globals(args[0]));
59-
} else {
60-
mp_obj_type_t *type;
61-
if (MP_OBJ_IS_TYPE(args[0], &mp_type_type)) {
62-
type = args[0];
63-
} else {
64-
type = mp_obj_get_type(args[0]);
65-
}
66-
if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) {
67-
map = mp_obj_dict_get_map(type->locals_dict);
68-
}
69-
}
70-
if (map != NULL) {
71-
for (uint i = 0; i < map->alloc; i++) {
72-
if (map->table[i].key != MP_OBJ_NULL) {
73-
pyb_help_print_info_about_object(map->table[i].key, map->table[i].value);
74-
}
75-
}
76-
}
43+
pyhelp_print_obj(args[0]);
7744
}
7845
return mp_const_none;
7946
}

stmhal/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ SRC_LIB = $(addprefix lib/,\
110110
netutils/netutils.c \
111111
timeutils/timeutils.c \
112112
utils/pyexec.c \
113+
utils/pyhelp.c \
113114
utils/printf.c \
114115
)
115116

stmhal/help.c

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626

2727
#include <stdio.h>
2828

29-
#include "py/nlr.h"
30-
#include "py/obj.h"
29+
#include "lib/utils/pyhelp.h"
3130

3231
STATIC const char *help_text =
3332
"Welcome to MicroPython!\n"
@@ -72,47 +71,14 @@ STATIC const char *help_text =
7271
"For further help on a specific object, type help(obj)\n"
7372
;
7473

75-
STATIC void pyb_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) {
76-
printf(" ");
77-
mp_obj_print(name_o, PRINT_STR);
78-
printf(" -- ");
79-
mp_obj_print(value, PRINT_STR);
80-
printf("\n");
81-
}
82-
8374
STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) {
8475
if (n_args == 0) {
8576
// print a general help message
8677
printf("%s", help_text);
8778

8879
} else {
8980
// try to print something sensible about the given object
90-
91-
printf("object ");
92-
mp_obj_print(args[0], PRINT_STR);
93-
printf(" is of type %s\n", mp_obj_get_type_str(args[0]));
94-
95-
mp_map_t *map = NULL;
96-
if (MP_OBJ_IS_TYPE(args[0], &mp_type_module)) {
97-
map = mp_obj_dict_get_map(mp_obj_module_get_globals(args[0]));
98-
} else {
99-
mp_obj_type_t *type;
100-
if (MP_OBJ_IS_TYPE(args[0], &mp_type_type)) {
101-
type = args[0];
102-
} else {
103-
type = mp_obj_get_type(args[0]);
104-
}
105-
if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) {
106-
map = mp_obj_dict_get_map(type->locals_dict);
107-
}
108-
}
109-
if (map != NULL) {
110-
for (uint i = 0; i < map->alloc; i++) {
111-
if (map->table[i].key != MP_OBJ_NULL) {
112-
pyb_help_print_info_about_object(map->table[i].key, map->table[i].value);
113-
}
114-
}
115-
}
81+
pyhelp_print_obj(args[0]);
11682
}
11783

11884
return mp_const_none;

teensy/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ LIB_SRC_C = $(addprefix lib/,\
109109
libc/string0.c \
110110
mp-readline/readline.c \
111111
utils/pyexec.c \
112+
utils/pyhelp.c \
112113
utils/printf.c \
113114
)
114115

teensy/help.c

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <stdio.h>
2828

29-
#include "py/obj.h"
29+
#include "lib/utils/pyhelp.h"
3030

3131
STATIC const char *help_text =
3232
"Welcome to MicroPython!\n"
@@ -70,47 +70,14 @@ STATIC const char *help_text =
7070
"For further help on a specific object, type help(obj)\n"
7171
;
7272

73-
STATIC void pyb_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) {
74-
printf(" ");
75-
mp_obj_print(name_o, PRINT_STR);
76-
printf(" -- ");
77-
mp_obj_print(value, PRINT_STR);
78-
printf("\n");
79-
}
80-
8173
STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) {
8274
if (n_args == 0) {
8375
// print a general help message
8476
printf("%s", help_text);
8577

8678
} else {
8779
// try to print something sensible about the given object
88-
89-
printf("object ");
90-
mp_obj_print(args[0], PRINT_STR);
91-
printf(" is of type %s\n", mp_obj_get_type_str(args[0]));
92-
93-
mp_map_t *map = NULL;
94-
if (MP_OBJ_IS_TYPE(args[0], &mp_type_module)) {
95-
map = mp_obj_dict_get_map(mp_obj_module_get_globals(args[0]));
96-
} else {
97-
mp_obj_type_t *type;
98-
if (MP_OBJ_IS_TYPE(args[0], &mp_type_type)) {
99-
type = args[0];
100-
} else {
101-
type = mp_obj_get_type(args[0]);
102-
}
103-
if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) {
104-
map = mp_obj_dict_get_map(type->locals_dict);
105-
}
106-
}
107-
if (map != NULL) {
108-
for (uint i = 0; i < map->alloc; i++) {
109-
if (map->table[i].key != MP_OBJ_NULL) {
110-
pyb_help_print_info_about_object(map->table[i].key, map->table[i].value);
111-
}
112-
}
113-
}
80+
pyhelp_print_obj(args[0]);
11481
}
11582

11683
return mp_const_none;

0 commit comments

Comments
 (0)