diff --git a/lib/libesp32/Berry/default/be_tasmotalib.c b/lib/libesp32/Berry/default/be_tasmotalib.c index 0951e1d21..ec2c5c5ea 100644 --- a/lib/libesp32/Berry/default/be_tasmotalib.c +++ b/lib/libesp32/Berry/default/be_tasmotalib.c @@ -50,6 +50,83 @@ extern int l_getswitch(bvm *vm); extern int l_i2cenabled(bvm *vm); +// KV class +/******************************************************************** +** Solidified function: init +********************************************************************/ +be_local_closure(kv_init, /* name */ + be_nested_proto( + 3, /* nstack */ + 3, /* argc */ + 0, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 2]) { /* constants */ + /* K0 */ be_nested_string("k", -301188886, 1), + /* K1 */ be_nested_string("v", -217300791, 1), + }), + (be_nested_const_str("init", 380752755, 4)), + (be_nested_const_str("input", -103256197, 5)), + ( &(const binstruction[ 3]) { /* code */ + 0x90020001, // 0000 SETMBR R0 K0 R1 + 0x90020202, // 0001 SETMBR R0 K1 R2 + 0x80000000, // 0002 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified class: KV +********************************************************************/ +be_local_class(KV, + 2, + NULL, + be_nested_map(3, + ( (struct bmapnode*) &(const bmapnode[]) { + { be_nested_key("k", -301188886, 1, 2), be_const_var(0) }, + { be_nested_key("v", -217300791, 1, -1), be_const_var(1) }, + { be_nested_key("init", 380752755, 4, -1), be_const_closure(kv_init_closure) }, + })), + (be_nested_const_str("KV", 955173972, 2)) +); + +/******************************************************************** +** Solidified function: kv +********************************************************************/ +be_local_closure(kv, /* name */ + be_nested_proto( + 7, /* nstack */ + 3, /* argc */ + 0, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 1]) { /* constants */ + /* K0 */ be_const_class(be_class_KV), + }), + (be_nested_const_str("kv", 1497177492, 2)), + (be_nested_const_str("input", -103256197, 5)), + ( &(const binstruction[ 7]) { /* code */ + 0x580C0000, // 0000 LDCONST R3 K0 + 0xB4000000, // 0001 CLASS K0 + 0x5C100600, // 0002 MOVE R4 R3 + 0x5C140200, // 0003 MOVE R5 R1 + 0x5C180400, // 0004 MOVE R6 R2 + 0x7C100400, // 0005 CALL R4 2 + 0x80040800, // 0006 RET 1 R4 + }) + ) +); +/*******************************************************************/ + + /******************************************************************** ** Solidified function: init ********************************************************************/ @@ -260,7 +337,7 @@ be_local_closure(set_light, /* name */ ********************************************************************/ be_local_closure(remove_rule, /* name */ be_nested_proto( - 5, /* nstack */ + 6, /* nstack */ 2, /* argc */ 0, /* varg */ 0, /* has upvals */ @@ -268,20 +345,37 @@ be_local_closure(remove_rule, /* name */ 0, /* has sup protos */ NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[ 2]) { /* constants */ + ( &(const bvalue[ 5]) { /* constants */ /* K0 */ be_nested_string("_rules", -28750191, 6), - /* K1 */ be_nested_string("remove", -611183107, 6), + /* K1 */ be_const_int(0), + /* K2 */ be_nested_string("k", -301188886, 1), + /* K3 */ be_nested_string("remove", -611183107, 6), + /* K4 */ be_const_int(1), }), (be_nested_const_str("remove_rule", -838755968, 11)), - (be_nested_const_str("Tasmota.be", 825809411, 10)), - ( &(const binstruction[ 7]) { /* code */ - 0x88080100, // 0000 GETMBR R2 R0 K0 - 0x780A0003, // 0001 JMPF R2 #0006 - 0x88080100, // 0002 GETMBR R2 R0 K0 - 0x8C080501, // 0003 GETMET R2 R2 K1 - 0x5C100200, // 0004 MOVE R4 R1 - 0x7C080400, // 0005 CALL R2 2 - 0x80000000, // 0006 RET 0 + (be_nested_const_str("input", -103256197, 5)), + ( &(const binstruction[21]) { /* code */ + 0x88080100, // 0000 GETMBR R2 R0 K0 + 0x780A0011, // 0001 JMPF R2 #0014 + 0x58080001, // 0002 LDCONST R2 K1 + 0x600C000C, // 0003 GETGBL R3 G12 + 0x88100100, // 0004 GETMBR R4 R0 K0 + 0x7C0C0200, // 0005 CALL R3 1 + 0x140C0403, // 0006 LT R3 R2 R3 + 0x780E000B, // 0007 JMPF R3 #0014 + 0x880C0100, // 0008 GETMBR R3 R0 K0 + 0x940C0602, // 0009 GETIDX R3 R3 R2 + 0x880C0702, // 000A GETMBR R3 R3 K2 + 0x1C0C0601, // 000B EQ R3 R3 R1 + 0x780E0004, // 000C JMPF R3 #0012 + 0x880C0100, // 000D GETMBR R3 R0 K0 + 0x8C0C0703, // 000E GETMET R3 R3 K3 + 0x5C140400, // 000F MOVE R5 R2 + 0x7C0C0400, // 0010 CALL R3 2 + 0x70020000, // 0011 JMP #0013 + 0x00080504, // 0012 ADD R2 R2 K4 + 0x7001FFEE, // 0013 JMP #0003 + 0x80000000, // 0014 RET 0 }) ) ); @@ -549,7 +643,7 @@ be_local_closure(set_timer, /* name */ ********************************************************************/ be_local_closure(add_rule, /* name */ be_nested_proto( - 5, /* nstack */ + 9, /* nstack */ 3, /* argc */ 0, /* varg */ 0, /* has upvals */ @@ -557,30 +651,37 @@ be_local_closure(add_rule, /* name */ 0, /* has sup protos */ NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[ 4]) { /* constants */ + ( &(const bvalue[ 6]) { /* constants */ /* K0 */ be_nested_string("_rules", -28750191, 6), /* K1 */ be_nested_string("function", -1630125495, 8), - /* K2 */ be_nested_string("value_error", 773297791, 11), - /* K3 */ be_nested_string("the second argument is not a function", -340392827, 37), + /* K2 */ be_nested_string("push", -2022703139, 4), + /* K3 */ be_nested_string("kv", 1497177492, 2), + /* K4 */ be_nested_string("value_error", 773297791, 11), + /* K5 */ be_nested_string("the second argument is not a function", -340392827, 37), }), (be_nested_const_str("add_rule", 596540743, 8)), - (be_nested_const_str("Tasmota.be", 825809411, 10)), - ( &(const binstruction[15]) { /* code */ - 0x880C0100, // 0000 GETMBR R3 R0 K0 - 0x740E0002, // 0001 JMPT R3 #0005 - 0x600C0013, // 0002 GETGBL R3 G19 - 0x7C0C0000, // 0003 CALL R3 0 - 0x90020003, // 0004 SETMBR R0 K0 R3 - 0x600C0004, // 0005 GETGBL R3 G4 - 0x5C100400, // 0006 MOVE R4 R2 - 0x7C0C0200, // 0007 CALL R3 1 - 0x1C0C0701, // 0008 EQ R3 R3 K1 - 0x780E0002, // 0009 JMPF R3 #000D - 0x880C0100, // 000A GETMBR R3 R0 K0 - 0x980C0202, // 000B SETIDX R3 R1 R2 - 0x70020000, // 000C JMP #000E - 0xB0060503, // 000D RAISE 1 K2 K3 - 0x80000000, // 000E RET 0 + (be_nested_const_str("input", -103256197, 5)), + ( &(const binstruction[20]) { /* code */ + 0x880C0100, // 0000 GETMBR R3 R0 K0 + 0x740E0002, // 0001 JMPT R3 #0005 + 0x600C0012, // 0002 GETGBL R3 G18 + 0x7C0C0000, // 0003 CALL R3 0 + 0x90020003, // 0004 SETMBR R0 K0 R3 + 0x600C0004, // 0005 GETGBL R3 G4 + 0x5C100400, // 0006 MOVE R4 R2 + 0x7C0C0200, // 0007 CALL R3 1 + 0x1C0C0701, // 0008 EQ R3 R3 K1 + 0x780E0007, // 0009 JMPF R3 #0012 + 0x880C0100, // 000A GETMBR R3 R0 K0 + 0x8C0C0702, // 000B GETMET R3 R3 K2 + 0x8C140103, // 000C GETMET R5 R0 K3 + 0x5C1C0200, // 000D MOVE R7 R1 + 0x5C200400, // 000E MOVE R8 R2 + 0x7C140600, // 000F CALL R5 3 + 0x7C0C0400, // 0010 CALL R3 2 + 0x70020000, // 0011 JMP #0013 + 0xB0060905, // 0012 RAISE 1 K4 K5 + 0x80000000, // 0013 RET 0 }) ) ); @@ -1037,47 +1138,15 @@ be_local_closure(get_light, /* name */ ********************************************************************/ be_local_closure(exec_rules, /* name */ be_nested_proto( - 10, /* nstack */ + 12, /* nstack */ 2, /* argc */ 0, /* varg */ 0, /* has upvals */ NULL, /* no upvals */ - 1, /* has sup protos */ - ( &(const struct bproto*[ 1]) { - be_nested_proto( - 8, /* nstack */ - 3, /* argc */ - 0, /* varg */ - 1, /* has upvals */ - ( &(const bupvaldesc[ 2]) { /* upvals */ - be_local_const_upval(1, 0), - be_local_const_upval(1, 3), - }), - 0, /* has sup protos */ - NULL, /* no sub protos */ - 1, /* has constants */ - ( &(const bvalue[ 1]) { /* constants */ - /* K0 */ be_nested_string("try_rule", 1986449405, 8), - }), - (be_nested_const_str("", 607256038, 8)), - (be_nested_const_str("tasmota.be", 1128870755, 10)), - ( &(const binstruction[11]) { /* code */ - 0x680C0000, // 0000 GETUPV R3 U0 - 0x8C0C0700, // 0001 GETMET R3 R3 K0 - 0x68140001, // 0002 GETUPV R5 U1 - 0x5C180000, // 0003 MOVE R6 R0 - 0x5C1C0200, // 0004 MOVE R7 R1 - 0x7C0C0800, // 0005 CALL R3 4 - 0x740E0001, // 0006 JMPT R3 #0009 - 0x740A0000, // 0007 JMPT R2 #0009 - 0x50080001, // 0008 LDBOOL R2 0 1 - 0x50080200, // 0009 LDBOOL R2 1 0 - 0x80040400, // 000A RET 1 R2 - }) - ), - }), + 0, /* has sup protos */ + NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[ 9]) { /* constants */ + ( &(const bvalue[12]) { /* constants */ /* K0 */ be_nested_string("_rules", -28750191, 6), /* K1 */ be_nested_string("cmd_res", 921166762, 7), /* K2 */ be_nested_string("json", 916562499, 4), @@ -1085,18 +1154,21 @@ be_local_closure(exec_rules, /* name */ /* K4 */ be_nested_string("log", 1062293841, 3), /* K5 */ be_nested_string("BRY: ERROR, bad json: ", -1579831487, 22), /* K6 */ be_const_int(3), - /* K7 */ be_nested_string("reduce", 2002030311, 6), - /* K8 */ be_nested_string("stop_iteration", -121173395, 14), + /* K7 */ be_const_int(0), + /* K8 */ be_nested_string("try_rule", 1986449405, 8), + /* K9 */ be_nested_string("k", -301188886, 1), + /* K10 */ be_nested_string("v", -217300791, 1), + /* K11 */ be_const_int(1), }), (be_nested_const_str("exec_rules", 1445221092, 10)), - (be_nested_const_str("tasmota.be", 1128870755, 10)), - ( &(const binstruction[47]) { /* code */ + (be_nested_const_str("input", -103256197, 5)), + ( &(const binstruction[48]) { /* code */ 0x88080100, // 0000 GETMBR R2 R0 K0 0x740A0003, // 0001 JMPT R2 #0006 0x88080101, // 0002 GETMBR R2 R0 K1 0x4C0C0000, // 0003 LDNIL R3 0x20080403, // 0004 NE R2 R2 R3 - 0x780A0025, // 0005 JMPF R2 #002C + 0x780A0027, // 0005 JMPF R2 #002E 0xA40A0400, // 0006 IMPORT R2 K2 0x8C0C0503, // 0007 GETMET R3 R2 K3 0x5C140200, // 0008 MOVE R5 R1 @@ -1116,28 +1188,29 @@ be_local_closure(exec_rules, /* name */ 0x78160000, // 0016 JMPF R5 #0018 0x90020203, // 0017 SETMBR R0 K1 R3 0x88140100, // 0018 GETMBR R5 R0 K0 - 0x7816000E, // 0019 JMPF R5 #0029 - 0xA8020008, // 001A EXBLK 0 #0024 - 0x88140100, // 001B GETMBR R5 R0 K0 - 0x8C140B07, // 001C GETMET R5 R5 K7 - 0x841C0000, // 001D CLOSURE R7 P0 - 0x4C200000, // 001E LDNIL R8 - 0x50240000, // 001F LDBOOL R9 0 0 - 0x7C140800, // 0020 CALL R5 4 - 0x5C100A00, // 0021 MOVE R4 R5 - 0xA8040001, // 0022 EXBLK 1 1 - 0x70020004, // 0023 JMP #0029 - 0x58140008, // 0024 LDCONST R5 K8 - 0xAC140200, // 0025 CATCH R5 1 0 - 0x70020000, // 0026 JMP #0028 - 0x70020000, // 0027 JMP #0029 - 0xB0080000, // 0028 RAISE 2 R0 R0 - 0xA0000000, // 0029 CLOSE R0 - 0x80040800, // 002A RET 1 R4 - 0xA0080000, // 002B CLOSE R2 - 0x50080000, // 002C LDBOOL R2 0 0 - 0xA0000000, // 002D CLOSE R0 - 0x80040400, // 002E RET 1 R2 + 0x78160012, // 0019 JMPF R5 #002D + 0x58140007, // 001A LDCONST R5 K7 + 0x6018000C, // 001B GETGBL R6 G12 + 0x881C0100, // 001C GETMBR R7 R0 K0 + 0x7C180200, // 001D CALL R6 1 + 0x14180A06, // 001E LT R6 R5 R6 + 0x781A000C, // 001F JMPF R6 #002D + 0x88180100, // 0020 GETMBR R6 R0 K0 + 0x94180C05, // 0021 GETIDX R6 R6 R5 + 0x8C1C0108, // 0022 GETMET R7 R0 K8 + 0x5C240600, // 0023 MOVE R9 R3 + 0x88280D09, // 0024 GETMBR R10 R6 K9 + 0x882C0D0A, // 0025 GETMBR R11 R6 K10 + 0x7C1C0800, // 0026 CALL R7 4 + 0x741E0001, // 0027 JMPT R7 #002A + 0x74120000, // 0028 JMPT R4 #002A + 0x50100001, // 0029 LDBOOL R4 0 1 + 0x50100200, // 002A LDBOOL R4 1 0 + 0x00140B0B, // 002B ADD R5 R5 K11 + 0x7001FFED, // 002C JMP #001B + 0x80040800, // 002D RET 1 R4 + 0x50080000, // 002E LDBOOL R2 0 0 + 0x80040400, // 002F RET 1 R2 }) ) ); @@ -1149,47 +1222,15 @@ be_local_closure(exec_rules, /* name */ ********************************************************************/ be_local_closure(exec_tele, /* name */ be_nested_proto( - 10, /* nstack */ + 12, /* nstack */ 2, /* argc */ 0, /* varg */ 0, /* has upvals */ NULL, /* no upvals */ - 1, /* has sup protos */ - ( &(const struct bproto*[ 1]) { - be_nested_proto( - 8, /* nstack */ - 3, /* argc */ - 0, /* varg */ - 1, /* has upvals */ - ( &(const bupvaldesc[ 2]) { /* upvals */ - be_local_const_upval(1, 0), - be_local_const_upval(1, 3), - }), - 0, /* has sup protos */ - NULL, /* no sub protos */ - 1, /* has constants */ - ( &(const bvalue[ 1]) { /* constants */ - /* K0 */ be_nested_string("try_rule", 1986449405, 8), - }), - (be_nested_const_str("", 607256038, 8)), - (be_nested_const_str("tasmota.be", 1128870755, 10)), - ( &(const binstruction[11]) { /* code */ - 0x680C0000, // 0000 GETUPV R3 U0 - 0x8C0C0700, // 0001 GETMET R3 R3 K0 - 0x68140001, // 0002 GETUPV R5 U1 - 0x5C180000, // 0003 MOVE R6 R0 - 0x5C1C0200, // 0004 MOVE R7 R1 - 0x7C0C0800, // 0005 CALL R3 4 - 0x740E0001, // 0006 JMPT R3 #0009 - 0x740A0000, // 0007 JMPT R2 #0009 - 0x50080001, // 0008 LDBOOL R2 0 1 - 0x50080200, // 0009 LDBOOL R2 1 0 - 0x80040400, // 000A RET 1 R2 - }) - ), - }), + 0, /* has sup protos */ + NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[ 9]) { /* constants */ + ( &(const bvalue[12]) { /* constants */ /* K0 */ be_nested_string("_rules", -28750191, 6), /* K1 */ be_nested_string("json", 916562499, 4), /* K2 */ be_nested_string("load", -435725847, 4), @@ -1197,14 +1238,17 @@ be_local_closure(exec_tele, /* name */ /* K4 */ be_nested_string("BRY: ERROR, bad json: ", -1579831487, 22), /* K5 */ be_const_int(3), /* K6 */ be_nested_string("Tele", 1329980653, 4), - /* K7 */ be_nested_string("reduce", 2002030311, 6), - /* K8 */ be_nested_string("stop_iteration", -121173395, 14), + /* K7 */ be_const_int(0), + /* K8 */ be_nested_string("try_rule", 1986449405, 8), + /* K9 */ be_nested_string("k", -301188886, 1), + /* K10 */ be_nested_string("v", -217300791, 1), + /* K11 */ be_const_int(1), }), (be_nested_const_str("exec_tele", 1020751601, 9)), - (be_nested_const_str("tasmota.be", 1128870755, 10)), - ( &(const binstruction[40]) { /* code */ + (be_nested_const_str("input", -103256197, 5)), + ( &(const binstruction[41]) { /* code */ 0x88080100, // 0000 GETMBR R2 R0 K0 - 0x780A0022, // 0001 JMPF R2 #0025 + 0x780A0024, // 0001 JMPF R2 #0027 0xA40A0200, // 0002 IMPORT R2 K1 0x8C0C0502, // 0003 GETMET R3 R2 K2 0x5C140200, // 0004 MOVE R5 R1 @@ -1222,27 +1266,28 @@ be_local_closure(exec_tele, /* name */ 0x7C140000, // 0010 CALL R5 0 0x98160C03, // 0011 SETIDX R5 K6 R3 0x5C0C0A00, // 0012 MOVE R3 R5 - 0xA8020008, // 0013 EXBLK 0 #001D - 0x88140100, // 0014 GETMBR R5 R0 K0 - 0x8C140B07, // 0015 GETMET R5 R5 K7 - 0x841C0000, // 0016 CLOSURE R7 P0 - 0x4C200000, // 0017 LDNIL R8 - 0x50240000, // 0018 LDBOOL R9 0 0 - 0x7C140800, // 0019 CALL R5 4 - 0x5C100A00, // 001A MOVE R4 R5 - 0xA8040001, // 001B EXBLK 1 1 - 0x70020004, // 001C JMP #0022 - 0x58140008, // 001D LDCONST R5 K8 - 0xAC140200, // 001E CATCH R5 1 0 - 0x70020000, // 001F JMP #0021 - 0x70020000, // 0020 JMP #0022 - 0xB0080000, // 0021 RAISE 2 R0 R0 - 0xA0000000, // 0022 CLOSE R0 - 0x80040800, // 0023 RET 1 R4 - 0xA0080000, // 0024 CLOSE R2 - 0x50080000, // 0025 LDBOOL R2 0 0 - 0xA0000000, // 0026 CLOSE R0 - 0x80040400, // 0027 RET 1 R2 + 0x58140007, // 0013 LDCONST R5 K7 + 0x6018000C, // 0014 GETGBL R6 G12 + 0x881C0100, // 0015 GETMBR R7 R0 K0 + 0x7C180200, // 0016 CALL R6 1 + 0x14180A06, // 0017 LT R6 R5 R6 + 0x781A000C, // 0018 JMPF R6 #0026 + 0x88180100, // 0019 GETMBR R6 R0 K0 + 0x94180C05, // 001A GETIDX R6 R6 R5 + 0x8C1C0108, // 001B GETMET R7 R0 K8 + 0x5C240600, // 001C MOVE R9 R3 + 0x88280D09, // 001D GETMBR R10 R6 K9 + 0x882C0D0A, // 001E GETMBR R11 R6 K10 + 0x7C1C0800, // 001F CALL R7 4 + 0x741E0001, // 0020 JMPT R7 #0023 + 0x74120000, // 0021 JMPT R4 #0023 + 0x50100001, // 0022 LDBOOL R4 0 1 + 0x50100200, // 0023 LDBOOL R4 1 0 + 0x00140B0B, // 0024 ADD R5 R5 K11 + 0x7001FFED, // 0025 JMP #0014 + 0x80040800, // 0026 RET 1 R4 + 0x50080000, // 0027 LDBOOL R2 0 0 + 0x80040400, // 0028 RET 1 R2 }) ) ); @@ -1808,6 +1853,7 @@ class be_class_tasmota (scope: global, name: Tasmota) { _settings_ptr, comptr(&Settings) init, closure(init_closure) + kv, closure(kv_closure) get_free_heap, func(l_getFreeHeap) publish, func(l_publish) diff --git a/lib/libesp32/Berry/default/embedded/Tasmota.be b/lib/libesp32/Berry/default/embedded/Tasmota.be index d0ca48821..e7ebe60f0 100644 --- a/lib/libesp32/Berry/default/embedded/Tasmota.be +++ b/lib/libesp32/Berry/default/embedded/Tasmota.be @@ -38,6 +38,20 @@ class Tasmota end end + # create a specific sub-class for rules: pattern(string) -> closure + # Classs KV has two members k and v + def kv(k, v) + class KV + var k, v + def init(k,v) + self.k = k + self.v = v + end + end + + return KV(k, v) + end + # add `chars_in_string(s:string,c:string) -> int`` # looks for any char in c, and return the position of the first char # or -1 if not found @@ -98,10 +112,10 @@ class Tasmota # Rules def add_rule(pat,f) if !self._rules - self._rules={} + self._rules=[] end if type(f) == 'function' - self._rules[pat] = f + self._rules.push(self.kv(pat, f)) else raise 'value_error', 'the second argument is not a function' end @@ -109,7 +123,14 @@ class Tasmota def remove_rule(pat) if self._rules - self._rules.remove(pat) + var i = 0 + while i < size(self._rules) + if self._rules[i].k == pat + self._rules.remove(i) #- don't increment i since we removed the object -# + else + i += 1 + end + end end end @@ -170,10 +191,11 @@ class Tasmota end # try all rule handlers if self._rules - try - ret = self._rules.reduce( /k,v,r-> self.try_rule(ev,k,v) || r, nil, false) - except "stop_iteration" - # silence stop_iteration which means that the map was resized during iteration + var i = 0 + while i < size(self._rules) + var kv = self._rules[i] + ret = self.try_rule(ev,kv.k,kv.v) || ret #- call should be first to avoid evaluation shortcut if ret is already true -# + i += 1 end end return ret @@ -193,10 +215,12 @@ class Tasmota end # insert tele prefix ev = { "Tele": ev } - try - ret = self._rules.reduce( /k,v,r-> self.try_rule(ev,k,v) || r, nil, false) - except "stop_iteration" - # silence stop_iteration which means that the map was resized during iteration + + var i = 0 + while i < size(self._rules) + var kv = self._rules[i] + ret = self.try_rule(ev,kv.k,kv.v) || ret #- call should be first to avoid evaluation shortcut -# + i += 1 end return ret end diff --git a/lib/libesp32/Berry/generate/be_const_strtab.h b/lib/libesp32/Berry/generate/be_const_strtab.h index eed728629..3875e9d20 100644 --- a/lib/libesp32/Berry/generate/be_const_strtab.h +++ b/lib/libesp32/Berry/generate/be_const_strtab.h @@ -3,6 +3,7 @@ extern const bcstring be_const_str_set_auth; extern const bcstring be_const_str_HIGH; extern const bcstring be_const_str_depower; extern const bcstring be_const_str_exec_rules; +extern const bcstring be_const_str_kv; extern const bcstring be_const_str_SERIAL_8E2; extern const bcstring be_const_str___upper__; extern const bcstring be_const_str_ctypes_bytes; diff --git a/lib/libesp32/Berry/generate/be_const_strtab_def.h b/lib/libesp32/Berry/generate/be_const_strtab_def.h index 8eec77b2c..065fb2f4b 100644 --- a/lib/libesp32/Berry/generate/be_const_strtab_def.h +++ b/lib/libesp32/Berry/generate/be_const_strtab_def.h @@ -2,7 +2,8 @@ be_define_const_str(KEY1_PD, "KEY1_PD", 3934075620u, 0, 7, &be_const_str_set_aut be_define_const_str(set_auth, "set_auth", 1057170930u, 0, 8, NULL); be_define_const_str(HIGH, "HIGH", 2066738941u, 0, 4, &be_const_str_depower); be_define_const_str(depower, "depower", 3563819571u, 0, 7, NULL); -be_define_const_str(exec_rules, "exec_rules", 1445221092u, 0, 10, NULL); +be_define_const_str(exec_rules, "exec_rules", 1445221092u, 0, 10, &be_const_str_kv); +be_define_const_str(kv, "kv", 1497177492u, 0, 2, NULL); be_define_const_str(SERIAL_8E2, "SERIAL_8E2", 2421454473u, 0, 10, &be_const_str___upper__); be_define_const_str(__upper__, "__upper__", 3612202883u, 0, 9, &be_const_str_ctypes_bytes); be_define_const_str(ctypes_bytes, "ctypes_bytes", 3879019703u, 0, 12, &be_const_str_get_option); @@ -896,6 +897,6 @@ static const bstring* const m_string_table[] = { static const struct bconststrtab m_const_string_table = { .size = 290, - .count = 580, + .count = 581, .table = m_string_table }; diff --git a/lib/libesp32/Berry/generate/be_fixed_be_class_tasmota.h b/lib/libesp32/Berry/generate/be_fixed_be_class_tasmota.h index bdd9ea780..a9f54b4b4 100644 --- a/lib/libesp32/Berry/generate/be_fixed_be_class_tasmota.h +++ b/lib/libesp32/Berry/generate/be_fixed_be_class_tasmota.h @@ -1,84 +1,85 @@ #include "be_constobj.h" static be_define_const_map_slots(be_class_tasmota_map) { - { be_const_key(add_rule, 52), be_const_closure(add_rule_closure) }, - { be_const_key(_global_addr, -1), be_const_comptr(&TasmotaGlobal) }, - { be_const_key(web_send, 14), be_const_func(l_webSend) }, - { be_const_key(settings, -1), be_const_var(0) }, - { be_const_key(set_power, -1), be_const_func(l_setpower) }, - { be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) }, - { be_const_key(publish, 13), be_const_func(l_publish) }, - { be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) }, - { be_const_key(resp_cmnd, 55), be_const_func(l_respCmnd) }, - { be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) }, - { be_const_key(time_reached, 38), be_const_func(l_timereached) }, - { be_const_key(resp_cmnd_error, 3), be_const_func(l_respCmndError) }, - { be_const_key(init, -1), be_const_closure(init_closure) }, - { be_const_key(eth, 35), be_const_func(l_eth) }, - { be_const_key(time_dump, -1), be_const_func(l_time_dump) }, - { be_const_key(_rules, 29), be_const_var(1) }, - { be_const_key(millis, 41), be_const_func(l_millis) }, - { be_const_key(get_option, -1), be_const_func(l_getoption) }, - { be_const_key(exec_cmd, 49), be_const_closure(exec_cmd_closure) }, - { be_const_key(_cb, -1), be_const_var(2) }, - { be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) }, - { be_const_key(response_append, 58), be_const_func(l_respAppend) }, - { be_const_key(add_driver, 44), be_const_closure(add_driver_closure) }, - { be_const_key(find_key_i, 28), be_const_closure(find_key_i_closure) }, - { be_const_key(remove_driver, 34), be_const_closure(remove_driver_closure) }, - { be_const_key(get_power, -1), be_const_func(l_getpower) }, - { be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) }, - { be_const_key(find_op, 21), be_const_closure(find_op_closure) }, - { be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) }, - { be_const_key(cb_dispatch, 40), be_const_closure(cb_dispatch_closure) }, - { be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) }, - { be_const_key(log, -1), be_const_func(l_logInfo) }, - { be_const_key(cmd_res, 45), be_const_var(3) }, - { be_const_key(wire1, 43), be_const_var(4) }, - { be_const_key(get_light, -1), be_const_closure(get_light_closure) }, - { be_const_key(strftime, -1), be_const_func(l_strftime) }, { be_const_key(set_light, -1), be_const_closure(set_light_closure) }, - { be_const_key(global, -1), be_const_var(5) }, - { be_const_key(publish_result, -1), be_const_func(l_publish_result) }, - { be_const_key(cmd, -1), be_const_closure(cmd_closure) }, - { be_const_key(_settings_def, 46), be_const_comptr(&be_tasmota_settings_struct) }, - { be_const_key(load, -1), be_const_closure(load_closure) }, - { be_const_key(resp_cmnd_done, 23), be_const_func(l_respCmndDone) }, - { be_const_key(event, 25), be_const_closure(event_closure) }, - { be_const_key(run_deferred, 57), be_const_closure(run_deferred_closure) }, - { be_const_key(_ccmd, -1), be_const_var(6) }, - { be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) }, - { be_const_key(exec_tele, -1), be_const_closure(exec_tele_closure) }, - { be_const_key(remove_rule, 63), be_const_closure(remove_rule_closure) }, - { be_const_key(_get_cb, -1), be_const_func(l_get_cb) }, - { be_const_key(try_rule, -1), be_const_closure(try_rule_closure) }, - { be_const_key(time_str, -1), be_const_closure(time_str_closure) }, - { be_const_key(scale_uint, -1), be_const_func(l_scaleuint) }, { be_const_key(gc, -1), be_const_closure(gc_closure) }, - { be_const_key(yield, -1), be_const_func(l_yield) }, - { be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) }, - { be_const_key(_timers, 32), be_const_var(7) }, - { be_const_key(get_switch, -1), be_const_func(l_getswitch) }, { be_const_key(remove_cmd, -1), be_const_closure(remove_cmd_closure) }, - { be_const_key(memory, -1), be_const_func(l_memory) }, - { be_const_key(save, 9), be_const_func(l_save) }, - { be_const_key(_settings_ptr, 26), be_const_comptr(&Settings) }, - { be_const_key(wire2, -1), be_const_var(8) }, - { be_const_key(_cmd, -1), be_const_func(l_cmd) }, - { be_const_key(set_timer, -1), be_const_closure(set_timer_closure) }, - { be_const_key(_drivers, 1), be_const_var(9) }, - { be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) }, - { be_const_key(rtc, -1), be_const_func(l_rtc) }, + { be_const_key(set_timer, 42), be_const_closure(set_timer_closure) }, + { be_const_key(_settings_ptr, -1), be_const_comptr(&Settings) }, + { be_const_key(set_power, -1), be_const_func(l_setpower) }, + { be_const_key(remove_driver, -1), be_const_closure(remove_driver_closure) }, + { be_const_key(try_rule, -1), be_const_closure(try_rule_closure) }, + { be_const_key(find_op, 58), be_const_closure(find_op_closure) }, + { be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) }, + { be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) }, + { be_const_key(_cb, 3), be_const_var(0) }, + { be_const_key(web_send, -1), be_const_func(l_webSend) }, + { be_const_key(log, 1), be_const_func(l_logInfo) }, + { be_const_key(get_switch, 50), be_const_func(l_getswitch) }, + { be_const_key(_ccmd, 19), be_const_var(1) }, + { be_const_key(eth, -1), be_const_func(l_eth) }, + { be_const_key(_settings_def, -1), be_const_comptr(&be_tasmota_settings_struct) }, + { be_const_key(init, 39), be_const_closure(init_closure) }, + { be_const_key(strftime, -1), be_const_func(l_strftime) }, + { be_const_key(kv, -1), be_const_closure(kv_closure) }, + { be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) }, + { be_const_key(cmd_res, 67), be_const_var(2) }, + { be_const_key(wire1, 43), be_const_var(3) }, + { be_const_key(get_light, -1), be_const_closure(get_light_closure) }, + { be_const_key(resp_cmnd_error, 62), be_const_func(l_respCmndError) }, + { be_const_key(publish_result, 9), be_const_func(l_publish_result) }, { be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) }, + { be_const_key(yield, -1), be_const_func(l_yield) }, + { be_const_key(add_rule, -1), be_const_closure(add_rule_closure) }, + { be_const_key(settings, -1), be_const_var(4) }, + { be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) }, + { be_const_key(resp_cmnd, 31), be_const_func(l_respCmnd) }, + { be_const_key(exec_tele, 68), be_const_closure(exec_tele_closure) }, + { be_const_key(exec_rules, 51), be_const_closure(exec_rules_closure) }, + { be_const_key(load, -1), be_const_closure(load_closure) }, + { be_const_key(remove_rule, 22), be_const_closure(remove_rule_closure) }, + { be_const_key(_rules, 18), be_const_var(5) }, + { be_const_key(publish, -1), be_const_func(l_publish) }, + { be_const_key(get_option, 15), be_const_func(l_getoption) }, + { be_const_key(global, -1), be_const_var(6) }, + { be_const_key(add_driver, 33), be_const_closure(add_driver_closure) }, + { be_const_key(cmd, -1), be_const_closure(cmd_closure) }, + { be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) }, + { be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) }, + { be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) }, { be_const_key(wifi, -1), be_const_func(l_wifi) }, + { be_const_key(time_dump, -1), be_const_func(l_time_dump) }, + { be_const_key(rtc, 24), be_const_func(l_rtc) }, + { be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) }, + { be_const_key(_get_cb, -1), be_const_func(l_get_cb) }, + { be_const_key(resp_cmnd_failed, 72), be_const_func(l_respCmndFailed) }, + { be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) }, + { be_const_key(exec_cmd, -1), be_const_closure(exec_cmd_closure) }, + { be_const_key(_cmd, 46), be_const_func(l_cmd) }, + { be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) }, + { be_const_key(time_str, 34), be_const_closure(time_str_closure) }, + { be_const_key(response_append, -1), be_const_func(l_respAppend) }, + { be_const_key(web_send_decimal, 60), be_const_func(l_webSendDecimal) }, + { be_const_key(_drivers, 71), be_const_var(7) }, { be_const_key(delay, -1), be_const_func(l_delay) }, - { be_const_key(_global_def, 37), be_const_comptr(&be_tasmota_global_struct) }, - { be_const_key(resp_cmnd_failed, 39), be_const_func(l_respCmndFailed) }, + { be_const_key(time_reached, -1), be_const_func(l_timereached) }, + { be_const_key(_global_def, -1), be_const_comptr(&be_tasmota_global_struct) }, + { be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) }, + { be_const_key(_timers, -1), be_const_var(8) }, + { be_const_key(event, 7), be_const_closure(event_closure) }, + { be_const_key(wire2, -1), be_const_var(9) }, + { be_const_key(scale_uint, -1), be_const_func(l_scaleuint) }, + { be_const_key(get_power, 73), be_const_func(l_getpower) }, + { be_const_key(millis, -1), be_const_func(l_millis) }, + { be_const_key(save, 44), be_const_func(l_save) }, + { be_const_key(_global_addr, -1), be_const_comptr(&TasmotaGlobal) }, + { be_const_key(memory, -1), be_const_func(l_memory) }, + { be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) }, }; static be_define_const_map( be_class_tasmota_map, - 73 + 74 ); BE_EXPORT_VARIABLE be_define_const_class( diff --git a/tasmota/xdrv_52_9_berry.ino b/tasmota/xdrv_52_9_berry.ino index 113866c6f..e8577b7aa 100644 --- a/tasmota/xdrv_52_9_berry.ino +++ b/tasmota/xdrv_52_9_berry.ino @@ -305,16 +305,14 @@ void BerryInit(void) { bool berry_init_ok = false; do { berry.vm = be_vm_new(); /* create a virtual machine instance */ - be_set_obs_hook(berry.vm, &BerryObservability); + be_set_obs_hook(berry.vm, &BerryObservability); /* attach observability hook */ comp_set_named_gbl(berry.vm); /* Enable named globals in Berry compiler */ - comp_set_strict(berry.vm); /* Enable strict mode in Berry compiler */ - be_load_custom_libs(berry.vm); + comp_set_strict(berry.vm); /* Enable strict mode in Berry compiler, equivalent of `import strict` */ - // Register functions - // be_regfunc(berry.vm, PSTR("log"), l_logInfo); - // be_regfunc(berry.vm, PSTR("save"), l_save); + be_load_custom_libs(berry.vm); // load classes and modules - // AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_BERRY "Berry function registered, RAM used=%u"), be_gc_memcount(berry.vm)); + // Set the GC threshold to 3584 bytes to avoid the first useless GC + berry.vm->gc.threshold = 3584; ret_code1 = be_loadstring(berry.vm, berry_prog); if (ret_code1 != 0) {