12345678910111213141516171819202122232425262728293031323334 |
- package codelines;
- import animation.CodeLine;
- import animation.ControlFlow;
- import animation.Memory;
- public class DeclareVariable <T> extends CodeLine {
- private boolean oldExists;
- private T val;
- private String name;
-
- public DeclareVariable( String name, T value )
- {
- this.val = value;
- this.name = name;
- }
- @Override
- public ControlFlow runForward(Memory m) {
-
- oldExists = m.isDefined( name, false );
- T oldVal = m.read( name, false );
- m.declare( name, val, false );
- actions.add( (Memory mem) -> {
- if( !oldExists )
- m.undeclare( name, false );
- else
- m.declare( name, oldVal, false );
- return new ControlFlow( ControlFlow.STEP_OVER );
- });
- return new ControlFlow( ControlFlow.STEP_OVER );
- }
- }
|