Skip to content

Commit 9fc7933

Browse files
committed
Add py_get_qstr.
1 parent e9f1e50 commit 9fc7933

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

py/runtime.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ py_obj_t py_builtin___build_class__(py_obj_t o_class_fun, py_obj_t o_class_name)
514514
}
515515

516516
py_obj_t py_builtin_range(py_obj_t o_arg) {
517-
return py_obj_new_range(0, rt_get_int(o_arg), 1);
517+
return py_obj_new_range(0, py_get_int(o_arg), 1);
518518
}
519519

520520
#ifdef WRITE_NATIVE
@@ -845,7 +845,7 @@ int rt_is_true(py_obj_t arg) {
845845
}
846846
}
847847

848-
int rt_get_int(py_obj_t arg) {
848+
int py_get_int(py_obj_t arg) {
849849
if (arg == py_const_false) {
850850
return 0;
851851
} else if (arg == py_const_true) {
@@ -858,6 +858,15 @@ int rt_get_int(py_obj_t arg) {
858858
}
859859
}
860860

861+
qstr py_get_qstr(py_obj_t arg) {
862+
if (IS_O(arg, O_STR)) {
863+
return ((py_obj_base_t*)arg)->u_str;
864+
} else {
865+
assert(0);
866+
return 0;
867+
}
868+
}
869+
861870
py_obj_t rt_load_const_str(qstr qstr) {
862871
DEBUG_OP_printf("load '%s'\n", qstr_str(qstr));
863872
return py_obj_new_str(qstr);

py/runtime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ void rt_assign_native_code(int unique_code_id, py_fun_t f, uint len, int n_args)
9797
void rt_assign_inline_asm_code(int unique_code_id, py_fun_t f, uint len, int n_args);
9898
void py_obj_print(py_obj_t o);
9999
int rt_is_true(py_obj_t arg);
100-
int rt_get_int(py_obj_t arg);
100+
int py_get_int(py_obj_t arg);
101+
qstr py_get_qstr(py_obj_t arg);
101102
py_obj_t rt_load_const_str(qstr qstr);
102103
py_obj_t rt_load_name(qstr qstr);
103104
py_obj_t rt_load_global(qstr qstr);

0 commit comments

Comments
 (0)