Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2d907e8

Browse files
Fix bitwise and logical AND/OR operators.
There were mistakes on multiple levels, e.g. the scanner returning the wrong operator symbols for & and |, the parser not adding the correct functions to the tree and the implementation of the bitwise AND/OR operators (| and &) were completely missing.
1 parent 6ebe221 commit 2d907e8

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

‎projectm-eval/Compiler.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,11 +2008,11 @@ YYLTYPE yylloc = yyloc_default;
20082008
break;
20092009

20102010
case 33: /* expression: expression BOOLOR expression */
2011-
{ PRJM_EVAL_FUNC2((yyval.expression), "bor", (yyvsp[-2].expression), (yyvsp[0].expression)) }
2011+
{ PRJM_EVAL_FUNC2((yyval.expression), "_or", (yyvsp[-2].expression), (yyvsp[0].expression)) }
20122012
break;
20132013

20142014
case 34: /* expression: expression BOOLAND expression */
2015-
{ PRJM_EVAL_FUNC2((yyval.expression), "band", (yyvsp[-2].expression), (yyvsp[0].expression)) }
2015+
{ PRJM_EVAL_FUNC2((yyval.expression), "_and", (yyvsp[-2].expression), (yyvsp[0].expression)) }
20162016
break;
20172017

20182018
case 35: /* expression: expression '=' expression */
@@ -2052,11 +2052,11 @@ YYLTYPE yylloc = yyloc_default;
20522052
break;
20532053

20542054
case 44: /* expression: expression '|' expression */
2055-
{ PRJM_EVAL_FUNC2((yyval.expression), "bor", (yyvsp[-2].expression), (yyvsp[0].expression)) }
2055+
{ PRJM_EVAL_FUNC2((yyval.expression), "/*or*/", (yyvsp[-2].expression), (yyvsp[0].expression)) }
20562056
break;
20572057

20582058
case 45: /* expression: expression '&' expression */
2059-
{ PRJM_EVAL_FUNC2((yyval.expression), "band", (yyvsp[-2].expression), (yyvsp[0].expression)) }
2059+
{ PRJM_EVAL_FUNC2((yyval.expression), "/*and*/", (yyvsp[-2].expression), (yyvsp[0].expression)) }
20602060
break;
20612061

20622062
case 46: /* expression: '-' expression */

‎projectm-eval/Compiler.y‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ expression:
145145
| expression[left] '>' expression[right] { PRJM_EVAL_FUNC2($$, "_above", $left, $right) }
146146

147147
/* Boolean operators */
148-
| expression[left] BOOLOR expression[right] { PRJM_EVAL_FUNC2($$, "bor", $left, $right) }
149-
| expression[left] BOOLAND expression[right] { PRJM_EVAL_FUNC2($$, "band", $left, $right) }
148+
| expression[left] BOOLOR expression[right] { PRJM_EVAL_FUNC2($$, "_or", $left, $right) }
149+
| expression[left] BOOLAND expression[right] { PRJM_EVAL_FUNC2($$, "_and", $left, $right) }
150150

151151
/* Assignment operator */
152152
| expression[left] '=' expression[right] { PRJM_EVAL_FUNC2($$, "_set", $left, $right) }
@@ -164,8 +164,8 @@ expression:
164164
| expression[left] '/' expression[right] { PRJM_EVAL_FUNC2($$, "_div", $left, $right) }
165165
| expression[left] '%' expression[right] { PRJM_EVAL_FUNC2($$, "_mod", $left, $right) }
166166
| expression[left] '^' expression[right] { PRJM_EVAL_FUNC2($$, "pow", $left, $right) }
167-
| expression[left] '|' expression[right] { PRJM_EVAL_FUNC2($$, "bor", $left, $right) }
168-
| expression[left] '&' expression[right] { PRJM_EVAL_FUNC2($$, "band", $left, $right) }
167+
| expression[left] '|' expression[right] { PRJM_EVAL_FUNC2($$, "/*or*/", $left, $right) }
168+
| expression[left] '&' expression[right] { PRJM_EVAL_FUNC2($$, "/*and*/", $left, $right) }
169169

