Skip to content

Commit

Permalink
remove compiler from server first attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruzihm committed Feb 23, 2025
1 parent a7661f6 commit 1e194cc
Show file tree
Hide file tree
Showing 94 changed files with 347 additions and 250 deletions.
2 changes: 1 addition & 1 deletion Content.Tests/DummyDreamMapManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using DMCompiler.Json;
using OpenDreamShared.Common.Json;
using OpenDreamRuntime.Map;
using OpenDreamRuntime.Objects;
using OpenDreamRuntime.Objects.Types;
Expand Down
2 changes: 1 addition & 1 deletion Content.Tests/RuntimeTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using DMCompiler.Bytecode;
using NUnit.Framework;
using OpenDreamShared.Common.Bytecode;

namespace Content.Tests;

Expand Down
2 changes: 1 addition & 1 deletion DMCompiler/Compiler/DM/AST/DMAST.Expression.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Linq;
using DMCompiler.DM;
using OpenDreamShared.Common.DM;

namespace DMCompiler.Compiler.DM.AST;

Expand Down
1 change: 1 addition & 0 deletions DMCompiler/Compiler/DM/AST/DMAST.ObjectStatements.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DMCompiler.DM;
using OpenDreamShared.Common;

namespace DMCompiler.Compiler.DM.AST;

Expand Down
1 change: 1 addition & 0 deletions DMCompiler/Compiler/DM/AST/DMAST.ProcStatements.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DMCompiler.DM;
using OpenDreamShared.Common;

namespace DMCompiler.Compiler.DM.AST;

Expand Down
1 change: 1 addition & 0 deletions DMCompiler/Compiler/DM/AST/DMAST.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DMCompiler.DM;
using OpenDreamShared.Common;

namespace DMCompiler.Compiler.DM.AST;

Expand Down
2 changes: 2 additions & 0 deletions DMCompiler/Compiler/DM/DMParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Linq;
using DMCompiler.Compiler.DM.AST;
using DMCompiler.DM;
using OpenDreamShared.Common;
using OpenDreamShared.Common.DM;

