-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
44 additions
and
3 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
32 changes: 32 additions & 0 deletions
32
src/main/java/org/lucylang/ljvm/machine/instruction/GetInstruction.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 org.lucylang.ljvm.machine.instruction; | ||
|
||
import org.lucylang.ljvm.machine.Machine; | ||
import org.lucylang.ljvm.machine.Register; | ||
import org.lucylang.ljvm.machine.module.Module; | ||
import org.lucylang.ljvm.scope.OverdefinedException; | ||
import org.lucylang.ljvm.scope.UndefinedException; | ||
import org.lucylang.ljvm.type.TypeUnmatchedException; | ||
import org.lucylang.ljvm.value.StringValue; | ||
import org.lucylang.ljvm.value.ValueUnavailableException; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class GetInstruction extends Instruction { | ||
public GetInstruction(Operand value) { | ||
this.type = Type.GET; | ||
this.operands = new ArrayList<Operand>(); | ||
this.operands.add(value); | ||
|
||
this.validSize = 1; | ||
this.validRefs = new int[]{0}; | ||
} | ||
|
||
@Override | ||
public boolean executeValid(Machine vm, Module module) throws InvalidInstruction, TypeUnmatchedException, ValueUnavailableException, UndefinedException, OverdefinedException { | ||
Register r = this.getRegister(vm, 0); | ||
Scanner scanner = new Scanner(System.in); | ||
r.assignValue(new StringValue(scanner.next())); | ||
return false; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,5 +5,5 @@ public enum Type { | |
PUSH, POP, PEEK, CALL, RET, | ||
GOTO, BEQ, BNE, | ||
NUM, STR, BOOL, | ||
PUT | ||
PUT, GET | ||
} |
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