home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / program / language / as / source / c / storage < prev    next >
Encoding:
Text File  |  1992-07-20  |  1.5 KB  |  69 lines

  1. /*
  2.  * storage.c
  3.  * Copyright © 1992 Niklas Röjemo
  4.  */
  5.  
  6. #include "storage.h"
  7. #include "value.h"
  8. #include "get.h"
  9. #include "lex.h"
  10. #include "input.h"
  11. #include "expr.h"
  12. #include "error.h"
  13.  
  14. static int   storageD = 0;
  15. static Value storageV; 
  16.  
  17. extern int pedantic;
  18. Value storageValue(void)
  19. {
  20.   if(!storageD) {
  21.     error(ErrorError,TRUE,"No storage declared (# or @ before ^).");
  22.     storageV.Tag = ValueInt;
  23.     storageV.ValueInt.i = 0;
  24.   }
  25.   return valueCopy(storageV);
  26. }
  27.  
  28. void c_record(void)
  29. {
  30.   Value value;
  31.   storageD = TRUE;
  32.   exprBuild();
  33.   value = exprEval(ValueInt);
  34.   switch(value.Tag) {
  35.     case ValueInt:
  36.       storageV = value;
  37.       break;
  38.     default:
  39.       storageV.Tag = ValueInt;
  40.       storageV.ValueInt.i = 0;
  41.       error(ErrorError,FALSE,"^ can not evaluate its offset expression.");
  42.   }
  43. }
  44.  
  45. void c_alloc(Symbol *sym)
  46. {
  47.   Value value;
  48.   if(!sym)
  49.     error(ErrorError,FALSE,"Missing label before #.");
  50.   sym->type |= SYMBOL_ABSOLUTE|SYMBOL_DEFINED;
  51.   sym->area.ptr = 0;
  52.   sym->value = storageValue();
  53.   exprBuild();
  54.   value = exprEval(ValueInt);
  55.   switch(value.Tag) {
  56.     case ValueInt:
  57.       if(value.ValueInt.i>=0) {
  58.         if(pedantic && value.ValueInt.i==0)
  59.           error(ErrorInfo,TRUE,"You are reserving zero bytes?");
  60.         storageV.ValueInt.i +=  value.ValueInt.i;
  61.       } else
  62.         error(ErrorError,TRUE,"Illegal to reserve negative amount of space %d.",value.ValueInt.i);
  63.       break;
  64.     default:
  65.       error(ErrorError,FALSE,"Illegal expression after #.");
  66.       break;
  67.   }
  68. }
  69.