Created
June 2, 2018 15:54
-
-
Save Galaxtone/53ec1d9bdb2b723c4d661ca161672021 to your computer and use it in GitHub Desktop.
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
package com.galaxtone.bytefuck.instructions; | |
public abstract class Instruction { | |
public byte getType() { | |
return 0; | |
} | |
public abstract byte getOpcode(); | |
public static abstract class IndexInstruction extends Instruction { | |
public final int index; | |
private IndexInstruction(int index) { | |
this.index = index; | |
} | |
@Override | |
public byte getType() { | |
return 1; | |
} | |
} | |
public static abstract class IndexValueInstruction extends IndexInstruction { | |
public final byte value; | |
private IndexValueInstruction(int index, short value) { | |
super(index); | |
this.value = (byte) (value & 0xFF); | |
} | |
@Override | |
public byte getType() { | |
return 2; | |
} | |
} | |
public static abstract class LongIndexInstruction extends Instruction { | |
public final long index; | |
private LongIndexInstruction(long lowerIndex, long upperIndex) { | |
this.index = (lowerIndex & 0xFFFFFFFF) | (upperIndex & 0xFFFFFFFF) << 32; | |
} | |
@Override | |
public byte getType() { | |
return 3; | |
} | |
} | |
public static abstract class LongIndexValueInstruction extends LongIndexInstruction { | |
public final int value; | |
private LongIndexValueInstruction(long lowerIndex, long upperIndex, long value) { | |
super(lowerIndex, upperIndex); | |
this.value = (int) (value & 0xFFFFFFFF); | |
} | |
@Override | |
public byte getType() { | |
return 4; | |
} | |
} | |
public static abstract class StringInstruction extends Instruction { | |
public final String value; | |
private StringInstruction(String value) { | |
this.value = value; | |
} | |
@Override | |
public byte getType() { | |
return 5; | |
} | |
} | |
public static final class Add extends IndexValueInstruction { | |
public Add(int index, short value) { | |
super(index, value); | |
} | |
@Override | |
public byte getOpcode() { | |
return 0; | |
} | |
} | |
public static final class Move extends IndexInstruction { | |
public Move(int index) { | |
super(index); | |
} | |
@Override | |
public byte getOpcode() { | |
return 1; | |
} | |
} | |
public static final class Input extends IndexInstruction { | |
public Input(int index) { | |
super(index); | |
} | |
@Override | |
public byte getOpcode() { | |
return 2; | |
} | |
} | |
public static final class Output extends IndexInstruction { | |
public Output(int index) { | |
super(index); | |
} | |
@Override | |
public byte getOpcode() { | |
return 3; | |
} | |
} | |
public static final class Skip extends Instruction { | |
public Skip() { | |
super(); | |
} | |
@Override | |
public byte getOpcode() { | |
return 4; | |
} | |
} | |
public static final class Jump extends IndexInstruction { | |
public Jump(int index) { | |
super(index); | |
} | |
@Override | |
public byte getOpcode() { | |
return 5; | |
} | |
} | |
public static final class Define extends LongIndexValueInstruction { | |
public Define(long lowerIndex, long upperIndex, long value) { | |
super(lowerIndex, upperIndex, value); | |
} | |
@Override | |
public byte getOpcode() { | |
return 6; | |
} | |
} | |
public static final class Call extends LongIndexInstruction { | |
public Call(long lowerIndex, long upperIndex) { | |
super(lowerIndex, upperIndex); | |
} | |
@Override | |
public byte getOpcode() { | |
return 7; | |
} | |
} | |
public static final class Import extends StringInstruction { | |
public Import(String value) { | |
super(value); | |
} | |
@Override | |
public byte getOpcode() { | |
return 8; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment