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: 35aef26
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: b86463c
Choose a head ref
  • 7 commits
  • 9 files changed
  • 1 contributor

Commits on Dec 31, 2011

  1. test/Common: change indentation from 4 spaces to 1 tab

    This is just cosmetic. No change in function.
    wpwrak committed Dec 31, 2011
    Copy the full SHA
    7c8a1d2 View commit details

Commits on Jan 2, 2012

  1. test/Data/flame.fnp: reformatted "Krash - Digital Flame.fnp" with new…

    … syntax
    
    Also added infrastructure for comparing two patches to the test
    framework.
    wpwrak committed Jan 2, 2012
    Copy the full SHA
    aceb5b5 View commit details
  2. compiler: added constant folding of sqrt()

    This also means that ptest now requires libm.
    wpwrak committed Jan 2, 2012
    Copy the full SHA
    709f98b View commit details

Commits on Jan 3, 2012

  1. compiler/Makefile: new targets "leak" and "leaks" to search for memor…

    …y leaks
    
    This also uses valgrind. Note that we still have plenty of memory
    leaks, so the regression tests won't pass with "make leak".
    wpwrak committed Jan 3, 2012
    Copy the full SHA
    55ca1d1 View commit details
  2. Copy the full SHA
    23d34b7 View commit details
  3. Copy the full SHA
    61ab85c View commit details
  4. parser.y: don't explicitly free items we don't need anyway

    We never access some identifiers, so the only effect of explicitly
    free(3)ing them is that this creates a reference which in turn prevents
    lemon from generating code that does the freeing automatically.
    wpwrak committed Jan 3, 2012
    Copy the full SHA
    b86463c View commit details
Showing with 206 additions and 55 deletions.
  1. +5 −1 src/compiler/Makefile
  2. +1 −0 src/compiler/compiler.c
  3. +12 −20 src/compiler/parser.y
  4. +2 −1 src/compiler/ptest/Makefile
  5. +14 −9 src/compiler/ptest/ptest.c
  6. +67 −24 src/compiler/test/Common
  7. +83 −0 src/compiler/test/Data/flame.fnp
  8. +9 −0 src/compiler/test/fold
  9. +13 −0 src/compiler/test/rewrite
6 changes: 5 additions & 1 deletion src/compiler/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: all clean
.PHONY: test tests valgrind
.PHONY: test tests valgrind leak leaks

all:
$(MAKE) -C ptest
@@ -16,6 +16,10 @@ test tests: all
valgrind:
VALGRIND="valgrind -q" $(MAKE) tests

leak leaks:
VALGRIND="valgrind -q --leak-check=full --show-reachable=yes" \
$(MAKE) tests

# ----- Cleanup ---------------------------------------------------------------

