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: e90101d
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: 64369d9
Choose a head ref
  • 9 commits
  • 17 files changed
  • 1 contributor

Commits on Jan 13, 2012

  1. parser: add newline after warnings in warn()

    ... instead of making it part of the warning message.
    wpwrak committed Jan 13, 2012
    Copy the full SHA
    5cc5c8b View commit details
  2. compiler: remove "FPVM, " prefix from error messages

    First, this saves precious space for more interesting information.
    Second, the compiler isn't part of libfpvm anymore, making that
    prefix a little cryptic.
    wpwrak committed Jan 13, 2012
    Copy the full SHA
    361ab20 View commit details
  3. compiler: when in Flickernoise, make warnings return an error string

    I.e., warnings become errors.
    wpwrak committed Jan 13, 2012
    Copy the full SHA
    57792ea View commit details
  4. compiler: make current assignment target part of the compiler state

    ... instead of tweaking the functions passed by the caller.
    wpwrak committed Jan 13, 2012
    Copy the full SHA
    35a9373 View commit details
  5. compiler: parse() returns success instead of message; pass message in…

    … "comm"
    
    This way, the caller can decide what to do. Current behaviour is that
    warnings don't keep us from proceeding, but they're shown in the patch
    editor. This means that the patch will run but when returning to the
    patch editor, the warning is shown. Improve this later.
    wpwrak committed Jan 13, 2012
    Copy the full SHA
    e057e27 View commit details
  6. compiler: prioritize diagnostics so that errors can override warnings

    Before, a warning preceding an error would cause the warning message
    to be shown, not the error message. This only applies to use in
    Flickernoise. In ptest, warnings don't compete with errors.
    wpwrak committed Jan 13, 2012
    Copy the full SHA
    47718fa View commit details

Commits on Jan 14, 2012

  1. compiler: further cleanup and debugging of diagostic mechanism

    This commit contains the following changes:
    
    - call diagnostics that can be errors or warnings just "msg", not "error",
    - errors now have priority over warnings,
    - streamlined the diagnostic passing a little.
    wpwrak committed Jan 14, 2012
    Copy the full SHA
    d886b04 View commit details
  2. comment out equations using *_residual in "Unchained - A Matter Of Ta…

    …ste"
    
    We have no known source for these values, so we may as well let
    things default to zero. This also makes the patch -Wundefined-clean.
    wpwrak committed Jan 14, 2012
    Copy the full SHA
    4ac760f View commit details
  3. compiler: enable warnings in Flickernoise and test/patches

    Also moved the global variables controlling variables from parser.y
    to parser_helper.c, consistent with their declaration in
    parser_helper.h
    
    ptest turns off the warnings by default and only enables them if
    explicitly requested.
    wpwrak committed Jan 14, 2012
    Copy the full SHA
    64369d9 View commit details
