Skip to content

Commit

Permalink
Merge branch 'master' into OpenDream-854
Browse files Browse the repository at this point in the history
  • Loading branch information
distributivgesetz committed Dec 26, 2023
2 parents a6ab3ed + 1bb067f commit c3f5139
Show file tree
Hide file tree
Showing 41 changed files with 681 additions and 669 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.101
dotnet-version: 8.0.100
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compiler-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.101
dotnet-version: 8.0.100
- name: Install dependencies
run: dotnet restore main/OpenDream.sln
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-tgs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ concurrency:
cancel-in-progress: true

env:
OD_DOTNET_VERSION: 7
OD_DOTNET_VERSION: 8
TGS_DOTNET_VERSION: 8
TGS_REFERENCE: V6 # This will break after the V6 branch gets deleted during the TGS6 release cycle. When it does, change this to `dev`
TGS_REFERENCE: dev

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion Content.IntegrationTests/Content.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<OutputPath>..\bin\Content.IntegrationTests\</OutputPath>
<IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.2" />
Expand Down
2 changes: 1 addition & 1 deletion Content.Tests/Content.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\bin\Content.Tests\</OutputPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

//Issue OD#996, kinda: https://github.com/OpenDreamProject/OpenDream/issues/996

/proc/RunTest()
var/x = 5
switch(x)
if(1)
CRASH("Strange branch chosen in switch statement")
if(4)
CRASH("Strange branch chosen in switch statement")
else if(x == 3)
CRASH("Parser failed to understand 'else if' in switch block")
else
return
CRASH("Parser failed to understand 'else if' in switch block")
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//COMPILE ERROR
//test to make sure SuspiciousSwitchCase is working

#pragma SuspiciousSwitchCase error

/proc/RunTest()
var/x = 5
switch(x)
if(1)
return
if(4)
return
else if(x == 3)
return
else
return
16 changes: 16 additions & 0 deletions Content.Tests/RuntimeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using DMCompiler.Bytecode;
using NUnit.Framework;

namespace Content.Tests;

