Implement compound operator patching.
This commit is contained in:
@@ -34,6 +34,16 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Patches an expression with a lefthand variable and a compound operator.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="target">The name of the lefthand variable.</param>
|
||||||
|
/// <param name="op">The name of the compound operator.</param>
|
||||||
|
/// <param name="exp">The expression.</param>
|
||||||
|
public void PatchCompound(int target, int op, PdtExpression exp) {
|
||||||
|
exp.Instructions.AddFirst(new PdtInstruction.PushVariable(target));
|
||||||
|
exp.Instructions.AddLast(new PdtInstruction.Operate(op, 2));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// Optimizes an expression by merging its instructions.
|
/// Optimizes an expression by merging its instructions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="exp">The expression to optimize.</param>
|
/// <param name="exp">The expression to optimize.</param>
|
||||||
|
@@ -51,9 +51,8 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
public class PushVariable : PdtInstruction {
|
public class PushVariable : PdtInstruction {
|
||||||
public int Name { get; private set; }
|
public int Name { get; private set; }
|
||||||
public PushVariable(string name) {
|
public PushVariable(int name) { Name = name; }
|
||||||
Name = IdentifierManager.SharedInstance.Request(name);
|
public PushVariable(string name) : this(IdentifierManager.SharedInstance.Request(name)) { }
|
||||||
}
|
|
||||||
internal override void Execute(PdtEvaluatorBase etor) {
|
internal override void Execute(PdtEvaluatorBase etor) {
|
||||||
etor.PushVariable(Name);
|
etor.PushVariable(Name);
|
||||||
}
|
}
|
||||||
@@ -63,6 +62,9 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
public class Operate : PdtInstruction {
|
public class Operate : PdtInstruction {
|
||||||
public PdtOperatorSignature Signature { get; private set; }
|
public PdtOperatorSignature Signature { get; private set; }
|
||||||
|
public Operate(int name, int paramCount) {
|
||||||
|
Signature = new PdtOperatorSignature(name, paramCount);
|
||||||
|
}
|
||||||
public Operate(string name, int paramCount) {
|
public Operate(string name, int paramCount) {
|
||||||
Signature = new PdtOperatorSignature(name, paramCount);
|
Signature = new PdtOperatorSignature(name, paramCount);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user