ide_run.c 21.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
/*
 * ide_run - Execute an ide parse tree
 *
 * $Revision: 1.1.1.1 $
 */

#include "ide.h"
#include "diag.h"

#include <getopt.h>

struct diagComm *pGlobalComm;
/*
 * Globals to be shared between ide and errlog().
 */
int errNumbers[120];
int errIndex;

char *ideTestName;

/* 
 * dostmt - Top level entry point
 *
 * Establishes a context for "return" statements and initiates execution.
 *
 */

context_t global_context;

/*
 * Create a global context for ide
 *
 * The $0..$n paramters are set up to be the same as the command
 * line arguments to ide.
 *
 */
init_context(argc,argv)
int argc;
char *argv[];
{
	int i;

	for ( i = 0; i < argc; i++ ) {
		global_context.argv[i] = makessym(argv[i]);
		global_context.argc++;
		}
}
/*
 *  handle interrupt - let ide scripts see and react to ^c
 *
 * Whenever ^C is pressed, the user defined function "trap"
 * is executed.  The trap function may be used to reset tty
 * or graphics or anything else.
 */
handle_interrupt()
{
	sym_t *psym;
	node_t *pnode;

	if ( (psym = findsym("trap")) && psym->sym_type == SYM_CMD ) {
		pnode = makenode();
		pnode->node_psym = psym;
		pnode->node_type = OP_CMD;
		dostmt(pnode);
		destroynode(pnode);
		}
}
/*
 * Top level entry point into command executor
 *
 */
dostmt(pnode)
node_t *pnode;
{

	if ( setjmp(global_context.rframe) )
		return;

	dotree(&global_context, pnode);

	return;
}
/*
 * dotree - execute a tree within a given context
 *
 */
dotree(context, pnode)
node_t *pnode;
context_t *context;
{
#ifdef STANDALONE
	_scandevs();
#endif

	if ( ! pnode )
		return;

	switch ( pnode->node_type ) {
		case OP_STMT:
			dotree(context, pnode->node_right);
			dotree(context, pnode->node_left);
			break;
		case OP_PRINT:
			doprint(context, pnode);
			break;
		case OP_IF:
			doif(context, pnode);
			break;
		case OP_WHILE:
			dowhile(context, pnode);
			break;
		case OP_FOR:
			dofor( context, pnode);
			break;
		case OP_DO:
			dodo( context, pnode);
			break;
		case OP_RETURN:
			doreturn(context,pnode);
			break;
		case OP_BREAK:
			longjmp(context->lframe, 2);
			break;
		case OP_CONTINUE:
			longjmp(context->lframe, 3);
			break;
		case OP_SWITCH:
			doswitch(context,pnode);
			break;
		case OP_REPEAT:
			dorepeat(context,pnode);
			break;
		default:
			destroysym(eval(context, pnode));
			break;
		}
}
/*
 * Promote symbol to integer
 *
 * This routine is used whenever the context of an expression requires
 * an integer and we don't have one.  If the symbol is a string, this
 * routine will try to figure out if it looks like a string of digits
 * and then converts it to binary (like awk).
 *
 */
sym_t *
pro_int(psym)
sym_t *psym;
{
	sym_t *tmp;
	int	v = 0;
	int	base = 10;
	char	*p;

	if ( psym->sym_basetype == SYM_INT )
		return psym;
	
	tmp = makesym();
	tmp->sym_basetype = SYM_INT;

	if ( psym->sym_basetype == SYM_STR ) {
		p = psym->sym_s;
		if ( *p == '0' ) {
			base = 8;
			p++;
			if ( *p == 'x' || *p == 'X' ) {
				base = 16;
				p++;
				}
			else
			if ( *p == 'b' || *p == 'B' ) {
				base = 2;
				p++;
				}
			}
		for ( ;isxdigit( *p ); p++ )
			if ( *p > '9' && base < 16 )
				break;
			else
			if ( *p >= 'a' && *p <= 'f' )
				v = (v * base) + (*p - 'a') + 10;
			else
			if ( *p >= 'A' && *p <= 'F' )
				v = (v * base) + (*p - 'A') + 10;
			else
			if ( (*p - '0') >= base )
				break;
			else
				v = (v * base) + (*p - '0');
		if ( *p )
			v = 0;
		tmp->sym_i = v;
		}
	
	destroysym(psym);

	return tmp;
}
/*
 * promote to string
 *
 * This routine is called whenever a string is needed.  It is much simpler
 * to convert to strings than to integers.
 */
