Skip to content

Commit

Permalink
Merge branch 'master' into easyfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ike709 authored Dec 30, 2024
2 parents ddd1196 + aab2f49 commit 94f0b53
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// COMPILE ERROR
// COMPILE ERROR OD0011

var/a = 1 / 0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// COMPILE ERROR
// COMPILE ERROR OD0011

var/static/a = 1 / 0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// COMPILE ERROR
// COMPILE ERROR OD0011

/proc/one()
return 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// COMPILE ERROR
// COMPILE ERROR OD0011

var/const/a = 0
var/b = 1 / a
Expand Down
5 changes: 2 additions & 3 deletions Content.Tests/DMTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags, int errorCode) {

Assert.That(compiledFile is not null && File.Exists(compiledFile), "Failed to compile DM source file");
Assert.That(_dreamMan.LoadJson(compiledFile), $"Failed to load {compiledFile}");
_dreamMan.LastDMException = null; // Nuke any exception from a prior test
_dreamMan.StartWorld();

(bool successfulRun, DreamValue? returned, Exception? exception) = RunTest();
Expand Down Expand Up @@ -114,8 +115,6 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags, int errorCode) {
}

private (bool Success, DreamValue? Returned, Exception? except) RunTest() {
var prev = _dreamMan.LastDMException;

DreamValue? retValue = null;
Task<DreamValue> callTask = null!;

Expand Down Expand Up @@ -143,7 +142,7 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags, int errorCode) {
}
}

bool retSuccess = _dreamMan.LastDMException == prev; // Works because "null == null" is true in this language.
bool retSuccess = _dreamMan.LastDMException == null; // Works because "null == null" is true in this language.
return (retSuccess, retValue, _dreamMan.LastDMException);
}

Expand Down
56 changes: 30 additions & 26 deletions DMCompiler/Json/DreamProcJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,50 @@
namespace DMCompiler.Json;

public sealed class ProcDefinitionJson {
public int OwningTypeId { get; set; }
public required string Name { get; set; }
public ProcAttributes Attributes { get; set; }

public int MaxStackSize { get; set; }
public List<ProcArgumentJson>? Arguments { get; set; }
public List<LocalVariableJson>? Locals { get; set; }
public required List<SourceInfoJson> SourceInfo { get; set; }
public byte[]? Bytecode { get; set; }

public bool IsVerb { get; set; }
public VerbSrc? VerbSrc { get; set; }
public string? VerbName { get; set; }
public string? VerbCategory { get; set; }
public string? VerbDesc { get; set; }
public sbyte Invisibility { get; set; }
public int OwningTypeId { get; init; }
public required string Name { get; init; }
public ProcAttributes Attributes { get; init; }

public int MaxStackSize { get; init; }
public List<ProcArgumentJson>? Arguments { get; init; }
public List<LocalVariableJson>? Locals { get; init; }
public required List<SourceInfoJson> SourceInfo { get; init; }
public byte[]? Bytecode { get; init; }

public bool IsVerb { get; init; }
public VerbSrc? VerbSrc { get; init; }
public string? VerbName { get; init; }
public string? VerbCategory { get; init; }
public string? VerbDesc { get; init; }
public sbyte Invisibility { get; init; }
}

public sealed class ProcArgumentJson {
public required string Name { get; set; }
public DMValueType Type { get; set; }
public struct ProcArgumentJson {
public required string Name { get; init; }
public DMValueType Type { get; init; }
}

public sealed class LocalVariableJson {
public int Offset { get; set; }
public int? Remove { get; set; }
public string? Add { get; set; }
public struct LocalVariableJson {
public int Offset { get; init; }
public int? Remove { get; init; }
public string? Add { get; init; }
}

public sealed class SourceInfoJson {
public int Offset { get; set; }
public struct SourceInfoJson {
public int Offset { get; init; }
public int? File { get; set; }
public int Line { get; set; }
public int Line { get; init; }
}

public class LineComparer : IEqualityComparer<SourceInfoJson> {
public bool Equals(SourceInfoJson? x, SourceInfoJson? y) {
return x?.Line == y?.Line;
}

public bool Equals(SourceInfoJson x, SourceInfoJson y) {
return x.Line == y.Line;
}

public int GetHashCode(SourceInfoJson obj) {
return obj.Line.GetHashCode();
}
Expand Down
2 changes: 2 additions & 0 deletions OpenDreamRuntime/Objects/DreamObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public void Delete(bool possiblyThreaded = false) {
}

public bool IsSubtypeOf(TreeEntry ancestor) {
if(Deleted) //null deref protection, deleted objects don't have ObjectDefinition anymore
return false;
return ObjectDefinition.IsSubtypeOf(ancestor);
}

Expand Down
6 changes: 5 additions & 1 deletion OpenDreamRuntime/Procs/DreamEnumerators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public DreamObjectEnumerator(IEnumerable<DreamObject> dreamObjects, TreeEntry? f

public bool Enumerate(DMProcState state, DreamReference? reference) {
bool success = _dreamObjectEnumerator.MoveNext();

while(success && _dreamObjectEnumerator.Current.Deleted) //skip over deleted
success = _dreamObjectEnumerator.MoveNext();

if (_filterType != null) {
while (success && !_dreamObjectEnumerator.Current.IsSubtypeOf(_filterType)) {
while (success && (_dreamObjectEnumerator.Current.Deleted || !_dreamObjectEnumerator.Current.IsSubtypeOf(_filterType))) {
success = _dreamObjectEnumerator.MoveNext();
}
}
Expand Down

0 comments on commit 94f0b53

Please sign in to comment.