mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
impl UNPACK_SEQUENCE
This commit is contained in:
parent
a4dc943c7b
commit
52ec435775
@ -26,6 +26,7 @@ OPCODE(BUILD_LIST)
|
||||
OPCODE(BUILD_TUPLE)
|
||||
OPCODE(BUILD_MAP)
|
||||
OPCODE(BUILD_SLICE)
|
||||
OPCODE(UNPACK_SEQUENCE)
|
||||
|
||||
OPCODE(BINARY_SUBSCR)
|
||||
OPCODE(STORE_SUBSCR)
|
||||
|
10
src/vm.h
10
src/vm.h
@ -203,6 +203,16 @@ public:
|
||||
callstack.pop();
|
||||
return ret;
|
||||
} break;
|
||||
case OP_UNPACK_SEQUENCE:
|
||||
{
|
||||
PyVar seq = frame->popValue();
|
||||
bool iterable = (seq->isType(_tp_tuple) || seq->isType(_tp_list));
|
||||
if(!iterable) _error("TypeError", "only tuple and list can be unpacked");
|
||||
const PyVarList& objs = std::get<PyVarList>(seq->_native);
|
||||
if(objs.size() > byte.arg) _error("ValueError", "too many values to unpack (expected " + std::to_string(byte.arg) + ")");
|
||||
if(objs.size() < byte.arg) _error("ValueError", "not enough values to unpack (expected " + std::to_string(byte.arg) + ", got " + std::to_string(objs.size()) + ")");
|
||||
for(auto it=objs.rbegin(); it!=objs.rend(); it++) frame->pushValue(*it);
|
||||
} break;
|
||||
case OP_PRINT_EXPR:
|
||||
{
|
||||
const PyVar& expr = frame->topValue();
|
||||
|
Loading…
x
Reference in New Issue
Block a user