/*****
* 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.
*****/
/* 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 */
static void frameError(position pos) {
// A local variable is being used when its frame is not active.
em.error(pos);
em << "static use of dynamic variable";
}
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);
}
else if (e.encode(level)) {
e.encode(act == WRITE ? inst::fieldsave : inst::fieldpush,
offset);
}
else {
frameError(pos);
}