namespace DMCompiler.Compiler.DM {
internal partial class DMParser(DMCompiler compiler, DMLexer lexer) : Parser<Token>(compiler, lexer) {
Expand Down
2 changes: 1 addition & 1 deletion DMCompiler/Compiler/DM/DMParserHelper.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using DMCompiler.Bytecode;
using DMCompiler.Compiler.DM.AST;
using OpenDreamShared.Common.Bytecode;

namespace DMCompiler.Compiler.DM;

Expand Down
4 changes: 3 additions & 1 deletion DMCompiler/Compiler/DM/DMPath.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace DMCompiler.Compiler.DM;
using OpenDreamShared.Common;

namespace DMCompiler.Compiler.DM;

internal abstract class VarDeclInfo {
public DreamPath? TypePath;
Expand Down
3 changes: 2 additions & 1 deletion DMCompiler/Compiler/DMM/DMMParser.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using DMCompiler.Compiler.DM;
using DMCompiler.Compiler.DM.AST;
using DMCompiler.DM.Builders;
using DMCompiler.Json;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Json;

namespace DMCompiler.Compiler.DMM;

Expand Down
1 change: 1 addition & 0 deletions DMCompiler/DM/Builders/DMCodeTreeBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DMCompiler.Compiler.DM.AST;
using OpenDreamShared.Common;

namespace DMCompiler.DM.Builders;

Expand Down
2 changes: 2 additions & 0 deletions DMCompiler/DM/Builders/DMExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using DMCompiler.DM.Expressions;
using static DMCompiler.DM.Builders.DMExpressionBuilder.ScopeMode;
using String = DMCompiler.DM.Expressions.String;
using OpenDreamShared.Common;
using OpenDreamShared.Common.DM;

namespace DMCompiler.DM.Builders;

Expand Down
4 changes: 3 additions & 1 deletion DMCompiler/DM/Builders/DMProcBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Diagnostics;
using DMCompiler.Bytecode;
using DMCompiler.Compiler;
using DMCompiler.Compiler.DM;
using DMCompiler.Compiler.DM.AST;
using DMCompiler.DM.Expressions;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Bytecode;
using OpenDreamShared.Common.DM;

namespace DMCompiler.DM.Builders {
internal sealed class DMProcBuilder(DMCompiler compiler, DMObject dmObject, DMProc proc) {
Expand Down
1 change: 1 addition & 0 deletions DMCompiler/DM/DMCodeTree.Procs.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DMCompiler.Compiler;
using DMCompiler.Compiler.DM.AST;
using OpenDreamShared.Common;

namespace DMCompiler.DM;

Expand Down
4 changes: 3 additions & 1 deletion DMCompiler/DM/DMCodeTree.Vars.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using DMCompiler.Bytecode;
using DMCompiler.Compiler;
using DMCompiler.Compiler.DM.AST;
using DMCompiler.DM.Builders;
using DMCompiler.DM.Expressions;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Bytecode;
using OpenDreamShared.Common.DM;
using ScopeMode = DMCompiler.DM.Builders.DMExpressionBuilder.ScopeMode;

namespace DMCompiler.DM;
Expand Down
1 change: 1 addition & 0 deletions DMCompiler/DM/DMCodeTree.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using DMCompiler.Compiler;
using DMCompiler.DM.Builders;
using OpenDreamShared.Common;

namespace DMCompiler.DM;

Expand Down
4 changes: 3 additions & 1 deletion DMCompiler/DM/DMExpression.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using DMCompiler.Bytecode;
using System.Diagnostics.CodeAnalysis;
using DMCompiler.Compiler;
using DMCompiler.DM.Expressions;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Bytecode;
using OpenDreamShared.Common.DM;

namespace DMCompiler.DM;

Expand Down
6 changes: 4 additions & 2 deletions DMCompiler/DM/DMObject.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Linq;
using DMCompiler.Bytecode;
using DMCompiler.DM.Expressions;
using DMCompiler.Json;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Bytecode;
using OpenDreamShared.Common.DM;
using OpenDreamShared.Common.Json;

namespace DMCompiler.DM;

Expand Down
3 changes: 2 additions & 1 deletion DMCompiler/DM/DMObjectTree.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using DMCompiler.Compiler;
using DMCompiler.Compiler.DM.AST;
using DMCompiler.Json;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Json;

namespace DMCompiler.DM;

Expand Down
6 changes: 4 additions & 2 deletions DMCompiler/DM/DMProc.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using DMCompiler.Bytecode;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using DMCompiler.DM.Expressions;
using DMCompiler.Compiler;
using DMCompiler.Compiler.DM.AST;
using DMCompiler.DM.Builders;
using DMCompiler.Json;
using DMCompiler.Optimizer;
using OpenDreamShared.Common.Bytecode;
using OpenDreamShared.Common.DM;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Json;

namespace DMCompiler.DM {
internal sealed class DMProc {
Expand Down
32 changes: 4 additions & 28 deletions DMCompiler/DM/DMValueType.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
namespace DMCompiler.DM;
using OpenDreamShared.Common;
using OpenDreamShared.Common.DM;

namespace DMCompiler.DM;

// If you are modifying this, you must also modify OpenDreamShared.Dream.DreamValueType !!
// Unfortunately the client needs this and it can't reference DMCompiler due to the sandbox

///<summary>
///Stores any explicit casting done via the "as" keyword. Also stores compiler hints for DMStandard.<br/>
///is a [Flags] enum because it's possible for something to have multiple values (especially with the quirky DMStandard ones)
/// </summary>
[Flags]
public enum DMValueType {
Anything = 0x0,
Null = 0x1,
Text = 0x2,
Obj = 0x4,
Mob = 0x8,
Turf = 0x10,
Num = 0x20,
Message = 0x40,
Area = 0x80,
Color = 0x100,
File = 0x200,
CommandText = 0x400,
Sound = 0x800,
Icon = 0x1000,
Path = 0x2000, // For proc return types

//Byond here be dragons
Unimplemented = 0x4000, // Marks that a method or property is not implemented. Throws a compiler warning if accessed.
CompiletimeReadonly = 0x8000, // Marks that a property can only ever be read from, never written to. This is a const-ier version of const, for certain standard values like list.type
NoConstFold = 0x10000 // Marks that a const var cannot be const-folded during compile
}

/// <summary>
/// Allows for more complex things than DMValueType does, such as supporting type paths
Expand Down
4 changes: 3 additions & 1 deletion DMCompiler/DM/DMVariable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using OpenDreamShared.Common;
using OpenDreamShared.Common.DM;
using System.Diagnostics.CodeAnalysis;

namespace DMCompiler.DM;

Expand Down
3 changes: 2 additions & 1 deletion DMCompiler/DM/Expressions/Binary.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using DMCompiler.Bytecode;
using DMCompiler.Compiler;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Bytecode;

namespace DMCompiler.DM.Expressions;

Expand Down
10 changes: 6 additions & 4 deletions DMCompiler/DM/Expressions/Builtins.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using DMCompiler.Bytecode;
using System.Diagnostics.CodeAnalysis;
using DMCompiler.Compiler;
using DMCompiler.Json;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Bytecode;
using OpenDreamShared.Common.DM;
using OpenDreamShared.Common.Json;

namespace DMCompiler.DM.Expressions;

Expand Down Expand Up @@ -61,7 +63,7 @@ public void EmitPushArglist(ExpressionContext ctx) {
internal sealed class New(DMCompiler compiler, Location location, DMExpression expr, ArgumentList arguments) : DMExpression(location) {
public override DreamPath? Path => expr.Path;
public override bool PathIsFuzzy => Path == null;
public override DMComplexValueType ValType => !expr.ValType.IsAnything ? expr.ValType : (Path?.GetAtomType(compiler) ?? DMValueType.Anything);
public override DMComplexValueType ValType => !expr.ValType.IsAnything ? expr.ValType : (compiler.GetAtomType(Path) ?? DMValueType.Anything);

public override void EmitPushValue(ExpressionContext ctx) {
var argumentInfo = arguments.EmitArguments(ctx, null);
Expand All @@ -74,7 +76,7 @@ public override void EmitPushValue(ExpressionContext ctx) {
// new /x/y/z (...)
internal sealed class NewPath(DMCompiler compiler, Location location, IConstantPath create, ArgumentList arguments) : DMExpression(location) {
public override DreamPath? Path => (create is ConstantTypeReference typeReference) ? typeReference.Path : null;
public override DMComplexValueType ValType => Path?.GetAtomType(compiler) ?? DMValueType.Anything;
public override DMComplexValueType ValType => compiler.GetAtomType(Path) ?? DMValueType.Anything;

public override void EmitPushValue(ExpressionContext ctx) {
DMCallArgumentsType argumentsType;
Expand Down
4 changes: 3 additions & 1 deletion DMCompiler/DM/Expressions/Constant.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using DMCompiler.Compiler;
using DMCompiler.Json;
using OpenDreamShared.Common;
using OpenDreamShared.Common.DM;
using OpenDreamShared.Common.Json;

namespace DMCompiler.DM.Expressions;

Expand Down
4 changes: 3 additions & 1 deletion DMCompiler/DM/Expressions/Dereference.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using DMCompiler.Bytecode;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using DMCompiler.Compiler;
using OpenDreamShared.Common;
using OpenDreamShared.Common.DM;
using OpenDreamShared.Common.Bytecode;

namespace DMCompiler.DM.Expressions;

Expand Down
4 changes: 3 additions & 1 deletion DMCompiler/DM/Expressions/LValue.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using DMCompiler.Bytecode;
using DMCompiler.Compiler;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Bytecode;
using OpenDreamShared.Common.DM;

namespace DMCompiler.DM.Expressions;

Expand Down
4 changes: 3 additions & 1 deletion DMCompiler/DM/Expressions/Procs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Linq;
using DMCompiler.Bytecode;
using DMCompiler.Compiler;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Bytecode;
using OpenDreamShared.Common.DM;

namespace DMCompiler.DM.Expressions;

Expand Down
2 changes: 1 addition & 1 deletion DMCompiler/DM/Expressions/Unary.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using DMCompiler.Bytecode;
using OpenDreamShared.Common.Bytecode;

namespace DMCompiler.DM.Expressions;

Expand Down
33 changes: 28 additions & 5 deletions DMCompiler/DMCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using DMCompiler.Bytecode;
using DMCompiler.Compiler.DM;
using DMCompiler.Compiler.DMM;
using DMCompiler.Compiler.DMPreprocessor;
Expand All @@ -13,8 +12,12 @@
using DMCompiler.Compiler;
using DMCompiler.Compiler.DM.AST;
using DMCompiler.DM.Builders;
using DMCompiler.Json;
using DMCompiler.Optimizer;
using OpenDreamShared.Common.DM;
using OpenDreamShared.Common;
using OpenDreamShared.Common.Json;
using OpenDreamShared.Common.Bytecode;
using OpenDreamNoClient.Bytecode;

namespace DMCompiler;

Expand Down Expand Up @@ -78,7 +81,7 @@ public bool Compile(DMCompilerSettings settings) {
if (ErrorCount > 0) {
successfulCompile = false;
} else {
var output = SaveJson(maps, preprocessor.IncludedInterface, outputFile);
var output = SaveJson(maps, preprocessor.IncludedInterface, outputFile, new OpcodeVerifier());
if (ErrorCount > 0) {
successfulCompile = false;
} else {
Expand Down Expand Up @@ -294,10 +297,10 @@ private List<DreamMapJson> ConvertMaps(DMCompiler compiler, List<string> mapPath
return maps;
}

private string SaveJson(List<DreamMapJson> maps, string interfaceFile, string outputFile) {
private string SaveJson(List<DreamMapJson> maps, string interfaceFile, string outputFile, IOpcodeVerifier verifier) {
var jsonRep = DMObjectTree.CreateJsonRepresentation();
var compiledDream = new DreamCompiledJson {
Metadata = new DreamCompiledJsonMetadata { Version = OpcodeVerifier.GetOpcodesHash() },
Metadata = new DreamCompiledJsonMetadata { Version = verifier.GetOpcodesHash() },
Strings = DMObjectTree.StringTable,
Resources = DMObjectTree.Resources.ToArray(),
Maps = maps,
Expand Down Expand Up @@ -389,6 +392,26 @@ public ErrorLevel CodeToLevel(WarningCode code) {

return ret;
}

public DMValueType? GetAtomType(DreamPath? path) {
if (path == null) {
return null;
}

if (!DMObjectTree.TryGetDMObject((DreamPath)path, out var dmType))
return DMValueType.Anything;

if (dmType.IsSubtypeOf(DreamPath.Obj))
return DMValueType.Obj;
if (dmType.IsSubtypeOf(DreamPath.Mob))
return DMValueType.Mob;
if (dmType.IsSubtypeOf(DreamPath.Turf))
return DMValueType.Turf;
if (dmType.IsSubtypeOf(DreamPath.Area))
return DMValueType.Area;

return DMValueType.Anything;
}
}

public struct DMCompilerSettings {
Expand Down
Loading

0 comments on commit 1e194cc

Please sign in to comment.