diff options
author | Karl Berry <karl@freefriends.org> | 2009-05-16 00:19:13 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-05-16 00:19:13 +0000 |
commit | bab45528d65eaafe68a705dbb2a57075c7b7cbd8 (patch) | |
tree | 10b4ae2b5195c8dede153ab89359ec00f55f325f /Build/source/utils/asymptote/access.cc | |
parent | 8643d90372e9c31e0f461c15c596b60a545bd7d3 (diff) |
asymptote 1.72 sources (not integrated into build yet)
git-svn-id: svn://tug.org/texlive/trunk@13110 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/access.cc')
-rw-r--r-- | Build/source/utils/asymptote/access.cc | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/access.cc b/Build/source/utils/asymptote/access.cc new file mode 100644 index 00000000000..60aee6fa659 --- /dev/null +++ b/Build/source/utils/asymptote/access.cc @@ -0,0 +1,133 @@ +/***** + * access.cc + * Andy Hammerlindl 2003/12/03 + * Describes an "access," a representation of where a variable will be + * stored at runtime, so that read, write, and call instructions can be + * made. + *****/ + +#include "access.h" +#include "frame.h" +#include "coder.h" +#include "callable.h" + +using vm::item; + +namespace trans { + +/* access */ +access::~access() +{} + +/* identAccess */ +void identAccess::encode(action act, position pos, coder& e) +{ + if (act != CALL) { + access::encode(act, pos, e); + } + // else - do nothing +} + + +/* bltinAccess */ +static void bltinError(position pos) +{ + em.error(pos); + em << "built-in functions cannot be modified"; +} + +void bltinAccess::encode(action act, position pos, coder &e) +{ + switch (act) { + case READ: + e.encode(inst::constpush,(item)(vm::callable*)new vm::bfunc(f)); + break; + case WRITE: + bltinError(pos); + break; + case CALL: + e.encode(inst::builtin, f); + break; + } +} + +void bltinAccess::encode(action act, position pos, coder &e, frame *) +{ + e.encode(inst::pop); + encode(act, pos, e); +} + + +/* frameAccess */ +void frameAccess::encode(action act, position pos, coder &e) +{ + if (act == READ) { + if (!e.encode(f)) { + em.compiler(pos); + em << "encoding frame out of context"; + } + } + else + access::encode(act, pos, e); +} + +void frameAccess::encode(action act, position pos, coder &e, frame *top) +{ + if (act == READ) { + if (!e.encode(f, top)) { + em.compiler(pos); + em << "encoding frame out of context"; + } + } + else + access::encode(act, pos, e, top); +} + +/* localAccess */ +void localAccess::encode(action act, position pos, coder &e) +{ + // Get the active frame of the virtual machine. + frame *active = e.getFrame(); + if (level == active) { + e.encode(act == WRITE ? inst::varsave : inst::varpush, + offset); + if (act == CALL) + e.encode(inst::popcall); + } + else { + // Put the parent frame (in local variable 0) on the stack. + e.encode(inst::varpush,0); + + // Encode the access from that frame. + this->encode(act, pos, e, active->getParent()); + } +} + +void localAccess::encode(action act, position pos, coder &e, frame *top) +{ + if (e.encode(level,top)) { + e.encode(act == WRITE ? inst::fieldsave : inst::fieldpush, + offset); + if (act == CALL) + e.encode(inst::popcall); + } + else { + // The local variable is being used when its frame is not active. + em.error(pos); + em << "static use of dynamic variable"; + } +} + + +void qualifiedAccess::encode(action act, position pos, coder &e) +{ + qualifier->encode(READ, pos, e); + field->encode(act, pos, e, qualifierLevel); +} + +void qualifiedAccess::encode(action act, position pos, coder &e, frame *top) +{ + qualifier->encode(READ, pos, e, top); + field->encode(act, pos, e, qualifierLevel); +} +} // namespace trans |