Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: m-labs/flickernoise
base: 35aef26
...
head fork: m-labs/flickernoise
compare: b86463c
  • 7 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 31, 2011
Werner Almesberger wpwrak test/Common: change indentation from 4 spaces to 1 tab
This is just cosmetic. No change in function.
7c8a1d2
Commits on Jan 02, 2012
Werner Almesberger wpwrak test/Data/flame.fnp: reformatted "Krash - Digital Flame.fnp" with new…
… syntax

Also added infrastructure for comparing two patches to the test
framework.
aceb5b5
Werner Almesberger wpwrak compiler: added constant folding of sqrt()
This also means that ptest now requires libm.
709f98b
Commits on Jan 03, 2012
Werner Almesberger wpwrak 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".
55ca1d1
Werner Almesberger wpwrak compiler.c: also free identifiers when parsing failed 23d34b7
Werner Almesberger wpwrak ptest.c: plugged various memory leaks in test framework 61ab85c
Werner Almesberger wpwrak 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.
b86463c
6 src/compiler/Makefile
View
@@ -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  src/compiler/compiler.c
View
@@ -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 src/compiler/parser.y
View
@@ -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  src/compiler/ptest/Makefile
View
@@ -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 src/compiler/ptest/ptest.c
View
@@ -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,10 +359,11 @@ 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);
@@ -363,13 +371,10 @@ int main(int argc, char **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 src/compiler/test/Common
View
@@ -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 src/compiler/test/Data/flame.fnp
View
@@ -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)));
9 src/compiler/test/fold
View
@@ -143,4 +143,13 @@ expect <<EOF
x = 9
EOF
+#------------------------------------------------------------------------------
+
+ptest "constant folding: sqrt" << EOF
+x = sqrt(2.25)
+EOF
+expect <<EOF
+x = 1.5
+EOF
+
###############################################################################
13 src/compiler/test/rewrite
View
@@ -0,0 +1,13 @@
+#!/bin/sh
+. ./Common
+
+###############################################################################
+
+PATCHDIR=../../../patches
+
+equiv1 "rewrite: prettier Krash - Digital Flame" \
+ "$PATCHDIR/Krash - Digital Flame.fnp"
+sedit s/swapcolour/swap/g
+equiv2 Data/flame.fnp
+
+###############################################################################

No commit comments for this range

Something went wrong with that request. Please try again.