sym_t *
pro_str(psym)
sym_t *psym;
{
	sym_t	*tmp;
	char	v[MAXSTRLEN];
	char	r[32];
	int	rp  = 0;
	char	*vp = v;
	int	p;

	if ( psym->sym_basetype == SYM_STR )
		return psym;
	
	tmp = makesym();
	tmp->sym_basetype = SYM_STR;

	if ( psym->sym_basetype == SYM_INT ) {
		if ( (p = psym->sym_i) < 0 ) {
			*vp++ = '-';
			p = -p;
			}
		do	{
			r[rp++] = (p % 10)+'0';
			p /= 10;
			} while ( p );
		while ( --rp >= 0 )
			*vp++ = r[rp];
		*vp = '\0';
		tmp->sym_s = makestr(v);
		}
	
	destroysym(psym);

	return tmp;
}
/*
 * docmd - run a command or function.
 *
 * There are two different types of commands:
 *  1. Those defined by the user as an ide function
 *  2. Those defined by ide as builtins.
 *
 */
sym_t *
docmd(context, pnode)
node_t *pnode;
context_t *context;
{
	context_t ccontext;
	sym_t *cmd = pnode->node_psym;
	sym_t *vsym = makesym();
	int i;
	int rc;

	ccontext = *context;

	if ( rc = setjmp(ccontext.rframe) ) {
		--rc;
		goto exit;
		}

	ccontext.argc = makeargv(context, pnode->node_right, ccontext.argv+1)+1;
	ccontext.argv[0] = cmd;

	if ( cmd->sym_flags & SYM_UDEF )
		dotree(&ccontext, cmd->sym_stmt);
	else
	if ( cmd->sym_flags & SYM_CHARARGV ) {
		char *argv[MAXARGC+1];

		argv[0] = cmd->sym_name;

		for ( i = 1; i < ccontext.argc; i++ ) {
			ccontext.argv[i] = pro_str(ccontext.argv[i]);
			argv[i] = ccontext.argv[i]->sym_s;
			}
		
		argv[ccontext.argc] = 0;

		rc = (*cmd->sym_func)(ccontext.argc, argv);
		}
	else
	if ( cmd->sym_flags & SYM_DIAGCOMM ) {
		for (i = 0; i < 120; i++)
		    errNumbers[i] = TEST_NULL;
		errIndex = 0;
		/*
		 * Setup argc, argv stuff, then initialize the global 
		 * communication structure (diagnostic module will access
		 * it as a global).
		 */
		myComm.argv[0] = cmd->sym_name;
		ideTestName = cmd->sym_name;

		for ( i = 1; i < ccontext.argc; i++ ) {
			ccontext.argv[i] = pro_str(ccontext.argv[i]);
			myComm.argv[i] = ccontext.argv[i]->sym_s;
			}
		
		myComm.argv[ccontext.argc] = 0;

		pGlobalComm = &myComm;
		myComm.errorCount = 0;
		myComm.entryNum = 0;
		myComm.errNums = errNumbers;
		myComm.argc = ccontext.argc;

		rc = (*cmd->sym_func)();
		/*
		 * Reset the global optind, in case the test used getopt()
		 * to parse its option arguments.
		 */
		optind = 1;
	}
	else
		rc = (*cmd->sym_func)(ccontext.argc, ccontext.argv);

	exit:
	for ( i = 1; i < ccontext.argc; i++ )
		destroysym(ccontext.argv[i]);
	
	vsym->sym_basetype = SYM_INT;
	vsym->sym_i = rc;

	return vsym;
}
/*
 * build up an argv for a command
 *
 */
