diff options
author | Karl Berry <karl@freefriends.org> | 2009-08-15 23:57:48 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-08-15 23:57:48 +0000 |
commit | 16d128e5e10d541a78654b86409d5a3539f07708 (patch) | |
tree | 66de0af63c3811bb3040c16e9b52c11985f70811 /Build/source/utils/asymptote/virtualfieldaccess.h | |
parent | b20f78c549859ec0e8610bdd3ad904245e86b489 (diff) |
asymptote 1.83
git-svn-id: svn://tug.org/texlive/trunk@14696 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/virtualfieldaccess.h')
-rw-r--r-- | Build/source/utils/asymptote/virtualfieldaccess.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/virtualfieldaccess.h b/Build/source/utils/asymptote/virtualfieldaccess.h new file mode 100644 index 00000000000..115900733ce --- /dev/null +++ b/Build/source/utils/asymptote/virtualfieldaccess.h @@ -0,0 +1,49 @@ +/***** + * virtualfieldaccess.h + * Andy Hammerlindl 2009/07/23 + * + * Implements the access subclass used to read and write virtual fields. + *****/ + +#include "access.h" + +namespace trans { +// In code such as +// pair z; write(z.x); +// to evaluate the expression z.x, first z is pushed onto the stack, then as +// it is not a record, instead of accessing its field in the usual way for a +// record, a builtin function is called which pops z off the stack and +// replaces it with z.x. virtualFieldAccess provides the access for the +// virtualField 'x', and 'getter' is the access to the builtin function which +// replaces z with z.x. +// +// If the virtual field z.x were mutable, then setter would access a builtin +// function, which pops a real number and then z off of the stack, sets the +// z.x to that new value, and puts the value back on the stack. In this case, +// pairs are immutable, but other virtual fields may not be. +class virtualFieldAccess : public access { + access *getter; + access *setter; + + // As an optimization could add a 'caller' field, to handle calls to + // functions such as 'a.push(x)' where a is an array more efficiently. +public: + virtualFieldAccess(access *getter, access *setter = 0) + : getter(getter), setter(setter) {} + + virtualFieldAccess(vm::bltin getter, vm::bltin setter = 0) + : getter(new bltinAccess(getter)), + setter(setter ? new bltinAccess(setter) : 0) {} + + void encode(action act, position pos, coder &e); + void encode(action act, position pos, coder &e, frame *); + + // Attempting to WRITE a read-only field will give an error, but if the + // error is caught at a higher level, a better error message (including the + // name of the field) can be given. This function allows such handling. + bool readonly() { + return (bool)setter; + } +}; + +} // namespace trans |