mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-08 16:04:10 -08:00
Emit neg and not
This commit is contained in:
parent
e95b537687
commit
57a39a156a
|
@ -45,4 +45,8 @@ public class ConditionEmitter {
|
|||
ForkEmitter newFork = fork.or(block, otherEmitter.fork);
|
||||
return new ConditionEmitter(pe, newFork);
|
||||
}
|
||||
|
||||
public ConditionEmitter not() {
|
||||
return new ConditionEmitter(pe, fork.not());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.teavm.model.instructions.IntegerSubtype;
|
|||
import org.teavm.model.instructions.InvocationType;
|
||||
import org.teavm.model.instructions.InvokeInstruction;
|
||||
import org.teavm.model.instructions.IsInstanceInstruction;
|
||||
import org.teavm.model.instructions.NegateInstruction;
|
||||
import org.teavm.model.instructions.NumericOperandType;
|
||||
import org.teavm.model.instructions.PutElementInstruction;
|
||||
import org.teavm.model.instructions.PutFieldInstruction;
|
||||
|
@ -119,6 +120,27 @@ public class ValueEmitter {
|
|||
return pe;
|
||||
}
|
||||
|
||||
public ValueEmitter neg() {
|
||||
if (!(type instanceof ValueType.Primitive)) {
|
||||
throw new EmitException("Can't negate non-primitive: " + type);
|
||||
}
|
||||
|
||||
ValueEmitter value = this;
|
||||
PrimitiveType type = ((ValueType.Primitive) this.type).getKind();
|
||||
IntegerSubtype subtype = convertToIntegerSubtype(type);
|
||||
if (subtype != null) {
|
||||
value = value.castToInteger(subtype);
|
||||
type = PrimitiveType.INTEGER;
|
||||
}
|
||||
|
||||
ValueEmitter result = pe.newVar(ValueType.primitive(type));
|
||||
NegateInstruction insn = new NegateInstruction(convertToNumeric(type));
|
||||
insn.setOperand(value.variable);
|
||||
insn.setReceiver(result.variable);
|
||||
pe.addInstruction(insn);
|
||||
return result;
|
||||
}
|
||||
|
||||
static class Pair {
|
||||
ValueEmitter first;
|
||||
ValueEmitter second;
|
||||
|
|
Loading…
Reference in New Issue
Block a user