170170
/* Unary operators */
171171
| '-' expression[value] %prec NEG { PRJM_EVAL_FUNC1($$, "_neg", $value) }

‎projectm-eval/Scanner.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,11 +1546,11 @@ YY_RULE_SETUP
15461546
YY_BREAK
15471547
case 37:
15481548
YY_RULE_SETUP
1549-
{ return '%'; }
1549+
{ return '&'; }
15501550
YY_BREAK
15511551
case 38:
15521552
YY_RULE_SETUP
1553-
{ return '^'; }
1553+
{ return '|'; }
15541554
YY_BREAK
15551555
case 39:
15561556
YY_RULE_SETUP

‎projectm-eval/Scanner.l‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ NAME [_a-zA-Z][_a-zA-Z0-9]*
105105
"/" { return '/'; }
106106
"%" { return '%'; }
107107
"^" { return '^'; }
108-
"&" { return '%'; }
109-
"|" { return '^'; }
108+
"&" { return '&'; }
109+
"|" { return '|'; }
110110
"!" { return '!'; }
111111
"=" { return '='; }
112112

‎projectm-eval/TreeFunctions.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ static prjm_eval_function_def_t intrinsic_function_table[] = {
2121
{ "/*const*/", prjm_eval_func_const, 0, true, false },
2222
{ "/*var*/", prjm_eval_func_var, 0, false, false },
2323
{ "/*list*/", prjm_eval_func_execute_list, 1, true, false },
24+
{ "/*or*/", prjm_eval_func_or, 2, true, false },
25+
{ "/*and*/", prjm_eval_func_and, 2, true, false },
2426

2527
{ "if", prjm_eval_func_if, 3, true, false },
2628
{ "_if", prjm_eval_func_if, 3, true, false },
@@ -777,6 +779,21 @@ prjm_eval_function_decl(orop)
777779
assign_ret_val((PRJM_EVAL_F) ((int)(**ret_val) | (int)(*val2_ptr)));
778780
}
779781

782+
prjm_eval_function_decl(or)
783+
{
784+
assert_valid_ctx();
785+
786+
PRJM_EVAL_F val1 = .0;
787+
PRJM_EVAL_F* val1_ptr = &val1;
788+
PRJM_EVAL_F val2 = .0;
789+
PRJM_EVAL_F* val2_ptr = &val2;
790+
791+
invoke_arg(0, &val1_ptr);
792+
invoke_arg(1, &val2_ptr);
793+
794+
assign_ret_val((PRJM_EVAL_F) ((int)(*val1_ptr) | (int)(*val2_ptr)));
795+
}
796+
780797
prjm_eval_function_decl(andop)
781798
{
782799
assert_valid_ctx();
@@ -790,6 +807,21 @@ prjm_eval_function_decl(andop)
790807
assign_ret_val((PRJM_EVAL_F) ((int)(**ret_val) & (int)(*val2_ptr)));
791808
}
792809

810+
prjm_eval_function_decl(and)
811+
{
812+
assert_valid_ctx();
813+
814+
PRJM_EVAL_F val1 = .0;
815+
PRJM_EVAL_F* val1_ptr = &val1;
816+
PRJM_EVAL_F val2 = .0;
817+
PRJM_EVAL_F* val2_ptr = &val2;
818+
819+
invoke_arg(0, &val1_ptr);
820+
invoke_arg(1, &val2_ptr);
821+
822+
assign_ret_val((PRJM_EVAL_F) ((int)(*val1_ptr) & (int)(*val2_ptr)));
823+
}
824+
793825
prjm_eval_function_decl(modop)
794826
{
795827
assert_valid_ctx();

‎projectm-eval/TreeFunctions.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ prjm_eval_function_decl(sub);
5656
prjm_eval_function_decl(mul);
5757
prjm_eval_function_decl(div);
5858
prjm_eval_function_decl(mod);
59+
prjm_eval_function_decl(or);
60+
prjm_eval_function_decl(and);
5961
prjm_eval_function_decl(band_op);
6062
prjm_eval_function_decl(bor_op);
6163
prjm_eval_function_decl(band_func);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /