some optimize

This commit is contained in:
blueloveTH 2023-02-19 23:26:57 +08:00
parent 8433d40f2c
commit ad99bd5b21
3 changed files with 12 additions and 3 deletions

View File

@ -401,11 +401,18 @@ private:
}
void exprAssign() {
int lhs = co()->codes.empty() ? -1 : co()->codes.size() - 1;
co()->_rvalue = true;
TokenIndex op = parser->prev.type;
if(op == TK("=")) { // a = (expr)
EXPR_TUPLE();
emit(OP_STORE_REF);
if(lhs!=-1 && co()->codes[lhs].op == OP_LOAD_NAME_REF){
emit(OP_STORE_NAME, co()->codes[lhs].arg);
co()->codes[lhs].op = OP_NO_OP;
co()->codes[lhs].arg = -1;
}else{
emit(OP_STORE_REF);
}
}else{ // a += (expr) -> a = a + (expr)
EXPR();
switch (op) {

View File

@ -591,7 +591,9 @@ void add_module_math(VM* vm){
void add_module_dis(VM* vm){
PyVar mod = vm->new_module("dis");
vm->bind_func<1>(mod, "dis", [](VM* vm, pkpy::Args& args) {
CodeObject_ code = vm->PyFunction_AS_C(args[0]).code;
PyVar f = args[0];
if(f->is_type(vm->tp_bound_method)) f = vm->PyBoundMethod_AS_C(args[0]).method;
CodeObject_ code = vm->PyFunction_AS_C(f).code;
(*vm->_stdout) << vm->disassemble(code);
return vm->None;
});

View File

@ -483,7 +483,7 @@ public:
if(byte.op == OP_LOAD_CONST){
argStr += " (" + PyStr_AS_C(asRepr(co->consts[byte.arg])) + ")";
}
if(byte.op == OP_LOAD_NAME_REF || byte.op == OP_LOAD_NAME || byte.op == OP_RAISE){
if(byte.op == OP_LOAD_NAME_REF || byte.op == OP_LOAD_NAME || byte.op == OP_RAISE || byte.op == OP_STORE_NAME){
argStr += " (" + co->names[byte.arg].first.escape(true) + ")";
}
if(byte.op == OP_FAST_INDEX || byte.op == OP_FAST_INDEX_REF){