Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typemaker 1.1 - fixes and improvements #2072

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b802573
Fix CallOperation in TypeMaker
out-of-phaze Oct 25, 2024
492c5ae
Normalize relative paths in error source file paths
out-of-phaze Oct 25, 2024
6a5ad57
Add ValType overrides to various expressions
out-of-phaze Oct 25, 2024
1981532
Infer ValType for local vars from path hints
out-of-phaze Oct 25, 2024
b7d1c33
Improve CallOperation type inference
out-of-phaze Oct 25, 2024
dde2f38
Add inference based on variable typepath
out-of-phaze Oct 25, 2024
031753a
Add Typemaker types to file resources
out-of-phaze Oct 25, 2024
32681f1
Improve DMStandard type hints
out-of-phaze Oct 25, 2024
2944747
Further expand DMStandard typehints
out-of-phaze Oct 31, 2024
57c6306
Expand GetAtomType
out-of-phaze Oct 31, 2024
0841b74
Make var declaration valtype nullable
out-of-phaze Oct 31, 2024
ffca9fd
Separate instance and path DMValueTypes
out-of-phaze Oct 31, 2024
700b8c0
Make automatic local valtype inference more permissive
out-of-phaze Oct 31, 2024
7a01273
Make typepath unions use common ancestors
out-of-phaze Oct 31, 2024
669154f
Add typed lists to Typemaker
out-of-phaze Oct 31, 2024
003dddf
Improve proc call return value checking
out-of-phaze Oct 31, 2024
c0a665c
Add ValType override to ScopeReference
out-of-phaze Oct 31, 2024
d0d3c12
Implement params[] typehints
out-of-phaze Oct 31, 2024
60e8c7c
Expand return value validation to check more code paths
out-of-phaze Nov 8, 2024
1f2d07d
Propagate valtype information from input() to vars
out-of-phaze Nov 8, 2024
4445086
Add more expression ValType overrides
out-of-phaze Nov 8, 2024
d7f84e3
Improve IndexOperation ValType inference
out-of-phaze Nov 8, 2024
2a2a6ed
Add type coercion for Message and Color types
out-of-phaze Nov 8, 2024
4c2434e
Add even more typehints to DMStandard
out-of-phaze Nov 8, 2024
a12a94d
Fix null reference exception in ProcVarEnd
out-of-phaze Nov 27, 2024
7a0e147
Fix nested list types in Typemaker
out-of-phaze Dec 6, 2024
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
4 changes: 2 additions & 2 deletions DMCompiler/Compiler/DM/AST/DMAST.ObjectStatements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public sealed class DMASTObjectVarDefinition(
Location location,
DreamPath path,
DMASTExpression value,
DMComplexValueType valType,
DMComplexValueType? valType,
DreamPath? valPath = null) : DMASTStatement(location) {
/// <summary>The path of the object that we are a property of.</summary>
public DreamPath ObjectPath => _varDecl.ObjectPath;
Expand All @@ -73,7 +73,7 @@ public sealed class DMASTObjectVarDefinition(
public bool IsConst => _varDecl.IsConst;
public bool IsTmp => _varDecl.IsTmp;

public readonly DMComplexValueType ValType = valType;
public readonly DMComplexValueType? ValType = valType;
}

public sealed class DMASTMultipleObjectVarDefinitions(Location location, DMASTObjectVarDefinition[] varDefinitions)
Expand Down
5 changes: 3 additions & 2 deletions DMCompiler/Compiler/DM/AST/DMAST.ProcStatements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ public sealed class DMASTProcStatementExpression(Location location, DMASTExpress
public DMASTExpression Expression = expression;
}

public sealed class DMASTProcStatementVarDeclaration(Location location, DMASTPath path, DMASTExpression? value, DMComplexValueType valType)
public sealed class DMASTProcStatementVarDeclaration(Location location, DMASTPath path, DMASTExpression? value, DMComplexValueType? valType)
: DMASTProcStatement(location) {
public DMASTExpression? Value = value;

public DreamPath? Type => _varDecl.IsList ? DreamPath.List : _varDecl.TypePath;
public DMComplexValueType? ExplicitValType => valType;

public DMComplexValueType ValType => valType;
public DMComplexValueType ValType => ExplicitValType ?? DMValueType.Anything;

public string Name => _varDecl.VarName;
public bool IsGlobal => _varDecl.IsStatic;
Expand Down
288 changes: 194 additions & 94 deletions DMCompiler/Compiler/DM/DMParser.cs

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions DMCompiler/DM/Builders/DMExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private static DMExpression BuildIdentifier(DMASTIdentifier identifier, DMObject
if (CurrentScopeMode == ScopeMode.Normal) {
var localVar = proc?.GetLocalVariable(name);
if (localVar != null)
return new Local(identifier.Location, localVar);
return new Local(identifier.Location, localVar, proc!, localVar.ExplicitValueType);

var field = dmObject?.GetVariable(name);
if (field != null) {
Expand Down Expand Up @@ -526,7 +526,7 @@ private static DMExpression BuildCallableProcIdentifier(DMASTCallableProcIdentif
if (CurrentScopeMode is ScopeMode.Static or ScopeMode.FirstPassStatic)
return new GlobalProc(procIdentifier.Location, procIdentifier.Identifier);
if (dmObject.HasProc(procIdentifier.Identifier))
return new Proc(procIdentifier.Location, procIdentifier.Identifier);
return new Proc(procIdentifier.Location, procIdentifier.Identifier, dmObject);
if (DMObjectTree.TryGetGlobalProc(procIdentifier.Identifier, out _))
return new GlobalProc(procIdentifier.Location, procIdentifier.Identifier);

Expand Down Expand Up @@ -763,6 +763,7 @@ private static DMExpression BuildDereference(DMASTDereference deref, DMObject dm
case DMASTDereference.CallOperation callOperation: {
var field = callOperation.Identifier;
ArgumentList argumentList = new(deref.Expression.Location, dmObject, proc, callOperation.Parameters);
DreamPath? nextPath = null;

if (!callOperation.NoSearch && !pathIsFuzzy) {
if (prevPath == null) {
Expand All @@ -777,16 +778,25 @@ private static DMExpression BuildDereference(DMASTDereference deref, DMObject dm
if (!fromObject.HasProc(field))
return BadExpression(WarningCode.ItemDoesntExist, callOperation.Location,
$"Type {prevPath.Value} does not have a proc named \"{field}\"");

var returnTypes = fromObject.GetProcReturnTypes(field, argumentList) ?? DMValueType.Anything;
nextPath = returnTypes.HasPath ? returnTypes.TypePath : returnTypes.AsPath();
if (!returnTypes.HasPath & nextPath.HasValue) {
var thePath = nextPath!.Value;
thePath.Type = DreamPath.PathType.UpwardSearch;
nextPath = thePath;
}
}

operation = new Dereference.CallOperation {
Parameters = argumentList,
Safe = callOperation.Safe,
Identifier = field,
Path = null
Path = prevPath
};
prevPath = null;
pathIsFuzzy = true;
prevPath = nextPath;
if(prevPath is null)
pathIsFuzzy = true;
break;
}

Expand Down
Loading
Loading