date and time created 82/01/18 19:21:27 by linton
authorMark Linton <linton@ucbvax.Berkeley.EDU>
Tue, 19 Jan 1982 11:21:27 +0000 (03:21 -0800)
committerMark Linton <linton@ucbvax.Berkeley.EDU>
Tue, 19 Jan 1982 11:21:27 +0000 (03:21 -0800)
SCCS-vsn: usr.bin/pascal/pdx/tree/assign.c 1.1

usr/src/usr.bin/pascal/pdx/tree/assign.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/pascal/pdx/tree/assign.c b/usr/src/usr.bin/pascal/pdx/tree/assign.c
new file mode 100644 (file)
index 0000000..33a55a8
--- /dev/null
@@ -0,0 +1,51 @@
+/* Copyright (c) 1982 Regents of the University of California */
+
+static char sccsid[] = "@(#)assign.c 1.1 %G%";
+
+/*
+ * assign the value of an expression to a variable (or term)
+ */
+
+#include "defs.h"
+#include "tree.h"
+#include "sym.h"
+#include "process.h"
+#include "tree.rep"
+
+assign(var, exp)
+NODE *var;
+NODE *exp;
+{
+       ADDRESS addr;
+       int varsize;
+       char cvalue;
+       short svalue;
+       long lvalue;
+
+       if (!compatible(var->nodetype, exp->nodetype)) {
+               error("incompatible types");
+       }
+       addr = lval(var);
+       eval(exp);
+       varsize = size(var->nodetype);
+       if (varsize < sizeof(long)) {
+               lvalue = pop(long);
+               switch (varsize) {
+                       case sizeof(char):
+                               cvalue = lvalue;
+                               dwrite(&cvalue, addr, varsize);
+                               break;
+
+                       case sizeof(short):
+                               svalue = lvalue;
+                               dwrite(&svalue, addr, varsize);
+                               break;
+
+                       default:
+                               panic("bad size %d", varsize);
+               }
+       } else {
+               sp -= varsize;
+               dwrite(sp, addr, varsize);
+       }
+}