|
@@ -14,6 +14,10 @@ public class FunctionDefinition extends CodeLine {
|
|
|
|
|
|
private String[] params;
|
|
private String[] params;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Erstellt eine neue Funktion
|
|
|
|
+ * @param params Eine Liste mit Namen von Argumenten die automatisch beim Aufruf aus den Globalen Registern in das neue Stackframe geladen werden sollen
|
|
|
|
+ */
|
|
public FunctionDefinition( String[] params )
|
|
public FunctionDefinition( String[] params )
|
|
{
|
|
{
|
|
this.params = params;
|
|
this.params = params;
|
|
@@ -22,19 +26,19 @@ public class FunctionDefinition extends CodeLine {
|
|
@Override
|
|
@Override
|
|
public ControlFlow runForward(Memory m) {
|
|
public ControlFlow runForward(Memory m) {
|
|
if( !m.isDefined( "line_" + lineId + "_inside", Visibility.LOCAL ) )
|
|
if( !m.isDefined( "line_" + lineId + "_inside", Visibility.LOCAL ) )
|
|
- {
|
|
|
|
- m.addFrame( new StackFrame( FrameType.FUNCTION ) );
|
|
|
|
|
|
+ { // Funktion wurde noch nicht aufgerufen
|
|
|
|
+ m.addFrame( new StackFrame( FrameType.FUNCTION ) ); // Füge neues Stackframe hinzu
|
|
m.declare( "line_" + lineId + "_inside", true, Visibility.LOCAL );
|
|
m.declare( "line_" + lineId + "_inside", true, Visibility.LOCAL );
|
|
int index = 1;
|
|
int index = 1;
|
|
Object[] olds = new Object[ params.length ];
|
|
Object[] olds = new Object[ params.length ];
|
|
for( String p : params )
|
|
for( String p : params )
|
|
- {
|
|
|
|
|
|
+ { // Lade alle Parameter aus den Globalen Registern
|
|
olds[ index - 1 ] = m.read( "param" + index, Visibility.GLOBAL );
|
|
olds[ index - 1 ] = m.read( "param" + index, Visibility.GLOBAL );
|
|
- m.declare( p, olds[ index - 1 ], Visibility.LOCAL );
|
|
|
|
|
|
+ m.declare( p, olds[ index - 1 ], Visibility.LOCAL ); // Speichere sie im Stack
|
|
m.undeclare( "param" + index, Visibility.GLOBAL );
|
|
m.undeclare( "param" + index, Visibility.GLOBAL );
|
|
index++;
|
|
index++;
|
|
}
|
|
}
|
|
- actions.push( (Memory mem) -> {
|
|
|
|
|
|
+ actions.push( (Memory mem) -> { // merkt sich die Rückwärtsaktion
|
|
mem.removeFrame();
|
|
mem.removeFrame();
|
|
int i = 1;
|
|
int i = 1;
|
|
for( @SuppressWarnings("unused") String p : params )
|
|
for( @SuppressWarnings("unused") String p : params )
|
|
@@ -43,10 +47,10 @@ public class FunctionDefinition extends CodeLine {
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|
|
} );
|
|
} );
|
|
- return new ControlFlow( ControlFlow.STEP_INTO );
|
|
|
|
|
|
+ return new ControlFlow( ControlFlow.STEP_INTO ); // springe in die Funktion
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {
|
|
|
|
|
|
+ { // Funktion ist bereits follständig ausgeführt worden
|
|
StackFrame frame = m.removeFrame();
|
|
StackFrame frame = m.removeFrame();
|
|
actions.push( (Memory mem) -> {
|
|
actions.push( (Memory mem) -> {
|
|
mem.addFrame( frame );
|
|
mem.addFrame( frame );
|