summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/refaccess.cc
blob: 32bc6607356b5be699214debf12889af14b30d5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*****
 * refaccess.cc
 * Andy Hammerlindl 2005/11/28
 *
 * An access which refers to a variable or other object in C++.
 *****/

#include "refaccess.h"

namespace trans {
  
using vm::item;
using vm::stack;
using vm::pop;

/* itemRefAccess */
void itemPointerRead(stack *s) {
  item *p=pop<item *>(s);
  s->push(*p);
}

void itemPointerWrite(stack *s) {
  item *p=pop<item *>(s);
  item value=pop(s);
  *p=value;
  s->push(value);
}

void itemRefAccess::encode(action act, position, coder &e)
{
  e.encode(inst::constpush, (item)ref);

  switch (act) {
    case READ:
      e.encode(inst::builtin, itemPointerRead);
      break;
    case WRITE:
      e.encode(inst::builtin, itemPointerWrite);
      break;
    case CALL:
      e.encode(inst::builtin, itemPointerRead);
      e.encode(inst::popcall);
      break;
  };
}

void itemRefAccess::encode(action act, position pos, coder &e, frame *)
{
  // Get rid of the useless top frame.
  e.encode(inst::pop);
  encode(act, pos, e);
}

}