This commit is contained in:
blueloveTH 2023-02-10 04:40:30 +08:00
parent c2d451695c
commit e36eb9ff19
2 changed files with 9 additions and 3 deletions

View File

@ -118,6 +118,7 @@ struct CodeObject {
/************************************************/ /************************************************/
int _curr_block_i = 0; int _curr_block_i = 0;
bool _rvalue = false;
bool _is_curr_block_loop() const { bool _is_curr_block_loop() const {
return blocks[_curr_block_i].type == FOR_LOOP || blocks[_curr_block_i].type == WHILE_LOOP; return blocks[_curr_block_i].type == FOR_LOOP || blocks[_curr_block_i].type == WHILE_LOOP;
} }

View File

@ -400,6 +400,7 @@ private:
} }
void exprAssign() { void exprAssign() {
co()->_rvalue = true;
TokenIndex op = parser->prev.type; TokenIndex op = parser->prev.type;
if(op == TK("=")) { // a = (expr) if(op == TK("=")) { // a = (expr)
EXPR_TUPLE(); EXPR_TUPLE();
@ -421,6 +422,7 @@ private:
} }
emit(OP_STORE_REF); emit(OP_STORE_REF);
} }
co()->_rvalue = false;
} }
void exprComma() { void exprComma() {
@ -608,13 +610,16 @@ __LISTCOMP:
emit(OP_CALL, (KWARGC << 16) | ARGC); emit(OP_CALL, (KWARGC << 16) | ARGC);
} }
void exprName() { void exprName(){ _exprName(false); }
void _exprName(bool force_lvalue) {
Token tkname = parser->prev; Token tkname = parser->prev;
int index = co()->add_name( int index = co()->add_name(
tkname.str(), tkname.str(),
codes.size()>1 ? NAME_LOCAL : NAME_GLOBAL codes.size()>1 ? NAME_LOCAL : NAME_GLOBAL
); );
emit(OP_LOAD_NAME_REF, index); bool fast_load = !force_lvalue && co()->_rvalue;
emit(fast_load ? OP_LOAD_NAME : OP_LOAD_NAME_REF, index);
} }
void exprAttrib() { void exprAttrib() {
@ -787,7 +792,7 @@ __LISTCOMP:
int size = 0; int size = 0;
do { do {
consume(TK("@id")); consume(TK("@id"));
exprName(); size++; _exprName(true); size++;
} while (match(TK(","))); } while (match(TK(",")));
if(size > 1) emit(OP_BUILD_SMART_TUPLE, size); if(size > 1) emit(OP_BUILD_SMART_TUPLE, size);
} }