Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: m-labs/flickernoise
base: 1c031ff
...
head fork: m-labs/flickernoise
compare: 0e5f809
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 30, 2011
@wpwrak wpwrak 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.
aeb1633
@wpwrak wpwrak 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.
0e5f809
View
48 src/compiler/parser.y
@@ -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,8 +120,7 @@
%type context {assign_callback}
%syntax_error {
- syntax_error(state);
- yy_parse_failed(yypParser);
+ FAIL;
}
start ::= TOK_START_EXPR node(N). {
@@ -111,10 +128,26 @@ start ::= TOK_START_EXPR node(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;
}
View
1  src/compiler/parser_helper.c
@@ -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;
View
5 src/compiler/parser_itf.h
@@ -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));
View
1  src/compiler/scanner.re
@@ -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; }
View
148 src/compiler/test/sections
@@ -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
+
+###############################################################################

No commit comments for this range

Something went wrong with that request. Please try again.