浏览代码

Endlosschleifenproblem behoben

Kolja Strohm 6 年之前
父节点
当前提交
2fb84b12c1
共有 3 个文件被更改,包括 3 次插入80 次删除
  1. 1 78
      src/animation/Memory.java
  2. 1 1
      src/codelines/FunctionDefinition.java
  3. 1 1
      src/codelines/IfLoop.java

+ 1 - 78
src/animation/Memory.java

@@ -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;

+ 1 - 1
src/codelines/FunctionDefinition.java

@@ -18,7 +18,7 @@ public class FunctionDefinition extends CodeLine {
 	
 	@Override
 	public ControlFlow runForward(Memory m) {
-		if( !m.isDefined( "line_" + lineId + "_inside", MemoryType.CURRENT ) )
+		if( !m.isDefined( "line_" + lineId + "_inside", MemoryType.LOCAL ) )
 		{
 			m.addFrame( new StackFrame( FrameType.FUNCTION ) );
 			m.declare( "line_" + lineId + "_inside", true, MemoryType.LOCAL );

+ 1 - 1
src/codelines/IfLoop.java

@@ -16,7 +16,7 @@ public abstract class IfLoop extends CodeLine {
 
 	@Override
 	public ControlFlow runForward(Memory m) {
-		if( m.isDefined( "line_" + lineId + "_inside", MemoryType.CURRENT ) )
+		if( m.isDefined( "line_" + lineId + "_inside", MemoryType.LOCAL ) )
 		{
 			StackFrame old = m.removeFrame();
 			actions.push( (Memory mem) -> {