This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Group 6 - help needed once again :D (#72)
Co-authored-by: Simon Hajek <[email protected]> Co-authored-by: Nick Möhrmann <[email protected]> Co-authored-by: nils bohland <[email protected]> Co-authored-by: Marc Auberer <[email protected]>
- Loading branch information
1 parent
838adbf
commit 6f533f4
Showing
16 changed files
with
314 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
src/main/java/com/auberer/compilerdesignlectureproject/ast/ASTParamNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...n/java/com/auberer/compilerdesignlectureproject/codegen/instructions/CallInstruction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.auberer.compilerdesignlectureproject.codegen.instructions; | ||
|
||
import com.auberer.compilerdesignlectureproject.ast.ASTCallParamsNode; | ||
import com.auberer.compilerdesignlectureproject.ast.ASTNode; | ||
import com.auberer.compilerdesignlectureproject.codegen.Function; | ||
import com.auberer.compilerdesignlectureproject.interpreter.InterpreterEnvironment; | ||
import lombok.Getter; | ||
|
||
import java.util.ListIterator; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
public class CallInstruction extends Instruction { | ||
private final Function function; | ||
private final ASTCallParamsNode callParamsNode; | ||
|
||
public CallInstruction(ASTNode node, Function function, ASTCallParamsNode callParamsNode) { | ||
super(node); | ||
this.function = function; | ||
this.callParamsNode = callParamsNode; | ||
} | ||
|
||
@Override | ||
public void run(InterpreterEnvironment env) { | ||
// Save the current instruction iterator | ||
ListIterator<Instruction> returnIterator = env.getInstructionIterator(); | ||
// Handle the function call in the interpreter environment | ||
env.callFunction(returnIterator, function); | ||
} | ||
|
||
@Override | ||
public void dumpIR(StringBuilder sb) { | ||
// call <functionName>(<params>) | ||
sb.append("call ").append(function.getName()).append("("); | ||
String params = callParamsNode.getParamsAsLogicNodes().stream().map(astLogicalExprNode -> astLogicalExprNode.getValue().getName()).collect(Collectors.joining(",")); | ||
sb.append(params).append(")"); | ||
} | ||
|
||
@Override | ||
public void trace(StringBuilder sb) { | ||
sb.append(node.getCodeLoc().toString()).append(": call "); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.