1 |
|
2 |
|
3 | if !inited
|
4 | inited = true
|
5 | init()
|
6 |
|
7 |
|
8 | $.init = init
|
9 |
|
10 | parse_internal = (argu) ->
|
11 | if typeof argu == 'string'
|
12 | scan(argu)
|
13 | # now its in the stack
|
14 | else if typeof argu == 'number'
|
15 | if argu % 1 == 0
|
16 | push_integer(argu)
|
17 | else
|
18 | push_double(argu)
|
19 | else if argu instanceof U
|
20 | # hey look its a U
|
21 | push(argu)
|
22 | else
|
23 | console.warn('unknown argument type', argu)
|
24 | push(symbol(NIL))
|
25 |
|
26 | parse = (argu) ->
|
27 | try
|
28 | parse_internal(argu)
|
29 | data = pop()
|
30 | check_stack()
|
31 | catch error
|
32 | reset_after_error()
|
33 | throw error
|
34 | return data
|
35 |
|
36 | # exec handles the running ia JS of all the algebrite
|
37 | # functions. The function name is passed in "name" and
|
38 | # the corresponding function is pushed at the top of the stack
|
39 | exec = (name, argus...) ->
|
40 | fn = get_binding(usr_symbol(name))
|
41 | check_stack()
|
42 | push(fn)
|
43 |
|
44 | for argu in argus
|
45 | parse_internal(argu)
|
46 |
|
47 | list(1 + argus.length)
|
48 |
|
49 | p1 = pop()
|
50 | push(p1)
|
51 |
|
52 | try
|
53 | fixed_top_level_eval()
|
54 | result = pop()
|
55 | check_stack()
|
56 | catch error
|
57 | reset_after_error()
|
58 | throw error
|
59 |
|
60 | return result
|
61 |
|
62 |
|
63 | fixed_top_level_eval = ->
|
64 | save()
|
65 |
|
66 | trigmode = 0
|
67 |
|
68 | p1 = symbol(AUTOEXPAND)
|
69 | if (iszero(get_binding(p1)))
|
70 | expanding = 0
|
71 | else
|
72 | expanding = 1
|
73 |
|
74 | p1 = pop()
|
75 | push(p1)
|
76 | Eval()
|
77 | p2 = pop()
|
78 |
|
79 | if (p2 == symbol(NIL))
|
80 | push(p2)
|
81 | restore()
|
82 | return
|
83 |
|
84 | if (!iszero(get_binding(symbol(BAKE))))
|
85 | push(p2)
|
86 | bake()
|
87 | p2 = pop()
|
88 |
|
89 | push(p2)
|
90 | restore()
|
91 |
|
92 |
|
93 | $.exec = exec
|
94 | $.parse = parse
|
95 |
|
96 | do ->
|
97 | builtin_fns = ["abs", "add", "adj", "and", "approxratio", "arccos", "arccosh", "arcsin", "arcsinh", "arctan", "arctanh", "arg", "atomize", "besselj", "bessely", "binding", "binomial", "ceiling", "check", "choose", "circexp", "clear", "clearall", "clearpatterns", "clock", "coeff", "cofactor", "condense", "conj", "contract", "cos", "cosh", "decomp", "defint", "deg", "denominator", "det", "derivative", "dim", "dirac", "divisors", "do", "dot", "draw", "dsolve", "eigen", "eigenval", "eigenvec", "erf", "erfc", "eval", "exp", "expand", "expcos", "expsin", "factor", "factorial", "factorpoly", "filter", "float", "floor", "for", "Gamma", "gcd", "hermite", "hilbert", "imag", "component", "inner", "integral", "inv", "invg", "isinteger", "isprime", "laguerre", "lcm", "leading", "legendre", "log", "mod", "multiply", "not", "nroots", "number", "numerator", "operator", "or", "outer", "pattern", "patternsinfo", "polar", "power", "prime", "print", "print2dascii", "printfull", "printlatex", "printlist", "printplain", "product", "quote", "quotient", "rank", "rationalize", "real", "rect", "roots", "round", "equals", "shape", "sgn", "silentpattern", "simplify", "sin", "sinh", "sqrt", "stop", "subst", "sum", "symbolsinfo", "tan", "tanh", "taylor", "test", "testeq", "testge", "testgt", "testle", "testlt", "transpose", "unit", "zero"]
|
98 |
|
99 | for fn in builtin_fns
|
100 | $[fn] = exec.bind(this, fn)
|