aboutsummaryrefslogtreecommitdiff
path: root/src/maple
diff options
context:
space:
mode:
authorjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-04-13 17:18:11 +0000
committerjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-04-13 17:18:11 +0000
commit182cc532cf7c15019b4254ff747ff3849b542cfc (patch)
treeb843c65a831a5f9fd288aba117fae18dc10a20d4 /src/maple
parent39fe29f9a5d91e149a794b22ba4d61cf07836fa8 (diff)
change fix_rational() to leave -1 factors in expressions, alone
git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@513 f88db872-0e4f-0410-b76b-b9085cfa78c5
Diffstat (limited to 'src/maple')
-rw-r--r--src/maple/codegen2.maple33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/maple/codegen2.maple b/src/maple/codegen2.maple
index a3a64a2..0f1f761 100644
--- a/src/maple/codegen2.maple
+++ b/src/maple/codegen2.maple
@@ -60,7 +60,7 @@ codegen2 :=
proc(expr_in::{algebraic, list(algebraic)},
lhs_name::{name, list(name)},
output_file_name::string)
-local expr;
+local expr, temps, expr_cost;
printf("codegen(%a)\n", lhs_name);
@@ -87,13 +87,21 @@ printf(" convert R_dd[2,3] --> R_dd_23 etc\n");
expr := unindex_names(expr);
saveit(10, procname, "unindex", expr);
+expr_cost := codegen[cost](expr);
+
printf(" convert p/q --> RATIONAL(p/q)\n");
expr := fix_rationals(expr);
saveit(10, procname, "fix_rationals", expr);
-printf(" generating C declarations for temporary variables\n");
+#
+# write the C code
+#
+printf(" writing C code\n");
+ftruncate(output_file_name);
+fprintf(output_file_name, "/*\n");
+fprintf(output_file_name, " * cost = %a\n", expr_cost);
+fprintf(output_file_name, " */\n");
print_name_list_dcl(temps, "fp", output_file_name);
-printf(" generating C code\n");
codegen[C](expr, filename=output_file_name);
NULL;
@@ -466,6 +474,7 @@ proc(expr::{algebraic, name = algebraic, list({algebraic, name = algebraic})})
local nn, k,
base, power, fbase, fpower,
fn, fn_args_list, fixed_fn_args_list,
+ expr_sign, temp,
num, den, mult;
# recurse over lists
@@ -500,7 +509,17 @@ fi;
# recurse over products
# ... leaving -1 factors intact
if (type(expr, `*`))
- then return product('fix_rationals(op(k,expr))', 'k'=1..nn);
+ then
+ if (member(-1, [op(expr)]))
+ then
+ expr_sign := -1;
+ temp := -expr;
+ else
+ expr_sign := 1;
+ temp := expr;
+ fi;
+ return expr_sign * product('fix_rationals(op(k,temp))',
+ 'k'=1..nops(temp));
fi;
# recurse over powers
@@ -519,7 +538,6 @@ if (type(expr, `^`))
fi;
# fix integers and fractions
-# ... leaving explicit -1 intact
if (type(expr, integer))
then return 'RATIONAL'(expr, 1);
fi;
@@ -561,8 +579,7 @@ end;
# Argument:
# name_list = A list of the names.
# name_type = The C type of the names, eg. "double".
-# file_name = The file name to write the declaration to. This is
-# truncated before writing.
+# file_name = The file name to write (append) the declaration to.
#
print_name_list_dcl :=
proc( name_list::list({name,string}),
@@ -570,8 +587,6 @@ proc( name_list::list({name,string}),
file_name::string )
local blanks, separator_string;
-ftruncate(file_name);
-
# a sequence of blanks with the same length as name_type
seq(" ", i=1..length(name_type));