They only differ in not having the per_frame= and per_vertex= prefixes.
The files are then converted to a header containing #defines of strings
with the file content inside. The compiler simply calls fpvm_chunk to
compile the prologue and epilogue.
---
 src/Makefile                |    7 ++++-
 src/compiler/compiler.c     |   61 +++++--------------------------------------
 src/compiler/file2h         |    9 ++++++
 src/compiler/finish-pfv.fnp |   19 +++++++++++++
 src/compiler/finish-pvv.fnp |   57 ++++++++++++++++++++++++++++++++++++++++
 src/compiler/fpvm.c         |    4 ++-
 src/compiler/init-pvv.fnp   |   22 +++++++++++++++
 7 files changed, 123 insertions(+), 56 deletions(-)
 create mode 100755 src/compiler/file2h
 create mode 100644 src/compiler/finish-pfv.fnp
 create mode 100644 src/compiler/finish-pvv.fnp
 create mode 100644 src/compiler/init-pvv.fnp

diff --git a/src/Makefile b/src/Makefile
index 410d3b9..151b250 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -85,11 +85,16 @@ bandfilters.h: bandfilters.sce
 %.h %.inc: %.ids
        cd compiler && ./idgen `basename $<`
 
+compiler/infra-fnp.h: \
+         compiler/finish-pfv.fnp compiler/init-pvv.fnp compiler/finish-pvv.fnp
+       compiler/file2h $^ >$@ || { rm -f $@; }
+
 compiler/parser.h: compiler/parser.c
 obj/compiler/scanner.o: compiler/parser.h
 obj/compiler/parser_helper.o: compiler/parser.h
 obj/compiler/fpvm.o: compiler/parser.h
 obj/compiler/unique.o: compiler/fnp.inc
+obj/compiler/compiler.o: compiler/infra-fnp.h
 
 # boot images for Milkymist One
 $(BINDIR)/flickernoise.bin: $(BINDIR)/flickernoise
@@ -119,6 +124,6 @@ clean:
        rm -f $(POBJS)
        rm -f compiler/scanner.c
        rm -f compiler/parser.c compiler/parser.h compiler/parser.out
-       rm -f compiler/fnp.h compiler/fnp.inc
+       rm -f compiler/fnp.h compiler/fnp.inc compiler/infra-fnp.h
 
 .PHONY: clean load flash
diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c
index 8861ba1..b907c56 100644
--- a/src/compiler/compiler.c
+++ b/src/compiler/compiler.c
@@ -31,6 +31,8 @@
 #include "unique.h"
 #include "compiler.h"
 
