Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Berry _class can be used in static var initialization code #19088

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Added
- Partition Wizard is now able to convert to safeboot from Shelly partition layout (#19034)
- Matter mini-profiler (#19075)
- Berry `_class` can be used in `static var` initialization code

### Breaking Changed

Expand Down
7 changes: 7 additions & 0 deletions lib/libesp32/berry/src/be_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ static bbool code_move(bfuncinfo *finfo, int a, int b)
return btrue;
}
}
if (!isK(b)) { /* OP_MOVE */
/* check if the previous OP_MOVE is not identical */
binstruction mov = ISET_OP(OP_MOVE) | ISET_RA(a) | ISET_RKB(b) | ISET_RKC(0);
if (mov == *i) {
return btrue; /* previous instruction is the same move, remove duplicate */
}
}
}
if (isK(b)) {
codeABx(finfo, OP_LDCONST, a, b & 0xFF);
Expand Down
18 changes: 18 additions & 0 deletions lib/libesp32/berry/src/be_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,25 @@ static void class_stmt(bparser *parser)
new_var(parser, name, &e);
be_code_class(parser->finfo, &e, c);
class_inherit(parser, &e);

bblockinfo binfo;
begin_block(parser->finfo, &binfo, 0);

bstring *class_str = parser_newstr(parser, "_class"); /* we always define `_class` local variable */
if (e.type == ETLOCAL) {
bexpdesc e1; /* if inline class, we add a second local variable for _class */
init_exp(&e1, ETLOCAL, 0);
e1.v.idx = new_localvar(parser, class_str);
be_code_setvar(parser->finfo, &e1, &e, 1);
} else { /* if global class, we just reuse the newly created class in the register */
init_exp(&e, ETLOCAL, 0);
e.v.idx = new_localvar(parser, class_str);
}
begin_varinfo(parser, class_str);

class_block(parser, c, &e);
end_block(parser);

be_class_compress(parser->vm, c); /* compress class size */
match_token(parser, KeyEnd); /* skip 'end' */
} else {
Expand Down
3 changes: 2 additions & 1 deletion lib/libesp32/berry/tests/class_static.be
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,5 @@ assert(classname(a) == 'A')
assert(classname(b) == 'B')
assert(A.B.f() == 1)
assert(b.g() == 2)
assert(super(B) == nil)
assert(super(b) == nil)
assert(super(A.B) == nil)
10 changes: 5 additions & 5 deletions lib/libesp32/berry_tasmota/src/embedded/rule_matcher.be
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#- Native code used for testing and code solidification -#
#- Do not use it directly -#

#@ solidify:Rule_Matcher_Key
#@ solidify:Rule_Matcher_Wildcard
#@ solidify:Rule_Matcher_Operator
#@ solidify:Rule_Matcher_Array
#@ solidify:Rule_Matcher_AND_List
#@ solidify:Rule_Matcher.Rule_Matcher_Key
#@ solidify:Rule_Matcher.Rule_Matcher_Wildcard
#@ solidify:Rule_Matcher.Rule_Matcher_Operator
#@ solidify:Rule_Matcher.Rule_Matcher_Array
#@ solidify:Rule_Matcher.Rule_Matcher_AND_List
#@ solidify:Rule_Matcher


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,121 +239,122 @@ be_local_closure(SPAKE2P_Matter_compute_TT_hash, /* name */
}),
be_str_weak(compute_TT_hash),
&be_const_str_solidified,
( &(const binstruction[114]) { /* code */
( &(const binstruction[115]) { /* code */
0x58080000, // 0000 LDCONST R2 K0
0xB4000000, // 0001 CLASS K0
0xA40E0200, // 0002 IMPORT R3 K1
0x5C100400, // 0003 MOVE R4 R2
0x7C100000, // 0004 CALL R4 0
0x8C140902, // 0005 GETMET R5 R4 K2
0x881C0103, // 0006 GETMBR R7 R0 K3
0x7C140400, // 0007 CALL R5 2
0x8C140902, // 0008 GETMET R5 R4 K2
0x881C0104, // 0009 GETMBR R7 R0 K4
0x7C140400, // 000A CALL R5 2
0x8C140902, // 000B GETMET R5 R4 K2
0x881C0105, // 000C GETMBR R7 R0 K5
0x7C140400, // 000D CALL R5 2
0x8C140902, // 000E GETMET R5 R4 K2
0x881C0106, // 000F GETMBR R7 R0 K6
0x7C140400, // 0010 CALL R5 2
0x8C140902, // 0011 GETMET R5 R4 K2
0x881C0107, // 0012 GETMBR R7 R0 K7
0x7C140400, // 0013 CALL R5 2
0x8C140902, // 0014 GETMET R5 R4 K2
0x881C0108, // 0015 GETMBR R7 R0 K8
0x7C140400, // 0016 CALL R5 2
0x8C140902, // 0017 GETMET R5 R4 K2
0x881C0109, // 0018 GETMBR R7 R0 K9
0x7C140400, // 0019 CALL R5 2
0x8C140902, // 001A GETMET R5 R4 K2
0x881C010A, // 001B GETMBR R7 R0 K10
0x7C140400, // 001C CALL R5 2
0x8C140902, // 001D GETMET R5 R4 K2
0x881C010B, // 001E GETMBR R7 R0 K11
0x7C140400, // 001F CALL R5 2
0x8C140902, // 0020 GETMET R5 R4 K2
0x881C010C, // 0021 GETMBR R7 R0 K12
0x7C140400, // 0022 CALL R5 2
0x8C14090E, // 0023 GETMET R5 R4 K14
0x7C140200, // 0024 CALL R5 1
0x90021A05, // 0025 SETMBR R0 K13 R5
0x7806000A, // 0026 JMPF R1 #0032
0x5416000F, // 0027 LDINT R5 16
0x541A001E, // 0028 LDINT R6 31
0x40140A06, // 0029 CONNECT R5 R5 R6
0x8818010D, // 002A GETMBR R6 R0 K13
0x94140C05, // 002B GETIDX R5 R6 R5
0x90021E05, // 002C SETMBR R0 K15 R5
0x5416000E, // 002D LDINT R5 15
0x40162005, // 002E CONNECT R5 K16 R5
0x8818010D, // 002F GETMBR R6 R0 K13
0x94140C05, // 0030 GETIDX R5 R6 R5
0x90021A05, // 0031 SETMBR R0 K13 R5
0x8C140711, // 0032 GETMET R5 R3 K17
0x7C140200, // 0033 CALL R5 1
0x8C180B12, // 0034 GETMET R6 R5 K18
0x8820010D, // 0035 GETMBR R8 R0 K13
0x60240015, // 0036 GETGBL R9 G21
0x7C240000, // 0037 CALL R9 0
0x60280015, // 0038 GETGBL R10 G21
0x7C280000, // 0039 CALL R10 0
0x8C281513, // 003A GETMET R10 R10 K19
0x58300014, // 003B LDCONST R12 K20
0x7C280400, // 003C CALL R10 2
0x542E003F, // 003D LDINT R11 64
0x7C180A00, // 003E CALL R6 5
0x78060003, // 003F JMPF R1 #0044
0x541E000E, // 0040 LDINT R7 15
0x401E2007, // 0041 CONNECT R7 K16 R7
0x941C0C07, // 0042 GETIDX R7 R6 R7
0x70020002, // 0043 JMP #0047
0x541E001E, // 0044 LDINT R7 31
0x401E2007, // 0045 CONNECT R7 K16 R7
0x941C0C07, // 0046 GETIDX R7 R6 R7
0x90022A07, // 0047 SETMBR R0 K21 R7
0x78060004, // 0048 JMPF R1 #004E
0x541E000F, // 0049 LDINT R7 16
0x5422001E, // 004A LDINT R8 31
0x401C0E08, // 004B CONNECT R7 R7 R8
0x941C0C07, // 004C GETIDX R7 R6 R7
0x70020003, // 004D JMP #0052
0x541E001F, // 004E LDINT R7 32
0x5422003E, // 004F LDINT R8 63
0x401C0E08, // 0050 CONNECT R7 R7 R8
0x941C0C07, // 0051 GETIDX R7 R6 R7
0x90022C07, // 0052 SETMBR R0 K22 R7
0x8C1C0B12, // 0053 GETMET R7 R5 K18
0x8824010D, // 0054 GETMBR R9 R0 K13
0x60280015, // 0055 GETGBL R10 G21
0x7C280000, // 0056 CALL R10 0
0x602C0015, // 0057 GETGBL R11 G21
0x7C2C0000, // 0058 CALL R11 0
0x8C2C1713, // 0059 GETMET R11 R11 K19
0x58340018, // 005A LDCONST R13 K24
0x7C2C0400, // 005B CALL R11 2
0x5432001F, // 005C LDINT R12 32
0x7C1C0A00, // 005D CALL R7 5
0x90022E07, // 005E SETMBR R0 K23 R7
0x8C1C071A, // 005F GETMET R7 R3 K26
0x88240115, // 0060 GETMBR R9 R0 K21
0x7C1C0400, // 0061 CALL R7 2
0x8C1C0F1B, // 0062 GETMET R7 R7 K27
0x88240109, // 0063 GETMBR R9 R0 K9
0x7C1C0400, // 0064 CALL R7 2
0x8C1C0F0E, // 0065 GETMET R7 R7 K14
0x7C1C0200, // 0066 CALL R7 1
0x90023207, // 0067 SETMBR R0 K25 R7
0x8C1C071A, // 0068 GETMET R7 R3 K26
0x88240116, // 0069 GETMBR R9 R0 K22
0x7C1C0400, // 006A CALL R7 2
0x8C1C0F1B, // 006B GETMET R7 R7 K27
0x88240108, // 006C GETMBR R9 R0 K8
0x7C1C0400, // 006D CALL R7 2
0x8C1C0F0E, // 006E GETMET R7 R7 K14
0x7C1C0200, // 006F CALL R7 1
0x90023807, // 0070 SETMBR R0 K28 R7
0x80000000, // 0071 RET 0
0x5C0C0400, // 0002 MOVE R3 R2
0xA40E0200, // 0003 IMPORT R3 K1
0x5C100400, // 0004 MOVE R4 R2
0x7C100000, // 0005 CALL R4 0
0x8C140902, // 0006 GETMET R5 R4 K2
0x881C0103, // 0007 GETMBR R7 R0 K3
0x7C140400, // 0008 CALL R5 2
0x8C140902, // 0009 GETMET R5 R4 K2
0x881C0104, // 000A GETMBR R7 R0 K4
0x7C140400, // 000B CALL R5 2
0x8C140902, // 000C GETMET R5 R4 K2
0x881C0105, // 000D GETMBR R7 R0 K5
0x7C140400, // 000E CALL R5 2
0x8C140902, // 000F GETMET R5 R4 K2
0x881C0106, // 0010 GETMBR R7 R0 K6
0x7C140400, // 0011 CALL R5 2
0x8C140902, // 0012 GETMET R5 R4 K2
0x881C0107, // 0013 GETMBR R7 R0 K7
0x7C140400, // 0014 CALL R5 2
0x8C140902, // 0015 GETMET R5 R4 K2
0x881C0108, // 0016 GETMBR R7 R0 K8
0x7C140400, // 0017 CALL R5 2
0x8C140902, // 0018 GETMET R5 R4 K2
0x881C0109, // 0019 GETMBR R7 R0 K9
0x7C140400, // 001A CALL R5 2
0x8C140902, // 001B GETMET R5 R4 K2
0x881C010A, // 001C GETMBR R7 R0 K10
0x7C140400, // 001D CALL R5 2
0x8C140902, // 001E GETMET R5 R4 K2
0x881C010B, // 001F GETMBR R7 R0 K11
0x7C140400, // 0020 CALL R5 2
0x8C140902, // 0021 GETMET R5 R4 K2
0x881C010C, // 0022 GETMBR R7 R0 K12
0x7C140400, // 0023 CALL R5 2
0x8C14090E, // 0024 GETMET R5 R4 K14
0x7C140200, // 0025 CALL R5 1
0x90021A05, // 0026 SETMBR R0 K13 R5
0x7806000A, // 0027 JMPF R1 #0033
0x5416000F, // 0028 LDINT R5 16
0x541A001E, // 0029 LDINT R6 31
0x40140A06, // 002A CONNECT R5 R5 R6
0x8818010D, // 002B GETMBR R6 R0 K13
0x94140C05, // 002C GETIDX R5 R6 R5
0x90021E05, // 002D SETMBR R0 K15 R5
0x5416000E, // 002E LDINT R5 15
0x40162005, // 002F CONNECT R5 K16 R5
0x8818010D, // 0030 GETMBR R6 R0 K13
0x94140C05, // 0031 GETIDX R5 R6 R5
0x90021A05, // 0032 SETMBR R0 K13 R5
0x8C140711, // 0033 GETMET R5 R3 K17
0x7C140200, // 0034 CALL R5 1
0x8C180B12, // 0035 GETMET R6 R5 K18
0x8820010D, // 0036 GETMBR R8 R0 K13
0x60240015, // 0037 GETGBL R9 G21
0x7C240000, // 0038 CALL R9 0
0x60280015, // 0039 GETGBL R10 G21
0x7C280000, // 003A CALL R10 0
0x8C281513, // 003B GETMET R10 R10 K19
0x58300014, // 003C LDCONST R12 K20
0x7C280400, // 003D CALL R10 2
0x542E003F, // 003E LDINT R11 64
0x7C180A00, // 003F CALL R6 5
0x78060003, // 0040 JMPF R1 #0045
0x541E000E, // 0041 LDINT R7 15
0x401E2007, // 0042 CONNECT R7 K16 R7
0x941C0C07, // 0043 GETIDX R7 R6 R7
0x70020002, // 0044 JMP #0048
0x541E001E, // 0045 LDINT R7 31
0x401E2007, // 0046 CONNECT R7 K16 R7
0x941C0C07, // 0047 GETIDX R7 R6 R7
0x90022A07, // 0048 SETMBR R0 K21 R7
0x78060004, // 0049 JMPF R1 #004F
0x541E000F, // 004A LDINT R7 16
0x5422001E, // 004B LDINT R8 31
0x401C0E08, // 004C CONNECT R7 R7 R8
0x941C0C07, // 004D GETIDX R7 R6 R7
0x70020003, // 004E JMP #0053
0x541E001F, // 004F LDINT R7 32
0x5422003E, // 0050 LDINT R8 63
0x401C0E08, // 0051 CONNECT R7 R7 R8
0x941C0C07, // 0052 GETIDX R7 R6 R7
0x90022C07, // 0053 SETMBR R0 K22 R7
0x8C1C0B12, // 0054 GETMET R7 R5 K18
0x8824010D, // 0055 GETMBR R9 R0 K13
0x60280015, // 0056 GETGBL R10 G21
0x7C280000, // 0057 CALL R10 0
0x602C0015, // 0058 GETGBL R11 G21
0x7C2C0000, // 0059 CALL R11 0
0x8C2C1713, // 005A GETMET R11 R11 K19
0x58340018, // 005B LDCONST R13 K24
0x7C2C0400, // 005C CALL R11 2
0x5432001F, // 005D LDINT R12 32
0x7C1C0A00, // 005E CALL R7 5
0x90022E07, // 005F SETMBR R0 K23 R7
0x8C1C071A, // 0060 GETMET R7 R3 K26
0x88240115, // 0061 GETMBR R9 R0 K21
0x7C1C0400, // 0062 CALL R7 2
0x8C1C0F1B, // 0063 GETMET R7 R7 K27
0x88240109, // 0064 GETMBR R9 R0 K9
0x7C1C0400, // 0065 CALL R7 2
0x8C1C0F0E, // 0066 GETMET R7 R7 K14
0x7C1C0200, // 0067 CALL R7 1
0x90023207, // 0068 SETMBR R0 K25 R7
0x8C1C071A, // 0069 GETMET R7 R3 K26
0x88240116, // 006A GETMBR R9 R0 K22
0x7C1C0400, // 006B CALL R7 2
0x8C1C0F1B, // 006C GETMET R7 R7 K27
0x88240108, // 006D GETMBR R9 R0 K8
0x7C1C0400, // 006E CALL R7 2
0x8C1C0F0E, // 006F GETMET R7 R7 K14
0x7C1C0200, // 0070 CALL R7 1
0x90023807, // 0071 SETMBR R0 K28 R7
0x80000000, // 0072 RET 0
})
)
);
Expand Down
7 changes: 4 additions & 3 deletions lib/libesp32/berry_tasmota/src/solidify/solidified_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ be_local_class(mqtt_listener,
********************************************************************/
be_local_closure(MQTT_mqtt_listener_class, /* name */
be_nested_proto(
2, /* nstack */
3, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
Expand All @@ -458,10 +458,11 @@ be_local_closure(MQTT_mqtt_listener_class, /* name */
}),
&be_const_str_mqtt_listener_class,
&be_const_str_solidified,
( &(const binstruction[ 3]) { /* code */
( &(const binstruction[ 4]) { /* code */
0x58040000, // 0000 LDCONST R1 K0
0xB4000000, // 0001 CLASS K0
0x80040200, // 0002 RET 1 R1
0x5C080200, // 0002 MOVE R2 R1
0x80040200, // 0003 RET 1 R1
})
)
);
Expand Down