本文整理汇总了C++中MP_OBJ_NEW_QSTR函数的典型用法代码示例。如果您正苦于以下问题:C++ MP_OBJ_NEW_QSTR函数的具体用法?C++ MP_OBJ_NEW_QSTR怎么用?C++ MP_OBJ_NEW_QSTR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MP_OBJ_NEW_QSTR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: neopixel_clear_
STATIC mp_obj_t neopixel_clear_(mp_obj_t self_in) {
neopixel_obj_t *self = (neopixel_obj_t*)self_in;
neopixel_clear(&self->strip);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(neopixel_clear_obj, neopixel_clear_);
STATIC mp_obj_t neopixel_show_(mp_obj_t self_in) {
neopixel_obj_t *self = (neopixel_obj_t*)self_in;
neopixel_show(&self->strip);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(neopixel_show_obj, neopixel_show_);
STATIC const mp_map_elem_t neopixel_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_clear), (mp_obj_t)&neopixel_clear_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_show), (mp_obj_t)&neopixel_show_obj },
};
STATIC MP_DEFINE_CONST_DICT(neopixel_locals_dict, neopixel_locals_dict_table);
const mp_obj_type_t neopixel_type = {
{ &mp_type_type },
.name = MP_QSTR_NeoPixel,
.print = NULL,
.make_new = neopixel_make_new,
.call = NULL,
.unary_op = neopixel_unary_op,
.binary_op = NULL,
.attr = NULL,
.subscr = neopixel_subscr,
示例2: dict_keys
STATIC mp_obj_t dict_keys(mp_obj_t self_in) {
return dict_view(self_in, MP_DICT_VIEW_KEYS);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_keys_obj, dict_keys);
STATIC mp_obj_t dict_values(mp_obj_t self_in) {
return dict_view(self_in, MP_DICT_VIEW_VALUES);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_values_obj, dict_values);
/******************************************************************************/
/* dict constructors & public C API */
STATIC const mp_map_elem_t dict_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_clear), (mp_obj_t)&dict_clear_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_copy), (mp_obj_t)&dict_copy_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_fromkeys), (mp_obj_t)&dict_fromkeys_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_get), (mp_obj_t)&dict_get_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_items), (mp_obj_t)&dict_items_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_keys), (mp_obj_t)&dict_keys_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_pop), (mp_obj_t)&dict_pop_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_popitem), (mp_obj_t)&dict_popitem_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_setdefault), (mp_obj_t)&dict_setdefault_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_update), (mp_obj_t)&dict_update_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_values), (mp_obj_t)&dict_values_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR___getitem__), (mp_obj_t)&mp_op_getitem_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR___setitem__), (mp_obj_t)&mp_op_setitem_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR___delitem__), (mp_obj_t)&mp_op_delitem_obj },
};
示例3: mp_builtin_bin
STATIC mp_obj_t mp_builtin_bin(mp_obj_t o_in) {
mp_obj_t args[] = { MP_OBJ_NEW_QSTR(MP_QSTR__brace_open__colon__hash_b_brace_close_), o_in };
return mp_obj_str_format(MP_ARRAY_SIZE(args), args, NULL);
}
示例4: MP_DEFINE_CONST_FUN_OBJ_1
MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_get_x_obj, microbit_compass_get_x);
mp_obj_t microbit_compass_get_y(mp_obj_t self_in) {
microbit_compass_obj_t *self = (microbit_compass_obj_t*)self_in;
return mp_obj_new_int(self->compass->getY());
}
MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_get_y_obj, microbit_compass_get_y);
mp_obj_t microbit_compass_get_z(mp_obj_t self_in) {
microbit_compass_obj_t *self = (microbit_compass_obj_t*)self_in;
return mp_obj_new_int(self->compass->getZ());
}
MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_get_z_obj, microbit_compass_get_z);
STATIC const mp_map_elem_t microbit_compass_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_heading), (mp_obj_t)µbit_compass_heading_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_is_calibrated), (mp_obj_t)µbit_compass_is_calibrated_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_calibrate), (mp_obj_t)µbit_compass_calibrate_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_is_calibrating), (mp_obj_t)µbit_compass_is_calibrating_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_clear_calibration), (mp_obj_t)µbit_compass_clear_calibration_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_get_x), (mp_obj_t)µbit_compass_get_x_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_get_y), (mp_obj_t)µbit_compass_get_y_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_get_z), (mp_obj_t)µbit_compass_get_z_obj },
};
STATIC MP_DEFINE_CONST_DICT(microbit_compass_locals_dict, microbit_compass_locals_dict_table);
STATIC const mp_obj_type_t microbit_compass_type = {
{ &mp_type_type },
.name = MP_QSTR_MicroBitCompass,
.print = NULL,
示例5: mp_builtin___import__
mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
#if DEBUG_PRINT
printf("__import__:\n");
for (int i = 0; i < n_args; i++) {
printf(" ");
mp_obj_print(args[i], PRINT_REPR);
printf("\n");
}
#endif
mp_obj_t module_name = args[0];
mp_obj_t fromtuple = mp_const_none;
int level = 0;
if (n_args >= 4) {
fromtuple = args[3];
if (n_args >= 5) {
level = MP_OBJ_SMALL_INT_VALUE(args[4]);
}
}
uint mod_len;
const char *mod_str = (const char*)mp_obj_str_get_data(module_name, &mod_len);
if (level != 0) {
// What we want to do here is to take name of current module,
// chop <level> trailing components, and concatenate with passed-in
// module name, thus resolving relative import name into absolue.
// This even appears to be correct per
// http://legacy.python.org/dev/peps/pep-0328/#relative-imports-and-name
// "Relative imports use a module's __name__ attribute to determine that
// module's position in the package hierarchy."
mp_obj_t this_name_q = mp_obj_dict_get(mp_globals_get(), MP_OBJ_NEW_QSTR(MP_QSTR___name__));
assert(this_name_q != MP_OBJ_NULL);
#if DEBUG_PRINT
printf("Current module: ");
mp_obj_print(this_name_q, PRINT_REPR);
printf("\n");
#endif
uint this_name_l;
const char *this_name = (const char*)mp_obj_str_get_data(this_name_q, &this_name_l);
uint dots_seen = 0;
const char *p = this_name + this_name_l - 1;
while (p > this_name) {
if (*p == '.') {
dots_seen++;
if (--level == 0) {
break;
}
}
p--;
}
if (dots_seen == 0 && level == 1) {
// http://legacy.python.org/dev/peps/pep-0328/#relative-imports-and-name
// "If the module's name does not contain any package information
// (e.g. it is set to '__main__') then relative imports are
// resolved as if the module were a top level module, regardless
// of where the module is actually located on the file system."
// Supposedly this if catches this condition and resolve it properly
// TODO: But nobody knows for sure. This condition happens when
// package's __init__.py does something like "import .submod". So,
// maybe we should check for package here? But quote above doesn't
// talk about packages, it talks about dot-less module names.
p = this_name + this_name_l;
} else if (level != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ImportError, "Invalid relative import"));
}
uint new_mod_l = (mod_len == 0 ? p - this_name : p - this_name + 1 + mod_len);
char *new_mod = alloca(new_mod_l);
memcpy(new_mod, this_name, p - this_name);
if (mod_len != 0) {
new_mod[p - this_name] = '.';
memcpy(new_mod + (p - this_name) + 1, mod_str, mod_len);
}
qstr new_mod_q = qstr_from_strn(new_mod, new_mod_l);
DEBUG_printf("Resolved relative name: %s\n", qstr_str(new_mod_q));
module_name = MP_OBJ_NEW_QSTR(new_mod_q);
mod_str = new_mod;
mod_len = new_mod_l;
}
// check if module already exists
mp_obj_t module_obj = mp_module_get(mp_obj_str_get_qstr(module_name));
if (module_obj != MP_OBJ_NULL) {
DEBUG_printf("Module already loaded\n");
// If it's not a package, return module right away
char *p = strchr(mod_str, '.');
if (p == NULL) {
return module_obj;
}
// If fromlist is not empty, return leaf module
if (fromtuple != mp_const_none) {
return module_obj;
}
// Otherwise, we need to return top-level package
qstr pkg_name = qstr_from_strn(mod_str, p - mod_str);
//.........这里部分代码省略.........
示例6: open
break;
case '+':
mode |= O_RDWR;
break;
}
}
int fd = open(fname, mode, 0644);
if (fd == -1) {
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
}
return fdfile_new(fd);
}
STATIC const mp_map_elem_t rawfile_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_fileno), (mp_obj_t)&fdfile_fileno_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_readall), (mp_obj_t)&mp_stream_readall_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&fdfile_close_obj },
};
STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table);
static const mp_obj_type_t rawfile_type = {
{ &mp_type_type },
.name = MP_QSTR_io_dot_FileIO,
.print = fdfile_print,
.make_new = fdfile_make_new,
.getiter = mp_identity,
示例7: main
int main(int argc, char **argv) {
volatile int stack_dummy;
stack_top = (void*)&stack_dummy;
pre_process_options(argc, argv);
#if MICROPY_ENABLE_GC
char *heap = malloc(heap_size);
gc_init(heap, heap + heap_size);
#endif
qstr_init();
mp_init();
char *home = getenv("HOME");
char *path = getenv("MICROPYPATH");
if (path == NULL) {
path = "~/.micropython/lib:/usr/lib/micropython";
}
uint path_num = 1; // [0] is for current dir (or base dir of the script)
for (char *p = path; p != NULL; p = strchr(p, ':')) {
path_num++;
if (p != NULL) {
p++;
}
}
mp_obj_list_init(mp_sys_path, path_num);
mp_obj_t *path_items;
mp_obj_list_get(mp_sys_path, &path_num, &path_items);
path_items[0] = MP_OBJ_NEW_QSTR(MP_QSTR_);
char *p = path;
for (int i = 1; i < path_num; i++) {
char *p1 = strchr(p, ':');
if (p1 == NULL) {
p1 = p + strlen(p);
}
if (p[0] == '~' && p[1] == '/' && home != NULL) {
// Expand standalone ~ to $HOME
CHECKBUF(buf, PATH_MAX);
CHECKBUF_APPEND(buf, home, strlen(home));
CHECKBUF_APPEND(buf, p + 1, p1 - p - 1);
path_items[i] = MP_OBJ_NEW_QSTR(qstr_from_strn(buf, CHECKBUF_LEN(buf)));
} else {
path_items[i] = MP_OBJ_NEW_QSTR(qstr_from_strn(p, p1 - p));
}
p = p1 + 1;
}
mp_obj_list_init(mp_sys_argv, 0);
mp_store_name(qstr_from_str("test"), test_obj_new(42));
mp_store_name(qstr_from_str("mem_info"), mp_make_function_n(0, mem_info));
mp_store_name(qstr_from_str("qstr_info"), mp_make_function_n(0, qstr_info));
#if MICROPY_ENABLE_GC
mp_store_name(qstr_from_str("gc"), (mp_obj_t)&pyb_gc_obj);
#endif
// Here is some example code to create a class and instance of that class.
// First is the Python, then the C code.
//
// class TestClass:
// pass
// test_obj = TestClass()
// test_obj.attr = 42
mp_obj_t test_class_type, test_class_instance;
test_class_type = mp_obj_new_type(QSTR_FROM_STR_STATIC("TestClass"), mp_const_empty_tuple, mp_obj_new_dict(0));
mp_store_name(QSTR_FROM_STR_STATIC("test_obj"), test_class_instance = mp_call_function_0(test_class_type));
mp_store_attr(test_class_instance, QSTR_FROM_STR_STATIC("attr"), mp_obj_new_int(42));
/*
printf("bytes:\n");
printf(" total %d\n", m_get_total_bytes_allocated());
printf(" cur %d\n", m_get_current_bytes_allocated());
printf(" peak %d\n", m_get_peak_bytes_allocated());
*/
bool executed = false;
for (int a = 1; a < argc; a++) {
if (argv[a][0] == '-') {
if (strcmp(argv[a], "-c") == 0) {
if (a + 1 >= argc) {
return usage(argv);
}
do_str(argv[a + 1]);
executed = true;
a += 1;
} else if (strcmp(argv[a], "-X") == 0) {
a += 1;
} else {
return usage(argv);
}
} else {
char *basedir = realpath(argv[a], NULL);
if (basedir == NULL) {
fprintf(stderr, "%s: can't open file '%s': [Errno %d] ", argv[0], argv[1], errno);
perror("");
// CPython exits with 2 in such case
exit(2);
}
//.........这里部分代码省略.........
示例8: mp_obj_get_int
// set speed immediately
self->time_left = 0;
} else {
// set speed over a given time (given in milli seconds)
self->time_left = mp_obj_get_int(args[2]) / 20;
self->pulse_accum = 0;
}
servo_timer_irq_callback();
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_speed_obj, 1, 3, pyb_servo_speed);
STATIC const mp_map_elem_t pyb_servo_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_pulse_width), (mp_obj_t)&pyb_servo_pulse_width_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_calibration), (mp_obj_t)&pyb_servo_calibration_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_angle), (mp_obj_t)&pyb_servo_angle_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_speed), (mp_obj_t)&pyb_servo_speed_obj },
};
STATIC MP_DEFINE_CONST_DICT(pyb_servo_locals_dict, pyb_servo_locals_dict_table);
const mp_obj_type_t pyb_servo_type = {
{ &mp_type_type },
.name = MP_QSTR_Servo,
.print = pyb_servo_print,
.make_new = pyb_servo_make_new,
.locals_dict = (mp_obj_t)&pyb_servo_locals_dict,
};
示例9: mod_os_mkdir
STATIC mp_obj_t mod_os_mkdir(mp_obj_t path_in) {
// TODO: Accept mode param
const char *path = mp_obj_str_get_str(path_in);
#ifdef _WIN32
int r = mkdir(path);
#else
int r = mkdir(path, 0777);
#endif
RAISE_ERRNO(r, errno);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_mkdir_obj, mod_os_mkdir);
STATIC const mp_map_elem_t mp_module_os_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR__os) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_stat), (mp_obj_t)&mod_os_stat_obj },
#if MICROPY_PY_OS_STATVFS
{ MP_OBJ_NEW_QSTR(MP_QSTR_statvfs), (mp_obj_t)&mod_os_statvfs_obj },
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_system), (mp_obj_t)&mod_os_system_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_unlink),(mp_obj_t)&mod_os_unlink_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_getenv),(mp_obj_t)&mod_os_getenv_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_mkdir),(mp_obj_t)&mod_os_mkdir_obj},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_os_globals, mp_module_os_globals_table);
const mp_obj_module_t mp_module_os = {
.base = { &mp_type_module },
.name = MP_QSTR__os,
示例10: netif_set_up
netif_set_up(n);
netif_set_default(n);
mod_lwip_register_poll(slip_lwip_poll, n);
return (mp_obj_t)&lwip_slip_obj;
}
STATIC mp_obj_t lwip_slip_status(mp_obj_t self_in) {
// Null function for now.
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(lwip_slip_status_obj, lwip_slip_status);
STATIC const mp_map_elem_t lwip_slip_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_status), (mp_obj_t)&lwip_slip_status_obj },
};
STATIC MP_DEFINE_CONST_DICT(lwip_slip_locals_dict, lwip_slip_locals_dict_table);
STATIC const mp_obj_type_t lwip_slip_type = {
{ &mp_type_type },
.name = MP_QSTR_slip,
.make_new = lwip_slip_make_new,
.locals_dict = (mp_obj_t)&lwip_slip_locals_dict,
};
#endif // MICROPY_PY_LWIP_SLIP
/******************************************************************************/
// Table to convert lwIP err_t codes to socket errno codes, from the lwIP
示例11: array_get_buffer
return mp_const_none;
}
}
}
}
STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
mp_obj_array_t *o = o_in;
bufinfo->buf = o->items;
bufinfo->len = o->len * mp_binary_get_size('@', o->typecode, NULL);
bufinfo->typecode = o->typecode;
return 0;
}
STATIC const mp_map_elem_t array_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_append), (mp_obj_t)&array_append_obj },
};
STATIC MP_DEFINE_CONST_DICT(array_locals_dict, array_locals_dict_table);
const mp_obj_type_t mp_type_array = {
{ &mp_type_type },
.name = MP_QSTR_array,
.print = array_print,
.make_new = array_make_new,
.getiter = array_iterator_new,
.unary_op = array_unary_op,
.binary_op = array_binary_op,
.subscr = array_subscr,
.buffer_p = { .get_buffer = array_get_buffer },
.locals_dict = (mp_obj_t)&array_locals_dict,
示例12: mp_task
void mp_task(void *pvParameter) {
volatile uint32_t sp = (uint32_t)get_sp();
#if MICROPY_PY_THREAD
mp_thread_init(&mp_task_stack[0], MP_TASK_STACK_LEN);
#endif
uart_init();
// Allocate the uPy heap using malloc and get the largest available region
size_t mp_task_heap_size = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
void *mp_task_heap = malloc(mp_task_heap_size);
soft_reset:
// initialise the stack pointer for the main thread
mp_stack_set_top((void *)sp);
mp_stack_set_limit(MP_TASK_STACK_SIZE - 1024);
gc_init(mp_task_heap, mp_task_heap + mp_task_heap_size);
mp_init();
mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_));
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
mp_obj_list_init(mp_sys_argv, 0);
readline_init0();
// initialise peripherals
machine_pins_init();
// run boot-up scripts
pyexec_frozen_module("_boot.py");
pyexec_file("boot.py");
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
pyexec_file("main.py");
}
for (;;) {
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
vprintf_like_t vprintf_log = esp_log_set_vprintf(vprintf_null);
if (pyexec_raw_repl() != 0) {
break;
}
esp_log_set_vprintf(vprintf_log);
} else {
if (pyexec_friendly_repl() != 0) {
break;
}
}
}
#if MICROPY_PY_THREAD
mp_thread_deinit();
#endif
gc_sweep_all();
mp_hal_stdout_tx_str("PYB: soft reboot\r\n");
// deinitialise peripherals
machine_pins_deinit();
usocket_events_deinit();
mp_deinit();
fflush(stdout);
goto soft_reset;
}
示例13: MP_OBJ_NEW_QSTR
}
}
STATIC const mp_obj_type_t machine_mem_type = {
{ &mp_type_type },
.name = MP_QSTR_mem,
.print = machine_mem_print,
.subscr = machine_mem_subscr,
};
STATIC const machine_mem_obj_t machine_mem8_obj = {{&machine_mem_type}, 1};
STATIC const machine_mem_obj_t machine_mem16_obj = {{&machine_mem_type}, 2};
STATIC const machine_mem_obj_t machine_mem32_obj = {{&machine_mem_type}, 4};
STATIC const mp_map_elem_t machine_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_machine) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_mem8), (mp_obj_t)&machine_mem8_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_mem16), (mp_obj_t)&machine_mem16_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_mem32), (mp_obj_t)&machine_mem32_obj },
};
STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table);
const mp_obj_module_t mp_module_machine = {
.base = { &mp_type_module },
.name = MP_QSTR_machine,
.globals = (mp_obj_dict_t*)&machine_module_globals,
};
#endif // MICROPY_PY_MACHINE
示例14: mp_obj_str_get_str
if (args[0] != mp_const_none) {
fname = mp_obj_str_get_str(args[0]);
}
void *mod = dlopen(fname, RTLD_NOW | RTLD_LOCAL);
if (mod == NULL) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
}
mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t);
o->base.type = type_in;
o->handle = mod;
return o;
}
STATIC const mp_map_elem_t ffimod_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_func), (mp_obj_t) &ffimod_func_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_var), (mp_obj_t) &ffimod_var_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_addr), (mp_obj_t) &ffimod_addr_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t) &ffimod_close_obj },
};
STATIC MP_DEFINE_CONST_DICT(ffimod_locals_dict, ffimod_locals_dict_table);
STATIC const mp_obj_type_t ffimod_type = {
{ &mp_type_type },
.name = MP_QSTR_ffimod,
.print = ffimod_print,
.make_new = ffimod_make_new,
.locals_dict = (mp_obj_t)&ffimod_locals_dict,
};
示例15: fun_bc_call
//.........这里部分代码省略.........
mp_obj_dict_store(dict, kwargs[2 * i], kwargs[2 * i + 1]);
continue2:;
}
DEBUG_printf("Args with kws flattened: ");
dump_args(code_state->state + n_state - self->n_pos_args - self->n_kwonly_args, self->n_pos_args + self->n_kwonly_args);
// fill in defaults for positional args
mp_obj_t *d = &code_state->state[n_state - self->n_pos_args];
mp_obj_t *s = &self->extra_args[self->n_def_args - 1];
for (int i = self->n_def_args; i > 0; i--, d++, s--) {
if (*d == MP_OBJ_NULL) {
*d = *s;
}
}
DEBUG_printf("Args after filling default positional: ");
dump_args(code_state->state + n_state - self->n_pos_args - self->n_kwonly_args, self->n_pos_args + self->n_kwonly_args);
// Check that all mandatory positional args are specified
while (d < &code_state->state[n_state]) {
if (*d++ == MP_OBJ_NULL) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"function missing required positional argument #%d", &code_state->state[n_state] - d));
}
}
// Check that all mandatory keyword args are specified
// Fill in default kw args if we have them
for (uint i = 0; i < self->n_kwonly_args; i++) {
if (code_state->state[n_state - 1 - self->n_pos_args - i] == MP_OBJ_NULL) {
mp_map_elem_t *elem = NULL;
if (self->has_def_kw_args) {
elem = mp_map_lookup(&((mp_obj_dict_t*)self->extra_args[self->n_def_args])->map, MP_OBJ_NEW_QSTR(self->args[self->n_pos_args + i]), MP_MAP_LOOKUP);
}
if (elem != NULL) {
code_state->state[n_state - 1 - self->n_pos_args - i] = elem->value;
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"function missing required keyword argument '%s'", qstr_str(self->args[self->n_pos_args + i])));
}
}
}
} else {
// no keyword arguments given
if (self->n_kwonly_args != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
"function missing keyword-only argument"));
}
if (self->takes_kw_args) {
*var_pos_kw_args = mp_obj_new_dict(0);
}
}
// bytecode prelude: initialise closed over variables
for (uint n_local = *ip++; n_local > 0; n_local--) {
uint local_num = *ip++;
code_state->state[n_state - 1 - local_num] = mp_obj_new_cell(code_state->state[n_state - 1 - local_num]);
}
// now that we skipped over the prelude, set the ip for the VM
code_state->ip = ip;
DEBUG_printf("Calling: n_pos_args=%d, n_kwonly_args=%d\n", self->n_pos_args, self->n_kwonly_args);
dump_args(code_state->state + n_state - self->n_pos_args - self->n_kwonly_args, self->n_pos_args + self->n_kwonly_args);