xref: /csrg-svn/usr.bin/pascal/pdx/tree/assign.c (revision 30852)
122557Sdist /*
222557Sdist  * Copyright (c) 1980 Regents of the University of California.
322557Sdist  * All rights reserved.  The Berkeley software License Agreement
422557Sdist  * specifies the terms and conditions for redistribution.
522557Sdist  */
65536Slinton 
722557Sdist #ifndef lint
8*30852Smckusick static char sccsid[] = "@(#)assign.c	5.2 (Berkeley) 04/07/87";
922557Sdist #endif not lint
105536Slinton 
115536Slinton /*
125536Slinton  * assign the value of an expression to a variable (or term)
135536Slinton  */
145536Slinton 
155536Slinton #include "defs.h"
165536Slinton #include "tree.h"
175536Slinton #include "sym.h"
185536Slinton #include "process.h"
195536Slinton #include "tree.rep"
20*30852Smckusick #include "process/process.rep"
21*30852Smckusick #include "process/pxinfo.h"
225536Slinton 
235536Slinton assign(var, exp)
245536Slinton NODE *var;
255536Slinton NODE *exp;
265536Slinton {
275536Slinton 	ADDRESS addr;
285536Slinton 	int varsize;
295536Slinton 	char cvalue;
305536Slinton 	short svalue;
315536Slinton 	long lvalue;
325536Slinton 
335536Slinton 	if (!compatible(var->nodetype, exp->nodetype)) {
345536Slinton 		error("incompatible types");
355536Slinton 	}
365536Slinton 	addr = lval(var);
375536Slinton 	eval(exp);
385536Slinton 	varsize = size(var->nodetype);
395536Slinton 	if (varsize < sizeof(long)) {
405536Slinton 		lvalue = pop(long);
415536Slinton 		switch (varsize) {
425536Slinton 			case sizeof(char):
435536Slinton 				cvalue = lvalue;
445536Slinton 				dwrite(&cvalue, addr, varsize);
455536Slinton 				break;
465536Slinton 
475536Slinton 			case sizeof(short):
485536Slinton 				svalue = lvalue;
495536Slinton 				dwrite(&svalue, addr, varsize);
505536Slinton 				break;
515536Slinton 
525536Slinton 			default:
53*30852Smckusick 				goto othersize;
54*30852Smckusick 				/*
555536Slinton 				panic("bad size %d", varsize);
56*30852Smckusick 				*/
575536Slinton 		}
585536Slinton 	} else {
59*30852Smckusick 	    othersize:
605536Slinton 		sp -= varsize;
615536Slinton 		dwrite(sp, addr, varsize);
62*30852Smckusick #ifdef tahoe
63*30852Smckusick 		downalignstack();
64*30852Smckusick #endif
655536Slinton 	}
665536Slinton }
67