Skip to content

Commit fa8f44e

Browse files
RuzihmwixoaGit
andauthored
Makes EmitPushIsSaved virtual (#2480)
Co-authored-by: wixoa <[email protected]>
1 parent 0343b3d commit fa8f44e

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

DMCompiler/DM/DMExpression.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public virtual DMReference EmitReference(ExpressionContext ctx, string endLabel,
4848
return DMReference.Invalid;
4949
}
5050

51+
public virtual void EmitPushIsSaved(ExpressionContext ctx) {
52+
ctx.Compiler.Emit(WarningCode.BadArgument, Location, $"can't get issaved() value of {this}");
53+
ctx.Proc.PushNullAndError();
54+
}
55+
5156
/// <summary>
5257
/// Gets the canonical name of the expression if it exists.
5358
/// </summary>

DMCompiler/DM/Expressions/Builtins.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,21 +348,7 @@ internal sealed class IsSaved(Location location, DMExpression expr) : DMExpressi
348348
public override DMComplexValueType ValType => DMValueType.Num;
349349

350350
public override void EmitPushValue(ExpressionContext ctx) {
351-
switch (expr) {
352-
case Dereference deref:
353-
deref.EmitPushIsSaved(ctx);
354-
return;
355-
case Field field:
356-
field.EmitPushIsSaved(ctx.Proc);
357-
return;
358-
case Local:
359-
ctx.Proc.PushFloat(0);
360-
return;
361-
default:
362-
ctx.Compiler.Emit(WarningCode.BadArgument, expr.Location, $"can't get saved value of {expr}");
363-
ctx.Proc.PushNullAndError();
364-
return;
365-
}
351+
expr.EmitPushIsSaved(ctx);
366352
}
367353
}
368354

DMCompiler/DM/Expressions/Dereference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public override void EmitPushInitial(ExpressionContext ctx) {
246246
ctx.Proc.AddLabel(endLabel);
247247
}
248248

249-
public void EmitPushIsSaved(ExpressionContext ctx) {
249+
public override void EmitPushIsSaved(ExpressionContext ctx) {
250250
string endLabel = ctx.Proc.NewLabelName();
251251

252252
if (_expression is LValue exprLValue) {

DMCompiler/DM/Expressions/LValue.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ public override void EmitPushInitial(ExpressionContext ctx) {
191191
}
192192

193193
public override string GetNameof(ExpressionContext ctx) => LocalVar.Name;
194+
195+
public override void EmitPushIsSaved(ExpressionContext ctx) {
196+
ctx.Proc.PushFloat(0);
197+
}
194198
}
195199

196200
// Identifier of field
@@ -209,10 +213,10 @@ public override void EmitPushInitial(ExpressionContext ctx) {
209213
}
210214
}
211215

212-
public void EmitPushIsSaved(DMProc proc) {
213-
proc.PushReferenceValue(DMReference.Src);
214-
proc.PushString(variable.Name);
215-
proc.IsSaved();
216+
public override void EmitPushIsSaved(ExpressionContext ctx) {
217+
ctx.Proc.PushReferenceValue(DMReference.Src);
218+
ctx.Proc.PushString(variable.Name);
219+
ctx.Proc.IsSaved();
216220
}
217221

218222
public override DMReference EmitReference(ExpressionContext ctx, string endLabel,

0 commit comments

Comments
 (0)