mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
fix a bug
This commit is contained in:
parent
264c2a093a
commit
b3b6f8c87c
@ -20,7 +20,7 @@
|
|||||||
#include <variant>
|
#include <variant>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#define PK_VERSION "1.0.4"
|
#define PK_VERSION "1.0.5"
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
@ -679,7 +679,7 @@ __SUBSCR_END:
|
|||||||
case TK("<<="): case TK(">>="): case TK("&="): case TK("|="): case TK("^="): {
|
case TK("<<="): case TK(">>="): case TK("&="): case TK("|="): case TK("^="): {
|
||||||
Expr* lhs_p = ctx()->s_expr.top().get();
|
Expr* lhs_p = ctx()->s_expr.top().get();
|
||||||
if(lhs_p->is_starred()) SyntaxError();
|
if(lhs_p->is_starred()) SyntaxError();
|
||||||
if(ctx()->is_compiling_class) SyntaxError();
|
if(ctx()->is_compiling_class) SyntaxError("can't use inplace operator in class definition");
|
||||||
advance();
|
advance();
|
||||||
auto e = make_expr<BinaryExpr>();
|
auto e = make_expr<BinaryExpr>();
|
||||||
e->op = prev().type - 1; // -1 to remove =
|
e->op = prev().type - 1; // -1 to remove =
|
||||||
@ -695,8 +695,15 @@ __SUBSCR_END:
|
|||||||
int n = 0;
|
int n = 0;
|
||||||
while(match(TK("="))){
|
while(match(TK("="))){
|
||||||
EXPR_TUPLE();
|
EXPR_TUPLE();
|
||||||
|
Expr* _tp = ctx()->s_expr.top().get();
|
||||||
|
if(ctx()->is_compiling_class && _tp->is_tuple()){
|
||||||
|
SyntaxError("can't use unpack tuple in class definition");
|
||||||
|
}
|
||||||
n += 1;
|
n += 1;
|
||||||
}
|
}
|
||||||
|
if(ctx()->is_compiling_class && n>1){
|
||||||
|
SyntaxError("can't assign to multiple targets in class definition");
|
||||||
|
}
|
||||||
// stack size is n+1
|
// stack size is n+1
|
||||||
Expr_ val = ctx()->s_expr.popx();
|
Expr_ val = ctx()->s_expr.popx();
|
||||||
val->emit(ctx());
|
val->emit(ctx());
|
||||||
|
@ -61,13 +61,17 @@ struct CodeEmitContext{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void exit_block(){
|
void exit_block(){
|
||||||
if(co->blocks[curr_block_i].type == FOR_LOOP) for_loop_depth--;
|
auto curr_type = co->blocks[curr_block_i].type;
|
||||||
|
if(curr_type == FOR_LOOP) for_loop_depth--;
|
||||||
co->blocks[curr_block_i].end = co->codes.size();
|
co->blocks[curr_block_i].end = co->codes.size();
|
||||||
curr_block_i = co->blocks[curr_block_i].parent;
|
curr_block_i = co->blocks[curr_block_i].parent;
|
||||||
if(curr_block_i < 0) FATAL_ERROR();
|
if(curr_block_i < 0) FATAL_ERROR();
|
||||||
|
|
||||||
|
if(curr_type == FOR_LOOP){
|
||||||
// add a no op here to make block check work
|
// add a no op here to make block check work
|
||||||
emit(OP_NO_OP, BC_NOARG, BC_KEEPLINE);
|
emit(OP_NO_OP, BC_NOARG, BC_KEEPLINE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// clear the expression stack and generate bytecode
|
// clear the expression stack and generate bytecode
|
||||||
void emit_expr(){
|
void emit_expr(){
|
||||||
|
2
src/vm.h
2
src/vm.h
@ -995,7 +995,7 @@ inline std::string _opcode_argstr(VM* vm, Bytecode byte, const CodeObject* co){
|
|||||||
case OP_LOAD_NAME: case OP_LOAD_GLOBAL: case OP_LOAD_NONLOCAL: case OP_STORE_GLOBAL:
|
case OP_LOAD_NAME: case OP_LOAD_GLOBAL: case OP_LOAD_NONLOCAL: case OP_STORE_GLOBAL:
|
||||||
case OP_LOAD_ATTR: case OP_LOAD_METHOD: case OP_STORE_ATTR: case OP_DELETE_ATTR:
|
case OP_LOAD_ATTR: case OP_LOAD_METHOD: case OP_STORE_ATTR: case OP_DELETE_ATTR:
|
||||||
case OP_IMPORT_NAME: case OP_BEGIN_CLASS: case OP_RAISE:
|
case OP_IMPORT_NAME: case OP_BEGIN_CLASS: case OP_RAISE:
|
||||||
case OP_DELETE_GLOBAL: case OP_INC_GLOBAL: case OP_DEC_GLOBAL:
|
case OP_DELETE_GLOBAL: case OP_INC_GLOBAL: case OP_DEC_GLOBAL: case OP_STORE_CLASS_ATTR:
|
||||||
argStr += fmt(" (", StrName(byte.arg).sv(), ")");
|
argStr += fmt(" (", StrName(byte.arg).sv(), ")");
|
||||||
break;
|
break;
|
||||||
case OP_LOAD_FAST: case OP_STORE_FAST: case OP_DELETE_FAST: case OP_INC_FAST: case OP_DEC_FAST:
|
case OP_LOAD_FAST: case OP_STORE_FAST: case OP_DELETE_FAST: case OP_INC_FAST: case OP_DEC_FAST:
|
||||||
|
@ -54,3 +54,6 @@ def f():
|
|||||||
_ = 0
|
_ = 0
|
||||||
while i: --i
|
while i: --i
|
||||||
f()
|
f()
|
||||||
|
|
||||||
|
# class A: a=b=1
|
||||||
|
# class A: a, b = 1, 2
|
Loading…
x
Reference in New Issue
Block a user