Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Content.Tests/DMProject/Tests/Expression/edge_comparison.dm
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@

/proc/RunTest()
// null violates the holy trichotomy here, with how it compares to an empty string.
ASSERT( (null > "") == 0 )
ASSERT( (null >= "") == 1 )
ASSERT( (null == "") == 0 )
ASSERT( (null <= "") == 1 )
ASSERT( (null < "") == 0 )

ASSERT( (null > 5) == 0 )
ASSERT( (null > -5) == 1 )
ASSERT( (null > "abc") == 0 )
ASSERT( (null > "") == 0 )
ASSERT( (null > null) == 0 )

ASSERT( (null < 5) == 1 )
ASSERT( (null < -5) == 0 )
ASSERT( (null < "abc") == 1 )
ASSERT( (null < "") == 0 )
ASSERT( (null < null) == 0 )

ASSERT( (0.15 <= null) == 0)
Expand Down
102 changes: 101 additions & 1 deletion DMCompiler/DM/Expressions/Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.Add();
Expand All @@ -60,6 +65,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.Subtract();
Expand All @@ -85,6 +95,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.Multiply();
Expand All @@ -110,6 +125,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.Divide();
Expand All @@ -125,7 +145,7 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

if (lhs is Number lhsNum && rhs is Number rhsNum) {
constant = new Number(Location, lhsNum.Value % rhsNum.Value);
constant = new Number(Location, (int)lhsNum.Value % (int)rhsNum.Value);
} else {
constant = null;
return false;
Expand All @@ -135,6 +155,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.Modulus();
Expand Down Expand Up @@ -163,6 +188,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.ModulusModulus();
Expand All @@ -188,6 +218,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.Power();
Expand All @@ -213,6 +248,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.BitShiftLeft();
Expand All @@ -238,6 +278,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.BitShiftRight();
Expand Down Expand Up @@ -265,6 +310,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.BinaryAnd();
Expand All @@ -290,6 +340,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.BinaryXor();
Expand All @@ -315,6 +370,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.BinaryOr();
Expand Down Expand Up @@ -378,6 +438,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.GreaterThan();
Expand All @@ -387,6 +452,11 @@ public override void EmitPushValue(ExpressionContext ctx) {
// x >= y
internal sealed class GreaterThanOrEqual(Location location, DMExpression lhs, DMExpression rhs) : BinaryOp(location, lhs, rhs) {
public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.GreaterThanOrEqual();
Expand Down Expand Up @@ -414,6 +484,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
// x < y
internal sealed class LessThan(Location location, DMExpression lhs, DMExpression rhs) : BinaryOp(location, lhs, rhs) {
public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.LessThan();
Expand Down Expand Up @@ -441,6 +516,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
// x <= y
internal sealed class LessThanOrEqual(Location location, DMExpression lhs, DMExpression rhs) : BinaryOp(location, lhs, rhs) {
public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

LHS.EmitPushValue(ctx);
RHS.EmitPushValue(ctx);
ctx.Proc.LessThanOrEqual();
Expand Down Expand Up @@ -485,6 +565,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

string endLabel = ctx.Proc.NewLabelName();

LHS.EmitPushValue(ctx);
Expand Down Expand Up @@ -512,6 +597,21 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (LHS.TryAsConstant(ctx.Compiler, out var lhs)) {
if (lhs.IsTruthy()) {
if (RHS.TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

RHS.EmitPushValue(ctx);
return;
}

lhs.EmitPushValue(ctx);
return;
}

string endLabel = ctx.Proc.NewLabelName();

LHS.EmitPushValue(ctx);
Expand Down
50 changes: 50 additions & 0 deletions DMCompiler/DM/Expressions/Builtins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

expr.EmitPushValue(ctx);
ctx.Proc.Sin();
}
Expand All @@ -734,6 +739,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

expr.EmitPushValue(ctx);
ctx.Proc.Cos();
}
Expand All @@ -759,6 +769,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

expr.EmitPushValue(ctx);
ctx.Proc.Tan();
}
Expand Down Expand Up @@ -789,6 +804,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

expr.EmitPushValue(ctx);
ctx.Proc.ArcSin();
}
Expand Down Expand Up @@ -819,6 +839,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

expr.EmitPushValue(ctx);
ctx.Proc.ArcCos();
}
Expand All @@ -844,6 +869,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

expr.EmitPushValue(ctx);
ctx.Proc.ArcTan();
}
Expand Down Expand Up @@ -873,6 +903,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

xExpr.EmitPushValue(ctx);
yExpr.EmitPushValue(ctx);
ctx.Proc.ArcTan2();
Expand Down Expand Up @@ -904,6 +939,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

expr.EmitPushValue(ctx);
ctx.Proc.Sqrt();
}
Expand Down Expand Up @@ -946,6 +986,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

expr.EmitPushValue(ctx);
if (baseExpr == null) {
ctx.Proc.LogE();
Expand Down Expand Up @@ -976,6 +1021,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

expr.EmitPushValue(ctx);
ctx.Proc.Abs();
}
Expand Down
5 changes: 5 additions & 0 deletions DMCompiler/DM/Expressions/Ternary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
}

public override void EmitPushValue(ExpressionContext ctx) {
if (TryAsConstant(ctx.Compiler, out var constant)) {
constant.EmitPushValue(ctx);
return;
}

string cLabel = ctx.Proc.NewLabelName();
string endLabel = ctx.Proc.NewLabelName();

Expand Down
Loading
Loading