diff options
-rw-r--r-- | src/Makefile.lsq_funcs | 4 | ||||
-rw-r--r-- | src/expr2c.mac | 14 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/Makefile.lsq_funcs b/src/Makefile.lsq_funcs index c33fe5f..46bab6e 100644 --- a/src/Makefile.lsq_funcs +++ b/src/Makefile.lsq_funcs @@ -1,7 +1,7 @@ all: ProjectionRectilinear_funcs.cxx ProjectionCylindrical_funcs.cxx ProjectionRectilinear_funcs.cxx: lsq_rectilinear.mac expr2c.mac - maxima -b lsq_rectilinear.mac | grep "^double" | sed s/%/_/g > ProjectionRectilinear_funcs.cxx + maxima -b lsq_rectilinear.mac | grep "^double" > ProjectionRectilinear_funcs.cxx ProjectionCylindrical_funcs.cxx: lsq_cylindrical.mac expr2c.mac - maxima -b lsq_cylindrical.mac | grep "^double" | sed s/%/_/g > ProjectionCylindrical_funcs.cxx + maxima -b lsq_cylindrical.mac | grep "^double" > ProjectionCylindrical_funcs.cxx diff --git a/src/expr2c.mac b/src/expr2c.mac index 2a33090..b1fe8d1 100644 --- a/src/expr2c.mac +++ b/src/expr2c.mac @@ -1,17 +1,21 @@ +load("stringproc")$ + +varsubst(v) := ssubst("_", "%", string(v))$ + printdecl(vars) := ( - sprint("double", first(vars)), - for v in rest(vars) do sprint(",", v), + sprint("double", varsubst(first(vars))), + for v in rest(vars) do sprint(",", varsubst(v)), sprint(";"))$ -printdef(expr) := sprint(first(expr), "=", second(expr), ";")$ +printdef(expr) := sprint(varsubst(first(expr)), "=", varsubst(second(expr)), ";")$ block2c(expr) := if ?equal(op(expr), block) then ( printdecl(first(expr)), for d in reverse(rest(reverse(rest(expr)))) do printdef(d), - sprint("return", string(last(expr)), ";")) + sprint("return", varsubst(last(expr)), ";")) else - sprint("return", string(expr), ";")$ + sprint("return", varsubst(expr), ";")$ expr2c(funcname, argstr, expr) := ( sprint("double", funcname, "(", argstr, ") {"), |