"Fossies" - the Fresh Open Source Software Archive

Member "asymptote-2.61/access.cc" (18 Nov 2019, 3309 Bytes) of package /linux/misc/asymptote-2.61.src.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "access.cc" see the Fossies "Dox" file reference documentation.

    1 /*****
    2  * access.cc
    3  * Andy Hammerlindl 2003/12/03
    4  * Describes an "access," a representation of where a variable will be
    5  * stored at runtime, so that read, write, and call instructions can be
    6  * made.
    7  *****/
    8 
    9 #include "access.h"
   10 #include "frame.h"
   11 #include "coder.h"
   12 #include "callable.h"
   13 
   14 using vm::item;
   15 
   16 namespace trans {
   17 
   18 /* access */
   19 access::~access()
   20 {}
   21 
   22 /* identAccess */
   23 void identAccess::encode(action act, position pos, coder& e)
   24 {
   25   if (act != CALL) {
   26     access::encode(act, pos, e);
   27   }
   28   // else - do nothing
   29 }
   30 
   31 
   32 /* bltinAccess */
   33 static void bltinError(position pos)
   34 {
   35   em.error(pos);
   36   em << "built-in functions cannot be modified";
   37 }
   38 
   39 void bltinAccess::encode(action act, position pos, coder &e)
   40 {
   41   switch (act) {
   42     case READ:
   43       e.encode(inst::constpush,(item)(vm::callable*)new vm::bfunc(f));
   44       break;
   45     case WRITE:
   46       bltinError(pos);
   47       break;
   48     case CALL:
   49       e.encode(inst::builtin, f);
   50       break;
   51   }
   52 }
   53 
   54 void bltinAccess::encode(action act, position pos, coder &e, frame *)
   55 {
   56   e.encode(inst::pop);
   57   encode(act, pos, e);
   58 }
   59   
   60 /* callableAccess */
   61 void callableAccess::encode(action act, position pos, coder &e)
   62 {
   63   switch (act) {
   64     case READ:
   65       e.encode(inst::constpush, (item)f);
   66       break;
   67     case WRITE:
   68       bltinError(pos);
   69       break;
   70     case CALL:
   71       this->encode(READ, pos, e);
   72       e.encode(inst::popcall);
   73       break;
   74   }
   75 }
   76 
   77 void callableAccess::encode(action act, position pos, coder &e, frame *)
   78 {
   79   e.encode(inst::pop);
   80   encode(act, pos, e);
   81 }
   82   
   83 
   84 /* frameAccess */
   85 void frameAccess::encode(action act, position pos, coder &e)
   86 {
   87   if (act == READ) {
   88     if (!e.encode(f)) {
   89       em.compiler(pos);
   90       em << "encoding frame out of context";
   91     }
   92   }
   93   else
   94     access::encode(act, pos, e);
   95 }
   96 
   97 void frameAccess::encode(action act, position pos, coder &e, frame *top)
   98 {
   99   if (act == READ) {
  100     if (!e.encode(f, top)) {
  101       em.compiler(pos);
  102       em << "encoding frame out of context";
  103     }
  104   }
  105   else
  106     access::encode(act, pos, e, top);
  107 }
  108 
  109 /* localAccess */
  110 static void frameError(position pos) {
  111   // A local variable is being used when its frame is not active.
  112   em.error(pos);
  113   em << "static use of dynamic variable";
  114 }
  115 
  116 void localAccess::encode(action act, position pos, coder &e)
  117 {
  118   // Get the active frame of the virtual machine.
  119   frame *active = e.getFrame();
  120   if (level == active) {
  121     e.encode(act == WRITE ? inst::varsave : inst::varpush,
  122              offset);
  123   }
  124   else if (e.encode(level)) {
  125       e.encode(act == WRITE ? inst::fieldsave : inst::fieldpush,
  126                offset);
  127   }
  128   else {
  129     frameError(pos);
  130   }
  131 
  132   if (act == CALL)
  133     e.encode(inst::popcall);
  134 }
  135 
  136 void localAccess::encode(action act, position pos, coder &e, frame *top)
  137 {
  138   if (e.encode(level,top)) {
  139     e.encode(act == WRITE ? inst::fieldsave : inst::fieldpush,
  140              offset);
  141     if (act == CALL)
  142       e.encode(inst::popcall);
  143   }
  144   else {
  145     frameError(pos);
  146   }
  147 }
  148 
  149 
  150 void qualifiedAccess::encode(action act, position pos, coder &e)
  151 {
  152   qualifier->encode(READ, pos, e);
  153   field->encode(act, pos, e, qualifierLevel);
  154 }
  155 
  156 void qualifiedAccess::encode(action act, position pos, coder &e, frame *top)
  157 {
  158   qualifier->encode(READ, pos, e, top);
  159   field->encode(act, pos, e, qualifierLevel);
  160 }
  161 
  162     
  163 } // namespace trans