Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
Dec 30, 2011
Werner Almesberger 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
Werner Almesberger 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
48  src/compiler/parser.y
@@ -34,6 +34,24 @@
34 34
 	typedef const char *(*assign_callback)(struct parser_comm *comm,
35 35
 	    const char *label, struct ast_node *node);
36 36
 
  37
+	#define	FAIL					\
  38
+		do {					\
  39
+			syntax_error(state);		\
  40
+			yy_parse_failed(yypParser);	\
  41
+		} while (0)
  42
+
  43
+	#define	OTHER_STYLE_new_style	old_style
  44
+	#define	OTHER_STYLE_old_style	new_style
  45
+
  46
+	#define	IS_STYLE(which)						\
  47
+		do {							\
  48
+			if (state->style == OTHER_STYLE_##which) {	\
  49
+				FAIL;					\
  50
+				return;					\
  51
+			}						\
  52
+			state->style = which;				\
  53
+		} while (0)
  54
+
37 55
 	const enum ast_op tok2op[] = {
38 56
 		[TOK_IDENT]	= op_ident,
39 57
 		[TOK_CONSTANT]	= op_constant,
@@ -102,8 +120,7 @@
102 120
 %type context {assign_callback}
103 121
 
104 122
 %syntax_error {
105  
-	syntax_error(state);
106  
-	yy_parse_failed(yypParser);
  123
+	FAIL;
107 124
 }
108 125
 
109 126
 start ::= TOK_START_EXPR node(N). {
@@ -111,10 +128,26 @@ start ::= TOK_START_EXPR node(N). {
111 128
 	state->success = 1;
112 129
 }
113 130
 
114  
-start ::= TOK_START_ASSIGN assignments. {
  131
+start ::= TOK_START_ASSIGN sections. {
115 132
 	state->success = 1;
116 133
 }
117 134
 
  135
+sections ::= assignments.
  136
+sections ::= assignments per_frame_label assignments.
  137
+sections ::= assignments per_frame_label assignments per_vertex_label
  138
+    assignments.
  139
+sections ::= assignments per_vertex_label assignments.
  140
+
  141
+per_frame_label ::= TOK_PER_FRAME TOK_COLON. {
  142
+	IS_STYLE(new_style);
  143
+	state->comm->assign_default = state->comm->assign_per_frame;
  144
+}
  145
+
  146
+per_vertex_label ::= TOK_PER_VERTEX TOK_COLON. {
  147
+	IS_STYLE(new_style);
  148
+	state->comm->assign_default = state->comm->assign_per_vertex;
  149
+}
  150
+
118 151
 assignments ::= assignments assignment.
119 152
 
120 153
 assignments ::= .
@@ -123,8 +156,7 @@ assignment ::= ident(I) TOK_ASSIGN node(N) opt_semi. {
123 156
 	state->error = state->comm->assign_default(state->comm, I->label, N);
124 157
 	free(I);
125 158
 	if(state->error) {
126  
-		syntax_error(state);
127  
-		yy_parse_failed(yypParser);
  159
+		FAIL;
128 160
 		return;
129 161
 	}
130 162
 	parse_free(N);
@@ -135,8 +167,7 @@ assignment ::= TOK_IMAGEFILE(I) TOK_ASSIGN TOK_FNAME(N). {
135 167
 	    atoi(I->label+9), N->label);
136 168
 	free(I);
137 169
 	if(state->error) {
138  
-		syntax_error(state);
139  
-		yy_parse_failed(yypParser);
  170
+		FAIL;
140 171
 		free((void *) N->label);
141 172
 		free(N);
142 173
 		return;
@@ -159,14 +190,17 @@ assignment ::= context(C). {
159 190
 }
160 191
 
161 192
 context(C) ::= TOK_PER_FRAME TOK_ASSIGN. {
  193
+	IS_STYLE(old_style);
162 194
 	C = state->comm->assign_per_frame;
163 195
 }
164 196
 
165 197
 context(C) ::= TOK_PER_VERTEX TOK_ASSIGN. {
  198
+	IS_STYLE(old_style);
166 199
 	C = state->comm->assign_per_vertex;
167 200
 }
168 201
 
169 202
 context(C) ::= TOK_PER_PIXEL TOK_ASSIGN. {
  203
+	IS_STYLE(old_style);
170 204
 	C = state->comm->assign_per_vertex;
171 205
 }
172 206
 
1  src/compiler/parser_helper.c
@@ -54,6 +54,7 @@ const char *parse(const char *expr, int start_token, struct parser_comm *comm)
54 54
 		.error = NULL,
55 55
 		.error_label = NULL,
56 56
 		.id = NULL,
  57
+		.style = unknown_style,
57 58
 	};
58 59
 	int tok;
59 60
 	struct id *identifier;
5  src/compiler/parser_itf.h
@@ -39,6 +39,11 @@ struct parser_state {
39 39
 	const char *error_label;/* details about the failing token */
40 40
 	int error_lineno;
41 41
 	const struct id *id;	/* input, for error handling */
  42
+	enum {
  43
+		unknown_style,	/* haven't seen any fragment selection yet */
  44
+		old_style,	/* patch uses per_frame=var=expr */
  45
+		new_style,	/* patch uses per_frame: var=expr ... */
  46
+	} style; 
42 47
 };
43 48
 
44 49
 void *ParseAlloc(void *(*mallocProc)(size_t));
1  src/compiler/scanner.re
@@ -136,6 +136,7 @@ int scan(struct scanner *s)
136 136
 		<N>"("			{ return TOK_LPAREN; }
137 137
 		<N>")"			{ return TOK_RPAREN; }
138 138
 		<N>","			{ return TOK_COMMA; }
  139
+		<N>":"			{ return TOK_COLON; }
139 140
 		<N,FNAME1>"="		{ if (YYGETCONDITION() == yycFNAME1)
140 141
 						YYSETCONDITION(yycFNAME2);
141 142
 					  return TOK_ASSIGN; }
148  src/compiler/test/sections
... ...
@@ -0,0 +1,148 @@
  1
+#!/bin/sh
  2
+. ./Common
  3
+
  4
+###############################################################################
  5
+
  6
+ptest "sections: only global" <<EOF
  7
+foo = bar
  8
+EOF
  9
+expect <<EOF
  10
+foo = bar
  11
+EOF
  12
+
  13
+#------------------------------------------------------------------------------
  14
+
  15
+ptest "sections: only per frame" <<EOF
  16
+per_frame:
  17
+	foo = bar
  18
+	bar = foo
  19
+EOF
  20
+expect <<EOF
  21
+per_frame = foo = bar
  22
+per_frame = bar = foo
  23
+EOF
  24
+
  25
+#------------------------------------------------------------------------------
  26
+
  27
+ptest "sections: empty per frame" <<EOF
  28
+per_frame:
  29
+EOF
  30
+expect <<EOF
  31
+EOF
  32
+
  33
+#------------------------------------------------------------------------------
  34
+
  35
+ptest "sections: only per vertex" <<EOF
  36
+per_vertex:
  37
+	foo = bar
  38
+	bar = foo
  39
+EOF
  40
+expect <<EOF
  41
+per_vertex = foo = bar
  42
+per_vertex = bar = foo
  43
+EOF
  44
+
  45
+#------------------------------------------------------------------------------
  46
+
  47
+ptest "sections: empty per vertex" <<EOF
  48
+per_vertex:
  49
+EOF
  50
+expect <<EOF
  51
+EOF
  52
+
  53
+#------------------------------------------------------------------------------
  54
+
  55
+ptest "sections: global, per frame, then per vertex" <<EOF
  56
+x = y
  57
+per_frame:
  58
+	a = b
  59
+	c = d
  60
+per_vertex:
  61
+	e = f
  62
+	g = h
  63
+EOF
  64
+expect <<EOF
  65
+x = y
  66
+per_frame = a = b
  67
+per_frame = c = d
  68
+per_vertex = e = f
  69
+per_vertex = g = h
  70
+EOF
  71
+
  72
+#------------------------------------------------------------------------------
  73
+
  74
+ptest "sections: empty per frame, then per vertex" <<EOF
  75
+per_frame:
  76
+per_vertex:
  77
+	a = c
  78
+	b = d
  79
+EOF
  80
+expect <<EOF
  81
+per_vertex = a = c
  82
+per_vertex = b = d
  83
+EOF
  84
+
  85
+#------------------------------------------------------------------------------
  86
+
  87
+ptest_fail "sections: double per frame" <<EOF
  88
+per_frame:
  89
+	a = b
  90
+per_frame:
  91
+	c = d
  92
+EOF
  93
+expect <<EOF
  94
+per_frame = a = b
  95
+FPVM, line 3: parse error near ':'
  96
+EOF
  97
+
  98
+#------------------------------------------------------------------------------
  99
+
  100
+ptest_fail "sections: double per vertex" <<EOF
  101
+per_vertex:
  102
+	a = b
  103
+per_vertex:
  104
+	c = d
  105
+EOF
  106
+expect <<EOF
  107
+per_vertex = a = b
  108
+FPVM, line 3: parse error near ':'
  109
+EOF
  110
+
  111
+#------------------------------------------------------------------------------
  112
+
  113
+ptest_fail "sections: per vertex, then per frame" <<EOF
  114
+per_vertex:
  115
+	a = b
  116
+per_frame:
  117
+	c = d
  118
+EOF
  119
+expect <<EOF
  120
+per_vertex = a = b
  121
+FPVM, line 3: parse error near ':'
  122
+EOF
  123
+
  124
+#------------------------------------------------------------------------------
  125
+
  126
+ptest_fail "sections: old-style selection in new-style section" <<EOF
  127
+per_frame:
  128
+	a = b
  129
+per_vertex=c=d
  130
+EOF
  131
+expect <<EOF
  132
+per_frame = a = b
  133
+FPVM, line 3: parse error near 'c'
  134
+EOF
  135
+
  136
+#------------------------------------------------------------------------------
  137
+
  138
+ptest_fail "sections: new-style section follows old-style selection" <<EOF
  139
+per_vertex=a=b
  140
+per_frame:
  141
+	c = d
  142
+EOF
  143
+expect <<EOF
  144
+per_vertex = a = b
  145
+FPVM, line 3: parse error near 'c'
  146
+EOF
  147
+
  148
+###############################################################################

No commit comments for this range

Something went wrong with that request. Please try again.