+#include "infra-fnp.h"
+
 struct compiler_sc {
        struct patch *p;
 
@@ -292,9 +294,8 @@ static bool init_pfv(struct compiler_sc *sc)
 static bool finalize_pfv(struct compiler_sc *sc)
 {
        /* assign dummy values for output */
-       if(!fpvm_assign(&sc->pfv_fragment, "_Xo", "_Xi")) goto fail_fpvm;
-       if(!fpvm_assign(&sc->pfv_fragment, "_Yo", "_Yi")) goto fail_fpvm;
-       if(!fpvm_finalize(&sc->pfv_fragment)) goto fail_fpvm;
+       if(!fpvm_chunk(&sc->pfv_fragment, FINISH_PFV_FNP))
+               goto fail_fpvm;
        #ifdef COMP_DEBUG
        printf("per-frame FPVM fragment:\n");
        fpvm_dump(&sc->pfv_fragment);
@@ -443,12 +444,8 @@ static bool init_pvv(struct compiler_sc *sc)
        fpvm_set_bind_callback(&sc->pvv_fragment, pvv_bind_callback, sc);
 
        fpvm_set_bind_mode(&sc->pvv_fragment, FPVM_BIND_SOURCE);
-       if(!fpvm_chunk(&sc->pvv_fragment,
-           "x = i2f(_Xi)*_hmeshsize\n"
-           "y = i2f(_Yi)*_vmeshsize\n"
-           "rad = sqrt(sqr(x-0.5)+sqr(y-0.5))"))
+       if(!fpvm_chunk(&sc->pvv_fragment, INIT_PVV_FNP))
                goto fail_assign;
-       /* TODO: generate ang */
        fpvm_set_bind_mode(&sc->pvv_fragment, FPVM_BIND_ALL);
 
        return true;
@@ -463,52 +460,8 @@ static int finalize_pvv(struct compiler_sc *sc)
 {
        fpvm_set_bind_mode(&sc->pvv_fragment, FPVM_BIND_SOURCE);
 
-       #define A(dest, val) \
-           if(!fpvm_assign(&sc->pvv_fragment, dest, val)) goto fail_assign
-
-       /* Zoom */
-       A("_invzoom", "1/zoom");
-       A("_xz", "_invzoom*(x-0.5)+0.5");
-       A("_yz", "_invzoom*(y-0.5)+0.5");
-
-       /* Scale */
-       A("_xs", "(_xz-cx)/sx+cx");
-       A("_ys", "(_yz-cy)/sy+cy");
-
-       /* Warp */
-       A("_warptime", "time*fWarpAnimSpeed");
-       A("_invwarpscale", "1/fWarpScale");
-       A("_f0", "11.68 + 4.0*cos(_warptime*1.413 + 10)");
-       A("_f1", "8.77 + 3.0*cos(_warptime*1.113 + 7)");
-       A("_f2", "10.54 + 3.0*cos(_warptime*1.233 + 3)");
-       A("_f3", "11.49 + 4.0*cos(_warptime*0.933 + 5)");
-       A("_ox2", "2*x-1");
-       A("_oy2", "2*y-1");
-       A("_xw", "_xs+warp*0.0035*("
-               "sin(_warptime*0.333+_invwarpscale*(_ox2*_f0-_oy2*_f3))"
-               "+cos(_warptime*0.753-_invwarpscale*(_ox2*_f1-_oy2*_f2)))");
-       A("_yw", "_ys+warp*0.0035*("
-               "cos(_warptime*0.375-_invwarpscale*(_ox2*_f2+_oy2*_f1))"
-               "+sin(_warptime*0.825+_invwarpscale*(_ox2*_f0+_oy2*_f3)))");
-
-       /* Rotate */
-       A("_cosr", "cos(rot)");
-       A("_sinr", "sin(0-rot)");
-       A("_u", "_xw-cx");
-       A("_v", "_yw-cy");
-       A("_xr", "_u*_cosr-_v*_sinr+cx");
-       A("_yr", "_u*_sinr+_v*_cosr+cy");
-
-       /* Translate */
-       A("_xd", "_xr-dx");
-       A("_yd", "_yr-dy");
-
-       /* Convert to framebuffer coordinates */
-       A("_Xo", "f2i(_xd*_texsize)");
-       A("_Yo", "f2i(_yd*_texsize)");
-
-       #undef A
-
+       if(!fpvm_chunk(&sc->pvv_fragment, FINISH_PVV_FNP))
+               goto fail_assign;
        if(!fpvm_finalize(&sc->pvv_fragment)) goto fail_finalize;
        #ifdef COMP_DEBUG
        printf("per-vertex FPVM fragment:\n");
diff --git a/src/compiler/file2h b/src/compiler/file2h
new file mode 100755
index 0000000..2c627d9
--- /dev/null
+++ b/src/compiler/file2h
@@ -0,0 +1,9 @@
+#!/bin/sh -e
+while [ "$1" ]; do
+       echo -n "#define "
+       basename $1 | sed 's/[^a-zA-Z0-9]/_/g' | tr a-z A-Z | tr -d '\n'
+       echo ' \'
+       sed 's/\\/\\\\/g;s/"/\\"/g;s/.*/    "&\\n" \\/' <$1
+       echo
+       shift
+done
diff --git a/src/compiler/finish-pfv.fnp b/src/compiler/finish-pfv.fnp
new file mode 100644
index 0000000..fecacfe
--- /dev/null
+++ b/src/compiler/finish-pfv.fnp
@@ -0,0 +1,19 @@
+/*
+ * Per-Frame Variables Epilogue
+ * Copyright (C) 2010, 2011 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+       _Xo = _Xi
+       _Yo = _Yi
diff --git a/src/compiler/finish-pvv.fnp b/src/compiler/finish-pvv.fnp
new file mode 100644
index 0000000..723802f
--- /dev/null
+++ b/src/compiler/finish-pvv.fnp
@@ -0,0 +1,57 @@
+/*
+ * Per-Vertex Variables Epilogue
+ * Copyright (C) 2010, 2011 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+       /* Zoom */
+       _invzoom = 1/zoom
+       _xz = _invzoom*(x-0.5)+0.5
+       _yz = _invzoom*(y-0.5)+0.5
+
+       /* Scale */
+       _xs = (_xz-cx)/sx+cx
+       _ys = (_yz-cy)/sy+cy
+
+       /* Warp */
+       _warptime = time*fWarpAnimSpeed
+       _invwarpscale = 1/fWarpScale
+       _f0 = 11.68 + 4.0*cos(_warptime*1.413 + 10)
+       _f1 = 8.77 + 3.0*cos(_warptime*1.113 + 7)
+       _f2 = 10.54 + 3.0*cos(_warptime*1.233 + 3)
+       _f3 = 11.49 + 4.0*cos(_warptime*0.933 + 5)
+       _ox2 = 2*x-1
+       _oy2 = 2*y-1
+       _xw = _xs+warp*0.0035*(
+               sin(_warptime*0.333+_invwarpscale*(_ox2*_f0-_oy2*_f3))
+               +cos(_warptime*0.753-_invwarpscale*(_ox2*_f1-_oy2*_f2)))
+       _yw = _ys+warp*0.0035*(
+               cos(_warptime*0.375-_invwarpscale*(_ox2*_f2+_oy2*_f1))
+               +sin(_warptime*0.825+_invwarpscale*(_ox2*_f0+_oy2*_f3)))
+
+               /* Rotate */
+       _cosr = cos(rot)
+       _sinr = sin(0-rot)
+       _u = _xw-cx
+       _v = _yw-cy
+       _xr = _u*_cosr-_v*_sinr+cx
+       _yr = _u*_sinr+_v*_cosr+cy
+
+       /* Translate */
+       _xd = _xr-dx
+       _yd = _yr-dy
+
+       /* Convert to framebuffer coordinates */
+       _Xo = f2i(_xd*_texsize)
+       _Yo = f2i(_yd*_texsize)
diff --git a/src/compiler/fpvm.c b/src/compiler/fpvm.c
index 5acd4ba..3bdd701 100644
--- a/src/compiler/fpvm.c
+++ b/src/compiler/fpvm.c
@@ -72,7 +72,9 @@ int fpvm_chunk(struct fpvm_fragment *fragment, const char 
*chunk)
        const char *error;
 
        error = fpvm_parse(chunk, TOK_START_ASSIGN, &comm);
-       if (error)
+       if(error) {
+               snprintf(fragment->last_error, FPVM_MAXERRLEN, "%s", error);
                free((void *) error);
+       }
        return !error;
 }
diff --git a/src/compiler/init-pvv.fnp b/src/compiler/init-pvv.fnp
new file mode 100644
index 0000000..893f86b
--- /dev/null
+++ b/src/compiler/init-pvv.fnp
@@ -0,0 +1,22 @@
+/*
+ * Per-Vector Variables Prologue
+ * Copyright (C) 2010, 2011 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+       x = i2f(_Xi)*_hmeshsize
+       y = i2f(_Yi)*_vmeshsize
+       rad = sqrt(sqr(x-0.5)+sqr(y-0.5))
+
+        /* TODO: generate ang */
-- 
1.7.1

_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode

Reply via email to