diff options
author | Karl Berry <karl@freefriends.org> | 2021-02-25 19:22:25 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-02-25 19:22:25 +0000 |
commit | ad547a6b5986815fda458221149728d9d9ab1d87 (patch) | |
tree | 16296910eb3eca724371474ea9aea3994dc69614 /Build/source/utils/asymptote/frame.h | |
parent | 947b43de3dd21d58ccc2ffadefc4441ea1c2a813 (diff) |
restore Build,TODO from r57911
git-svn-id: svn://tug.org/texlive/trunk@57915 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/frame.h')
-rw-r--r-- | Build/source/utils/asymptote/frame.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/frame.h b/Build/source/utils/asymptote/frame.h new file mode 100644 index 00000000000..9afa4c51ec4 --- /dev/null +++ b/Build/source/utils/asymptote/frame.h @@ -0,0 +1,98 @@ +/***** + * frame.h + * Andy Hammerlindl 2002/07/22 + * + * Describes the frame levels for the functions of the language. + * Also creates accesses for the variable for automated loading + * and saving of variables. + *****/ + +#ifndef FRAME_H +#define FRAME_H + +#include <cassert> + +#include "access.h" + +namespace trans { + +class frame : public gc { + frame *parent; + size_t numFormals; + Int numLocals; + + // With the SIMPLE_FRAME flag, the size of frames cannot be changed at + // runtime. This is an issue for runnable-at-a-time mode, where global + // variables can be continually added. To handle this, the frame for + // global variables is an "indirect" frame. It holds one variable, which is + // a link to another frame. When the subframe is too small, a larger + // runtime array is allocated, and the link is changed. + enum {DIRECT_FRAME, INDIRECT_FRAME} style; + +#ifdef DEBUG_FRAME + string name; +#endif + + frame(string name) + : parent(new frame("<subframe of " + name + ">", 0, 0)), + numFormals(0), numLocals(1), style(INDIRECT_FRAME) +#ifdef DEBUG_FRAME + , name(name) +#endif + {} + +public: + frame(string name, frame *parent, size_t numFormals) + : parent(parent), numFormals(numFormals), numLocals(0), + style(DIRECT_FRAME) +#ifdef DEBUG_FRAME + , name(name) +#endif + {} + + static frame *indirect_frame(string name) { + return new frame(name); + } + + frame *getParent() { + return parent; + } + + // Which variable stores the link to the parent frame. + Int parentIndex() { + return numFormals; + } + + Int size() { + if (style == DIRECT_FRAME) + return (Int) (1+numFormals+numLocals); + else + return parent->size(); + } + + access *accessFormal(size_t index) { + assert(index < numFormals); + assert(style == DIRECT_FRAME); + return new localAccess((Int) (index), this); + } + + access *allocLocal() { + if (style == DIRECT_FRAME) + return new localAccess((Int) (1 + numFormals + numLocals++), this); + else + return parent->allocLocal(); + } +}; + +inline void print(ostream& out, frame *f) { + out << f; + if (f != 0) { + out << " -> "; + print(out, f->getParent()); + } +} + +} // namespace trans + +#endif + |