update changelog and version bump

This commit is contained in:
2025-12-11 23:33:17 -07:00
parent 098d689750
commit d3974ad590
9 changed files with 128 additions and 15 deletions

View File

@@ -1,5 +1,11 @@
# Changelog # Changelog
[0.2.4]
- Groundwork laid to collect and track source maps
- IC Housing will now display the `Slang` source error line (if available)
instead of the `IC10` source error line
[0.2.3] [0.2.3]
- Fixed stack underflow with function invocations - Fixed stack underflow with function invocations

View File

@@ -2,7 +2,7 @@
<ModMetadata xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ModMetadata xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>Slang</Name> <Name>Slang</Name>
<Author>JoeDiertay</Author> <Author>JoeDiertay</Author>
<Version>0.2.3</Version> <Version>0.2.4</Version>
<Description> <Description>
[h1]Slang: High-Level Programming for Stationeers[/h1] [h1]Slang: High-Level Programming for Stationeers[/h1]

View File

@@ -44,10 +44,12 @@ public static class GlobalCode
public static bool GetSlangErrorLineFromICError( public static bool GetSlangErrorLineFromICError(
Guid reference, Guid reference,
uint icErrorLine, uint icErrorLine,
out uint slangSrc out uint slangSrc,
out Range slangSpan
) )
{ {
slangSrc = icErrorLine; slangSrc = icErrorLine;
slangSpan = new Range { };
if (!sourceMaps.ContainsKey(reference)) if (!sourceMaps.ContainsKey(reference))
{ {
@@ -62,6 +64,7 @@ public static class GlobalCode
} }
slangSrc = foundRange[0].StartLine; slangSrc = foundRange[0].StartLine;
slangSpan = foundRange[0];
return true; return true;
} }

View File

@@ -10,10 +10,23 @@ using StationeersIC10Editor;
public struct Range public struct Range
{ {
public uint StartCol; public uint StartCol = 0;
public uint EndCol; public uint EndCol = 0;
public uint StartLine; public uint StartLine = 0;
public uint EndLine; public uint EndLine = 0;
public Range(uint startLine, uint startCol, uint endLine, uint endCol)
{
StartLine = startLine;
StartCol = startCol;
EndLine = endLine;
EndCol = endCol;
}
public override string ToString()
{
return $"L{StartLine}C{StartCol} - L{EndLine}C{EndCol}";
}
} }
public struct Diagnostic public struct Diagnostic
@@ -27,6 +40,11 @@ public struct SourceMapEntry
{ {
public Range SlangSource; public Range SlangSource;
public uint Ic10Line; public uint Ic10Line;
public override string ToString()
{
return $"IC10: {Ic10Line} Slang: `{SlangSource}`";
}
} }
public static class Marshal public static class Marshal

View File

