mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
fix a bug
This commit is contained in:
parent
ad2dd26cb2
commit
65d20a384a
@ -301,6 +301,9 @@ class Compiler {
|
|||||||
EXPR_TUPLE(); // () is just for change precedence
|
EXPR_TUPLE(); // () is just for change precedence
|
||||||
match_newlines_repl();
|
match_newlines_repl();
|
||||||
consume(TK(")"));
|
consume(TK(")"));
|
||||||
|
if(ctx()->s_expr.top()->is_tuple()) return;
|
||||||
|
Expr_ g = make_expr<GroupedExpr>(ctx()->s_expr.popx());
|
||||||
|
ctx()->s_expr.push(std::move(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
13
src/expr.h
13
src/expr.h
@ -24,6 +24,7 @@ struct Expr{
|
|||||||
virtual bool is_attrib() const { return false; }
|
virtual bool is_attrib() const { return false; }
|
||||||
virtual bool is_compare() const { return false; }
|
virtual bool is_compare() const { return false; }
|
||||||
virtual int star_level() const { return 0; }
|
virtual int star_level() const { return 0; }
|
||||||
|
virtual bool is_tuple() const { return false; }
|
||||||
bool is_starred() const { return star_level() > 0; }
|
bool is_starred() const { return star_level() > 0; }
|
||||||
|
|
||||||
// for OP_DELETE_XXX
|
// for OP_DELETE_XXX
|
||||||
@ -445,6 +446,7 @@ struct SetExpr: SequenceExpr{
|
|||||||
struct TupleExpr: SequenceExpr{
|
struct TupleExpr: SequenceExpr{
|
||||||
using SequenceExpr::SequenceExpr;
|
using SequenceExpr::SequenceExpr;
|
||||||
std::string str() const override { return "Tuple()"; }
|
std::string str() const override { return "Tuple()"; }
|
||||||
|
bool is_tuple() const override { return true; }
|
||||||
Opcode opcode() const override {
|
Opcode opcode() const override {
|
||||||
for(auto& e: items) if(e->is_starred()) return OP_BUILD_TUPLE_UNPACK;
|
for(auto& e: items) if(e->is_starred()) return OP_BUILD_TUPLE_UNPACK;
|
||||||
return OP_BUILD_TUPLE;
|
return OP_BUILD_TUPLE;
|
||||||
@ -734,6 +736,17 @@ struct CallExpr: Expr{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct GroupedExpr: Expr{
|
||||||
|
Expr_ a;
|
||||||
|
std::string str() const override { return "Grouped()"; }
|
||||||
|
|
||||||
|
GroupedExpr(Expr_&& a): a(std::move(a)) {}
|
||||||
|
|
||||||
|
void emit(CodeEmitContext* ctx) override{
|
||||||
|
a->emit(ctx);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct BinaryExpr: Expr{
|
struct BinaryExpr: Expr{
|
||||||
TokenIndex op;
|
TokenIndex op;
|
||||||
Expr_ lhs;
|
Expr_ lhs;
|
||||||
|
@ -13,4 +13,7 @@ assert 1<1+1<3<2+2<5
|
|||||||
a = [1,2,3]
|
a = [1,2,3]
|
||||||
assert a[0] < a[1] < a[2]
|
assert a[0] < a[1] < a[2]
|
||||||
assert a[0]+1 == a[1] < a[2]
|
assert a[0]+1 == a[1] < a[2]
|
||||||
assert a[0]+1 == a[1] < a[2]+1 < 5
|
assert a[0]+1 == a[1] < a[2]+1 < 5
|
||||||
|
|
||||||
|
assert (4>3<2) == False
|
||||||
|
# assert ((4>3)<2) == True
|
Loading…
x
Reference in New Issue
Block a user