|
|
1.1 ! root 1: /* Copyright (c) 1982 Regents of the University of California */ ! 2: ! 3: static char sccsid[] = "@(#)assign.c 1.1 1/18/82"; ! 4: ! 5: /* ! 6: * assign the value of an expression to a variable (or term) ! 7: */ ! 8: ! 9: #include "defs.h" ! 10: #include "tree.h" ! 11: #include "sym.h" ! 12: #include "process.h" ! 13: #include "tree.rep" ! 14: ! 15: assign(var, exp) ! 16: NODE *var; ! 17: NODE *exp; ! 18: { ! 19: ADDRESS addr; ! 20: int varsize; ! 21: char cvalue; ! 22: short svalue; ! 23: long lvalue; ! 24: ! 25: if (!compatible(var->nodetype, exp->nodetype)) { ! 26: error("incompatible types"); ! 27: } ! 28: addr = lval(var); ! 29: eval(exp); ! 30: varsize = size(var->nodetype); ! 31: if (varsize < sizeof(long)) { ! 32: lvalue = pop(long); ! 33: switch (varsize) { ! 34: case sizeof(char): ! 35: cvalue = lvalue; ! 36: dwrite(&cvalue, addr, varsize); ! 37: break; ! 38: ! 39: case sizeof(short): ! 40: svalue = lvalue; ! 41: dwrite(&svalue, addr, varsize); ! 42: break; ! 43: ! 44: default: ! 45: panic("bad size %d", varsize); ! 46: } ! 47: } else { ! 48: sp -= varsize; ! 49: dwrite(sp, addr, varsize); ! 50: } ! 51: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.