|
@@ -9,7 +9,8 @@ public class Memory {
|
|
|
public enum MemoryType
|
|
|
{
|
|
|
GLOBAL,
|
|
|
- LOCAL
|
|
|
+ LOCAL,
|
|
|
+ COMPLETE_STACK
|
|
|
}
|
|
|
|
|
|
public class ReadOnlyMemory
|
|
@@ -67,6 +68,7 @@ public class Memory {
|
|
|
case GLOBAL:
|
|
|
this.global.declare( name, value );
|
|
|
break;
|
|
|
+ case COMPLETE_STACK:
|
|
|
case LOCAL:
|
|
|
if( stack.size() == 0 )
|
|
|
return;
|
|
@@ -82,6 +84,7 @@ public class Memory {
|
|
|
case GLOBAL:
|
|
|
this.global.set( name, value );
|
|
|
break;
|
|
|
+ case COMPLETE_STACK:
|
|
|
case LOCAL:
|
|
|
int index = stack.size() - 1;
|
|
|
while( index >= 0 ) {
|
|
@@ -99,12 +102,12 @@ public class Memory {
|
|
|
|
|
|
public <T> T read( String name, MemoryType type )
|
|
|
{
|
|
|
+ int index = stack.size() - 1;
|
|
|
switch( type )
|
|
|
{
|
|
|
case GLOBAL:
|
|
|
return this.global.get( name );
|
|
|
case LOCAL:
|
|
|
- int index = stack.size() - 1;
|
|
|
while( index >= 0 ) {
|
|
|
StackFrame stackF = stack.get( index-- );
|
|
|
if( stackF.isDefined( name ) )
|
|
@@ -112,18 +115,25 @@ public class Memory {
|
|
|
if( stackF.getType() == FrameType.FUNCTION )
|
|
|
break;
|
|
|
}
|
|
|
+ break;
|
|
|
+ case COMPLETE_STACK:
|
|
|
+ while( index >= 0 ) {
|
|
|
+ StackFrame stackF = stack.get( index-- );
|
|
|
+ if( stackF.isDefined( name ) )
|
|
|
+ return stackF.get( name );
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public boolean isSomewhereDefined( String name, MemoryType type )
|
|
|
{
|
|
|
+ int index = stack.size() - 1;
|
|
|
switch( type )
|
|
|
{
|
|
|
case GLOBAL:
|
|
|
return this.global.isDefined( name );
|
|
|
case LOCAL:
|
|
|
- int index = stack.size() - 1;
|
|
|
while( index >= 0 ) {
|
|
|
StackFrame stackF = stack.get( index-- );
|
|
|
if( stackF.isDefined( name ) )
|
|
@@ -131,6 +141,13 @@ public class Memory {
|
|
|
if( stackF.getType() == FrameType.FUNCTION )
|
|
|
break;
|
|
|
}
|
|
|
+ break;
|
|
|
+ case COMPLETE_STACK:
|
|
|
+ while( index >= 0 ) {
|
|
|
+ StackFrame stackF = stack.get( index-- );
|
|
|
+ if( stackF.isDefined( name ) )
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@@ -141,6 +158,7 @@ public class Memory {
|
|
|
{
|
|
|
case GLOBAL:
|
|
|
return this.global.isDefined( name );
|
|
|
+ case COMPLETE_STACK:
|
|
|
case LOCAL:
|
|
|
if( stack.size() == 0 )
|
|
|
return false;
|
|
@@ -156,6 +174,7 @@ public class Memory {
|
|
|
case GLOBAL:
|
|
|
this.global.undeclare( name );
|
|
|
break;
|
|
|
+ case COMPLETE_STACK:
|
|
|
case LOCAL:
|
|
|
if( stack.size() == 0 )
|
|
|
return;
|