2004-03-03 21:24:06 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
2007-08-04 01:27:52 +02:00
|
|
|
jmp_buf stop_return, draw_stop_return;
|
2004-03-03 21:24:06 +01:00
|
|
|
|
|
|
|
void
|
2007-08-04 01:27:52 +02:00
|
|
|
stop(char *s)
|
2004-03-03 21:24:06 +01:00
|
|
|
{
|
2007-08-04 01:27:52 +02:00
|
|
|
if (draw_flag == 2)
|
|
|
|
longjmp(draw_stop_return, 1);
|
|
|
|
else {
|
|
|
|
printstr("Stop: ");
|
|
|
|
printstr(s);
|
|
|
|
printstr("\n");
|
|
|
|
longjmp(stop_return, 1);
|
|
|
|
}
|
2004-03-03 21:24:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
run(char *s)
|
|
|
|
{
|
2007-07-21 21:53:56 +02:00
|
|
|
int i, n;
|
2004-03-03 21:24:06 +01:00
|
|
|
|
2007-08-04 02:36:46 +02:00
|
|
|
if (strncmp(s, "selftest", 8) == 0) {
|
|
|
|
selftest();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-04 01:27:52 +02:00
|
|
|
if (setjmp(stop_return))
|
2004-03-03 21:24:06 +01:00
|
|
|
return;
|
|
|
|
|
2004-08-28 00:09:03 +02:00
|
|
|
init();
|
2004-03-03 21:24:06 +01:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
|
|
|
n = scan(s);
|
|
|
|
|
2007-08-04 02:51:53 +02:00
|
|
|
p1 = pop();
|
|
|
|
check_stack();
|
|
|
|
|
2004-03-03 21:24:06 +01:00
|
|
|
if (n == 0)
|
|
|
|
break;
|
|
|
|
|
2007-07-21 21:53:56 +02:00
|
|
|
// if debug mode then print the source text
|
|
|
|
|
2007-07-21 22:30:51 +02:00
|
|
|
if (equaln(get_binding(symbol(TRACE)), 1)) {
|
2007-07-21 21:53:56 +02:00
|
|
|
for (i = 0; i < n; i++)
|
2007-11-22 16:05:28 +01:00
|
|
|
if (s[i] != '\r')
|
|
|
|
printchar(s[i]);
|
2007-07-21 21:53:56 +02:00
|
|
|
if (s[n - 1] != '\n') // n is not zero, see above
|
|
|
|
printchar('\n');
|
|
|
|
}
|
|
|
|
|
2004-03-03 21:24:06 +01:00
|
|
|
s += n;
|
|
|
|
|
2007-05-02 07:18:20 +02:00
|
|
|
push(p1);
|
2006-09-20 18:46:38 +02:00
|
|
|
top_level_eval();
|
2004-08-28 00:09:03 +02:00
|
|
|
|
2004-03-03 21:24:06 +01:00
|
|
|
p2 = pop();
|
2004-08-28 00:09:03 +02:00
|
|
|
check_stack();
|
2004-03-03 21:24:06 +01:00
|
|
|
|
2007-05-02 21:54:17 +02:00
|
|
|
if (p2 == symbol(NIL))
|
|
|
|
continue;
|
|
|
|
|
2004-03-03 21:24:06 +01:00
|
|
|
// print string w/o quotes
|
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
if (isstr(p2)) {
|
2004-03-03 21:24:06 +01:00
|
|
|
printstr(p2->u.str);
|
|
|
|
printstr("\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-07-21 21:53:56 +02:00
|
|
|
if (equaln(get_binding(symbol(TTY)), 1) || test_flag) // tty mode?
|
2004-03-03 21:24:06 +01:00
|
|
|
printline(p2);
|
|
|
|
else {
|
2004-06-12 01:27:33 +02:00
|
|
|
#ifdef LINUX
|
|
|
|
display(p2);
|
|
|
|
#else
|
2007-06-03 17:43:00 +02:00
|
|
|
push(p2);
|
|
|
|
cmdisplay();
|
2004-06-12 01:27:33 +02:00
|
|
|
#endif
|
2004-03-03 21:24:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-16 02:09:51 +01:00
|
|
|
void
|
2004-08-28 00:09:03 +02:00
|
|
|
check_stack(void)
|
2004-03-03 21:24:06 +01:00
|
|
|
{
|
|
|
|
if (tos != 0)
|
2004-08-28 00:09:03 +02:00
|
|
|
stop("stack error");
|
2004-03-03 21:24:06 +01:00
|
|
|
if (frame != stack + TOS)
|
2004-08-28 00:09:03 +02:00
|
|
|
stop("frame error");
|
2004-03-03 21:24:06 +01:00
|
|
|
}
|
|
|
|
|
2006-07-13 02:09:33 +02:00
|
|
|
// cannot reference symbols yet
|
|
|
|
|
2004-08-29 21:54:40 +02:00
|
|
|
void
|
|
|
|
echo_input(char *s)
|
|
|
|
{
|
|
|
|
printstr(s);
|
|
|
|
printstr("\n");
|
|
|
|
}
|
2006-09-20 18:46:38 +02:00
|
|
|
|
2007-05-02 21:54:17 +02:00
|
|
|
// returns nil on stack if no result to print
|
|
|
|
|
2006-09-20 18:46:38 +02:00
|
|
|
void
|
|
|
|
top_level_eval(void)
|
|
|
|
{
|
2007-05-02 07:18:20 +02:00
|
|
|
save();
|
2006-09-20 18:46:38 +02:00
|
|
|
|
2007-08-04 02:51:53 +02:00
|
|
|
trigmode = 0;
|
|
|
|
|
|
|
|
p1 = symbol(AUTOEXPAND);
|
|
|
|
|
|
|
|
if (iszero(get_binding(p1)))
|
|
|
|
expanding = 0;
|
|
|
|
else
|
|
|
|
expanding = 1;
|
|
|
|
|
2007-05-02 07:18:20 +02:00
|
|
|
p1 = pop();
|
2007-05-02 06:13:54 +02:00
|
|
|
push(p1);
|
|
|
|
eval();
|
2007-05-02 07:18:20 +02:00
|
|
|
p2 = pop();
|
|
|
|
|
2007-05-05 06:55:43 +02:00
|
|
|
// "draw", "for" and "setq" return "nil", there is no result to print
|
2007-05-02 21:54:17 +02:00
|
|
|
|
2007-05-05 06:55:43 +02:00
|
|
|
if (p2 == symbol(NIL)) {
|
2007-05-02 21:54:17 +02:00
|
|
|
push(p2);
|
|
|
|
restore();
|
|
|
|
return;
|
|
|
|
}
|
2006-09-20 18:46:38 +02:00
|
|
|
|
2007-05-05 06:55:43 +02:00
|
|
|
// update "last"
|
|
|
|
|
2007-06-29 00:34:34 +02:00
|
|
|
set_binding(symbol(LAST), p2);
|
2006-09-20 18:46:38 +02:00
|
|
|
|
2007-06-29 00:34:34 +02:00
|
|
|
if (!iszero(get_binding(symbol(BAKE)))) {
|
2007-05-02 21:54:17 +02:00
|
|
|
push(p2);
|
|
|
|
bake();
|
|
|
|
p2 = pop();
|
2006-09-20 18:46:38 +02:00
|
|
|
}
|
2007-05-02 07:18:20 +02:00
|
|
|
|
2007-05-02 21:54:17 +02:00
|
|
|
// If we evaluated the symbol "i" or "j" and the result was sqrt(-1)
|
|
|
|
|
|
|
|
// then don't do anything.
|
|
|
|
|
|
|
|
// Otherwise if "j" is an imaginary unit then subst.
|
|
|
|
|
|
|
|
// Otherwise if "i" is an imaginary unit then subst.
|
|
|
|
|
|
|
|
if ((p1 == symbol(SYMBOL_I) || p1 == symbol(SYMBOL_J))
|
|
|
|
&& isimaginaryunit(p2))
|
|
|
|
;
|
2007-06-29 00:34:34 +02:00
|
|
|
else if (isimaginaryunit(get_binding(symbol(SYMBOL_J)))) {
|
2007-05-02 21:54:17 +02:00
|
|
|
push(p2);
|
|
|
|
push(imaginaryunit);
|
|
|
|
push_symbol(SYMBOL_J);
|
|
|
|
subst();
|
|
|
|
p2 = pop();
|
2007-06-29 00:34:34 +02:00
|
|
|
} else if (isimaginaryunit(get_binding(symbol(SYMBOL_I)))) {
|
2007-05-02 21:54:17 +02:00
|
|
|
push(p2);
|
|
|
|
push(imaginaryunit);
|
|
|
|
push_symbol(SYMBOL_I);
|
|
|
|
subst();
|
|
|
|
p2 = pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef LINUX
|
|
|
|
|
|
|
|
// if we evaluated the symbol "a" and got "b" then print "a=b"
|
|
|
|
|
|
|
|
// do not print "a=a"
|
|
|
|
|
2007-05-08 20:58:41 +02:00
|
|
|
if (issymbol(p1) && !iskeyword(p1) && p1 != p2 && test_flag == 0) {
|
2007-05-02 21:54:17 +02:00
|
|
|
push_symbol(SETQ);
|
|
|
|
push(p1);
|
|
|
|
push(p2);
|
|
|
|
list(3);
|
|
|
|
p2 = pop();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
push(p2);
|
|
|
|
|
2007-05-02 07:18:20 +02:00
|
|
|
restore();
|
2006-09-20 18:46:38 +02:00
|
|
|
}
|
2006-10-09 21:13:45 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
check_esc_flag(void)
|
|
|
|
{
|
|
|
|
if (esc_flag)
|
|
|
|
stop("esc key");
|
|
|
|
}
|