-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from UQuark/advanced-control-flow
add JAB instruction & MOV labels support
- Loading branch information
Showing
6 changed files
with
117 additions
and
1 deletion.
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
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
23 changes: 23 additions & 0 deletions
23
...va/li/cil/tis3d/common/module/execution/instruction/JumpAbsoluteImmediateInstruction.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,23 @@ | ||
package li.cil.tis3d.common.module.execution.instruction; | ||
|
||
import li.cil.tis3d.common.module.execution.Machine; | ||
import li.cil.tis3d.common.module.execution.target.Target; | ||
import li.cil.tis3d.common.module.execution.target.TargetInterface; | ||
|
||
public class JumpAbsoluteImmediateInstruction implements Instruction { | ||
private final short pc; | ||
|
||
public JumpAbsoluteImmediateInstruction(final short pc) { | ||
this.pc = pc; | ||
} | ||
|
||
@Override | ||
public void step(final Machine machine) { | ||
machine.getState().pc = pc; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return JumpAbsoluteInstruction.NAME + " " + pc; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...c/main/java/li/cil/tis3d/common/module/execution/instruction/JumpAbsoluteInstruction.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,32 @@ | ||
package li.cil.tis3d.common.module.execution.instruction; | ||
|
||
import li.cil.tis3d.common.module.execution.Machine; | ||
import li.cil.tis3d.common.module.execution.target.Target; | ||
import li.cil.tis3d.common.module.execution.target.TargetInterface; | ||
|
||
public class JumpAbsoluteInstruction implements Instruction { | ||
public static final String NAME = "JAB"; | ||
|
||
private final Target source; | ||
|
||
public JumpAbsoluteInstruction(final Target source) { | ||
this.source = source; | ||
} | ||
|
||
@Override | ||
public void step(final Machine machine) { | ||
final TargetInterface sourceInterface = machine.getInterface(source); | ||
|
||
if (!sourceInterface.isReading()) { | ||
sourceInterface.beginRead(); | ||
} | ||
if (sourceInterface.canTransfer()) { | ||
machine.getState().pc = sourceInterface.read(); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return NAME + " " + source; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../src/main/java/li/cil/tis3d/common/module/execution/instruction/MoveLabelInstruction.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,31 @@ | ||
package li.cil.tis3d.common.module.execution.instruction; | ||
|
||
import li.cil.tis3d.common.module.execution.Machine; | ||
import li.cil.tis3d.common.module.execution.target.Target; | ||
import li.cil.tis3d.common.module.execution.target.TargetInterface; | ||
|
||
public class MoveLabelInstruction extends AbstractMoveInstruction { | ||
private final String label; | ||
|
||
public MoveLabelInstruction(final String label, final Target destination) { | ||
super(destination); | ||
this.label = label; | ||
} | ||
|
||
@Override | ||
public void step(final Machine machine) { | ||
final TargetInterface destinationInterface = machine.getInterface(destination); | ||
int addr = machine.getState().labels.get(label); | ||
|
||
if (!destinationInterface.isWriting()) { | ||
if (destinationInterface.beginWrite((short) addr)) { | ||
machine.getState().pc++; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoveInstruction.NAME + " " + label + " " + destination; | ||
} | ||
} |