makeargv(context, pnode, argv )
context_t *context;
node_t *pnode;
sym_t *argv[];
{
	int argc;

	if ( ! pnode )
		return 0;

	argc = makeargv( context, pnode->node_right, argv );

	if ( argc < MAXARGC )
		argv[argc++] = eval( context, pnode->node_left );

	return argc;
}
/*
 * doif - Do an if-then-else statement
 *
 */
doif( context, pnode)
node_t *pnode;
context_t *context;
{
	sym_t *tmp = pro_int(eval(context, pnode->node_left));

	if ( pnode->node_right && pnode->node_right->node_type == OP_ELSE ) {
		if ( tmp->sym_i )
			dotree(context,pnode->node_right->node_left);
		else
			dotree(context,pnode->node_right->node_right);
		}
	else
		if ( tmp->sym_i)
			dotree(context,pnode->node_right);
	
	destroysym(tmp);
}
/*
 * dorepeat - do a repeat loop
 *
 */
dorepeat(context, pnode)
node_t *pnode;
context_t *context;
{
	int tmp;

	tmp = pnode->node_psym->sym_i;

	if ( tmp )
		while( tmp-- )
			dotree(context, pnode->node_right);
	else
		while( 1 )
			dotree(context, pnode->node_right);

}
/*
 * dowhile - do a while loop
 *
 */
dowhile(context, pnode)
node_t *pnode;
context_t *context;
{
	sym_t *tmp;
	int done = 0;

	do	{
		tmp = pro_int(eval(context, pnode->node_left));
		if ( tmp->sym_i ) {
			context_t lcontext;
			int s;

			lcontext = *context;
			if ( s = setjmp( lcontext.lframe ) ) {
				if ( s == 2 ) /* break */
					done = 1;
				}
			else
				dotree(&lcontext, pnode->node_right);
			}
		else
			done = 1;
		destroysym(tmp);
		} while(!done);

}
/*
 * dofor - do a for loop
 *
 */
dofor(context, pnode)
node_t *pnode;
context_t *context;
{
	node_t *pre;
	node_t *con;
	node_t *end;
	node_t *bod;
	sym_t *tmp;
	context_t lcontext;
	int s;

	pre = pnode->node_left->node_left;
	con = pnode->node_left->node_right;
	end = pnode->node_right->node_left;
	bod = pnode->node_right->node_right;

	if (pre) destroysym(eval(context,pre));

	do	{
		if ( con ) {
			tmp = pro_int(eval(context, con));
			if ( ! tmp->sym_i ) {
				destroysym(tmp);
				break;
				}
			destroysym(tmp);
			}

		lcontext = *context;

		if ( s = setjmp( lcontext.lframe ) ) {
			if ( s == 2 ) /* break */
				break;
			}
		else
			dotree(&lcontext, bod);

		if ( end )
			destroysym(eval(context, end));
		} while (1);

}
/*
 * doreturn - return statement
 *
 */
doreturn(context, pnode)
node_t *pnode;
context_t *context;
{
	int rc;
	sym_t *rsym;

	if (pnode->node_right) {
		rsym = pro_int(eval(context,pnode->node_right));
		rc = rsym->sym_i;
		destroysym(rsym);
		}
	else
		rc = 0;

	longjmp(context->rframe, rc+1);
	/*NOTREACHED*/
}
/*
 * dodo - do a do loop
 *
 */
dodo(context, pnode)
node_t *pnode;
context_t *context;
{
	sym_t *tmp;
	int done = 0;
	context_t lcontext;
	int s;

	do	{
		lcontext = *context;
		if ( s = setjmp( lcontext.lframe ) ) {
			if ( s == 2 ) { /* break = 2 */
				done = 1;
				destroysym(tmp);
				break;
				}
			/* continue = 1 */
			}
		else
			dotree(&lcontext, pnode->node_right);

		tmp = pro_int(eval(context, pnode->node_left));

		if ( !tmp->sym_i )
			done = 1;

		destroysym(tmp);

		} while(!done);
}

doswitch(context, pnode)
node_t *pnode;
context_t *context;
{
	context_t scontext;
	int val;
	sym_t *psym = pro_int(eval(context, pnode->node_left));

	val = psym->sym_i;

	destroysym(psym);

	scontext = *context;

	if ( setjmp(scontext.lframe) )
		return; /* break */

	if (!findcase(&scontext, val, pnode->node_right, 0))
		findcase(&scontext, val, pnode->node_right, 1);
}

