@@ -103,6 +103,8 @@ static int _break_before_value_or_string(int i, struct stack_item *si) {
103
103
return SUCCEEDED ;
104
104
if (si -> type == STACK_ITEM_TYPE_STRING )
105
105
return SUCCEEDED ;
106
+ if (si -> type == STACK_ITEM_TYPE_LABEL )
107
+ return SUCCEEDED ;
106
108
if (si -> type == STACK_ITEM_TYPE_OPERATOR && si -> value == SI_OP_RIGHT )
107
109
return SUCCEEDED ;
108
110
@@ -265,7 +267,7 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
265
267
}
266
268
else if (* in == '-' ) {
267
269
if (* (in + 1 ) == '-' ) {
268
- si [q ].type = STACK_ITEM_TYPE_STRING ;
270
+ si [q ].type = STACK_ITEM_TYPE_LABEL ;
269
271
si [q ].sign = SI_SIGN_POSITIVE ;
270
272
for (k = 0 ; * in == '-' && k < 32 ; k ++ , in ++ ) {
271
273
si [q ].string [k ] = '-' ;
@@ -281,7 +283,7 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
281
283
}
282
284
else if (* in == '+' ) {
283
285
if (* (in + 1 ) == '+' ) {
284
- si [q ].type = STACK_ITEM_TYPE_STRING ;
286
+ si [q ].type = STACK_ITEM_TYPE_LABEL ;
285
287
si [q ].sign = SI_SIGN_POSITIVE ;
286
288
for (k = 0 ; * in == '+' && k < 32 ; k ++ , in ++ )
287
289
si [q ].string [k ] = '+' ;
@@ -382,7 +384,8 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
382
384
/* should we end parsing here? */
383
385
if (b == 0 && q > 0 ) {
384
386
if ((si [q - 1 ].type == STACK_ITEM_TYPE_OPERATOR && si [q - 1 ].value == SI_OP_RIGHT ) ||
385
- si [q - 1 ].type == STACK_ITEM_TYPE_VALUE || si [q - 1 ].type == STACK_ITEM_TYPE_STRING )
387
+ si [q - 1 ].type == STACK_ITEM_TYPE_VALUE || si [q - 1 ].type == STACK_ITEM_TYPE_STRING ||
388
+ si [q - 1 ].type == STACK_ITEM_TYPE_LABEL )
386
389
break ;
387
390
}
388
391
@@ -419,7 +422,8 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
419
422
/* should we end parsing here? */
420
423
if (b == 0 && q > 0 ) {
421
424
if ((si [q - 1 ].type == STACK_ITEM_TYPE_OPERATOR && si [q - 1 ].value == SI_OP_RIGHT ) ||
422
- si [q - 1 ].type == STACK_ITEM_TYPE_VALUE || si [q - 1 ].type == STACK_ITEM_TYPE_STRING )
425
+ si [q - 1 ].type == STACK_ITEM_TYPE_VALUE || si [q - 1 ].type == STACK_ITEM_TYPE_STRING ||
426
+ si [q - 1 ].type == STACK_ITEM_TYPE_LABEL )
423
427
break ;
424
428
}
425
429
@@ -921,7 +925,7 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
921
925
else if (is_string == YES ) {
922
926
process_special_labels (si [q ].string );
923
927
si [q ].string [k ] = 0 ;
924
- si [q ].type = STACK_ITEM_TYPE_STRING ;
928
+ si [q ].type = STACK_ITEM_TYPE_LABEL ;
925
929
got_label = YES ;
926
930
927
931
if (from_substitutor == NO && expand_variables_inside_string (si [q ].string , sizeof (((struct stack_item * )0 )-> string ), NULL ) == FAILED )
@@ -953,8 +957,8 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
953
957
return STACK_CALCULATE_DELAY ;
954
958
955
959
/* check if there was data before the computation */
956
- if (q > 1 && (si [0 ].type == STACK_ITEM_TYPE_STRING || si [0 ].type == STACK_ITEM_TYPE_VALUE )) {
957
- if (si [1 ].type == STACK_ITEM_TYPE_STRING || si [1 ].type == STACK_ITEM_TYPE_VALUE )
960
+ if (q > 1 && (si [0 ].type == STACK_ITEM_TYPE_LABEL || si [0 ].type == STACK_ITEM_TYPE_VALUE )) {
961
+ if (si [1 ].type == STACK_ITEM_TYPE_LABEL || si [1 ].type == STACK_ITEM_TYPE_VALUE )
958
962
return STACK_CALCULATE_DELAY ;
959
963
if (si [1 ].type == STACK_ITEM_TYPE_OPERATOR ) {
960
964
if (si [1 ].value == SI_OP_LEFT )
@@ -965,7 +969,7 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
965
969
#ifdef SPC700
966
970
/* check if the computation is of the form "y+X" or "y+Y" and remove that "+X" or "+Y" */
967
971
if (q > 2 && si [q - 2 ].type == STACK_ITEM_TYPE_OPERATOR && si [q - 2 ].value == SI_OP_ADD ) {
968
- if (si [q - 1 ].type == STACK_ITEM_TYPE_STRING && si [q - 1 ].string [1 ] == 0 ) {
972
+ if (si [q - 1 ].type == STACK_ITEM_TYPE_LABEL && si [q - 1 ].string [1 ] == 0 ) {
969
973
char w = si [q - 1 ].string [0 ];
970
974
971
975
if (w == 'x' || w == 'X' || w == 'y' || w == 'Y' ) {
@@ -999,7 +1003,7 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
999
1003
}
1000
1004
}
1001
1005
if (si [k ].type == STACK_ITEM_TYPE_OPERATOR && si [k ].value == SI_OP_SUB && b == 1 ) {
1002
- if (si [k + 1 ].type == STACK_ITEM_TYPE_VALUE || si [k + 1 ].type == STACK_ITEM_TYPE_STRING ) {
1006
+ if (si [k + 1 ].type == STACK_ITEM_TYPE_VALUE || si [k + 1 ].type == STACK_ITEM_TYPE_LABEL ) {
1003
1007
if (si [k + 1 ].sign == SI_SIGN_POSITIVE )
1004
1008
si [k + 1 ].sign = SI_SIGN_NEGATIVE ;
1005
1009
else
@@ -1011,7 +1015,7 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
1011
1015
o = 1 ;
1012
1016
l = k + 2 ;
1013
1017
while (o > 0 && l < q ) {
1014
- if (si [l ].type == STACK_ITEM_TYPE_VALUE || si [l ].type == STACK_ITEM_TYPE_STRING ) {
1018
+ if (si [l ].type == STACK_ITEM_TYPE_VALUE || si [l ].type == STACK_ITEM_TYPE_LABEL ) {
1015
1019
if (si [l ].sign == SI_SIGN_POSITIVE )
1016
1020
si [l ].sign = SI_SIGN_NEGATIVE ;
1017
1021
else
@@ -1036,12 +1040,12 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
1036
1040
}
1037
1041
/* remove unnecessary + */
1038
1042
if (si [k ].type == STACK_ITEM_TYPE_OPERATOR && si [k ].value == SI_OP_ADD && b == 1 ) {
1039
- if (si [k + 1 ].type == STACK_ITEM_TYPE_VALUE || si [k + 1 ].type == STACK_ITEM_TYPE_STRING )
1043
+ if (si [k + 1 ].type == STACK_ITEM_TYPE_VALUE || si [k + 1 ].type == STACK_ITEM_TYPE_LABEL )
1040
1044
si [k ].type = STACK_ITEM_TYPE_DELETED ;
1041
1045
else if (si [k + 1 ].type == STACK_ITEM_TYPE_OPERATOR && si [k + 1 ].value == SI_OP_LEFT )
1042
1046
si [k ].type = STACK_ITEM_TYPE_DELETED ;
1043
1047
}
1044
- else if (si [k ].type == STACK_ITEM_TYPE_VALUE || si [k ].type == STACK_ITEM_TYPE_STRING )
1048
+ else if (si [k ].type == STACK_ITEM_TYPE_VALUE || si [k ].type == STACK_ITEM_TYPE_LABEL )
1045
1049
b = 0 ;
1046
1050
else if (si [k ].type == STACK_ITEM_TYPE_OPERATOR && si [k ].value == SI_OP_LEFT )
1047
1051
b = 1 ;
@@ -1058,7 +1062,7 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
1058
1062
for (b = 1 , k = 0 ; k < q ; k ++ ) {
1059
1063
if (si [k ].type == STACK_ITEM_TYPE_OPERATOR && si [k ].value == SI_OP_XOR && b == 1 )
1060
1064
si [k ].value = SI_OP_NOT ;
1061
- else if (si [k ].type == STACK_ITEM_TYPE_VALUE || si [k ].type == STACK_ITEM_TYPE_STRING )
1065
+ else if (si [k ].type == STACK_ITEM_TYPE_VALUE || si [k ].type == STACK_ITEM_TYPE_LABEL )
1062
1066
b = 0 ;
1063
1067
else if (si [k ].type == STACK_ITEM_TYPE_OPERATOR && si [k ].value == SI_OP_LEFT )
1064
1068
b = 1 ;
@@ -1069,8 +1073,8 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
1069
1073
g_delta_counter = 0 ;
1070
1074
1071
1075
for (k = 0 ; k < q ; k ++ ) {
1072
- if (si [k ].type == STACK_ITEM_TYPE_STRING ) {
1073
- if (k + 2 < q && si [k + 1 ].type == STACK_ITEM_TYPE_OPERATOR && si [k + 1 ].value == SI_OP_SUB && si [k + 2 ].type == STACK_ITEM_TYPE_STRING ) {
1076
+ if (si [k ].type == STACK_ITEM_TYPE_LABEL ) {
1077
+ if (k + 2 < q && si [k + 1 ].type == STACK_ITEM_TYPE_OPERATOR && si [k + 1 ].value == SI_OP_SUB && si [k + 2 ].type == STACK_ITEM_TYPE_LABEL ) {
1074
1078
k += 2 ;
1075
1079
g_is_calculating_deltas = YES ;
1076
1080
}
@@ -1090,7 +1094,7 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
1090
1094
ta [d ].sign = si [k ].sign ;
1091
1095
d ++ ;
1092
1096
}
1093
- else if (si [k ].type == STACK_ITEM_TYPE_STRING ) {
1097
+ else if (si [k ].type == STACK_ITEM_TYPE_STRING || si [ k ]. type == STACK_ITEM_TYPE_LABEL ) {
1094
1098
ta [d ].type = si [k ].type ;
1095
1099
strcpy (ta [d ].string , si [k ].string );
1096
1100
ta [d ].sign = si [k ].sign ;
@@ -1165,6 +1169,12 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
1165
1169
1166
1170
/* only one string? */
1167
1171
if (d == 1 && ta [0 ].type == STACK_ITEM_TYPE_STRING && ta [0 ].sign == SI_SIGN_POSITIVE ) {
1172
+ strcpy (g_label , ta [0 ].string );
1173
+ process_special_labels (g_label );
1174
+ return STACK_RETURN_STRING ;
1175
+ }
1176
+ /* only one label? */
1177
+ if (d == 1 && ta [0 ].type == STACK_ITEM_TYPE_LABEL && ta [0 ].sign == SI_SIGN_POSITIVE ) {
1168
1178
strcpy (g_label , ta [0 ].string );
1169
1179
process_special_labels (g_label );
1170
1180
return STACK_RETURN_LABEL ;
@@ -1217,11 +1227,20 @@ static int _stack_calculate(char *in, int *value, int *bytes_parsed, unsigned ch
1217
1227
g_stacks_tmp -> stack [q ].value = ta [q ].value ;
1218
1228
g_stacks_tmp -> stack [q ].sign = ta [q ].sign ;
1219
1229
}
1220
- else {
1221
- g_stacks_tmp -> stack [q ].type = STACK_ITEM_TYPE_STRING ;
1230
+ else if (ta [q ].type == STACK_ITEM_TYPE_STRING ) {
1231
+ /* fail if we have a string inside a pending calculation! */
1232
+ print_error (ERROR_STC , "A string (\"%s\") inside a calculation doesn't make any sense...\n" , ta [q ].string );
1233
+ return FAILED ;
1234
+ }
1235
+ else if (ta [q ].type == STACK_ITEM_TYPE_LABEL ) {
1236
+ g_stacks_tmp -> stack [q ].type = STACK_ITEM_TYPE_LABEL ;
1222
1237
g_stacks_tmp -> stack [q ].sign = ta [q ].sign ;
1223
1238
strcpy (g_stacks_tmp -> stack [q ].string , ta [q ].string );
1224
1239
}
1240
+ else {
1241
+ print_error (ERROR_STC , "Unhandled stack item type '%d' in _stack_calculate()! Please submit a bug report!\n" , ta [q ].type );
1242
+ return FAILED ;
1243
+ }
1225
1244
}
1226
1245
1227
1246
#if WLA_DEBUG
@@ -1311,6 +1330,7 @@ static int _resolve_string(struct stack_item *s, int *cannot_resolve) {
1311
1330
if (g_tmp_def -> type == DEFINITION_TYPE_STRING ) {
1312
1331
if (g_input_parse_if == NO ) {
1313
1332
/* change the contents */
1333
+ s -> type = STACK_ITEM_TYPE_STRING ;
1314
1334
strcpy (s -> string , g_tmp_def -> string );
1315
1335
/*
1316
1336
print_error(ERROR_STC, "Definition \"%s\" is a string definition.\n", g_tmp_def->alias);
@@ -1539,7 +1559,7 @@ int resolve_stack(struct stack_item s[], int stack_item_count) {
1539
1559
s -= 2 ;
1540
1560
stack_item_count += 2 ;
1541
1561
1542
- if (s -> type == STACK_ITEM_TYPE_STRING ) {
1562
+ if (s -> type == STACK_ITEM_TYPE_LABEL ) {
1543
1563
int cannot ;
1544
1564
1545
1565
if (_process_string (s , & cannot ) == FAILED )
@@ -1549,7 +1569,7 @@ int resolve_stack(struct stack_item s[], int stack_item_count) {
1549
1569
s ++ ;
1550
1570
stack_item_count -- ;
1551
1571
1552
- if (s -> type == STACK_ITEM_TYPE_STRING ) {
1572
+ if (s -> type == STACK_ITEM_TYPE_LABEL ) {
1553
1573
int cannot ;
1554
1574
1555
1575
if (_process_string (s , & cannot ) == FAILED )
@@ -1568,7 +1588,7 @@ int resolve_stack(struct stack_item s[], int stack_item_count) {
1568
1588
}
1569
1589
1570
1590
if (process_single == YES ) {
1571
- if (s -> type == STACK_ITEM_TYPE_STRING ) {
1591
+ if (s -> type == STACK_ITEM_TYPE_LABEL ) {
1572
1592
if (_process_string (s , & cannot_resolve ) == FAILED )
1573
1593
return FAILED ;
1574
1594
}
@@ -1616,7 +1636,7 @@ int resolve_stack(struct stack_item s[], int stack_item_count) {
1616
1636
}
1617
1637
1618
1638
if (process_single == YES ) {
1619
- if (st -> type == STACK_ITEM_TYPE_STRING || st -> type == STACK_ITEM_TYPE_STACK || (st -> type == STACK_ITEM_TYPE_OPERATOR && st -> value == SI_OP_BANK ))
1639
+ if (st -> type == STACK_ITEM_TYPE_STRING || st -> type == STACK_ITEM_TYPE_LABEL || st -> type == STACK_ITEM_TYPE_STACK || (st -> type == STACK_ITEM_TYPE_OPERATOR && st -> value == SI_OP_BANK ))
1620
1640
return FAILED ;
1621
1641
if (g_input_parse_if == NO && st -> type == STACK_ITEM_TYPE_OPERATOR && st -> value == SI_OP_NOT )
1622
1642
return FAILED ;
@@ -1662,7 +1682,7 @@ int compute_stack(struct stack *sta, int stack_item_count, double *result) {
1662
1682
sp [t ] = NULL ;
1663
1683
t ++ ;
1664
1684
}
1665
- else if (s -> type == STACK_ITEM_TYPE_STRING ) {
1685
+ else if (s -> type == STACK_ITEM_TYPE_LABEL || s -> type == STACK_ITEM_TYPE_STRING ) {
1666
1686
sp [t ] = s -> string ;
1667
1687
v [t ] = 0 ;
1668
1688
t ++ ;
@@ -2007,7 +2027,7 @@ int stack_create_label_stack(char *label) {
2007
2027
those that are referenced to be STACK_POSITION_CODE stacks */
2008
2028
g_stacks_tmp -> position = STACK_POSITION_DEFINITION ;
2009
2029
2010
- g_stacks_tmp -> stack [0 ].type = STACK_ITEM_TYPE_STRING ;
2030
+ g_stacks_tmp -> stack [0 ].type = STACK_ITEM_TYPE_LABEL ;
2011
2031
g_stacks_tmp -> stack [0 ].sign = SI_SIGN_POSITIVE ;
2012
2032
strcpy (g_stacks_tmp -> stack [0 ].string , label );
2013
2033
0 commit comments