home *** CD-ROM | disk | FTP | other *** search
- /*
- * storage.c
- * Copyright © 1992 Niklas Röjemo
- */
-
- #include "storage.h"
- #include "value.h"
- #include "get.h"
- #include "lex.h"
- #include "input.h"
- #include "expr.h"
- #include "error.h"
-
- static int storageD = 0;
- static Value storageV;
-
- extern int pedantic;
- Value storageValue(void)
- {
- if(!storageD) {
- error(ErrorError,TRUE,"No storage declared (# or @ before ^).");
- storageV.Tag = ValueInt;
- storageV.ValueInt.i = 0;
- }
- return valueCopy(storageV);
- }
-
- void c_record(void)
- {
- Value value;
- storageD = TRUE;
- exprBuild();
- value = exprEval(ValueInt);
- switch(value.Tag) {
- case ValueInt:
- storageV = value;
- break;
- default:
- storageV.Tag = ValueInt;
- storageV.ValueInt.i = 0;
- error(ErrorError,FALSE,"^ can not evaluate its offset expression.");
- }
- }
-
- void c_alloc(Symbol *sym)
- {
- Value value;
- if(!sym)
- error(ErrorError,FALSE,"Missing label before #.");
- sym->type |= SYMBOL_ABSOLUTE|SYMBOL_DEFINED;
- sym->area.ptr = 0;
- sym->value = storageValue();
- exprBuild();
- value = exprEval(ValueInt);
- switch(value.Tag) {
- case ValueInt:
- if(value.ValueInt.i>=0) {
- if(pedantic && value.ValueInt.i==0)
- error(ErrorInfo,TRUE,"You are reserving zero bytes?");
- storageV.ValueInt.i += value.ValueInt.i;
- } else
- error(ErrorError,TRUE,"Illegal to reserve negative amount of space %d.",value.ValueInt.i);
- break;
- default:
- error(ErrorError,FALSE,"Illegal expression after #.");
- break;
- }
- }
-