Skip to content

Commit

Permalink
Removes 2 unused opcodes (#2056)
Browse files Browse the repository at this point in the history
Co-authored-by: ike709 <ike709@github.com>
  • Loading branch information
ike709 and ike709 authored Oct 22, 2024
1 parent 87fe63d commit 1b3251c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 33 deletions.
6 changes: 2 additions & 4 deletions DMCompiler/Bytecode/DreamProcOpcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ public enum DreamProcOpcode : byte {
[OpcodeMetadata]
Abs = 0x83,
// Peephole optimization opcodes
[OpcodeMetadata(0, OpcodeArgType.Reference, OpcodeArgType.Label)]
PushRefandJumpIfNotNull = 0x84,
//0x84
[OpcodeMetadata(-1, OpcodeArgType.Reference)]
AssignPop = 0x85,
[OpcodeMetadata(1, OpcodeArgType.Reference, OpcodeArgType.String)]
Expand Down Expand Up @@ -285,8 +284,7 @@ public enum DreamProcOpcode : byte {
CreateListNResources = 0x92,
[OpcodeMetadata(0, OpcodeArgType.String, OpcodeArgType.Label)]
SwitchOnString = 0x93,
[OpcodeMetadata(1, OpcodeArgType.Label)]
JumpIfNotNull = 0x94,
//0x94
[OpcodeMetadata(0, OpcodeArgType.TypeId)]
IsTypeDirect = 0x95,
[OpcodeMetadata(0, OpcodeArgType.Reference)]
Expand Down
28 changes: 1 addition & 27 deletions OpenDreamRuntime/Procs/DMOpcodeHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2867,26 +2867,11 @@ private static DreamValue IconOperationAdd(DMProcState state, DreamValue icon, D
DreamProcNativeIcon.Blend(iconObj.Icon, blend, DreamIconOperationBlend.BlendType.Add, 0, 0);
return new DreamValue(iconObj);
}

#endregion Helpers

#region Peephole Optimizations

public static ProcStatus PushReferenceAndJumpIfNotNull(DMProcState state) {
DreamReference reference = state.ReadReference();
int jumpTo = state.ReadInt();

DreamValue value = state.GetReferenceValue(reference);

if (!value.IsNull) {
state.Push(value);
state.Jump(jumpTo);
} else {
state.Push(DreamValue.Null);
}

return ProcStatus.Continue;
}

public static ProcStatus NullRef(DMProcState state) {
state.AssignReference(state.ReadReference(), DreamValue.Null);
return ProcStatus.Continue;
Expand Down Expand Up @@ -3085,17 +3070,6 @@ public static ProcStatus CreateListNResources(DMProcState state) {
return ProcStatus.Continue;
}

public static ProcStatus JumpIfNotNull(DMProcState state) {
int position = state.ReadInt();

if (!state.Peek().IsNull) {
state.PopDrop();
state.Jump(position);
}

return ProcStatus.Continue;
}

public static ProcStatus IsTypeDirect(DMProcState state) {
DreamValue value = state.Pop();
int typeId = state.ReadInt();
Expand Down
4 changes: 2 additions & 2 deletions OpenDreamRuntime/Procs/DMProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public sealed class DMProcState : ProcState {
private static readonly ArrayPool<DreamValue> _dreamValuePool = ArrayPool<DreamValue>.Create();

#region Opcode Handlers

//Human readable friendly version, which will be converted to a more efficient lookup at runtime.
private static readonly Dictionary<DreamProcOpcode, OpcodeHandler> _opcodeHandlers = new() {
{DreamProcOpcode.BitShiftLeft, DMOpcodeHandlers.BitShiftLeft},
Expand Down Expand Up @@ -302,7 +303,6 @@ public sealed class DMProcState : ProcState {
{DreamProcOpcode.DebuggerBreakpoint, DMOpcodeHandlers.DebuggerBreakpoint},
{DreamProcOpcode.Rgb, DMOpcodeHandlers.Rgb},
// Peephole optimizer opcode handlers
{DreamProcOpcode.PushRefandJumpIfNotNull, DMOpcodeHandlers.PushReferenceAndJumpIfNotNull},
{DreamProcOpcode.NullRef, DMOpcodeHandlers.NullRef},
{DreamProcOpcode.AssignPop, DMOpcodeHandlers.AssignPop},
{DreamProcOpcode.PushRefAndDereferenceField, DMOpcodeHandlers.PushReferenceAndDereferenceField},
Expand All @@ -319,12 +319,12 @@ public sealed class DMProcState : ProcState {
{DreamProcOpcode.CreateListNStrings, DMOpcodeHandlers.CreateListNStrings},
{DreamProcOpcode.CreateListNRefs, DMOpcodeHandlers.CreateListNRefs},
{DreamProcOpcode.CreateListNResources, DMOpcodeHandlers.CreateListNResources},
{DreamProcOpcode.JumpIfNotNull, DMOpcodeHandlers.JumpIfNotNull},
{DreamProcOpcode.IsTypeDirect, DMOpcodeHandlers.IsTypeDirect},
{DreamProcOpcode.ReturnReferenceValue, DMOpcodeHandlers.ReturnReferenceValue}
};

public static readonly unsafe delegate*<DMProcState, ProcStatus>[] OpcodeHandlers;

#endregion

public DreamManager DreamManager => _proc.DreamManager;
Expand Down

0 comments on commit 1b3251c

Please sign in to comment.