Skip to content

Commit a478647

Browse files
committed
Better identify individual formulas
1 parent 9c34aa3 commit a478647

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

main.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ struct unittest_t {
127127
{ "if $z == $z then $z = $z; end", { { "[1]$z = NULL", 115 } }, { { "", 115 } }, 0 },
128128
{ "if $z == $y then $z = $y; end", { { "[1]$z = NULL", 134 } }, { { "", 134 } }, 0 },
129129
{ "if $z == $y then $z = $x; end", { { "[1]$z = NULL", 153 } }, { { "", 153 } }, 0 },
130-
{ "if $z == $y then $z = $x; $z = $z; $y = $x; end", { { "[1]$z = NULL[1]$y = NULL", 173 } }, { { "", 173 } }, 0 },
130+
{ "if $z == $y then $z = $x; $z = $z; $y = $x; end", { { "[1]$z = NULL[1]$y = NULL", 177 } }, { { "", 177 } }, 0 },
131131
{ "if $a == $b then $a = $c + $a / $b; end", { { "[1]$a = 3.5", 173 } }, { { "", 173 } }, 0 },
132132
{ "if $a == $b then $a = $c + 1 / $b; end", { { "[1]$a = 3.5", 169 } }, { { "", 169 } }, 0 },
133133
{ "if $a == $b then $a = $c + $a / 2; end", { { "[1]$a = 3.5", 169 } }, { { "", 169 } }, 0 },
@@ -164,8 +164,9 @@ struct unittest_t {
164164
{ "if 3 == 3 then $a = concat(1, 2, 3); end", { { "[1]$a = 123", 147 } }, { { "[1]$a = 123", 147 } }, 0 },
165165
{ "if 3 == 3 then $a = concat(1.2, NULL, 3); end", { { "[1]$a = 1.2NULL3", 143 } }, { { "[1]$a = 1.2NULL3", 143 } }, 0 },
166166
{ "if 3 == 3 then $a = 'foo bar'; $b = concat($a, ' ', 'foo'); end", { { "[1]$a = foo bar[1]$b = foo bar foo", 228 } }, { { "[1]$a = foo bar[1]$b = foo bar foo", 228 } }, 0 },
167-
{ "if 3 == 3 then $a = 'foo bar'; $b = concat($a, ' ', 'foo'); $b = concat($a, ' ', $a); $c = concat($a, ' ', 'test'); end", { { "[1]$a = foo bar[1]$b = foo bar foo bar[1]$c = foo bar test", 360 } }, { { "[1]$a = foo bar[1]$b = foo bar foo bar[1]$c = foo bar test", 360 } }, 0 },
167+
{ "if 3 == 3 then $a = 'foo bar'; $b = concat($a, ' ', 'foo'); $b = concat($a, ' ', $a); $c = concat($a, ' ', 'test'); end", { { "[1]$a = foo bar[1]$b = foo bar foo bar[1]$c = foo bar test", 348 } }, { { "[1]$a = foo bar[1]$b = foo bar foo bar[1]$c = foo bar test", 348 } }, 0 },
168168
{ "if 3 == 3 then $a = 1; $b = concat('{zone1:{heat:{target:{high:', $a + 1, ',low:', $a + 1, '}}}}'); end", { { "[1]$a = 1[1]$b = {zone1:{heat:{target:{high:2,low:2}}}}", 281 } }, { { "[1]$a = 1[1]$b = {zone1:{heat:{target:{high:2,low:2}}}}", 281 } }, 0 },
169+
{ "if 3 == 3 then $a = 27; $b = 1; $c = concat('{zone1:{heat:{target:{high:', $a + $b, ',low:', $a + $b, '}}}}'); end", { { "[1]$a = 27[1]$b = 1[1]$c = {zone1:{heat:{target:{high:28,low:28}}}}", 324 } }, { { "[1]$a = 27[1]$b = 1[1]$c = {zone1:{heat:{target:{high:28,low:28}}}}", 324 } }, 0 },
169170
{ "if 1 == 1 then $a = 'foo bar'; end", { { "[1]$a = foo bar", 127 } }, { { "[1]$a = foo bar", 127 } } }, // TAB
170171
{ "if 1 == 1 then $a = \"foo bar\"; end", { { "[1]$a = foo bar", 127 } }, { { "[1]$a = foo bar", 127 } } }, // TAB
171172
{ "if 1 == 1 then $a = \"foo\\tbar\"; end", { { "[1]$a = foo bar", 127 } }, { { "[1]$a = foo bar", 127 } } }, // TAB
@@ -480,7 +481,7 @@ bar", 127 } } }, // Newline
480481
{ "on foo then if 5 == 6 then $a = 1; end if 1 == 3 then $b = 3; end $a = 2; end", { "[1]$a = 2[1]$b = 3", 174 }, { "[1]$a = 2", 174 }, 0 },
481482
{ "if 1 == 1 then $a = 1; else $a = min(1, 2, 3); end", { "[1]$a = 1", 139 }, { "[1]$a = 1", 139 }, 0 },
482483
{ "if 1 == 1 then $a = 1; else $a = min(max(1, 2), 2, 3); end", { "[1]$a = 2", 155 }, { "[1]$a = 1", 155 }, 0 },
483-
{ "on bar then $a = 1; end on foo then $b = max(1, 2); bar(); end if 3 == 3 then foo(); $a = min(1, 2); end", { { "[1]$a = 1", 111 }, { "[1]$a = 1[2]$b = 2", 226 }, { "[1]$a = 1[2]$b = 2[3]$a = 1", 274 } }, { { "[1]$a = 1", 16 }, { "[1]$a = 1[2]$b = 2", 16 }, { "[1]$a = 1[2]$b = 2[3]$a = 1", 16 } }, 0 },
484+
{ "on bar then $a = 1; end on foo then $b = max(1, 2); bar(); end if 3 == 3 then foo(); $a = min(1, 2); end", { { "[1]$a = 1", 111 }, { "[1]$a = 1[2]$b = 2", 222 }, { "[1]$a = 1[2]$b = 2[3]$a = 1", 274 } }, { { "[1]$a = 1", 16 }, { "[1]$a = 1[2]$b = 2", 16 }, { "[1]$a = 1[2]$b = 2[3]$a = 1", 16 } }, 0 },
484485
{ "on foo then if max(1) == max(1) then $a = 1; end end", { "[1]$a = 1", 143 }, { "[1]$a = 1", 143 }, 0 },
485486
{ "on foo then if max($c) == 3 && max($a) then $a = 1; end end", { "[1]$a = 1", 178 }, { "[1]$a = 1", 178 }, 0 },
486487
{ "on foo then $a = 6; end if 3 == 3 then $b = 3; end ", { { "[1]$a = 6", 111 }, { "[2]$b = 3", 182 } }, { { "[1]$a = 6", 111 }, { "[2]$b = 3", 111 } }, 0 },
@@ -500,6 +501,7 @@ bar", 127 } } }, // Newline
500501
{ "on foo then $a = 1; end if 3 == 3 then foo(); else $a = 1; end", { { "[1]$a = 1", 111 }, { "[1]$a = 1[2]$a = 1", 179 } }, { { "[1]$a = 1", 119 }, { "[1]$a = 1", 119 } }, 0 },
501502
{ "on foo then $a = 1; end if 3 == 3 then foo(); elseif 1 == 1 then $a = 1; end", { { "[1]$a = 1", 111 }, { "[1]$a = 1[2]$a = 1", 187 } }, { { "[1]$a = 1", 147 }, { "[1]$a = 1", 147 } }, 0 },
502503
{ "on foo then $a = 1; end if 3 == 3 then $a = 'foo'; end", { { "[1]$a = 1", 111 }, { "[2]$a = foo", 163 } }, { { "[1]$a = 1", 111 }, { "[2]$a = foo", 202 } }, 0 },
504+
{ "if 1 == 1 then $a = 1; $b = 2; $aa = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.1; $bb = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.2; $cc = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.3; $dd = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.4; $dd = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.5; $ee = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.6; $ff = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.7; $ff = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.8; $gg = round($a / (($b * 230) + 50) * 10) / 10; end", { "[1]$a = 1[1]$b = 2.8[1]$aa = 0[1]$bb = 0[1]$cc = 0[1]$dd = 0[1]$ee = 0[1]$ff = 0[1]$gg = 0", 710 }, { "[1]$a = 1[1]$b = 2.8[1]$aa = 0[1]$bb = 0[1]$cc = 0[1]$dd = 0[1]$ee = 0[1]$ff = 0[1]$gg = 0", 710 }, 0 },
503505

504506
/*
505507
* Invalid rules
@@ -872,7 +874,7 @@ void run_test(int *i, unsigned char *mempool, uint16_t size) {
872874
mem.len = 0;
873875
mem.tot_len = size;
874876

875-
uint8_t y = 0;
877+
uint16_t y = 0;
876878
uint16_t txtoffset = alignedbuffer(size-len-5);
877879
#if (!defined(NON32XFER_HANDLER) && defined(MMU_SEC_HEAP)) || defined(COVERALLS)
878880
if((void *)mempool >= (void *)MMU_SEC_HEAP) {

src/rules/rules.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,10 @@ static void bc_assign_slots(struct rules_t *obj) {
19851985
gettype(obj->bc.buffer[a]) == OP_RET)) {
19861986
end = bc_before(obj, a);
19871987
break;
1988+
} else if(bc_next(obj, a) >= 0 &&
1989+
gettype(obj->bc.buffer[a]) == OP_SETVAL && gettype(obj->bc.buffer[a+4]) == OP_SETVAL) {
1990+
end = a;
1991+
break;
19881992
}
19891993
}
19901994
tmp = a;
@@ -3177,6 +3181,7 @@ static int16_t rule_create(char **text, struct rules_t *obj) {
31773181
if(type == TVAR) {
31783182
uint16_t c = varstack_add(text, start+1, len, 1);
31793183
bc_parent(obj, OP_SETVAL, c/sizeof(struct vm_vchar_t), 0, 0);
3184+
mathcnt = 0;
31803185
} else {
31813186
/* LCOV_EXCL_START*/
31823187
logprintf_P(F("FATAL: Internal error in %s #%d"), __FUNCTION__, __LINE__);
@@ -3332,6 +3337,7 @@ static int16_t rule_create(char **text, struct rules_t *obj) {
33323337
uint16_t a = varstack_add(text, start+1, len, 1);
33333338

33343339
bc_parent(obj, OP_SETVAL, a/sizeof(struct vm_vchar_t), val, 0);
3340+
mathcnt = 0;
33353341
pos++;
33363342

33373343
if(lexer_peek(text, pos, &type, &start, &len) < 0) {

0 commit comments

Comments
 (0)