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: 1c031ff
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: 0e5f809
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Dec 30, 2011

  1. compiler: alternative section syntax per_frame: and per_vertex:

    Patch sections can now be marked with the section labels that end
    in a colon and not an equal sign. This makes it clearer that they
    are something very different from an assignment.
    
    Order of sections using this new syntax is also more strictly
    enforced: per_frame: must precede per_vertex: and neither of them
    can appear more than once in a patch. Both sections are optional
    and they can also be left empty.
    wpwrak committed Dec 30, 2011
    Copy the full SHA
    aeb1633 View commit details
  2. compiler: disallow mixing of old-style and new-style fragment selection

    Any such mixing is almost certainly by mistake. So we better guide
    the user back towards consistency.
    wpwrak committed Dec 30, 2011
    Copy the full SHA
    0e5f809 View commit details
Showing with 196 additions and 7 deletions.
  1. +41 −7 src/compiler/parser.y
  2. +1 −0 src/compiler/parser_helper.c
  3. +5 −0 src/compiler/parser_itf.h
  4. +1 −0 src/compiler/scanner.re
  5. +148 −0 src/compiler/test/sections
48 changes: 41 additions & 7 deletions src/compiler/parser.y
Original file line number Diff line number Diff line change
@@ -34,6 +34,24 @@
typedef const char *(*assign_callback)(struct parser_comm *comm,
const char *label, struct ast_node *node);

#define FAIL \
do { \
syntax_error(state); \
yy_parse_failed(yypParser); \
} while (0)

#define OTHER_STYLE_new_style old_style
#define OTHER_STYLE_old_style new_style

#define IS_STYLE(which) \
do { \
if (state->style == OTHER_STYLE_##which) { \
FAIL; \
return; \
} \
state->style = which; \
} while (0)

