Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/flickernoise
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 57592ac
Choose a base ref
...
head repository: m-labs/flickernoise
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0e6cf55
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 17, 2012

  1. Copy the full SHA
    eb2cb6b View commit details
  2. Copy the full SHA
    b66d924 View commit details

Commits on Jan 19, 2012

  1. Copy the full SHA
    0e6cf55 View commit details
Showing with 105 additions and 7 deletions.
  1. +44 −6 src/compiler/parser.y
  2. +29 −1 src/compiler/ptest/ptest.c
  3. +5 −0 src/compiler/scanner.re
  4. +27 −0 src/compiler/test/not
50 changes: 44 additions & 6 deletions src/compiler/parser.y
Original file line number Diff line number Diff line change
@@ -84,6 +84,9 @@ static const enum ast_op tok2op[] = {
[TOK_MIN] = op_min,
[TOK_MAX] = op_max,
[TOK_INT] = op_int,
[TOK_BNOT] = op_bnot,
[TOK_BAND] = op_band,
[TOK_BOR] = op_bor,
};

static struct ast_node *node_op(enum ast_op op,
@@ -149,7 +152,7 @@ static struct ast_node *constant(float n)
static struct ast_node *conditional(struct ast_node *a,
struct ast_node *b, struct ast_node *c)
{
if(a->op == op_not) {
if(a->op == op_bnot) {
struct ast_node *next = a->contents.branches.a;

parse_free_one(a);
@@ -191,6 +194,8 @@ static struct id *symbolify(struct id *id)

%type expr {struct ast_node *}
%type cond_expr {struct ast_node *}
%type bool_or_expr {struct ast_node *}
%type bool_and_expr {struct ast_node *}
%type equal_expr {struct ast_node *}
%type rel_expr {struct ast_node *}
%type add_expr {struct ast_node *}
@@ -200,6 +205,8 @@ static struct id *symbolify(struct id *id)

%destructor expr { free($$); }
%destructor cond_expr { free($$); }
%destructor bool_or_expr { free($$); }
%destructor bool_and_expr { free($$); }
%destructor equal_expr { free($$); }
%destructor rel_expr { free($$); }
%destructor add_expr { free($$); }
@@ -348,10 +355,26 @@ cond_expr(N) ::= equal_expr(A). {
N = A;
}

cond_expr(N) ::= equal_expr(A) TOK_QUESTION expr(B) TOK_COLON cond_expr(C). {
cond_expr(N) ::= bool_or_expr(A) TOK_QUESTION expr(B) TOK_COLON cond_expr(C). {
N = conditional(A, B, C);
}

bool_or_expr(N) ::= bool_and_expr(A). {
N = A;
}

bool_or_expr(N) ::= bool_or_expr(A) TOK_OROR bool_and_expr(B). {
FOLD_BINARY(N, op_bor, A, B, a || b);
}

bool_and_expr(N) ::= equal_expr(A). {
N = A;
}

bool_and_expr(N) ::= bool_and_expr(A) TOK_ANDAND equal_expr(B). {
FOLD_BINARY(N, op_band, A, B, a && b);
}

equal_expr(N) ::= rel_expr(A). {
N = A;
}
@@ -364,7 +387,7 @@ equal_expr(N) ::= equal_expr(A) TOK_NE rel_expr(B). {
struct ast_node *tmp;

FOLD_BINARY(tmp, op_equal, A, B, a == b);
FOLD_UNARY(N, op_not, tmp, !a);
FOLD_UNARY(N, op_bnot, tmp, !a);
}

rel_expr(N) ::= add_expr(A). {
@@ -383,14 +406,14 @@ rel_expr(N) ::= rel_expr(A) TOK_LE add_expr(B). {
struct ast_node *tmp;

FOLD_BINARY(tmp, op_above, A, B, a > b);
FOLD_UNARY(N, op_not, tmp, !a);
FOLD_UNARY(N, op_bnot, tmp, !a);
}

rel_expr(N) ::= rel_expr(A) TOK_GE add_expr(B). {
struct ast_node *tmp;

FOLD_BINARY(tmp, op_below, A, B, a < b);
FOLD_UNARY(N, op_not, tmp, !a);
FOLD_UNARY(N, op_bnot, tmp, !a);
}

add_expr(N) ::= mult_expr(A). {
@@ -430,7 +453,7 @@ unary_expr(N) ::= TOK_MINUS unary_expr(A). {
}

unary_expr(N) ::= TOK_NOT unary_expr(A). {
FOLD_UNARY(N, op_not, A, !a);
FOLD_UNARY(N, op_bnot, A, !a);
}


@@ -450,6 +473,10 @@ primary_expr(N) ::= TOK_SQRT TOK_LPAREN expr(A) TOK_RPAREN. {
FOLD_UNARY(N, op_sqrt, A, sqrtf(a));
}

primary_expr(N) ::= TOK_BNOT TOK_LPAREN expr(A) TOK_RPAREN. {
FOLD_UNARY(N, op_bnot, A, !a);
}


/* ----- Binary functions -------------------------------------------------- */

@@ -480,6 +507,14 @@ primary_expr(N) ::= TOK_MIN TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_RPAREN. {
FOLD_BINARY(N, op_min, A, B, a < b ? a : b);
}

primary_expr(N) ::= TOK_BAND TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_RPAREN. {
FOLD_BINARY(N, op_band, A, B, a && b);
}

primary_expr(N) ::= TOK_BOR TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_RPAREN. {
FOLD_BINARY(N, op_bor, A, B, a || b);
}


/* ----- Trinary functions ------------------------------------------------- */

@@ -559,9 +594,12 @@ unary_misc(O) ::= TOK_QUAKE(I). { O = I; }
unary_misc(O) ::= TOK_SIN(I). { O = I; }
unary(O) ::= TOK_SQR(I). { O = I; }
unary(O) ::= TOK_SQRT(I). { O = I; }
unary(O) ::= TOK_BNOT(I). { O = I; }

binary(O) ::= TOK_ABOVE(I). { O = I; }
binary(O) ::= TOK_BAND(I). { O = I; }
binary(O) ::= TOK_BELOW(I). { O = I; }
binary(O) ::= TOK_BOR(I). { O = I; }
binary(O) ::= TOK_EQUAL(I). { O = I; }
binary(O) ::= TOK_MAX(I). { O = I; }
binary(O) ::= TOK_MIN(I). { O = I; }
30 changes: 29 additions & 1 deletion src/compiler/ptest/ptest.c
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
#include <string.h>

#include "fpvm/pfpu.h"
#include "fpvm/schedulers.h"

#include "../parser_helper.h"
#include "../parser.h"
@@ -134,7 +135,7 @@ static void dump_ast(const struct ast_node *ast)
case op_int:
op("int", ast);
break;
case op_not:
case op_bnot:
op("!", ast);
break;
default:
@@ -343,6 +344,33 @@ static void compile(const char *pgm)
}


static void compile_raw(const char *pgm)
{
struct patch patch;
struct compiler_sc sc = {
.p = &patch
};
struct patch *p;

memset(&patch, 0, sizeof(patch));
patch.rmc = report;

if (!parse_patch(&sc, pgm)) {
symtab_free();
exit(1);
}
patch.perframe_prog_length = fpvm_default_schedule(&sc.pfv_fragment,
(unsigned *) patch.perframe_prog,
(unsigned *) patch.perframe_regs);
patch.pervertex_prog_length = fpvm_default_schedule(&sc.pvv_fragment,
(unsigned *) patch.pervertex_prog,
(unsigned *) patch.pervertex_regs);

if (!quiet)
show_patch(p);
}


static void free_buffer(void)
{
free((void *) buffer);
5 changes: 5 additions & 0 deletions src/compiler/scanner.re
Original file line number Diff line number Diff line change
@@ -100,7 +100,10 @@ int scan(struct scanner *s)

<N>"above" { return TOK_ABOVE; }
<N>"abs" { return TOK_ABS; }
<N>"band" { return TOK_BAND; }
<N>"below" { return TOK_BELOW; }
<N>"bnot" { return TOK_BNOT; }
<N>"bor" { return TOK_BOR; }
<N>"cos" { return TOK_COS; }
<N>"equal" { return TOK_EQUAL; }
<N>"f2i" { return TOK_F2I; }
@@ -149,6 +152,8 @@ int scan(struct scanner *s)
<N>">" { return TOK_GT; }
<N>"<=" { return TOK_LE; }
<N>">=" { return TOK_GE; }
<N>"&&" { return TOK_ANDAND; }
<N>"||" { return TOK_OROR; }

<N,FNAME1>"=" { if (YYGETCONDITION() == yycFNAME1)
YYSETCONDITION(yycFNAME2);
27 changes: 27 additions & 0 deletions src/compiler/test/not
Original file line number Diff line number Diff line change
@@ -110,4 +110,31 @@ R004 = 1.000000 sx
Efficiency: 50%
EOF

#------------------------------------------------------------------------------

ptest "not: bnot(a)" << EOF
sx = bnot(a)
EOF
expect <<EOF
sx = (! a)
EOF

#------------------------------------------------------------------------------

ptest "not: bnot(0)" << EOF
sx = bnot(0)
EOF
expect <<EOF
sx = 1
EOF

#------------------------------------------------------------------------------

ptest "not: if(bnot(a), b, c)" << EOF
sx = if(bnot(a), b, c)
EOF
expect <<EOF
sx = (if a c b)
EOF

###############################################################################