diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pile.c | 81 | ||||
| -rw-r--r-- | lib/scalaires.c | 1 | 
2 files changed, 54 insertions, 28 deletions
@@ -36,7 +36,6 @@ void push_pile(char *st)  	d_number = char_to_double(st, &valid2);  	valid3 = is_mute(st);  	poly = (polynome) NomVarToVar(st, variables, &valid4); -	printf("%p\n", poly);  	if (valid1) {		/* il s agit d un entier */  		pushcontext("c est un entier");  		push_pile_poly(ply_constr(rat_constr(i_number, 1), 0)); @@ -47,7 +46,7 @@ void push_pile(char *st)  		popcontext();  	} else if (valid3) {	/* il s agit de x */  		pushcontext("c est X"); -		push_pile_poly(ply_constr(rat_constr(1, 1), 0)); +		push_pile_poly(ply_constr(rat_constr(1, 1), 1));  		popcontext();  	} else if (valid4) {	/* il s agit d une variable */  		pushcontext("c est une variable"); @@ -59,13 +58,14 @@ void push_pile(char *st)  		popcontext();  	}  	popcontext(); +	affichage_pile(); +  	fprintf(stderr, "sortie de push_pile\n");  }  void push_pile_poly(polynome poly)  { -	pushcontext("entree dans push_pile_poly");  	if (pile_ptr != PILE_MAX) {  		pile[pile_ptr].type = T_POLY;  		pile[pile_ptr].poly = poly; @@ -73,15 +73,11 @@ void push_pile_poly(polynome poly)  	} else {  		exception(1, _("push_pile_poly: Stack Overflow"));  	} -	pushcontext("sortie de push_pile_poly"); -	popcontext(); -	popcontext();  }  void push_pile_int(int val)  { -	pushcontext("appel a push_pile_int");  	fprintf(stderr,"%d",val);  	if (pile_ptr != PILE_MAX) {  		pile[pile_ptr].type = T_INT; @@ -90,16 +86,12 @@ void push_pile_int(int val)  	} else {  		exception(1, _("push_pile_int: Stack Overflow"));  	} -	pushcontext("sortie de push-pile_int"); -	popcontext(); -	popcontext();  }  void push_pile_string(char *st)  { -	pushcontext("appel a push_pile_string");  	if (pile_ptr != PILE_MAX) {  		pile[pile_ptr].type = T_STRING;  		pile[pile_ptr].label = Estrdup(st); @@ -107,9 +99,6 @@ void push_pile_string(char *st)  	} else {  		exception(1, _("push_pile_string: Stack Overflow"));  	} -	pushcontext("sortie de push_pile_string"); -	popcontext(); -	popcontext();  } @@ -124,7 +113,6 @@ pile_elem pop_pile(unsigned int count)  		sprintf(buf, _("pop_pile: Can't pop %u elements"), count);  		exception(1, buf);  	} -	fprintf(stderr,"pile_ptr = %d\n", pile_ptr);  	return pile[pile_ptr];  } @@ -162,8 +150,10 @@ void act_pile(int func)  	sprintf(buf, _("Calling act_pile(%i)\n"), func);  	pushcontext(buf); +	affichage_pile();  	switch (func) {  	case OP_PLUS: +		printf("----- OP_PLUS\n");  		operande1 = pop_pile(1);  		operande2 = pop_pile(1);  		if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { @@ -177,6 +167,7 @@ void act_pile(int func)  		}  		break;  	case OP_MOINS: +		printf("----- OP_MOINS\n");  		operande1 = pop_pile(1);  		operande2 = pop_pile(1);  		if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { @@ -190,6 +181,7 @@ void act_pile(int func)  		}  		break;  	case OP_MUL: +		printf("----- OP_MUL\n");  		operande1 = pop_pile(1);  		operande2 = pop_pile(1);  		if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { @@ -203,6 +195,7 @@ void act_pile(int func)  		}  		break;  	case OP_DIV: +		printf("----- OP_DIV\n");  		operande1 = pop_pile(1);  		operande2 = pop_pile(1);  		if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { @@ -216,6 +209,7 @@ void act_pile(int func)  		}  		break;  	case OP_MOD: +		printf("----- OP_MOD\n");  		operande1 = pop_pile(1);  		operande2 = pop_pile(1);  		if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { @@ -229,17 +223,18 @@ void act_pile(int func)  		}  		break;  	case OP_EXP: +		printf("----- OP_EXP\n");  		operande1 = pop_pile(1);  		operande2 = pop_pile(1);  		if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { -			if (operande2.poly) { -				if ((operande2.poly->coef.denom == 1) -				    && (operande2.poly->coef.num >= 0)) { +			if (operande1.poly) { +				if ((operande1.poly->coef.denom == 1) +				    && (operande1.poly->coef.num >= 0)) {  					push_pile_poly(ply_exposant -						       (operande1.poly, operande2.poly->coef.num)); -					if (operande1.poly) -						ply_destruct(operande1.poly); -					ply_destruct(operande2.poly); +						       (operande2.poly, operande1.poly->coef.num)); +					if (operande2.poly) +						ply_destruct(operande2.poly); +					ply_destruct(operande1.poly);  				} else {  					exception(1, _("act_pile: OP_EXP invalid arguments"));  				} @@ -251,6 +246,7 @@ void act_pile(int func)  		}  		break;  	case OP_ASSIGN: +		printf("----- OP_ASSIGN\n");  		operande1 = pop_pile(1);  		operande2 = pop_pile(1);  		if ((operande1.type == T_POLY) && (operande2.type == T_STRING)) { @@ -258,7 +254,7 @@ void act_pile(int func)  				InsererVarDansTab(&variables,  						  CreerElement(operande2.label,  							       (void *) operande1.poly)); -				/* free(operande2.label); */ +				 free(operande2.label);  			} else {  				exception(1, _("act_pile: OP_ASSIGN empty string"));  			} @@ -267,8 +263,12 @@ void act_pile(int func)  		}  		break;  	case OP_PLUS_UNARY: +		printf("----- OP_PLUS_UNARY\n"); +  		break;  	case OP_MOINS_UNARY: +		printf("----- OP_MOINS_UNARY\n"); +  		operande1 = pop_pile(1);  		if (operande1.type == T_POLY) {  			push_pile_poly(ply_soustraction @@ -280,6 +280,8 @@ void act_pile(int func)  		}  		break;  	case OP_FUNC_CALL: +		printf("----- OP_FUNC_CALL\n"); +  		operande1 = pop_pile(1);  		if ((operande1.type == T_INT) && (operande1.val == 1)) {  			operande1 = pop_pile(1); @@ -287,7 +289,7 @@ void act_pile(int func)  			if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) {  				if (operande2.poly) {  					if (operande1.poly->degre == 0) { -					double soja, soja2; +					/*double soja, soja2;  					rationnel rat;  					polynome pl;  					fprintf(stderr,"soja");		 @@ -297,10 +299,10 @@ void act_pile(int func)  					fprintf(stderr,"%f", soja2);  					rat=rat_constr_from_double(soja2);  					fprintf(stderr,"pl"); -					pl=ply_constr(rat, 1); -/* -push_pile_poly(ply_constr(rat_constr_from_double(ply_valuation(operande2.poly,rat_to_double(operande1.poly->coef))), 1)); -*/ +					pl=ply_constr(rat, 1);*/ + +push_pile_poly(ply_constr(rat_constr_from_double(ply_valuation(operande2.poly,rat_to_double(operande1.poly->coef))), 0)); +  						if (operande1.poly)  							ply_destruct(operande1.poly);  						ply_destruct(operande2.poly); @@ -324,3 +326,26 @@ push_pile_poly(ply_constr(rat_constr_from_double(ply_valuation(operande2.poly,ra  	}  	popcontext();  } + + +void affichage_pile(void) { +	int i; +	printf("\t-- affichage de la pile\n"); +	if (pile_ptr) { +		for (i=0;i<=pile_ptr-1;i++) { +			switch (pile[i].type) { +			case T_INT: +				printf("\t\t%d:I: %d\n", i, pile[i].val); +				break; +			case T_STRING: +				printf("\t\t%d:S: %s\n", i, pile[i].label); +				break; +			case T_POLY: +				printf("\t\t%d:P: %s\n", i, ply_affichage(pile[i].poly)); +				break; +			} +		} +	} +	printf("\t-- fin d affichage de pile\n"); +}	 + diff --git a/lib/scalaires.c b/lib/scalaires.c index 10c9196..b853741 100644 --- a/lib/scalaires.c +++ b/lib/scalaires.c @@ -5,6 +5,7 @@   */  #include "scalaires.h" +#include "exceptions.h"  #include <math.h>  #define PRECISION 1E6  | 