[TestFixture]
public sealed class RuntimeTests {
/// <summary>
/// Validates that the opcodes in DreamProcOpcode are all unique, such that none resolve to the same byte.
/// </summary>
[Test]
public void EnsureOpcodesUnique() {
Assert.That(Enum.GetValues<DreamProcOpcode>(), Is.Unique);
}
}
21 changes: 0 additions & 21 deletions DMCompiler/Bytecode/DreamProcOpcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,27 +363,6 @@ public override string ToString() {

// Dummy class-as-namespace because C# just kinda be like this
public static class OpcodeVerifier {
/// <summary>
/// Validates that the opcodes in DreamProcOpcode are all unique, such that none resolve to the same byte.
/// </summary>
/// <returns>True if there are duplicate opcodes, false if not</returns>
// FIXME: Can this be made into something done during compiletime? Like, *this code's* compiletime? >:/
public static bool AreOpcodesInvalid() {
// I'm not *too* satisfied with this boolean schtick, as opposed to throwing,
// but I want each executable to be able to do what they want with this information.

HashSet<DreamProcOpcode> bytePool = new();
foreach (DreamProcOpcode usedInt in Enum.GetValues(typeof(DreamProcOpcode))) {
if(bytePool.Contains(usedInt)) {
return true;
}

bytePool.Add(usedInt);
}

return false;
}

/// <summary>
/// Calculates a hash of all the <c>DreamProcOpcode</c>s for warning on incompatibilities.
/// </summary>
Expand Down
42 changes: 22 additions & 20 deletions DMCompiler/Compiler/DM/DMParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@

namespace DMCompiler.Compiler.DM {
public partial class DMParser : Parser<Token> {

private DreamPath _currentPath = DreamPath.Root;

private bool _allowVarDeclExpression = false;

public DMParser(DMLexer lexer) : base(lexer) {
}

private static readonly TokenType[] AssignTypes = {
TokenType.DM_Equals,
TokenType.DM_PlusEquals,
Expand Down Expand Up @@ -150,6 +145,9 @@ public DMParser(DMLexer lexer) : base(lexer) {
TokenType.DM_XorEquals,
};

public DMParser(DMLexer lexer) : base(lexer) {
}

public DMASTFile File() {
var loc = Current().Location;
List<DMASTStatement> statements = new();
Expand Down Expand Up @@ -1315,7 +1313,7 @@ DMASTProcBlockInner GetForBody() {

DMASTProcStatementSwitch.SwitchCase[]? switchCases = SwitchCases();

if (switchCases == null) Error("Expected switch cases");
if (switchCases == null) Error(WarningCode.BadExpression, "Expected switch cases");
return new DMASTProcStatementSwitch(loc, value, switchCases);
}

Expand Down Expand Up @@ -1366,7 +1364,7 @@ public DMASTProcStatementSwitch.SwitchCase[] SwitchInner() {
List<DMASTProcStatementSwitch.SwitchCase> switchCases = new();
DMASTProcStatementSwitch.SwitchCase? switchCase = SwitchCase();

while (switchCase != null) {
while (switchCase is not null) {
switchCases.Add(switchCase);
Newline();
Whitespace();
Expand All @@ -1388,19 +1386,20 @@ public DMASTProcStatementSwitch.SwitchCase[] SwitchInner() {

DMASTExpression? expression = Expression();
if (expression == null) {
if (expressions.Count == 0) {
Error("Expected an expression");
} else {
//Eat a trailing comma if there's at least 1 expression
break;
}
if (expressions.Count == 0)
DMCompiler.Emit(WarningCode.BadExpression, Current().Location, "Expected an expression");

break;
}

if (Check(TokenType.DM_To)) {
var loc = Current().Location;
Whitespace();
var loc = Current().Location;
DMASTExpression? rangeEnd = Expression();
if (rangeEnd == null) Error("Expected an upper limit");
if (rangeEnd == null) {
DMCompiler.Emit(WarningCode.BadExpression, loc, "Expected an upper limit");
rangeEnd = new DMASTConstantNull(loc); // Fallback to null
}

expressions.Add(new DMASTSwitchCaseRange(loc, expression, rangeEnd));
} else {
Expand All @@ -1416,22 +1415,25 @@ public DMASTProcStatementSwitch.SwitchCase[] SwitchInner() {

if (body == null) {
DMASTProcStatement? statement = ProcStatement();
var loc = Current().Location;

if (statement != null) {
body = new DMASTProcBlockInner(loc,statement);
body = new DMASTProcBlockInner(statement.Location, statement);
} else {
body = new DMASTProcBlockInner(loc);
body = new DMASTProcBlockInner(Current().Location);
}
}

return new DMASTProcStatementSwitch.SwitchCaseValues(expressions.ToArray(), body);
} else if (Check(TokenType.DM_Else)) {
var loc = Current().Location;
Whitespace();
var loc = Current().Location;
if (Current().Type == TokenType.DM_If) {
Error("Expected \"if\" or \"else\", \"else if\" is not permitted as a switch case");
//From now on, all ifs/elseifs/elses are actually part of this if's chain, not the switch's.
//Ambiguous, but that is parity behaviour. Ergo, the following emission.
DMCompiler.Emit(WarningCode.SuspiciousSwitchCase, loc,
"Expected \"if\" or \"else\" - \"else if\" is ambiguous as a switch case and may cause unintended flow");
}

DMASTProcBlockInner? body = ProcBlock();

if (body == null) {
Expand Down
10 changes: 7 additions & 3 deletions DMCompiler/Compiler/DM/DMParserHelper.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using OpenDreamShared.Compiler;
using DMCompiler.Compiler.DMPreprocessor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DMCompiler.Bytecode;

namespace DMCompiler.Compiler.DM {
public partial class DMParser : Parser<Token> {

public partial class DMParser {
/// <summary>
/// A special override of Error() since, for DMParser, we know we are in a compilation context and can make use of error codes.
/// </summary>
Expand All @@ -23,6 +21,12 @@ protected bool Error(WarningCode code, string message) {
return level == ErrorLevel.Error;
}

/// <inheritdoc cref="Parser{SourceType}.Error(string, bool)"/>
[Obsolete("This is not a desirable way for DMParser to emit an error, as errors should emit an error code and not cause unnecessary throws. Use DMParser's overrides of this method, instead.")]
new protected void Error(string message, bool throwException = true) {
base.Error(message, throwException);
}

protected bool PeekDelimiter() {
return Current().Type == TokenType.Newline || Current().Type == TokenType.DM_Semicolon;
}
Expand Down
10 changes: 3 additions & 7 deletions DMCompiler/DMCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
using DMCompiler.Bytecode;
using DMCompiler.Compiler.DM;
using DMCompiler.Compiler.DMM;
using DMCompiler.Compiler.DMPreprocessor;
using DMCompiler.DM;
using DMCompiler.DM.Visitors;
using OpenDreamShared.Compiler;
using OpenDreamShared.Json;
using Robust.Shared.Utility;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using DMCompiler.Bytecode;
using Robust.Shared.Utility;

namespace DMCompiler;

Expand Down Expand Up @@ -51,10 +51,6 @@ public static bool Compile(DMCompilerSettings settings) {
ForcedWarning("Unimplemented proc & var warnings are currently suppressed");
}

if(OpcodeVerifier.AreOpcodesInvalid()) {
ForcedError("Some opcodes have the same byte value! Output assembly may be corrupted.");
}

DMPreprocessor preprocessor = Preprocess(settings.Files, settings.MacroDefines);
bool successfulCompile = preprocessor is not null && Compile(preprocessor);

Expand Down
2 changes: 1 addition & 1 deletion DMCompiler/DMCompiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;Tools</Configurations>
<Platforms>AnyCPU</Platforms>
Expand Down
1 change: 1 addition & 0 deletions DMCompiler/DMStandard/DefaultPragmaConfig.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#pragma DanglingVarType warning
#pragma MissingInterpolatedExpression warning
#pragma AmbiguousResourcePath warning
#pragma SuspiciousSwitchCase warning

//3000-3999
#pragma EmptyBlock notice
Expand Down
8 changes: 4 additions & 4 deletions DMCompiler/copy_standard.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
if not exist bin\Debug\net7.0\DMStandard mkdir bin\Debug\net7.0\DMStandard
xcopy DMStandard bin\Debug\net7.0\DMStandard /y /s /e
if not exist bin\Release\net7.0\DMStandard mkdir bin\Release\net7.0\DMStandard
xcopy DMStandard bin\Release\net7.0\DMStandard /y /s /e
if not exist bin\Debug\net8.0\DMStandard mkdir bin\Debug\net8.0\DMStandard
xcopy DMStandard bin\Debug\net8.0\DMStandard /y /s /e
if not exist bin\Release\net8.0\DMStandard mkdir bin\Release\net8.0\DMStandard
xcopy DMStandard bin\Release\net8.0\DMStandard /y /s /e
16 changes: 8 additions & 8 deletions DMCompiler/copy_standard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ set -xe
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")

if [ -d "$SCRIPTPATH/bin/Debug/net7.0/DMStandard" ]; then
cp -r $SCRIPTPATH/DMStandard $SCRIPTPATH/bin/Debug/net7.0/DMStandard
if [ -d "$SCRIPTPATH/bin/Debug/net8.0/DMStandard" ]; then
cp -r $SCRIPTPATH/DMStandard $SCRIPTPATH/bin/Debug/net8.0/DMStandard
else
mkdir -p $SCRIPTPATH/bin/Debug/net7.0/DMStandard
cp -r $SCRIPTPATH/DMStandard $SCRIPTPATH/bin/Debug/net7.0/DMStandard
mkdir -p $SCRIPTPATH/bin/Debug/net8.0/DMStandard
cp -r $SCRIPTPATH/DMStandard $SCRIPTPATH/bin/Debug/net8.0/DMStandard
fi

if [ -d "$SCRIPTPATH/bin/Release/net7.0/DMStandard" ]; then
cp -r $SCRIPTPATH/DMStandard $SCRIPTPATH/bin/Release/net7.0/DMStandard
if [ -d "$SCRIPTPATH/bin/Release/net8.0/DMStandard" ]; then
cp -r $SCRIPTPATH/DMStandard $SCRIPTPATH/bin/Release/net8.0/DMStandard
else
mkdir -p $SCRIPTPATH/bin/Release/net7.0/DMStandard
cp -r $SCRIPTPATH/DMStandard $SCRIPTPATH/bin/Release/net7.0/DMStandard
mkdir -p $SCRIPTPATH/bin/Release/net8.0/DMStandard
cp -r $SCRIPTPATH/DMStandard $SCRIPTPATH/bin/Release/net8.0/DMStandard
fi
2 changes: 1 addition & 1 deletion DMDisassembler/DMDisassembler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Configurations>Debug;Release;Tools</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
Expand Down
18 changes: 5 additions & 13 deletions OpenDreamClient/Audio/DreamSoundChannel.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
using Robust.Client.Graphics;
using Robust.Client.Audio;
using Robust.Shared.Audio.Components;

namespace OpenDreamClient.Audio;

public sealed class DreamSoundChannel : IDisposable {
public IClydeAudioSource Source { get; }

public DreamSoundChannel(IClydeAudioSource source) {
Source = source;
}
public sealed class DreamSoundChannel(AudioSystem audioSystem, (EntityUid Entity, AudioComponent Component) source) {
public readonly (EntityUid Entity, AudioComponent Component) Source = source;

public void Stop() {
Source.StopPlaying();
}

public void Dispose() {
Stop();
Source.Dispose();
audioSystem.Stop(Source.Entity, Source.Component);
}
}
Loading

0 comments on commit c3f5139

Please sign in to comment.