clean:
1 change: 1 addition & 0 deletions src/compiler/compiler.c
Original file line number Diff line number Diff line change
@@ -683,6 +683,7 @@ struct patch *patch_compile(const char *basedir, const char *patch_code,
return p;

fail:
unique_free();
free(sc->p);
free(sc);
return NULL;
32 changes: 12 additions & 20 deletions src/compiler/parser.y
Original file line number Diff line number Diff line change
@@ -398,9 +398,12 @@ primary_expr(N) ::= unary_misc(I) TOK_LPAREN expr(A) TOK_RPAREN. {
free(I);
}

primary_expr(N) ::= TOK_SQR(I) TOK_LPAREN expr(A) TOK_RPAREN. {
primary_expr(N) ::= TOK_SQR TOK_LPAREN expr(A) TOK_RPAREN. {
FOLD_UNARY(N, op_sqr, "sqr", A, a*a);
free(I);
}

primary_expr(N) ::= TOK_SQRT TOK_LPAREN expr(A) TOK_RPAREN. {
FOLD_UNARY(N, op_sqrt, "sqrt", A, sqrtf(a));
}


@@ -413,44 +416,33 @@ primary_expr(N) ::= binary_misc(I) TOK_LPAREN expr(A) TOK_COMMA expr(B)
free(I);
}

primary_expr(N) ::= TOK_ABOVE(I) TOK_LPAREN expr(A) TOK_COMMA expr(B)
TOK_RPAREN. {
primary_expr(N) ::= TOK_ABOVE TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_RPAREN. {
FOLD_BINARY(N, op_above, "above", A, B, a > b);
free(I);
}

primary_expr(N) ::= TOK_BELOW(I) TOK_LPAREN expr(A) TOK_COMMA expr(B)
TOK_RPAREN. {
primary_expr(N) ::= TOK_BELOW TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_RPAREN. {
FOLD_BINARY(N, op_below, "below", A, B, a < b);
free(I);
}

primary_expr(N) ::= TOK_EQUAL(I) TOK_LPAREN expr(A) TOK_COMMA expr(B)
TOK_RPAREN. {
primary_expr(N) ::= TOK_EQUAL TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_RPAREN. {
FOLD_BINARY(N, op_equal, "equal", A, B, a == b);
free(I);
}

primary_expr(N) ::= TOK_MAX(I) TOK_LPAREN expr(A) TOK_COMMA expr(B)
TOK_RPAREN. {
primary_expr(N) ::= TOK_MAX TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_RPAREN. {
FOLD_BINARY(N, op_max, "max", A, B, a > b ? a : b);
free(I);
}

primary_expr(N) ::= TOK_MIN(I) TOK_LPAREN expr(A) TOK_COMMA expr(B)
TOK_RPAREN. {
primary_expr(N) ::= TOK_MIN TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_RPAREN. {
FOLD_BINARY(N, op_min, "min", A, B, a < b ? a : b);
free(I);
}


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


primary_expr(N) ::= TOK_IF(I) TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_COMMA
primary_expr(N) ::= TOK_IF TOK_LPAREN expr(A) TOK_COMMA expr(B) TOK_COMMA
expr(C) TOK_RPAREN. {
N = conditional(A, B, C);
free(I);
}


@@ -502,7 +494,7 @@ unary_misc(O) ::= TOK_ISIN(I). { O = I; }
unary_misc(O) ::= TOK_QUAKE(I). { O = I; }
unary_misc(O) ::= TOK_SIN(I). { O = I; }
unary(O) ::= TOK_SQR(I). { O = I; }
unary_misc(O) ::= TOK_SQRT(I). { O = I; }
unary(O) ::= TOK_SQRT(I). { O = I; }

binary(O) ::= TOK_ABOVE(I). { O = I; }
binary(O) ::= TOK_BELOW(I). { O = I; }
3 changes: 2 additions & 1 deletion src/compiler/ptest/Makefile
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ CFLAGS_STANDALONE = -DSTANDALONE=\"standalone.h\"
CFLAGS = -Wall -g -I.. -I. $(CFLAGS_STANDALONE)
OBJS = ptest.o scanner.o parser.o parser_helper.o unique.o compiler.o \
libfpvm.a
LDLIBS = -lm

# ----- Verbosity control -----------------------------------------------------

@@ -32,7 +33,7 @@ fpvm:
$(GEN) ln -s $(FPVM_H) fpvm

ptest: $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS)

%.o: ../%.c
$(CC) $(CFLAGS) -c -o $@ $<
23 changes: 14 additions & 9 deletions src/compiler/ptest/ptest.c
Original file line number Diff line number Diff line change
@@ -19,10 +19,12 @@
#include "../parser_helper.h"
#include "../parser.h"
#include "../compiler.h"
#include "../unique.h"


static int quiet = 0;
static const char *fail = NULL;
static const char *buffer;


static void dump_ast(const struct ast_node *ast);
@@ -190,7 +192,6 @@ static const char *assign_image_name(struct parser_comm *comm,
static void report(const char *s)
{
fprintf(stderr, "%s\n", s);
exit(1);
}


@@ -237,6 +238,7 @@ static void parse_only(const char *pgm)
const char *error;

error = parse(pgm, TOK_START_ASSIGN, &comm);
unique_free();
if (!error)
return;
fflush(stdout);
@@ -306,6 +308,12 @@ static void compile(const char *pgm)
}


static void free_buffer(void)
{
free((void *) buffer);
}


static void usage(const char *name)
{
fprintf(stderr,
@@ -322,7 +330,6 @@ static void usage(const char *name)
int main(int argc, char **argv)
{
int c;
const char *buf;
int codegen = 0;
unsigned long repeat = 1;
char *end;
@@ -352,24 +359,22 @@ int main(int argc, char **argv)

switch (argc-optind) {
case 0:
buf = read_stdin();
buffer = read_stdin();
atexit(free_buffer);
break;
case 1:
buf = argv[optind];
buffer = argv[optind];
break;
default:
usage(*argv);
}

while (repeat--) {
if (codegen)
compile(buf);
compile(buffer);
else
parse_only(buf);
parse_only(buffer);
}

if (argc == optind)
free((void *) buf);

return 0;
}
91 changes: 67 additions & 24 deletions src/compiler/test/Common
Original file line number Diff line number Diff line change
@@ -14,39 +14,82 @@

ptest()
{
echo -n "$1: " 1>&2
shift
$VALGRIND ${PTST:-../ptest/ptest} "$@" >_out 2>&1 || {
echo FAILED "($SCRIPT)" 1>&2
cat _out
rm -f _out
exit 1
}
echo -n "$1: " 1>&2
shift
$VALGRIND ${PTST:-../ptest/ptest} "$@" >_out 2>&1 || {
echo FAILED "($SCRIPT)" 1>&2
cat _out
rm -f _out
exit 1
}
}


ptest_fail()
{
echo -n "$1: " 1>&2
shift
$VALGRIND ${PTST:-../ptest/ptest} "$@" >_out 2>&1 && {
echo FAILED "($SCRIPT)" 1>&2
cat _out
rm -f _out
exit 1
}
echo -n "$1: " 1>&2
shift
$VALGRIND ${PTST:-../ptest/ptest} "$@" >_out 2>&1 && {
echo FAILED "($SCRIPT)" 1>&2
cat _out
rm -f _out
exit 1
}
}


expect()
{
diff -u - "$@" _out >_diff || {
echo FAILED "($SCRIPT)" 1>&2
cat _diff 1>&2
diff -u - "$@" _out >_diff || {
echo FAILED "($SCRIPT)" 1>&2
cat _diff 1>&2
rm -f _out _diff
exit 1
}
echo PASSED 1>&2
rm -f _out _diff
exit 1
}
echo PASSED 1>&2
rm -f _out _diff
passed=`expr ${passed:-0} + 1`
passed=`expr ${passed:-0} + 1`
}


sedit()
{
sed "$1" _out >_tmp || exit 1
mv _tmp _out
}


equiv1()
{
echo -n "$1: " 1>&2
one=$2
shift 2
$VALGRIND ${PTST:-../ptest/ptest} "$@" <"$one" >_out 2>&1 || {
echo FAILED "($SCRIPT)" 1>&2
cat _out
rm -f _out
exit 1
}
}


equiv2()
{
two=$1
shift
$VALGRIND ${PTST:-../ptest/ptest} "$@" <"$two" >_two 2>&1 || {
echo FAILED "($SCRIPT)" 1>&2
cat _two
rm -f _out _two
exit 1
}
diff -u _out _two >_diff || {
echo FAILED "($SCRIPT)" 1>&2
cat _diff 1>&2
rm -f _out _two _diff
exit 1
}
echo PASSED 1>&2
rm -f _out _two _diff
passed=`expr ${passed:-0} + 1`
}
83 changes: 83 additions & 0 deletions src/compiler/test/Data/flame.fnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Krash - Digital Flame.fnp
*
* Formatted for improved syntax.
*/

fDecay = 0.9
fVideoEchoZoom = 1
fVideoEchoAlpha = 0
nVideoEchoOrientation = 0
nWaveMode = 6
bAdditiveWaves = 0
bWaveDots = 0
bMaximizeWaveColor = 0
bTexWrap = 0
fWaveAlpha = 1
fWaveScale = 0.3697
fWarpAnimSpeed = 53.523884
fWarpScale = 0.408391
zoom = 1
rot = 0
cx = 0.5
cy = 0.5
dx = 0
dy = 0
warp = 1
sx = 1
sy = 1
wave_r = 0.6999
wave_g = 0.6
wave_b = 0.8
wave_x = 0
wave_y = 0.5
ob_size = 0
ob_r = 0
ob_g = 0
ob_b = 0
ob_a = 0
ib_size = 0
ib_r = 0
ib_g = 0
ib_b = 0
ib_a = 0
nMotionVectorsX = 12
nMotionVectorsY = 9
mv_l = 0.9
mv_r = 1
mv_g = 1
mv_b = 1
mv_a = 0

per_frame:
q1 = (bass_att + mid_att + treb_att)/3;
q2 = time + 1000;

bass_thresh = (bass_att > bass_thresh)*2 +
(1-(bass_att > bass_thresh))*((bass_thresh-1.4)*0.95+1.4);
treb_thresh = (treb_att > treb_thresh)*2 +
(1-(treb_att > treb_thresh))*((treb_thresh-1.5)*0.85+1.2);

bass_on = bass_thresh > 1.9;
treb_on = treb_thresh > 1.9;
swap = bass_on - treb_on;

// bass_on | same | treb_on
red_aim = swap == 1 ? 1 : swap == 0 ? 0.9 : 0.7;
green_aim = swap == 1 ? 0.7 : swap == 0 ? 0.3 : 0.6;
blue_aim = swap == 1 ? 0 : swap == 0 ? 0.2 : 0.8;
// orange red white

red = red + (red_aim - red)*0.5;
green = green + (green_aim - green)*0.5;
blue = blue + (blue_aim - blue)*0.5;

wave_r = red;
wave_g = green;
wave_b = blue;

per_vertex:
dy = 0.1*(1-q1);
dy = (dy < 0.02)*dy - 0.02;
dy = dy + 0.01*(sin((x*q2*0.483) + (y*q2*1.238)) +
sin((x*q2*1.612) + (y*q2*0.648)));
Loading