15 changes: 8 additions & 7 deletions patches/Unchained - A Matter Of Taste (Remix).fnp
Original file line number Diff line number Diff line change
@@ -38,16 +38,17 @@ ib_r=0.250000
ib_g=0.250000
ib_b=0.250000
ib_a=0.000000
per_frame=pulse=above(bass,0.7)//if(above(abs(pulse),9.42),-9.42,pulse+.1*bor(bor(bass_changed*bnot(treb_changed),treb_changed*bnot(bass_changed))*bnot(mid_changed),mid_changed)+(mid+bass+treb)*entropy*.01);
per_frame=q1=mid_residual;
per_frame=q2=bass_residual;
per_frame=q3=treb_residual;
per_frame=pulse=above(bass,0.7);
//if(above(abs(pulse),9.42),-9.42,pulse+.1*bor(bor(bass_changed*bnot(treb_changed),treb_changed*bnot(bass_changed))*bnot(mid_changed),mid_changed)+(mid+bass+treb)*entropy*.01);
//per_frame=q1=mid_residual;
//per_frame=q2=bass_residual;
//per_frame=q3=treb_residual;
per_frame=q4=sin(pulse);
per_frame=q5=cos(pulse);
per_frame=wave_mystery=-.2+.2*q4;
per_frame=wave_r=wave_r+.5*bass_residual;
per_frame=wave_r=wave_g+.5*mid_residual;
per_frame=wave_r=wave_b+.5*treb_residual;
//per_frame=wave_r=wave_r+.5*bass_residual;
//per_frame=wave_r=wave_g+.5*mid_residual;
//per_frame=wave_r=wave_b+.5*treb_residual;
per_frame=zoom=zoom-.0035*q1;
per_frame=decay=decay+.003*sin(pulse);
per_vertex=anti_rad=(1-rad);
25 changes: 11 additions & 14 deletions src/compiler/compiler.c
Original file line number Diff line number Diff line change
@@ -93,14 +93,12 @@ static int compile_chunk(struct fpvm_fragment *fragment, const char *chunk)
.assign_per_frame = NULL, /* crash ... */
.assign_per_vertex = NULL, /* and burn */
};
const char *error;

error = parse(chunk, TOK_START_ASSIGN, &comm);
if(error) {
snprintf(fragment->last_error, FPVM_MAXERRLEN, "%s", error);
free((void *) error);
}
return !error;
if(parse(chunk, TOK_START_ASSIGN, &comm))
return 1;
snprintf(fragment->last_error, FPVM_MAXERRLEN, "%s", comm.msg);
free((void *) comm.msg);
return 0;
}


@@ -431,14 +429,13 @@ static bool parse_patch(struct compiler_sc *sc, const char *patch_code)
.assign_per_vertex = assign_per_vertex,
.assign_image_name = assign_image_name,
};
const char *error;
int ok;

error = parse(patch_code, TOK_START_ASSIGN, &comm);
if(error) {
sc->rmc(error);
free((void *) error);
}
return !error;
ok = parse(patch_code, TOK_START_ASSIGN, &comm);
if(comm.msg)
sc->rmc(comm.msg);
free((void *) comm.msg);
return ok;
}

struct patch *patch_compile(const char *basedir, const char *patch_code,
50 changes: 24 additions & 26 deletions src/compiler/parser.y
Original file line number Diff line number Diff line change
@@ -33,9 +33,6 @@
#include "parser.h"


int warn_section = 0;
int warn_undefined = 0;

struct yyParser;
static void yy_parse_failed(struct yyParser *yypParser);

@@ -228,7 +225,7 @@ start ::= TOK_START_ASSIGN sections. {
foreach_sym(sym)
if(!(sym->flags & (SF_SYSTEM | SF_ASSIGNED)))
warn(state,
"variable %s is only read, never set\n",
"variable %s is only read, never set",
sym->fpvm_sym.name);
}
state->success = 1;
@@ -246,12 +243,12 @@ 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;
state->assign = 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;
state->assign = state->comm->assign_per_vertex;
}