findcase(context, val, pnode, flag)
context_t *context;
node_t *pnode;
int val, flag;
{
	sym_t *psym;
	int found = 0;

	if ( ! pnode )
		return;

	if ( pnode->node_type == OP_CASELIST ) {
		found = findcase(context, val, pnode->node_right, flag);
		pnode = pnode->node_left;
		}
	
	if ( ! found ) {
		if ( flag && pnode->node_psym )
			return 0;

		if (!flag && !pnode->node_psym )
			return 0; /* hit default case but still looking */

		if (!flag && pnode->node_psym->sym_i != val)
			return 0;
		
		}
	
	dotree(context, pnode->node_right);

	return 1;
}

doprint(context, pnode)
node_t *pnode;
context_t *context;
{
	sym_t *tmp = eval(context, pnode->node_right);

	if ( pnode->node_psym )
		printf(pnode->node_psym->sym_s, tmp->sym_i);
	else
	switch( tmp->sym_basetype ) {
		case SYM_INT:
			printf("value = %d\n", tmp->sym_i );
			break;
		case SYM_STR:
			printf("value = \"%s\"\n", tmp->sym_s );
			break;
		}
	
	destroysym(tmp);

}

/*
 * eval - expression evaluator
 *
 * This is the heart of the ide interpreter.  Given an expression
 * tree this routine returns a symbol record containing the result
 * of the evaluation. The symbol returned is a temporary symbol and
 * should be destroyed after it is used.
 *
 */
