package runEnv; import env.*; public class RunEnv { /* Represents the run time environment, composed of the globals, current instance, and current invocation. */ private PtrValue globals; private PtrValue instance; private PtrValue locals; public PtrValue globals() { return globals; } public PtrValue instance() { return instance; } public PtrValue locals() { return locals; } public RunEnv( PtrValue globals, PtrValue instance, PtrValue locals ) { this.globals = globals; this.instance = instance; this.locals = locals; } public RunEnv( PtrValue globals ) { this.globals = globals; this.instance = null; this.locals = null; } public PtrValue elementAt( Decl decl ) { switch ( decl.env().envKind() ) { case Env.ENV_GLOBAL: return globals().elementAt( decl.offset().interp() ); case Env.ENV_CLASS: return instance().elementAt( decl.offset().interp() ); case Env.ENV_METHOD: return locals().elementAt( decl.offset().interp() ); default: throw new Error( "Invalid section of " + Decl.sectionText( decl.section() ) + " for identifier " + decl.ident() ); } } public RunValue getValue( Decl decl ) { return elementAt( decl ).getValue(); } }