Skip to content

Commit

Permalink
turns out I just reinvented Assign
Browse files Browse the repository at this point in the history
  • Loading branch information
ike709 committed Oct 20, 2024
1 parent 260c10e commit 83f8e05
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 16 deletions.
2 changes: 0 additions & 2 deletions DMCompiler/Bytecode/DreamProcOpcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,6 @@ public enum DreamProcOpcode : byte {
NullRef = 0x96,
[OpcodeMetadata(0, OpcodeArgType.Reference)]
ReturnReferenceValue = 0x97,
[OpcodeMetadata(0, OpcodeArgType.Reference)]
AssignAndPushReferenceValue = 0x98,
}
// ReSharper restore MissingBlankLines

Expand Down
5 changes: 3 additions & 2 deletions DMCompiler/Optimizer/PeepholeOptimizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,8 @@ public void Apply(List<IAnnotatedBytecode> input, int index) {

// AssignPop [ref]
// PushReferenceValue [ref]
// -> AssignAndPushReferenceValue [ref]
// -> Assign [ref]
// These opcodes can be reduced to a single Assign as long as the [ref]s are the same
internal sealed class AssignAndPushReferenceValue : IPeepholeOptimization {
public ReadOnlySpan<DreamProcOpcode> GetOpcodes() {
return [
Expand Down Expand Up @@ -776,7 +777,7 @@ public void Apply(List<IAnnotatedBytecode> input, int index) {
AnnotatedBytecodeReference assignTarget = firstInstruction.GetArg<AnnotatedBytecodeReference>(0);

input.RemoveRange(index, 2);
input.Insert(index, new AnnotatedBytecodeInstruction(DreamProcOpcode.AssignAndPushReferenceValue, [assignTarget]));
input.Insert(index, new AnnotatedBytecodeInstruction(DreamProcOpcode.Assign, [assignTarget]));
}
}

Expand Down
10 changes: 0 additions & 10 deletions OpenDreamRuntime/Procs/DMOpcodeHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2900,16 +2900,6 @@ public static ProcStatus AssignPop(DMProcState state) {
return ProcStatus.Continue;
}

public static ProcStatus AssignAndPushReferenceValue(DMProcState state) {
DreamReference reference = state.ReadReference();
DreamValue value = state.Pop();

state.AssignReference(reference, value);
state.Push(value);

return ProcStatus.Continue;
}

public static ProcStatus PushReferenceAndDereferenceField(DMProcState state) {
DreamReference reference = state.ReadReference();
string fieldName = state.ReadString();
Expand Down
1 change: 0 additions & 1 deletion OpenDreamRuntime/Procs/DMProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ public sealed class DMProcState : ProcState {
{DreamProcOpcode.PushRefandJumpIfNotNull, DMOpcodeHandlers.PushReferenceAndJumpIfNotNull},
{DreamProcOpcode.NullRef, DMOpcodeHandlers.NullRef},
{DreamProcOpcode.AssignPop, DMOpcodeHandlers.AssignPop},
{DreamProcOpcode.AssignAndPushReferenceValue, DMOpcodeHandlers.AssignAndPushReferenceValue},
{DreamProcOpcode.PushRefAndDereferenceField, DMOpcodeHandlers.PushReferenceAndDereferenceField},
{DreamProcOpcode.PushNRefs, DMOpcodeHandlers.PushNRefs},
{DreamProcOpcode.PushNFloats, DMOpcodeHandlers.PushNFloats},
Expand Down
1 change: 0 additions & 1 deletion OpenDreamRuntime/Procs/ProcDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public ITuple DecodeInstruction() {
case DreamProcOpcode.PushReferenceValue:
case DreamProcOpcode.PopReference:
case DreamProcOpcode.AssignPop:
case DreamProcOpcode.AssignAndPushReferenceValue:
case DreamProcOpcode.ReturnReferenceValue:
return (opcode, ReadReference());

Expand Down

0 comments on commit 83f8e05

Please sign in to comment.