assignments ::= assignments assignment.
@@ -267,8 +264,8 @@ assignment ::= ident(I) TOK_ASSIGN expr(N) opt_semi. {
* - must not assign to a per-frame system variable
*/
if(state->comm->assign_per_frame &&
state->comm->assign_default != state->comm->assign_per_frame &&
state->comm->assign_default != state->comm->assign_per_vertex &&
state->assign != state->comm->assign_per_frame &&
state->assign != state->comm->assign_per_vertex &&
I->sym->pfv_idx == -1) {
free(I);
if(N->op != op_constant || N->contents.constant) {
@@ -278,23 +275,28 @@ assignment ::= ident(I) TOK_ASSIGN expr(N) opt_semi. {
}
IS_STYLE(new_style);
} else {
state->error =
state->comm->assign_default(state->comm, I->sym, N);
const char *msg;

msg = state->assign(state->comm, I->sym, N);
free(I);
if(state->error) {
FAIL(NULL);
if(msg) {
FAIL(msg);
free((void *) msg);
return;
}
}
parse_free(N);
}

assignment ::= TOK_IMAGEFILE(I) TOK_ASSIGN TOK_FNAME(N). {
state->error = state->comm->assign_image_name(state->comm,
const char *msg;

msg = state->comm->assign_image_name(state->comm,
atoi(I->label+9), N->fname);
free(I);
if(state->error) {
FAIL(NULL);
if(msg) {
FAIL(msg);
free((void *) msg);
free((void *) N->fname);
free(N);
return;
@@ -309,11 +311,9 @@ assignment ::= context(C). {
* per_vertex= tags followed by nothing else. We work around the
* syntax issue by making these tags "sticky".
*
* This subtly changes the semantics. Also, changing assign_default
* is not a good idea, since the caller may rely on it staying the
* same.
* This subtly changes the semantics.
*/
state->comm->assign_default = C;
state->assign = C;
}

context(C) ::= old_per_frame TOK_ASSIGN. {
@@ -507,7 +507,7 @@ primary_expr(N) ::= TOK_CONSTANT(C). {
primary_expr(N) ::= ident(I). {
if(warn_undefined && state->style == new_style &&
!(I->sym->flags & (SF_SYSTEM | SF_ASSIGNED)))
warn(state, "reading undefined variable %s\n",
warn(state, "reading undefined variable %s",
I->sym->fpvm_sym.name);
N = node(I->token, I->sym, NULL, NULL, NULL);
free(I);
@@ -531,16 +531,14 @@ primary_expr(N) ::= ident(I). {

ident(O) ::= TOK_IDENT(I). {
if(warn_section) {
if(state->comm->assign_default ==
state->comm->assign_per_frame &&
if(state->assign == state->comm->assign_per_frame &&
I->sym->pfv_idx == -1 && I->sym->pvv_idx != -1)
warn(state, "using per-vertex variable %s in "
"per-frame section\n", I->sym->fpvm_sym.name);
if(state->comm->assign_default ==
state->comm->assign_per_vertex &&
"per-frame section", I->sym->fpvm_sym.name);
if(state->assign == state->comm->assign_per_vertex &&
I->sym->pfv_idx != -1 && I->sym->pvv_idx == -1)
warn(state, "using per-frame variable %s in "
"per-vertex section\n", I->sym->fpvm_sym.name);
"per-vertex section", I->sym->fpvm_sym.name);
}
O = I;
}
77 changes: 49 additions & 28 deletions src/compiler/parser_helper.c
Original file line number Diff line number Diff line change
@@ -31,36 +31,45 @@
#include "parser_helper.h"


void verror(struct parser_state *state, const char *fmt, va_list ap)
int warn_section = 1;
int warn_undefined = 1;

static void vmsg(struct parser_state *state, const char *fmt, va_list ap,
int is_error)
{
char *tmp;

if(is_error && !state->is_error) {
free((void *) state->msg);
state->msg = NULL;
state->is_error = 1;
}

/*
* If "error" or "error_label" are already set, then we keep the
* previous value. There are two reasons for this:
* If "msg" is already set, then we keep the previous value. There are
* two reasons for this:
*
* - "error" may have already been set before calling error()
* - "msg" may have already been set before calling vmsg()
*
* - we may be in the process of exiting the parser and are running
* into false or unrelated problems
*/

if(!state->error) {
char *tmp;
if(state->msg)
return;

vasprintf(&tmp, fmt, ap);
state->error = tmp;
}
if(!state->error_label) {
state->error_label = state->id->label;
state->error_lineno = state->id->lineno;
}
vasprintf(&tmp, fmt, ap);
state->msg = tmp;
state->msg_label = state->id->label;
state->msg_lineno = state->id->lineno;
}

void error(struct parser_state *state, const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
verror(state, fmt, ap);
vmsg(state, fmt, ap, 1);
va_end(ap);
}

@@ -69,7 +78,12 @@ void warn(struct parser_state *state, const char *fmt, ...)
va_list ap;

va_start(ap, fmt);
#ifdef STANDALONE
vprintf(fmt, ap);
putchar('\n');
#else
vmsg(state, fmt, ap, 0);
#endif
va_end(ap);
}

@@ -95,14 +109,16 @@ static int printable_label(const char *s)
return p-s;
}

const char *parse(const char *expr, int start_token, struct parser_comm *comm)
int parse(const char *expr, int start_token, struct parser_comm *comm)
{
struct scanner *s;
struct parser_state state = {
.comm = comm,
.assign = comm->assign_default,
.success = 0,
.error = NULL,
.error_label = NULL,
.msg = NULL,
.msg_label = NULL,
.is_error = 0,
.id = NULL,
.style = unknown_style,
};
@@ -111,18 +127,20 @@ const char *parse(const char *expr, int start_token, struct parser_comm *comm)
void *p;
char *error = NULL;

comm->msg = NULL;
s = new_scanner((unsigned char *)expr);
p = ParseAlloc(malloc);
Parse(p, start_token, NULL, &state);
tok = scan(s);
while(tok != TOK_EOF) {
if(tok == TOK_ERROR) {
asprintf(&error,
"FPVM, line %d: scan error near '%c'",
"line %d: scan error near '%c'",
s->lineno, printable_char(s->cursor[-1]));
ParseFree(p, free);
delete_scanner(s);
return error;
comm->msg = error;
return 0;
}

identifier = malloc(sizeof(struct id));
@@ -164,16 +182,19 @@ const char *parse(const char *expr, int start_token, struct parser_comm *comm)

free(identifier);

if(!state.success) {
if(!state.success)
asprintf(&error,
"FPVM, line %d: %s near '%.*s'",
state.error_lineno,
state.error ? state.error : "parse error",
printable_label(state.error_label), state.error_label);
free((void *) state.error);
}

return error;
"line %d: %s near '%.*s'",
state.msg_lineno,
state.msg ? state.msg : "parse error",
printable_label(state.msg_label), state.msg_label);
if(state.success && state.msg)
asprintf(&error, "line %d: %s",
state.msg_lineno, state.msg);
free((void *) state.msg);
comm->msg = error;

return state.success;
}

void parse_free_one(struct ast_node *node)
4 changes: 2 additions & 2 deletions src/compiler/parser_helper.h
Original file line number Diff line number Diff line change
@@ -43,16 +43,16 @@ struct parser_comm {
struct sym *sym, struct ast_node *node);
const char *(*assign_image_name)(struct parser_comm *comm,
int number, const char *name);
const char *msg; /* NULL if neither error nor warning */
};

extern int warn_section;
extern int warn_undefined;

void verror(struct parser_state *state, const char *fmt, va_list ap);
void error(struct parser_state *state, const char *fmt, ...);
void warn(struct parser_state *state, const char *fmt, ...);

const char *parse(const char *expr, int start_token, struct parser_comm *comm);
int parse(const char *expr, int start_token, struct parser_comm *comm);
void parse_free_one(struct ast_node *node);
void parse_free(struct ast_node *node);

12 changes: 9 additions & 3 deletions src/compiler/parser_itf.h
Original file line number Diff line number Diff line change
@@ -37,10 +37,16 @@ struct id {
struct parser_state {
int success;
struct parser_comm *comm;
const char *error; /* malloc'ed error message or NULL */
const char *error_label;/* details about the failing token */
int error_lineno;
const char *(*assign)(struct parser_comm *comm,
struct sym *sym, struct ast_node *node);

const char *msg; /* malloc'ed diagnostic message or NULL */
const char *msg_label; /* details about the failing token */
int msg_lineno;
int is_error; /* non-zero if error (not just warning) */

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 */
Loading