From ad547a6b5986815fda458221149728d9d9ab1d87 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 25 Feb 2021 19:22:25 +0000 Subject: restore Build,TODO from r57911 git-svn-id: svn://tug.org/texlive/trunk@57915 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/utils/asymptote/refaccess.h | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Build/source/utils/asymptote/refaccess.h (limited to 'Build/source/utils/asymptote/refaccess.h') diff --git a/Build/source/utils/asymptote/refaccess.h b/Build/source/utils/asymptote/refaccess.h new file mode 100644 index 00000000000..3357438115a --- /dev/null +++ b/Build/source/utils/asymptote/refaccess.h @@ -0,0 +1,90 @@ +/***** + * 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 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 +void pointerRead(vm::stack *s) { + T *ptr=vm::pop(s); + s->push(*ptr); +} + +template +void pointerWrite(vm::stack *s) { + T *ptr=vm::pop(s); + T value=vm::pop(s); + *ptr=value; + s->push(value); +} + +template +void refAccess::encode(action act, position, coder &e) +{ + // You may be able to use typeid(T).name() to get a better label. + REGISTER_BLTIN((bltin) pointerRead, "pointerRead"); + REGISTER_BLTIN((bltin) pointerWrite, "pointerWrite"); + + e.encode(vm::inst::constpush, (vm::item)ref); + + switch (act) { + case READ: + e.encode(vm::inst::builtin, (bltin) pointerRead); + break; + case WRITE: + e.encode(vm::inst::builtin, (bltin) pointerWrite); + break; + case CALL: + e.encode(vm::inst::builtin, (bltin) pointerRead); + e.encode(vm::inst::popcall); + break; + }; +} + +template +void refAccess::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 -- cgit v1.2.3