const enum ast_op tok2op[] = {
[TOK_IDENT] = op_ident,
[TOK_CONSTANT] = op_constant,
@@ -102,19 +120,34 @@
%type context {assign_callback}

%syntax_error {
syntax_error(state);
yy_parse_failed(yypParser);
FAIL;
}

start ::= TOK_START_EXPR node(N). {
state->comm->u.parseout = N;
state->success = 1;
}

start ::= TOK_START_ASSIGN assignments. {
start ::= TOK_START_ASSIGN sections. {
state->success = 1;
}

sections ::= assignments.
sections ::= assignments per_frame_label assignments.
sections ::= assignments per_frame_label assignments per_vertex_label
assignments.
sections ::= assignments per_vertex_label assignments.

per_frame_label ::= TOK_PER_FRAME TOK_COLON. {
IS_STYLE(new_style);
state->comm->assign_default = state->comm->assign_per_frame;
}

per_vertex_label ::= TOK_PER_VERTEX TOK_COLON. {
IS_STYLE(new_style);
state->comm->assign_default = state->comm->assign_per_vertex;
}

assignments ::= assignments assignment.

assignments ::= .
@@ -123,8 +156,7 @@ assignment ::= ident(I) TOK_ASSIGN node(N) opt_semi. {
state->error = state->comm->assign_default(state->comm, I->label, N);
free(I);
if(state->error) {
syntax_error(state);
yy_parse_failed(yypParser);
FAIL;
return;
}
parse_free(N);
@@ -135,8 +167,7 @@ assignment ::= TOK_IMAGEFILE(I) TOK_ASSIGN TOK_FNAME(N). {
atoi(I->label+9), N->label);
free(I);
if(state->error) {
syntax_error(state);
yy_parse_failed(yypParser);
FAIL;
free((void *) N->label);
free(N);
return;
@@ -159,14 +190,17 @@ assignment ::= context(C). {
}

context(C) ::= TOK_PER_FRAME TOK_ASSIGN. {
IS_STYLE(old_style);
C = state->comm->assign_per_frame;
}

context(C) ::= TOK_PER_VERTEX TOK_ASSIGN. {
IS_STYLE(old_style);
C = state->comm->assign_per_vertex;
}

context(C) ::= TOK_PER_PIXEL TOK_ASSIGN. {
IS_STYLE(old_style);
C = state->comm->assign_per_vertex;
}

1 change: 1 addition & 0 deletions src/compiler/parser_helper.c
Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@ const char *parse(const char *expr, int start_token, struct parser_comm *comm)
.error = NULL,
.error_label = NULL,
.id = NULL,
.style = unknown_style,
};
int tok;
struct id *identifier;
5 changes: 5 additions & 0 deletions src/compiler/parser_itf.h
Original file line number Diff line number Diff line change
@@ -39,6 +39,11 @@ struct parser_state {
const char *error_label;/* details about the failing token */
int error_lineno;
const struct id *id; /* input, for error handling */
enum {
unknown_style, /* haven't seen any fragment selection yet */
old_style, /* patch uses per_frame=var=expr */
new_style, /* patch uses per_frame: var=expr ... */
} style;
};

void *ParseAlloc(void *(*mallocProc)(size_t));
1 change: 1 addition & 0 deletions src/compiler/scanner.re
Original file line number Diff line number Diff line change
@@ -136,6 +136,7 @@ int scan(struct scanner *s)
<N>"(" { return TOK_LPAREN; }
<N>")" { return TOK_RPAREN; }
<N>"," { return TOK_COMMA; }
<N>":" { return TOK_COLON; }
<N,FNAME1>"=" { if (YYGETCONDITION() == yycFNAME1)
YYSETCONDITION(yycFNAME2);
return TOK_ASSIGN; }
148 changes: 148 additions & 0 deletions src/compiler/test/sections
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/bin/sh
. ./Common

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

ptest "sections: only global" <<EOF
foo = bar
EOF
expect <<EOF
foo = bar
EOF

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

ptest "sections: only per frame" <<EOF
per_frame:
foo = bar
bar = foo
EOF
expect <<EOF
per_frame = foo = bar
per_frame = bar = foo
EOF

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

ptest "sections: empty per frame" <<EOF
per_frame:
EOF
expect <<EOF
EOF

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

ptest "sections: only per vertex" <<EOF
per_vertex:
foo = bar
bar = foo
EOF
expect <<EOF
per_vertex = foo = bar
per_vertex = bar = foo
EOF

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

ptest "sections: empty per vertex" <<EOF
per_vertex:
EOF
expect <<EOF
EOF

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

ptest "sections: global, per frame, then per vertex" <<EOF
x = y
per_frame:
a = b
c = d
per_vertex:
e = f
g = h
EOF
expect <<EOF
x = y
per_frame = a = b
per_frame = c = d
per_vertex = e = f
per_vertex = g = h
EOF

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

ptest "sections: empty per frame, then per vertex" <<EOF
per_frame:
per_vertex:
a = c
b = d
EOF
expect <<EOF
per_vertex = a = c
per_vertex = b = d
EOF

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

ptest_fail "sections: double per frame" <<EOF
per_frame:
a = b
per_frame:
c = d
EOF
expect <<EOF
per_frame = a = b
FPVM, line 3: parse error near ':'
EOF

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

ptest_fail "sections: double per vertex" <<EOF
per_vertex:
a = b
per_vertex:
c = d
EOF
expect <<EOF
per_vertex = a = b
FPVM, line 3: parse error near ':'
EOF

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

ptest_fail "sections: per vertex, then per frame" <<EOF
per_vertex:
a = b
per_frame:
c = d
EOF
expect <<EOF
per_vertex = a = b
FPVM, line 3: parse error near ':'
EOF

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

ptest_fail "sections: old-style selection in new-style section" <<EOF
per_frame:
a = b
per_vertex=c=d
EOF
expect <<EOF
per_frame = a = b
FPVM, line 3: parse error near 'c'
EOF

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

ptest_fail "sections: new-style section follows old-style selection" <<EOF
per_vertex=a=b
per_frame:
c = d
EOF
expect <<EOF
per_vertex = a = b
FPVM, line 3: parse error near 'c'
EOF

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