Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / rewrite.cpp
blob65cef578deef0d42c527afec8dd78dcc7cd40192
1 // Rewrite by expanding all symbols
3 #include "stdafx.h"
4 #include "defs.h"
6 void
7 rewrite(void)
9 int h;
10 save();
12 p1 = pop();
14 if (istensor(p1)) {
15 rewrite_tensor();
16 restore();
17 return;
20 if (iscons(p1)) {
21 h = tos;
22 push(car(p1)); // Do not rewrite function name
23 p1 = cdr(p1);
24 while (iscons(p1)) {
25 push(car(p1));
26 rewrite();
27 p1 = cdr(p1);
29 list(tos - h);
30 restore();
31 return;
34 // If not a symbol then done
36 if (!issymbol(p1)) {
37 push(p1);
38 restore();
39 return;
42 // Get the symbol's binding, try again
44 p2 = get_binding(p1);
45 push(p2);
46 if (p1 != p2)
47 rewrite();
49 restore();
52 void
53 rewrite_tensor(void)
55 int i;
56 push(p1);
57 copy_tensor();
58 p1 = pop();
59 for (i = 0; i < p1->u.tensor->nelem; i++) {
60 push(p1->u.tensor->elem[i]);
61 rewrite();
62 p1->u.tensor->elem[i] = pop();
64 push(p1);