Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DMCompiler/Bytecode/OpcodeMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public OpcodeMetadataAttribute(bool variableArgs, int stackDelta,
/// </summary>
public struct OpcodeMetadata(int stackDelta = 0, bool variableArgs = false, params OpcodeArgType[] requiredArgs) {
public readonly int StackDelta = stackDelta; // Net change in stack size caused by this opcode
public readonly List<OpcodeArgType> RequiredArgs = [..requiredArgs]; // The types of arguments this opcode requires
public readonly OpcodeArgType[] RequiredArgs = requiredArgs; // The types of arguments this opcode requires
public readonly bool VariableArgs = variableArgs; // Whether this opcode takes a variable number of arguments
}

Expand Down
6 changes: 3 additions & 3 deletions DMCompiler/Optimizer/AnnotatedByteCodeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public List<IAnnotatedBytecode> GetAnnotatedBytecode() {
public void WriteOpcode(DreamProcOpcode opcode, Location location) {
_location = location;
if (_currentMetadata is not null) {
if (_requiredArgIdx < _currentMetadata.Value.RequiredArgs.Count - 1) {
if (_requiredArgIdx < _currentMetadata.Value.RequiredArgs.Length - 1) {
compiler.ForcedError(location, "Expected argument");
} else if (_requiredArgIdx > _currentMetadata.Value.RequiredArgs.Count) {
} else if (_requiredArgIdx > _currentMetadata.Value.RequiredArgs.Length) {
compiler.ForcedError(location, "Unexpected argument count. Opcode arguments have likely been mishandled internally");
}
}
Expand All @@ -56,7 +56,7 @@ public void WriteOpcode(DreamProcOpcode opcode, Location location) {

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ValidateArgument(Location location, OpcodeArgType argType) {
if (_currentMetadata!.Value.RequiredArgs.Count == 0 || _requiredArgIdx >= _currentMetadata.Value.RequiredArgs.Count || _currentMetadata.Value.RequiredArgs[_requiredArgIdx] != argType) {
if (_currentMetadata!.Value.RequiredArgs.Length == 0 || _requiredArgIdx >= _currentMetadata.Value.RequiredArgs.Length || _currentMetadata.Value.RequiredArgs[_requiredArgIdx] != argType) {
compiler.ForcedError(location, $"Expected {argType.ToString()} argument");
}

Expand Down
6 changes: 3 additions & 3 deletions DMCompiler/Optimizer/AnnotatedBytecode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ private void ValidateArgs(OpcodeMetadata metadata, List<IAnnotatedBytecode> args
return;
}

if (metadata.RequiredArgs.Count != args.Count) {
throw new Exception($"Expected {metadata.RequiredArgs.Count} args, got {args.Count}");
if (metadata.RequiredArgs.Length != args.Count) {
throw new Exception($"Expected {metadata.RequiredArgs.Length} args, got {args.Count}");
}

for (int i = 0; i < metadata.RequiredArgs.Count; i++) {
for (int i = 0; i < metadata.RequiredArgs.Length; i++) {
if (!MatchArgs(metadata.RequiredArgs[i], args[i])) {
throw new Exception($"Expected arg {i} to be {metadata.RequiredArgs[i]}, got {args[i].GetType()}");
}
Expand Down
2 changes: 1 addition & 1 deletion DMCompiler/Optimizer/AnnotatedBytecodeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void SerializeInstruction(AnnotatedBytecodeInstruction instruction) {

_bytecodeWriter.Write((byte)instruction.Opcode);
var opcodeMetadata = OpcodeMetadataCache.GetMetadata(instruction.Opcode);
if (opcodeMetadata.RequiredArgs.Count != instruction.GetArgs().Count && !opcodeMetadata.VariableArgs) {
if (opcodeMetadata.RequiredArgs.Length != instruction.GetArgs().Count && !opcodeMetadata.VariableArgs) {
throw new Exception("Invalid number of arguments for opcode " + instruction.Opcode);
}

Expand Down
Loading