package runEnv; import env.*; import type.*; public class RunEnv { /* Represents the run time environment, composed of the globals, current instance, and current invocation. */ private StaticValue currentStatic; private InstanceValue currentInstance; private InvocationValue currentInvocation; public StaticValue currentStatic() { return currentStatic; } public InstanceValue currentInstance() { return currentInstance; } public InvocationValue currentInvocation() { return currentInvocation; } public RunEnv( StaticValue currentStatic, InstanceValue currentInstance, InvocationValue currentInvocation ) { this.currentStatic = currentStatic; this.currentInstance = currentInstance; this.currentInvocation = currentInvocation; } public RunData getData( Decl decl ) { switch ( decl.section() ) { case Decl.SECT_GLOBAL: case Decl.SECT_STATIC: return currentStatic.fields().getData( decl.offset() ); case Decl.SECT_INSTANCE: return currentInstance.fields().getData( decl.offset() ); case Decl.SECT_VARPARAM: return currentInvocation.locals().getValue( decl.offset() ).dataValue(); case Decl.SECT_VALUEPARAM: case Decl.SECT_LOCAL: return currentInvocation.locals().getData( decl.offset() ); default: throw new Error( "Invalid section in declaration of " + decl.section() ); } } }