Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / init.cpp
blobcd49d8785aef760240161dbef534d4351dbf880d
1 #include "stdafx.h"
2 #include "defs.h"
4 void
5 init(void)
7 int i;
8 static int flag;
10 tos = 0;
11 esc_flag = 0;
12 draw_flag = 0;
13 frame = stack + TOS;
15 p0 = symbol(NIL);
16 p1 = symbol(NIL);
17 p2 = symbol(NIL);
18 p3 = symbol(NIL);
19 p4 = symbol(NIL);
20 p5 = symbol(NIL);
21 p6 = symbol(NIL);
22 p7 = symbol(NIL);
23 p8 = symbol(NIL);
24 p9 = symbol(NIL);
26 if (flag)
27 return; // already initted
29 flag = 1;
31 for (i = 0; i < NSYM; i++) {
32 symtab[i].k = SYM;
33 binding[i] = symtab + i;
34 arglist[i] = symbol(NIL);
37 std_symbol("abs", ABS);
38 std_symbol("add", ADD);
39 std_symbol("adj", ADJ);
40 std_symbol("and", AND);
41 std_symbol("arccos", ARCCOS);
42 std_symbol("arccosh", ARCCOSH);
43 std_symbol("arcsin", ARCSIN);
44 std_symbol("arcsinh", ARCSINH);
45 std_symbol("arctan", ARCTAN);
46 std_symbol("arctanh", ARCTANH);
47 std_symbol("arg", ARG);
48 std_symbol("atomize", ATOMIZE);
49 std_symbol("besselj", BESSELJ);
50 std_symbol("bessely", BESSELY);
51 std_symbol("binding", BINDING);
52 std_symbol("binomial", BINOMIAL);
53 std_symbol("ceiling", CEILING);
54 std_symbol("check", CHECK);
55 std_symbol("choose", CHOOSE);
56 std_symbol("circexp", CIRCEXP);
57 std_symbol("clear", CLEAR);
58 std_symbol("clock", CLOCK);
59 std_symbol("coeff", COEFF);
60 std_symbol("cofactor", COFACTOR);
61 std_symbol("condense", CONDENSE);
62 std_symbol("conj", CONJ);
63 std_symbol("contract", CONTRACT);
64 std_symbol("cos", COS);
65 std_symbol("cosh", COSH);
66 std_symbol("decomp", DECOMP);
67 std_symbol("defint", DEFINT);
68 std_symbol("deg", DEGREE);
69 std_symbol("denominator", DENOMINATOR);
70 std_symbol("det", DET);
71 std_symbol("derivative", DERIVATIVE);
72 std_symbol("dim", DIM);
73 std_symbol("dirac", DIRAC);
74 std_symbol("display", DISPLAY);
75 std_symbol("divisors", DIVISORS);
76 std_symbol("do", DO);
77 std_symbol("dot", DOT);
78 std_symbol("draw", DRAW);
79 std_symbol("dsolve", DSOLVE);
80 std_symbol("erf", ERF);
81 std_symbol("erfc", ERFC);
82 std_symbol("eigen", EIGEN);
83 std_symbol("eigenval", EIGENVAL);
84 std_symbol("eigenvec", EIGENVEC);
85 std_symbol("eval", EVAL);
86 std_symbol("exp", EXP);
87 std_symbol("expand", EXPAND);
88 std_symbol("expcos", EXPCOS);
89 std_symbol("expsin", EXPSIN);
90 std_symbol("factor", FACTOR);
91 std_symbol("factorial", FACTORIAL);
92 std_symbol("factorpoly", FACTORPOLY);
93 std_symbol("filter", FILTER);
94 std_symbol("float", FLOATF);
95 std_symbol("floor", FLOOR);
96 std_symbol("for", FOR);
97 std_symbol("Gamma", GAMMA);
98 std_symbol("gcd", GCD);
99 std_symbol("hermite", HERMITE);
100 std_symbol("hilbert", HILBERT);
101 std_symbol("imag", IMAG);
102 std_symbol("component", INDEX);
103 std_symbol("inner", INNER);
104 std_symbol("integral", INTEGRAL);
105 std_symbol("inv", INV);
106 std_symbol("invg", INVG);
107 std_symbol("isinteger", ISINTEGER);
108 std_symbol("isprime", ISPRIME);
109 std_symbol("laguerre", LAGUERRE);
110 // std_symbol("laplace", LAPLACE);
111 std_symbol("lcm", LCM);
112 std_symbol("leading", LEADING);
113 std_symbol("legendre", LEGENDRE);
114 std_symbol("log", LOG);
115 std_symbol("mag", MAG);
116 std_symbol("mod", MOD);
117 std_symbol("multiply", MULTIPLY);
118 std_symbol("not", NOT);
119 std_symbol("nroots", NROOTS);
120 std_symbol("number", NUMBER);
121 std_symbol("numerator", NUMERATOR);
122 std_symbol("operator", OPERATOR);
123 std_symbol("or", OR);
124 std_symbol("outer", OUTER);
125 std_symbol("polar", POLAR);
126 std_symbol("power", POWER);
127 std_symbol("prime", PRIME);
128 std_symbol("print", PRINT);
129 std_symbol("product", PRODUCT);
130 std_symbol("quote", QUOTE);
131 std_symbol("quotient", QUOTIENT);
132 // std_symbol("random", RANDOM);
133 std_symbol("rank", RANK);
134 std_symbol("rationalize", RATIONALIZE);
135 std_symbol("real", REAL);
136 std_symbol("rect", YYRECT);
137 std_symbol("roots", ROOTS);
138 std_symbol("equals", SETQ);
139 std_symbol("sgn", SGN);
140 std_symbol("simplify", SIMPLIFY);
141 std_symbol("sin", SIN);
142 std_symbol("sinh", SINH);
143 std_symbol("sqrt", SQRT);
144 std_symbol("stop", STOP);
145 std_symbol("subst", SUBST);
146 std_symbol("sum", SUM);
147 std_symbol("tan", TAN);
148 std_symbol("tanh", TANH);
149 std_symbol("taylor", TAYLOR);
150 std_symbol("test", TEST);
151 std_symbol("testeq", TESTEQ);
152 std_symbol("testge", TESTGE);
153 std_symbol("testgt", TESTGT);
154 std_symbol("testle", TESTLE);
155 std_symbol("testlt", TESTLT);
156 std_symbol("transpose", TRANSPOSE);
157 std_symbol("unit", UNIT);
158 std_symbol("zero", ZERO);
160 std_symbol("nil", NIL);
162 // each symbol needs a unique name because equal() compares printnames
164 std_symbol("autoexpand", AUTOEXPAND);
165 std_symbol("bake", BAKE);
166 std_symbol("last", LAST);
167 std_symbol("trace", TRACE);
168 std_symbol("tty", TTY);
170 std_symbol("~", YYE); // tilde so sort puts it after other symbols
172 std_symbol("$DRAWX", DRAWX); // special purpose internal symbols
173 std_symbol("$METAA", METAA);
174 std_symbol("$METAB", METAB);
175 std_symbol("$METAX", METAX);
176 std_symbol("$SECRETX", SECRETX);
178 std_symbol("pi", PI);
179 std_symbol("a", SYMBOL_A);
180 std_symbol("b", SYMBOL_B);
181 std_symbol("c", SYMBOL_C);
182 std_symbol("d", SYMBOL_D);
183 std_symbol("i", SYMBOL_I);
184 std_symbol("j", SYMBOL_J);
185 std_symbol("n", SYMBOL_N);
186 std_symbol("r", SYMBOL_R);
187 std_symbol("s", SYMBOL_S);
188 std_symbol("t", SYMBOL_T);
189 std_symbol("x", SYMBOL_X);
190 std_symbol("y", SYMBOL_Y);
191 std_symbol("z", SYMBOL_Z);
193 std_symbol("$C1", C1);
194 std_symbol("$C2", C2);
195 std_symbol("$C3", C3);
196 std_symbol("$C4", C4);
197 std_symbol("$C5", C5);
198 std_symbol("$C6", C6);
200 push_integer(0);
201 zero = pop(); // must be untagged in gc
203 push_integer(1);
204 one = pop(); // must be untagged in gc
206 push_symbol(POWER);
207 push_integer(-1);
208 push_rational(1, 2);
209 list(3);
210 imaginaryunit = pop(); // must be untagged in gc
212 defn();
215 static char *defn_str[] = {
216 "e=exp(1)",
217 "i=sqrt(-1)",
218 "autoexpand=1",
219 "trange=(-pi,pi)",
220 "xrange=(-10,10)",
221 "yrange=(-10,10)",
222 "last=0",
223 "trace=0",
224 "tty=0",
225 "cross(u,v)=(u[2]*v[3]-u[3]*v[2],u[3]*v[1]-u[1]*v[3],u[1]*v[2]-u[2]*v[1])",
226 "curl(v)=(d(v[3],y)-d(v[2],z),d(v[1],z)-d(v[3],x),d(v[2],x)-d(v[1],y))",
227 "div(v)=d(v[1],x)+d(v[2],y)+d(v[3],z)",
228 "ln(x)=log(x)",
231 void
232 defn(void)
234 int i, n;
235 n = sizeof defn_str / sizeof (char *);
236 for (i = 0; i < n; i++) {
237 scan(defn_str[i]);
238 eval();
239 pop();