sym_t *
eval(context, pnode)
node_t *pnode;
context_t *context;
{
	sym_t *rsym;
	sym_t *lsym;
	sym_t *vsym;

	switch ( pnode->node_type ) {
		case OP_VAR:
			lsym = pnode->node_psym;
			vsym = makesym();

			if ( lsym->sym_type == SYM_PARAM )
				/* $# */
				if ( lsym->sym_indx == MAXARGC+1 ) {
					vsym->sym_basetype = SYM_INT;
					vsym->sym_type = SYM_VAR;
					vsym->sym_i = context->argc;
					break;
					}
				else
				/* $n where n > argc  */
				if ( lsym->sym_indx >= context->argc ) {
					vsym->sym_basetype = SYM_STR;
					vsym->sym_type = SYM_VAR;
					vsym->sym_s = makestr("");
					break;
					}
				else
				/* $n where n <= argc  */
					lsym = context->argv[lsym->sym_indx];
			
			if ( lsym->sym_basetype == SYM_STR )
				vsym->sym_s = makestr(lsym->sym_s);
			else
			if ( lsym->sym_basetype == SYM_RANGE) {
				vsym->sym_start = lsym->sym_start;
				vsym->sym_count = lsym->sym_count;
				}
			else
				vsym->sym_i = lsym->sym_i;
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_type = SYM_VAR;
			break;
		case OP_ADD:
			rsym = eval(context, pnode->node_right);
			lsym = eval(context, pnode->node_left);
			vsym = makesym();

			if ( rsym->sym_basetype == SYM_STR &&
			     lsym->sym_basetype == SYM_STR  ) {
				vsym->sym_basetype = SYM_STR;
				vsym->sym_s = talloc( strlen(rsym->sym_s)+
						strlen(lsym->sym_s) + 1 );
				strcpy( vsym->sym_s, lsym->sym_s );
				strcat( vsym->sym_s, rsym->sym_s );
				}
			else	{
				rsym = pro_int(rsym);
				lsym = pro_int(lsym);
				vsym->sym_basetype = SYM_INT;
				vsym->sym_i = lsym->sym_i + rsym->sym_i;
				}
			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_SUB:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pro_int(eval(context, pnode->node_left));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;
			vsym->sym_i = lsym->sym_i - rsym->sym_i;
			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_MUL:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pro_int(eval(context, pnode->node_left));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;
			vsym->sym_i = lsym->sym_i * rsym->sym_i;
			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_DIV:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pro_int(eval(context, pnode->node_left));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;
			if ( rsym->sym_i == 0 )
				vsym->sym_i = DIV0RESULT;
			else
				vsym->sym_i = lsym->sym_i / rsym->sym_i;
			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_MOD:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pro_int(eval(context, pnode->node_left));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;
			if ( rsym->sym_i == 0 )
				vsym->sym_i = DIV0RESULT;
			else
				vsym->sym_i = lsym->sym_i % rsym->sym_i;
			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_OR:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pro_int(eval(context, pnode->node_left));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;
			vsym->sym_i = lsym->sym_i | rsym->sym_i;
			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_AND:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pro_int(eval(context, pnode->node_left));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;
			vsym->sym_i = lsym->sym_i & rsym->sym_i;
			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_XOR:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pro_int(eval(context, pnode->node_left));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;
			vsym->sym_i = lsym->sym_i ^ rsym->sym_i;
			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_COM: /* complement */
			rsym = pro_int(eval(context, pnode->node_right));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;
			vsym->sym_i =  ~rsym->sym_i;
			destroysym(rsym);
			break;
		case OP_NOT: /* logical not */
			rsym = pro_int(eval(context, pnode->node_right));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;
			if ( rsym->sym_i )
				vsym->sym_i = 0;
			else
				vsym->sym_i = 1;
			destroysym(rsym);
			break;
		case OP_ANDAND:
			lsym = pro_int(eval(context, pnode->node_left));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;

			/* C evaluation semantics */
			if ( lsym->sym_i ) {
				rsym = pro_int(eval(context,pnode->node_right));
				if ( rsym->sym_i )
					vsym->sym_i = 1;
				}
			else
				vsym->sym_i = 0;

			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_OROR:
			lsym = pro_int(eval(context, pnode->node_left));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;

			/* C evaluation semantics */
			if ( ! lsym->sym_i ) {
				rsym = pro_int(eval(context,pnode->node_right));
				if ( rsym->sym_i )
					vsym->sym_i = 1;
				}
			else
				vsym->sym_i = 1;

			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_LT:
		case OP_LE:
		case OP_GT:
		case OP_GE:
		case OP_EQ:
		case OP_NE:
			{
			int i;
			rsym = eval(context, pnode->node_right);
			lsym = eval(context, pnode->node_left);

			vsym = makesym();
			vsym->sym_basetype = SYM_INT;

			if ( rsym->sym_basetype == SYM_STR &&
			     lsym->sym_basetype == SYM_STR  )
				i = strcmp(lsym->sym_s, rsym->sym_s);
			else	{
				rsym = pro_int(rsym);
				lsym = pro_int(lsym);

				i = lsym->sym_i - rsym->sym_i;
				}

			switch(pnode->node_type) {
				case OP_EQ:
					vsym->sym_i = (i == 0);
					break;
				case OP_NE:
					vsym->sym_i = (i != 0);
					break;
				case OP_GT:
					vsym->sym_i = (i >  0);
					break;
				case OP_LT:
					vsym->sym_i = (i <  0);
					break;
				case OP_GE:
					vsym->sym_i = (i >= 0);
					break;
				case OP_LE:
					vsym->sym_i = (i <= 0);
					break;
				}
			destroysym(rsym);
			destroysym(lsym);
			}
			break;
		case OP_POSTD:
			lsym = pnode->node_psym;
			if ( lsym->sym_basetype == SYM_STR )
				destroystr(lsym->sym_s);
			lsym->sym_basetype = SYM_INT;
			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i--;
			break;
		case OP_POSTI:
			lsym = pnode->node_psym;
			if ( lsym->sym_basetype == SYM_STR )
				destroystr(lsym->sym_s);
			lsym->sym_basetype = SYM_INT;
			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i++;
			break;
		case OP_PRED:
			lsym = pnode->node_psym;
			if ( lsym->sym_basetype == SYM_STR )
				destroystr(lsym->sym_s);
			lsym->sym_basetype = SYM_INT;
			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = --lsym->sym_i;
			break;
		case OP_PREI:
			lsym = pnode->node_psym;
			if ( lsym->sym_basetype == SYM_STR )
				destroystr(lsym->sym_s);
			lsym->sym_basetype = SYM_INT;
			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = ++lsym->sym_i;
			break;
		case OP_SHL:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pro_int(eval(context, pnode->node_left));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;
			vsym->sym_i = lsym->sym_i << rsym->sym_i;
			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_SHR:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pro_int(eval(context, pnode->node_left));
			vsym = makesym();
			vsym->sym_basetype = SYM_INT;
			vsym->sym_i = lsym->sym_i >> rsym->sym_i;
			destroysym(rsym);
			destroysym(lsym);
			break;
		case OP_ASSIGN:
			rsym = eval(context, pnode->node_right);
			lsym = pnode->node_psym;

			if ( lsym->sym_basetype == SYM_STR )
				destroystr(lsym->sym_s);

			if ( lsym->sym_type == SYM_GLOBAL )
				set_global(lsym, rsym);
			else	{
				if ( rsym->sym_basetype == SYM_INT ) {
					lsym->sym_basetype = SYM_INT;
					lsym->sym_i = rsym->sym_i;
					}
				else
				if ( rsym->sym_basetype == SYM_STR ) {
					lsym->sym_basetype = SYM_STR;
					lsym->sym_s = makestr(rsym->sym_s);
					}
				destroysym(rsym);
				}

			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			if ( lsym->sym_basetype == SYM_STR )
				vsym->sym_s = makestr(lsym->sym_s);
			else
				vsym->sym_i = lsym->sym_i;
			break;
		case OP_SUBASS:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pnode->node_psym;

			lsym->sym_basetype = SYM_INT;
			lsym->sym_i -= rsym->sym_i;

			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i;
			destroysym(rsym);
			break;
		case OP_ADDASS:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pnode->node_psym;

			lsym->sym_basetype = SYM_INT;
			lsym->sym_i += rsym->sym_i;

			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i;
			destroysym(rsym);
			break;
		case OP_MULASS:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pnode->node_psym;

			lsym->sym_basetype = SYM_INT;
			lsym->sym_i *= rsym->sym_i;

			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i;
			destroysym(rsym);
			break;
		case OP_DIVASS:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pnode->node_psym;

			lsym->sym_basetype = SYM_INT;

			if ( rsym->sym_i == 0 )
				lsym->sym_i = DIV0RESULT;
			else
				lsym->sym_i /= rsym->sym_i;

			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i;
			destroysym(rsym);
			break;
		case OP_MODASS:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pnode->node_psym;

			lsym->sym_basetype = SYM_INT;

			if ( rsym->sym_i == 0 )
				lsym->sym_i = DIV0RESULT;
			else
				lsym->sym_i %= rsym->sym_i;

			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i;
			destroysym(rsym);
			break;
		case OP_SHLASS:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pnode->node_psym;

			lsym->sym_basetype = SYM_INT;
			lsym->sym_i <<= rsym->sym_i;

			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i;
			destroysym(rsym);
			break;
		case OP_SHRASS:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pnode->node_psym;

			lsym->sym_basetype = SYM_INT;
			lsym->sym_i >>= rsym->sym_i;

			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i;
			destroysym(rsym);
			break;
		case OP_ANDASS:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pnode->node_psym;

			lsym->sym_basetype = SYM_INT;
			lsym->sym_i &= rsym->sym_i;

			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i;
			destroysym(rsym);
			break;
		case OP_ORASS:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pnode->node_psym;

			lsym->sym_basetype = SYM_INT;
			lsym->sym_i |= rsym->sym_i;

			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i;
			destroysym(rsym);
			break;
		case OP_XORASS:
			rsym = pro_int(eval(context, pnode->node_right));
			lsym = pnode->node_psym;

			lsym->sym_basetype = SYM_INT;
			lsym->sym_i ^= rsym->sym_i;

			vsym = makesym();
			vsym->sym_basetype = lsym->sym_basetype;
			vsym->sym_i = lsym->sym_i;
			destroysym(rsym);
			break;
		case OP_CMD:
			vsym = docmd(context,pnode);
			break;
		default:
			vsym = makesym();
			printf("ide: eval bad node type %d\n",pnode->node_type);
			break;
		}
	
	return vsym;
}