summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/program.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/program.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/program.h')
-rw-r--r--Build/source/utils/asymptote/program.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/program.h b/Build/source/utils/asymptote/program.h
new file mode 100644
index 00000000000..c6e37562bc5
--- /dev/null
+++ b/Build/source/utils/asymptote/program.h
@@ -0,0 +1,89 @@
+/*****
+ * program.h
+ * Tom Prince
+ *
+ * The list of instructions used by the virtual machine.
+ *****/
+
+#ifndef PROGRAM_H
+#define PROGRAM_H
+
+#include "common.h"
+#include "inst.h"
+
+namespace vm {
+class inst;
+
+class program : public gc {
+public:
+ class label;
+ program();
+ void encode(inst i);
+ label begin();
+ label end();
+private:
+ friend class label;
+ typedef mem::vector<inst> code_t;
+ code_t code;
+ inst& operator[](size_t);
+};
+
+class program::label
+{
+public: // interface
+ label() : where(0), code() {}
+public: //interface
+ label& operator++();
+ label& operator--();
+ bool operator==(const label& right) const;
+ bool operator!=(const label& right) const;
+ inst& operator*() const;
+ inst* operator->() const;
+ friend ptrdiff_t offset(const label& left,
+ const label& right);
+private:
+ label (size_t where, program* code)
+ : where(where), code(code) {}
+ size_t where;
+ program* code;
+ friend class program;
+};
+
+// Prints one instruction (including arguments) and returns how many
+// positions in the code stream were shown.
+void printInst(std::ostream& out, const program::label& code,
+ const program::label& base);
+
+// Prints code until a ret opcode is printed.
+void print(std::ostream& out, program *base);
+
+// Inline forwarding functions for vm::program
+inline program::program()
+ : code() {}
+inline program::label program::end()
+{ return label(code.size(), this); }
+inline program::label program::begin()
+{ return label(0, this); }
+inline void program::encode(inst i)
+{ code.push_back(i); }
+inline inst& program::operator[](size_t n)
+{ return code[n]; }
+inline program::label& program::label::operator++()
+{ ++where; return *this; }
+inline program::label& program::label::operator--()
+{ --where; return *this; }
+inline bool program::label::operator==(const label& right) const
+{ return (code == right.code) && (where == right.where); }
+inline bool program::label::operator!=(const label& right) const
+{ return !(*this == right); }
+inline inst& program::label::operator*() const
+{ return (*code)[where]; }
+inline inst* program::label::operator->() const
+{ return &**this; }
+inline ptrdiff_t offset(const program::label& left,
+ const program::label& right)
+{ return right.where - left.where; }
+
+} // namespace vm
+
+#endif // PROGRAM_H