mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-23 07:40:42 +01:00
[python] Update to MicroPython 1.9.4
This commit is contained in:
committed by
EmilieNumworks
parent
caff93cda0
commit
73250e727a
@@ -4,7 +4,7 @@
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013, 2014 Damien P. George
|
||||
* Copyright (c) 2014 Paul Sokolovsky
|
||||
* Copyright (c) 2014-2017 Paul Sokolovsky
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "py/bc.h"
|
||||
#include "py/objgenerator.h"
|
||||
#include "py/objfun.h"
|
||||
#include "py/stackctrl.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/* generator wrapper */
|
||||
@@ -92,6 +93,7 @@ STATIC void gen_instance_print(const mp_print_t *print, mp_obj_t self_in, mp_pri
|
||||
}
|
||||
|
||||
mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val) {
|
||||
MP_STACK_CHECK();
|
||||
mp_check_self(MP_OBJ_IS_TYPE(self_in, &mp_type_gen_instance));
|
||||
mp_obj_gen_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (self->code_state.ip == 0) {
|
||||
@@ -104,7 +106,16 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_
|
||||
mp_raise_TypeError("can't send non-None value to a just-started generator");
|
||||
}
|
||||
} else {
|
||||
*self->code_state.sp = send_value;
|
||||
#if MICROPY_PY_GENERATOR_PEND_THROW
|
||||
// If exception is pending (set using .pend_throw()), process it now.
|
||||
if (*self->code_state.sp != mp_const_none) {
|
||||
throw_value = *self->code_state.sp;
|
||||
*self->code_state.sp = MP_OBJ_NULL;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
*self->code_state.sp = send_value;
|
||||
}
|
||||
}
|
||||
mp_obj_dict_t *old_globals = mp_globals_get();
|
||||
mp_globals_set(self->globals);
|
||||
@@ -125,9 +136,9 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_
|
||||
|
||||
case MP_VM_RETURN_YIELD:
|
||||
*ret_val = *self->code_state.sp;
|
||||
if (*ret_val == MP_OBJ_STOP_ITERATION) {
|
||||
self->code_state.ip = 0;
|
||||
}
|
||||
#if MICROPY_PY_GENERATOR_PEND_THROW
|
||||
*self->code_state.sp = mp_const_none;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case MP_VM_RETURN_EXCEPTION: {
|
||||
@@ -222,10 +233,24 @@ STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) {
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(gen_instance_close_obj, gen_instance_close);
|
||||
|
||||
STATIC mp_obj_t gen_instance_pend_throw(mp_obj_t self_in, mp_obj_t exc_in) {
|
||||
mp_obj_gen_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (self->code_state.sp == self->code_state.state - 1) {
|
||||
mp_raise_TypeError("can't pend throw to just-started generator");
|
||||
}
|
||||
mp_obj_t prev = *self->code_state.sp;
|
||||
*self->code_state.sp = exc_in;
|
||||
return prev;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(gen_instance_pend_throw_obj, gen_instance_pend_throw);
|
||||
|
||||
STATIC const mp_rom_map_elem_t gen_instance_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&gen_instance_close_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&gen_instance_send_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_throw), MP_ROM_PTR(&gen_instance_throw_obj) },
|
||||
#if MICROPY_PY_GENERATOR_PEND_THROW
|
||||
{ MP_ROM_QSTR(MP_QSTR_pend_throw), MP_ROM_PTR(&gen_instance_pend_throw_obj) },
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(gen_instance_locals_dict, gen_instance_locals_dict_table);
|
||||
|
||||
Reference in New Issue
Block a user