mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
an tuple optimization
This commit is contained in:
parent
6db30e61ce
commit
9d7204fe3a
@ -426,7 +426,14 @@ struct TupleExpr: SequenceExpr{
|
||||
}
|
||||
|
||||
if(starred_i == -1){
|
||||
Bytecode& prev = ctx->co->codes.back();
|
||||
if(prev.op == OP_BUILD_TUPLE && prev.arg == items.size()){
|
||||
// build tuple and unpack it is meaningless
|
||||
prev.op = OP_NO_OP;
|
||||
prev.arg = BC_NOARG;
|
||||
}else{
|
||||
ctx->emit(OP_UNPACK_SEQUENCE, items.size(), line);
|
||||
}
|
||||
}else{
|
||||
// starred assignment target must be in a tuple
|
||||
if(items.size() == 1) return false;
|
||||
|
@ -1124,6 +1124,12 @@ inline void add_module_math(VM* vm){
|
||||
inline void add_module_dis(VM* vm){
|
||||
PyObject* mod = vm->new_module("dis");
|
||||
vm->bind_func<1>(mod, "dis", [](VM* vm, ArgsView args) {
|
||||
if(is_type(args[0], vm->tp_str)){
|
||||
const Str& source = CAST(Str, args[0]);
|
||||
CodeObject_ code = vm->compile(source, "<dis>", EXEC_MODE);
|
||||
vm->_stdout(vm, vm->disassemble(code));
|
||||
return vm->None;
|
||||
}
|
||||
PyObject* f = args[0];
|
||||
if(is_type(f, vm->tp_bound_method)) f = CAST(BoundMethod, args[0]).func;
|
||||
CodeObject_ code = CAST(Function&, f).decl->code;
|
||||
|
Loading…
x
Reference in New Issue
Block a user