A New Revealation: Semi-Permeable Membranes

Per Bothner per@bothner.com
26 Oct 1999 20:47:39 -0700


"Mark S. Miller" <markm@caplet.com> writes:

> >The gnu.bytecode.Type is an abstract "type" concept, similar
> >to your SlotGuard idea.  It includes the following methods:
> >
> >public abstract class Type {
> >   ...
> >
> >   public abstract Object coerceFromObject (Object obj);
> >
> >   public Object coerceToObject (Object obj)
> >   {
> >     return obj;
> >   }
> >   /** Compile code to convert an object (on the stack) to this Type. */
> >   public void emitCoerceToObject (CodeAttr code)
> >   {
> >   }
> >
> >   /** Compile code to coerce/convert from Object to this type. */
> >   public void emitCoerceFromObject (CodeAttr code)
> >   {
> >     throw new Error ("unimplemented emitCoerceFromObject for "+this);
> >   }
> >}
> 
> Sorry, I didn't get it.  Could you provide some examples?

T.coerceFromObject(x) is used to coerce a value x from Object to type T.
T.coerceToObject(x) is used use to coerce a value x from type T to Object.
These can be used by an evaluator.

The compiler calls T.emitCoerceFromObject(compilation_state) to
generate code to convert an Object instance on the JVM evaluation stack,
leaving a T (which may be a primitive type) on the stack.
emitCoerceToObject does the opposite conversion.
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/