@@ -1,12 +1,34 @@
namespace Slang; namespace Slang;
using System; using System;
using System.Runtime.CompilerServices;
using Assets.Scripts.Objects; using Assets.Scripts.Objects;
using Assets.Scripts.Objects.Electrical; using Assets.Scripts.Objects.Electrical;
using Assets.Scripts.Objects.Motherboards; using Assets.Scripts.Objects.Motherboards;
using Assets.Scripts.UI; using Assets.Scripts.UI;
using HarmonyLib; using HarmonyLib;
class LineErrorData
{
public AsciiString SourceRef;
public uint IC10ErrorSource;
public string SlangErrorReference;
public Range SlangErrorSpan;
public LineErrorData(
AsciiString sourceRef,
uint ic10ErrorSource,
string slangErrorRef,
Range slangErrorSpan
)
{
this.SourceRef = sourceRef;
this.IC10ErrorSource = ic10ErrorSource;
this.SlangErrorReference = slangErrorRef;
this.SlangErrorSpan = slangErrorSpan;
}
}
[HarmonyPatch] [HarmonyPatch]
public static class SlangPatches public static class SlangPatches
{ {
@@ -14,6 +36,9 @@ public static class SlangPatches
private static AsciiString? _motherboardCachedCode; private static AsciiString? _motherboardCachedCode;
private static Guid? _currentlyEditingGuid; private static Guid? _currentlyEditingGuid;
private static ConditionalWeakTable<ProgrammableChip, LineErrorData> _errorReferenceTable =
new();
[HarmonyPatch( [HarmonyPatch(
typeof(ProgrammableChipMotherboard), typeof(ProgrammableChipMotherboard),
nameof(ProgrammableChipMotherboard.InputFinished) nameof(ProgrammableChipMotherboard.InputFinished)
@@ -151,27 +176,88 @@ public static class SlangPatches
{ {
if ( if (
String.IsNullOrEmpty(__result) String.IsNullOrEmpty(__result)
|| __result.LastIndexOf(GlobalCode.SLANG_REF) < 0 || !uint.TryParse(__result.Trim(), out var ic10ErrorLineNumber)
)
{
return;
}
var sourceAscii = __instance.GetSourceCode();
if (_errorReferenceTable.TryGetValue(__instance, out var cache))
{
if (cache.SourceRef.Equals(sourceAscii) && cache.IC10ErrorSource == ic10ErrorLineNumber)
{
__result = cache.SlangErrorReference;
return;
}
}
var source = System.Text.Encoding.UTF8.GetString(
System.Text.Encoding.ASCII.GetBytes(__instance.GetSourceCode())
);
var slangIndex = source.LastIndexOf(GlobalCode.SLANG_REF);
if (
slangIndex < 0
|| !Guid.TryParse( || !Guid.TryParse(
__result source
.Substring( .Substring(
__result.LastIndexOf(GlobalCode.SLANG_REF) + GlobalCode.SLANG_REF.Length source.LastIndexOf(GlobalCode.SLANG_REF) + GlobalCode.SLANG_REF.Length
) )
.Trim(), .Trim(),
out var slangGuid out var slangGuid
) )
|| !uint.TryParse(__result.Trim(), out var ic10ErrorLineNumber)
|| !GlobalCode.GetSlangErrorLineFromICError( || !GlobalCode.GetSlangErrorLineFromICError(
slangGuid, slangGuid,
ic10ErrorLineNumber, ic10ErrorLineNumber,
out var slangErrorLineNumber out var slangErrorLineNumber,
out var slangSpan
) )
) )
{ {
return; return;
} }
L.Warning($"IC error at: {__result} -- Slang source error line: {slangErrorLineNumber}");
__result = slangErrorLineNumber.ToString(); __result = slangErrorLineNumber.ToString();
_errorReferenceTable.Remove(__instance);
_errorReferenceTable.Add(
__instance,
new LineErrorData(
sourceAscii,
ic10ErrorLineNumber,
slangErrorLineNumber.ToString(),
slangSpan
)
);
}
[HarmonyPatch(
typeof(ProgrammableChip),
nameof(ProgrammableChip.SetSourceCode),
new Type[] { typeof(string) }
)]
[HarmonyPostfix]
public static void pgc_SetSourceCode_string(ProgrammableChip __instance, string sourceCode)
{
_errorReferenceTable.Remove(__instance);
}
[HarmonyPatch(
typeof(ProgrammableChip),
nameof(ProgrammableChip.SetSourceCode),
new Type[] { typeof(string), typeof(ICircuitHolder) }
)]
[HarmonyPostfix]
public static void pgc_SetSourceCode_string_parent(
ProgrammableChip __instance,
string sourceCode,
ICircuitHolder parent
)
{
_errorReferenceTable.Remove(__instance);
} }
[HarmonyPatch( [HarmonyPatch(

View File

@@ -41,7 +41,7 @@ namespace Slang
{ {
public const string PluginGuid = "com.biddydev.slang"; public const string PluginGuid = "com.biddydev.slang";
public const string PluginName = "Slang"; public const string PluginName = "Slang";
public const string PluginVersion = "0.1.1"; public const string PluginVersion = "0.2.4";
public static Mod MOD = new Mod(PluginName, PluginVersion); public static Mod MOD = new Mod(PluginName, PluginVersion);

View File

@@ -5,7 +5,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AssemblyName>StationeersSlang</AssemblyName> <AssemblyName>StationeersSlang</AssemblyName>
<Description>Slang Compiler Bridge</Description> <Description>Slang Compiler Bridge</Description>
<Version>0.2.3</Version> <Version>0.2.4</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
</PropertyGroup> </PropertyGroup>

View File

@@ -910,7 +910,7 @@ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
[[package]] [[package]]
name = "slang" name = "slang"
version = "0.2.3" version = "0.2.4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "slang" name = "slang"
version = "0.2.3" version = "0.2.4"
edition = "2021" edition = "2021"
[workspace] [workspace]