Implement compound operator patching.
This commit is contained in:
@@ -34,6 +34,16 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
}
|
||||
/// <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.
|
||||
/// </summary>
|
||||
/// <param name="exp">The expression to optimize.</param>
|
||||
|
@@ -51,9 +51,8 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
public class PushVariable : PdtInstruction {
|
||||
public int Name { get; private set; }
|
||||
public PushVariable(string name) {
|
||||
Name = IdentifierManager.SharedInstance.Request(name);
|
||||
}
|
||||
public PushVariable(int name) { Name = name; }
|
||||
public PushVariable(string name) : this(IdentifierManager.SharedInstance.Request(name)) { }
|
||||
internal override void Execute(PdtEvaluatorBase etor) {
|
||||
etor.PushVariable(Name);
|
||||
}
|
||||
@@ -63,6 +62,9 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
public class Operate : PdtInstruction {
|
||||
public PdtOperatorSignature Signature { get; private set; }
|
||||
public Operate(int name, int paramCount) {
|
||||
Signature = new PdtOperatorSignature(name, paramCount);
|
||||
}
|
||||
public Operate(string name, int paramCount) {
|
||||
Signature = new PdtOperatorSignature(name, paramCount);
|
||||
}
|
||||
|
Reference in New Issue
Block a user