1 /*-
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)assign.c 8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11
12 /*
13 * assign the value of an expression to a variable (or term)
14 */
15
16 #include "defs.h"
17 #include "tree.h"
18 #include "sym.h"
19 #include "process.h"
20 #include "tree.rep"
21 #include "process/process.rep"
22 #include "process/pxinfo.h"
23
assign(var,exp)24 assign(var, exp)
25 NODE *var;
26 NODE *exp;
27 {
28 ADDRESS addr;
29 int varsize;
30 char cvalue;
31 short svalue;
32 long lvalue;
33
34 if (!compatible(var->nodetype, exp->nodetype)) {
35 error("incompatible types");
36 }
37 addr = lval(var);
38 eval(exp);
39 varsize = size(var->nodetype);
40 if (varsize < sizeof(long)) {
41 lvalue = pop(long);
42 switch (varsize) {
43 case sizeof(char):
44 cvalue = lvalue;
45 dwrite(&cvalue, addr, varsize);
46 break;
47
48 case sizeof(short):
49 svalue = lvalue;
50 dwrite(&svalue, addr, varsize);
51 break;
52
53 default:
54 goto othersize;
55 /*
56 panic("bad size %d", varsize);
57 */
58 }
59 } else {
60 othersize:
61 sp -= varsize;
62 dwrite(sp, addr, varsize);
63 #ifdef tahoe
64 downalignstack();
65 #endif
66 }
67 }
68