|
@@ -9,11 +9,9 @@ public class Memory {
|
|
|
public enum MemoryType
|
|
|
{
|
|
|
GLOBAL,
|
|
|
- LOCAL,
|
|
|
- CURRENT
|
|
|
+ LOCAL
|
|
|
}
|
|
|
|
|
|
- private StackFrame current;
|
|
|
private StackFrame global;
|
|
|
private Stack< StackFrame > stack;
|
|
|
|
|
@@ -21,7 +19,6 @@ public class Memory {
|
|
|
{
|
|
|
stack = new Stack<StackFrame>();
|
|
|
global = new StackFrame( FrameType.FUNCTION );
|
|
|
- current = null;
|
|
|
}
|
|
|
|
|
|
public int getSize()
|
|
@@ -29,11 +26,6 @@ public class Memory {
|
|
|
return stack.size();
|
|
|
}
|
|
|
|
|
|
- public void setCurrent( StackFrame frame )
|
|
|
- {
|
|
|
- this.current = frame;
|
|
|
- }
|
|
|
-
|
|
|
public void addFrame( StackFrame frame )
|
|
|
{
|
|
|
stack.push( frame );
|
|
@@ -51,10 +43,6 @@ public class Memory {
|
|
|
case GLOBAL:
|
|
|
this.global.declare( name, value );
|
|
|
break;
|
|
|
- case CURRENT:
|
|
|
- if( current != null )
|
|
|
- current.declare( name, value );
|
|
|
- break;
|
|
|
case LOCAL:
|
|
|
if( stack.size() == 0 )
|
|
|
return;
|
|
@@ -70,27 +58,6 @@ public class Memory {
|
|
|
case GLOBAL:
|
|
|
this.global.set( name, value );
|
|
|
break;
|
|
|
- case CURRENT:
|
|
|
- if( current != null )
|
|
|
- {
|
|
|
- int index = stack.size() - 1;
|
|
|
- while( index >= 0 && stack.get( index ) != current ) {
|
|
|
- index--;
|
|
|
- }
|
|
|
- if( index < 0 )
|
|
|
- break;
|
|
|
- while( index >= 0 ) {
|
|
|
- StackFrame stackF = stack.get( index-- );
|
|
|
- if( stackF.isDefined( name ) )
|
|
|
- {
|
|
|
- stackF.set( name, value );
|
|
|
- return;
|
|
|
- }
|
|
|
- if( stackF.getType() == FrameType.FUNCTION )
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
case LOCAL:
|
|
|
int index = stack.size() - 1;
|
|
|
while( index >= 0 ) {
|
|
@@ -112,24 +79,6 @@ public class Memory {
|
|
|
{
|
|
|
case GLOBAL:
|
|
|
return this.global.get( name );
|
|
|
- case CURRENT:
|
|
|
- if( current != null )
|
|
|
- {
|
|
|
- int index = stack.size() - 1;
|
|
|
- while( index >= 0 && stack.get( index ) != current ) {
|
|
|
- index--;
|
|
|
- }
|
|
|
- if( index < 0 )
|
|
|
- break;
|
|
|
- while( index >= 0 ) {
|
|
|
- StackFrame stackF = stack.get( index-- );
|
|
|
- if( stackF.isDefined( name ) )
|
|
|
- return stackF.get( name );
|
|
|
- if( stackF.getType() == FrameType.FUNCTION )
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
case LOCAL:
|
|
|
int index = stack.size() - 1;
|
|
|
while( index >= 0 ) {
|
|
@@ -149,24 +98,6 @@ public class Memory {
|
|
|
{
|
|
|
case GLOBAL:
|
|
|
return this.global.isDefined( name );
|
|
|
- case CURRENT:
|
|
|
- if( current != null )
|
|
|
- {
|
|
|
- int index = stack.size() - 1;
|
|
|
- while( index >= 0 && stack.get( index ) != current ) {
|
|
|
- index--;
|
|
|
- }
|
|
|
- if( index < 0 )
|
|
|
- break;
|
|
|
- while( index >= 0 ) {
|
|
|
- StackFrame stackF = stack.get( index-- );
|
|
|
- if( stackF.isDefined( name ) )
|
|
|
- return true;
|
|
|
- if( stackF.getType() == FrameType.FUNCTION )
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
case LOCAL:
|
|
|
int index = stack.size() - 1;
|
|
|
while( index >= 0 ) {
|
|
@@ -186,10 +117,6 @@ public class Memory {
|
|
|
{
|
|
|
case GLOBAL:
|
|
|
return this.global.isDefined( name );
|
|
|
- case CURRENT:
|
|
|
- if( current != null)
|
|
|
- return current.isDefined( name );
|
|
|
- return false;
|
|
|
case LOCAL:
|
|
|
if( stack.size() == 0 )
|
|
|
return false;
|
|
@@ -205,10 +132,6 @@ public class Memory {
|
|
|
case GLOBAL:
|
|
|
this.global.undeclare( name );
|
|
|
break;
|
|
|
- case CURRENT:
|
|
|
- if( current != null )
|
|
|
- current.undeclare( name );
|
|
|
- break;
|
|
|
case LOCAL:
|
|
|
if( stack.size() == 0 )
|
|
|
return;
|