summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/refaccess.h
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-05-16 00:19:13 +0000
committerKarl Berry <karl@freefriends.org>2009-05-16 00:19:13 +0000
commitbab45528d65eaafe68a705dbb2a57075c7b7cbd8 (patch)
tree10b4ae2b5195c8dede153ab89359ec00f55f325f /Build/source/utils/asymptote/refaccess.h
parent8643d90372e9c31e0f461c15c596b60a545bd7d3 (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/refaccess.h')
-rw-r--r--Build/source/utils/asymptote/refaccess.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/refaccess.h b/Build/source/utils/asymptote/refaccess.h
new file mode 100644
index 00000000000..c848f8f171d
--- /dev/null
+++ b/Build/source/utils/asymptote/refaccess.h
@@ -0,0 +1,86 @@
+/*****
+ * refaccess.h
+ * Andy Hammerlindl 2003/12/03
+ *
+ * An access which refers to a variable or other object in C++.
+ *****/
+
+#ifndef REFACCESS_H
+#define REFACCESS_H
+
+#include "access.h"
+#include "inst.h"
+#include "coder.h"
+#include "stack.h"
+
+namespace trans {
+
+// Access refers to a piece of data, represented by an item, somewhere in the
+// C++ code.
+class itemRefAccess : public access {
+ vm::item *ref;
+
+public:
+ itemRefAccess(vm::item *ref)
+ : ref(ref) {}
+
+ void encode(action act, position pos, coder &e);
+ void encode(action act, position pos, coder &e, frame *);
+};
+
+// Access refers to an arbitrary piece of data of type T.
+template <class T>
+class refAccess : public access {
+ T *ref;
+
+public:
+ refAccess(T *ref)
+ : ref(ref) {}
+
+ void encode(action act, position pos, coder &e);
+ void encode(action act, position pos, coder &e, frame *);
+};
+
+template <class T>
+void pointerRead(vm::stack *s) {
+ T *ptr=vm::pop<T *>(s);
+ s->push(*ptr);
+}
+
+template <class T>
+void pointerWrite(vm::stack *s) {
+ T *ptr=vm::pop<T *>(s);
+ T value=vm::pop<T>(s);
+ *ptr=value;
+ s->push(value);
+}
+
+template <class T>
+void refAccess<T>::encode(action act, position, coder &e)
+{
+ e.encode(vm::inst::constpush, (vm::item)ref);
+
+ switch (act) {
+ case READ:
+ e.encode(vm::inst::builtin, (bltin) pointerRead<T>);
+ break;
+ case WRITE:
+ e.encode(vm::inst::builtin, (bltin) pointerWrite<T>);
+ break;
+ case CALL:
+ e.encode(vm::inst::builtin, (bltin) pointerRead<T>);
+ e.encode(vm::inst::popcall);
+ break;
+ };
+}
+
+template <class T>
+void refAccess<T>::encode(action act, position pos, coder &e, frame *)
+{
+ // Get rid of the useless top frame.
+ e.encode(vm::inst::pop);
+ encode(act, pos, e);
+}
+
+}
+#endif