Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
50  src/compiler/parser.y
@@ -84,6 +84,9 @@ static const enum ast_op tok2op[] = {
84 84
 	[TOK_MIN]	= op_min,
85 85
 	[TOK_MAX]	= op_max,
86 86
 	[TOK_INT]	= op_int,
  87
+	[TOK_BNOT]	= op_bnot,
  88
+	[TOK_BAND]	= op_band,
  89
+	[TOK_BOR]	= op_bor,
87 90
 };
88 91
 
89 92
 static struct ast_node *node_op(enum ast_op op,
@@ -149,7 +152,7 @@ static struct ast_node *constant(float n)
149 152
 static struct ast_node *conditional(struct ast_node *a,
150 153
     struct ast_node *b, struct ast_node *c)
151 154
 {
152  
-	if(a->op == op_not) {
  155
+	if(a->op == op_bnot) {
153 156
 		struct ast_node *next = a->contents.branches.a;
154 157
 
155 158
 		parse_free_one(a);
@@ -191,6 +194,8 @@ static struct id *symbolify(struct id *id)
191 194
 
192 195
 %type expr {struct ast_node *}
193 196
 %type cond_expr {struct ast_node *}
  197
+%type bool_or_expr {struct ast_node *}
  198
+%type bool_and_expr {struct ast_node *}
194 199
 %type equal_expr {struct ast_node *}
195 200
 %type rel_expr {struct ast_node *}
196 201
 %type add_expr {struct ast_node *}
@@ -200,6 +205,8 @@ static struct id *symbolify(struct id *id)
200 205
 
201 206
 %destructor expr { free($$); }
202 207
 %destructor cond_expr { free($$); }
  208
+%destructor bool_or_expr { free($$); }
  209
+%destructor bool_and_expr { free($$); }
203 210
 %destructor equal_expr { free($$); }
204 211
 %destructor rel_expr { free($$); }
205 212
 %destructor add_expr { free($$); }
@@ -348,10 +355,26 @@ cond_expr(N) ::= equal_expr(A). {
348 355
 	N = A;
349 356
 }
350 357
 
351  
-cond_expr(N) ::= equal_expr(A) TOK_QUESTION expr(B) TOK_COLON cond_expr(C). {
  358
+cond_expr(N) ::= bool_or_expr(A) TOK_QUESTION expr(B) TOK_COLON cond_expr(C). {
352 359
 	N = conditional(A, B, C);
353 360
 }
354 361
 
  362
+bool_or_expr(N) ::= bool_and_expr(A). {
  363
+	N = A;
  364
+}
  365
+
  366
+bool_or_expr(N) ::= bool_or_expr(A) TOK_OROR bool_and_expr(B). {
  367
+	FOLD_BINARY(N, op_bor, A, B, a || b);
  368
+}
  369
+
  370
+bool_and_expr(N) ::= equal_expr(A). {
  371
+	N = A;
  372
+}
  373
+
  374
+bool_and_expr(N) ::= bool_and_expr(A) TOK_ANDAND equal_expr(B). {
  375
+	FOLD_BINARY(N, op_band, A, B, a && b);
  376
+}
  377
+
355 378
 equal_expr(N) ::= rel_expr(A). {
356 379
 	N = A;
357 380
 }
@@ -364,7 +387,7 @@ equal_expr(N) ::= equal_expr(A) TOK_NE rel_expr(B). {
364 387
 	struct ast_node *tmp;
365 388
 
366 389
 	FOLD_BINARY(tmp, op_equal, A, B, a == b);
367  
-	FOLD_UNARY(N, op_not, tmp, !a);
  390
+	FOLD_UNARY(N, op_bnot, tmp, !a);
368 391
 }
369 392
 
370 393
 rel_expr(N) ::= add_expr(A). {
@@ -383,14 +406,14 @@ rel_expr(N) ::= rel_expr(A) TOK_LE add_expr(B). {
383 406
 	struct ast_node *tmp;
384 407
 
385 408
 	FOLD_BINARY(tmp, op_above, A, B, a > b);
386  
-	FOLD_UNARY(N, op_not, tmp, !a);
  409
+	FOLD_UNARY(N, op_bnot, tmp, !a);
387 410
 }
388 411
 
389 412
 rel_expr(N) ::= rel_expr(A) TOK_GE add_expr(B). {
390 413
 	struct ast_node *tmp;
391 414
 
392 415
 	FOLD_BINARY(tmp, op_below, A, B, a < b);
393  
-	FOLD_UNARY(N, op_not, tmp, !a);
  416
+	FOLD_UNARY(N, op_bnot, tmp, !a);
394 417
 }
395 418
 
396 419
 add_expr(N) ::= mult_expr(A). {
@@ -430,7 +453,7 @@ unary_expr(N) ::= TOK_MINUS unary_expr(A). {
430 453
 }
431 454
 
432 455
 unary_expr(N) ::= TOK_NOT unary_expr(A). {
433  
-	FOLD_UNARY(N, op_not, A, !a);
  456
+	FOLD_UNARY(N, op_bnot, A, !a);
434 457
 }
435 458
 
436 459
 
@@ -450,6 +473,10 @@ primary_expr(N) ::= TOK_SQRT TOK_LPAREN expr(A) TOK_RPAREN. {
450 473
 	FOLD_UNARY(N, op_sqrt, A, sqrtf(a));
451 474
 }
452 475
 
  476
+primary_expr(N) ::= TOK_BNOT TOK_LPAREN expr(A) TOK_RPAREN. {
  477
+	FOLD_UNARY(N, op_bnot, A, !a);
  478
+}
  479
+
453 480
 
454 481
 /* ----- Binary functions -------------------------------------------------- */
455 482
 
@@ -480,6 +507,14 @@ primary_expr(N) ::= TOK_MIN TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_RPAREN. {
480 507
 	FOLD_BINARY(N, op_min, A, B, a < b ? a : b);
481 508
 }
482 509
 
  510
+primary_expr(N) ::= TOK_BAND TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_RPAREN. {
  511
+	FOLD_BINARY(N, op_band, A, B, a && b);
  512
+}
  513
+
  514
+primary_expr(N) ::= TOK_BOR TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_RPAREN. {
  515
+	FOLD_BINARY(N, op_bor, A, B, a || b);
  516
+}
  517
+
483 518
 
484 519
 /* ----- Trinary functions ------------------------------------------------- */
485 520
 
@@ -559,9 +594,12 @@ unary_misc(O) ::= TOK_QUAKE(I).	{ O = I; }
559 594
 unary_misc(O) ::= TOK_SIN(I).	{ O = I; }
560 595
 unary(O) ::= TOK_SQR(I).	{ O = I; }
561 596
 unary(O) ::= TOK_SQRT(I).	{ O = I; }
  597
+unary(O) ::= TOK_BNOT(I).	{ O = I; }
562 598
 
563 599
 binary(O) ::= TOK_ABOVE(I).	{ O = I; }
  600
+binary(O) ::= TOK_BAND(I).	{ O = I; }
564 601
 binary(O) ::= TOK_BELOW(I).	{ O = I; }
  602
+binary(O) ::= TOK_BOR(I).	{ O = I; }
565 603
 binary(O) ::= TOK_EQUAL(I).	{ O = I; }
566 604
 binary(O) ::= TOK_MAX(I).	{ O = I; }
567 605
 binary(O) ::= TOK_MIN(I).	{ O = I; }
30  src/compiler/ptest/ptest.c
@@ -15,6 +15,7 @@
15 15
 #include <string.h>
16 16
 
17 17
 #include "fpvm/pfpu.h"
  18
+#include "fpvm/schedulers.h"
18 19
 
19 20
 #include "../parser_helper.h"
20 21
 #include "../parser.h"
@@ -134,7 +135,7 @@ static void dump_ast(const struct ast_node *ast)
134 135
         case op_int:
135 136
 		op("int", ast);
136 137
 		break;
137  
-	case op_not:
  138
+	case op_bnot:
138 139
 		op("!", ast);
139 140
 		break;
140 141
 	default:
@@ -343,6 +344,33 @@ static void compile(const char *pgm)
343 344
 }
344 345
 
345 346
 
  347
+static void compile_raw(const char *pgm)
  348
+{
  349
+	struct patch patch;
  350
+	struct compiler_sc sc = {
  351
+		.p = &patch
  352
+	};
  353
+	struct patch *p;
  354
+
  355
+	memset(&patch, 0, sizeof(patch));
  356
+	patch.rmc = report;
  357
+
  358
+	if (!parse_patch(&sc, pgm)) {
  359
+		symtab_free();
  360
+		exit(1);
  361
+	}
  362
+	patch.perframe_prog_length = fpvm_default_schedule(&sc.pfv_fragment,
  363
+	    (unsigned *) patch.perframe_prog,
  364
+	    (unsigned *) patch.perframe_regs);
  365
+	patch.pervertex_prog_length = fpvm_default_schedule(&sc.pvv_fragment,
  366
+	    (unsigned *) patch.pervertex_prog,
  367
+	    (unsigned *) patch.pervertex_regs);
  368
+
  369
+	if (!quiet)
  370
+		show_patch(p);
  371
+}
  372
+
  373
+
346 374
 static void free_buffer(void)
347 375
 {
348 376
 	free((void *) buffer);
5  src/compiler/scanner.re
@@ -100,7 +100,10 @@ int scan(struct scanner *s)
100 100
 
101 101
 		<N>"above"		{ return TOK_ABOVE; }
102 102
 		<N>"abs"		{ return TOK_ABS; }
  103
+		<N>"band"		{ return TOK_BAND; }
103 104
 		<N>"below"		{ return TOK_BELOW; }
  105
+		<N>"bnot"		{ return TOK_BNOT; }
  106
+		<N>"bor"		{ return TOK_BOR; }
104 107
 		<N>"cos"		{ return TOK_COS; }
105 108
 		<N>"equal"		{ return TOK_EQUAL; }
106 109
 		<N>"f2i"		{ return TOK_F2I; }
@@ -149,6 +152,8 @@ int scan(struct scanner *s)
149 152
 		<N>">"			{ return TOK_GT; }
150 153
 		<N>"<="			{ return TOK_LE; }
151 154
 		<N>">="			{ return TOK_GE; }
  155
+		<N>"&&"			{ return TOK_ANDAND; }
  156
+		<N>"||"			{ return TOK_OROR; }
152 157
 
153 158
 		<N,FNAME1>"="		{ if (YYGETCONDITION() == yycFNAME1)
154 159
 						YYSETCONDITION(yycFNAME2);
27  src/compiler/test/not
@@ -110,4 +110,31 @@ R004 = 1.000000 sx
110 110
 Efficiency: 50%
111 111
 EOF
112 112
 
  113
+#------------------------------------------------------------------------------
  114
+
  115
+ptest "not: bnot(a)" << EOF
  116
+sx = bnot(a)
  117
+EOF
  118
+expect <<EOF
  119
+sx = (! a)
  120
+EOF
  121
+
  122
+#------------------------------------------------------------------------------
  123
+
  124
+ptest "not: bnot(0)" << EOF
  125
+sx = bnot(0)
  126
+EOF
  127
+expect <<EOF
  128
+sx = 1
  129
+EOF
  130
+
  131
+#------------------------------------------------------------------------------
  132
+
  133
+ptest "not: if(bnot(a), b, c)" << EOF
  134
+sx = if(bnot(a), b, c)
  135
+EOF
  136
+expect <<EOF
  137
+sx = (if a c b)
  138
+EOF
  139
+
113 140
 ###############################################################################

No commit comments for this range

Something went wrong with that request. Please try again.