From ac5ef6b127f7c4f5619db20555af667cac5fba9b Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Tue, 28 Jan 2025 15:36:23 -0600 Subject: [PATCH] [WIP] Fix assembler bugs --- UIXC/Commands/DecompileCommand.cs | 2 +- UIXC/Properties/launchSettings.json | 8 +++++++- libs/UIX.Asm/AsmMarkupLoader.cs | 10 ++++++++++ libs/UIX.Asm/Disassembler.cs | 9 ++++++++- libs/UIX.Asm/Lexer.Imports.cs | 1 + libs/UIX.Asm/Lexer.cs | 6 ++++++ libs/UIX.Asm/Models/Imports.cs | 2 +- libs/UIX.Asm/UIX.Asm.csproj | 4 ++-- 8 files changed, 36 insertions(+), 6 deletions(-) diff --git a/UIXC/Commands/DecompileCommand.cs b/UIXC/Commands/DecompileCommand.cs index d95b7ed..f95a0e1 100644 --- a/UIXC/Commands/DecompileCommand.cs +++ b/UIXC/Commands/DecompileCommand.cs @@ -73,7 +73,7 @@ public class DecompileCommand : CompilerCommandBase if (settings.Language == SourceLanguage.Asm) { - foreach (var input in enumeratedInputs) + foreach (var input in enumeratedInputs.Where(f => !f.EndsWith(".uixa"))) { try { diff --git a/UIXC/Properties/launchSettings.json b/UIXC/Properties/launchSettings.json index 0312d30..1e728f9 100644 --- a/UIXC/Properties/launchSettings.json +++ b/UIXC/Properties/launchSettings.json @@ -2,11 +2,17 @@ "profiles": { "UIXC": { "commandName": "Project", - "commandLineArgs": "compile \"D:\\Documents\\REProj\\Zune\\UIXA\\ZuneShell.dll!_DataTable.uixa\" -A ZuneShell.dll -A UIXControls.dll -A ZuneDBApi.dll -o D:\\Documents\\REProj\\Zune\\UIXA", + "commandLineArgs": "decompile C:\\Users\\jjask\\Documents\\Dump\\Zune\\ZuneShellResources -A ZuneShell.dll -A UIXControls.dll -A ZuneDBApi.dll -o C:\\Users\\jjask\\Documents\\Dump\\Zune\\ZuneShellResources_uixa -t C:\\Users\\jjask\\Documents\\Dump\\Zune\\ZuneShellResources_uixa\\_DATATABLE.uixa", + //"commandLineArgs": "compile C:\\Users\\jjask\\Documents\\Dump\\Zune\\ZuneShellResources\\CreatePassport.uixa -A ZuneShell.dll -A UIXControls.dll -A ZuneDBApi.dll -o C:\\Users\\jjask\\Documents\\Dump\\Zune", + //"commandLineArgs": "compile C:\\Users\\jjask\\Documents\\Dump\\Zune\\_DATATABLE.uixa -A ZuneShell.dll -A UIXControls.dll -A ZuneDBApi.dll -o C:\\Users\\jjask\\Documents\\Dump\\Zune", + //"commandLineArgs": "decompile C:\\Users\\jjask\\Documents\\Dump\\Zune\\ZuneShellResources\\_DATATABLE.UIB -A ZuneShell.dll -A UIXControls.dll -A ZuneDBApi.dll -o C:\\Users\\jjask\\Documents\\Dump\\Zune\\ZuneShellResources_uixa", + + //"commandLineArgs": "compile \"D:\\Documents\\REProj\\Zune\\UIXA\\ZuneShell.dll!_DataTable.uixa\" -A ZuneShell.dll -A UIXControls.dll -A ZuneDBApi.dll -o D:\\Documents\\REProj\\Zune\\UIXA", //"commandLineArgs": "compile \"D:\\Documents\\REProj\\Zune\\UIXA\\ZuneShellResources.dll!_DataTable.uixa\" -A ZuneShell.dll -A UIXControls.dll -A ZuneDBApi.dll -o D:\\Documents\\REProj\\Zune\\UIXA", //"commandLineArgs": "decompile \"res://ZuneShellResources.dll!_DataTable.uib\" -A ZuneShell.dll -A UIXControls.dll -A ZuneDBApi.dll -o D:\\Documents\\REProj\\Zune\\UIXA", //"commandLineArgs": "decompile \"res://ZuneShellResources.dll!TOOLTIP.uix\" -A ZuneShell.dll -A UIXControls.dll -A ZuneDBApi.dll -o D:\\Documents\\REProj\\Zune\\UIXA", //"commandLineArgs": "compile \"D:\\Documents\\REProj\\Zune\\UIXA\\UIXControls!ComboBox.uixa\" -A ZuneShell.dll -A UIXControls.dll -A ZuneDBApi.dll -o D:\\Documents\\REProj\\Zune\\UIXA", + "workingDirectory": "C:\\Program Files\\Zune" } } diff --git a/libs/UIX.Asm/AsmMarkupLoader.cs b/libs/UIX.Asm/AsmMarkupLoader.cs index 1413eb9..d196f20 100644 --- a/libs/UIX.Asm/AsmMarkupLoader.cs +++ b/libs/UIX.Asm/AsmMarkupLoader.cs @@ -85,6 +85,16 @@ internal class AsmMarkupLoader var type = result.FindType(typeName); + //if (type is null) + //{ + // foreach (var tryResult in _importedNamespaces.Values) + // { + // type = tryResult.FindType(typeName); + // if (type is not null) + // break; + // } + //} + if (type is null) { ErrorManager.ReportError(qualifiedName.Line, qualifiedName.Column, diff --git a/libs/UIX.Asm/Disassembler.cs b/libs/UIX.Asm/Disassembler.cs index cb33d48..65d93ec 100644 --- a/libs/UIX.Asm/Disassembler.cs +++ b/libs/UIX.Asm/Disassembler.cs @@ -153,10 +153,13 @@ public class Disassembler foreach (var typeImport in _loadResult.ImportTables.TypeImports) { + var typeName = typeImport.Name; var uri = typeImport.Owner.Uri; if (!_importedUris.TryGetValue(uri, out var namespacePrefix)) { var baseNamespacePrefix = uri; + + var ownerUri = uri; var schemeLength = uri.IndexOf("://"); if (schemeLength > 0) { @@ -207,9 +210,13 @@ public class Disassembler yield return new NamespaceImport(uri, namespacePrefix); } + + // Ensure that the original, un-normalized URI is saved too + if (!_importedUris.ContainsKey(ownerUri)) + _importedUris.Add(ownerUri, namespacePrefix); } - yield return new TypeImport(new(namespacePrefix, typeImport.Name)); + yield return new TypeImport(new(namespacePrefix, typeName)); }; foreach (var constructorImport in _loadResult.ImportTables.ConstructorImports) diff --git a/libs/UIX.Asm/Lexer.Imports.cs b/libs/UIX.Asm/Lexer.Imports.cs index 4af1f7d..2c52c4c 100644 --- a/libs/UIX.Asm/Lexer.Imports.cs +++ b/libs/UIX.Asm/Lexer.Imports.cs @@ -101,6 +101,7 @@ partial class Lexer if (!ctorMemberTypeNameResult.WasSuccessful) return Result.Failure(input, "Invalid constructor import", ["Expected qualified type name"]); + input = Parse.Char('.').Optional()(input).Remainder; input = Parse.Char('(')(input).Remainder; var ctorParameterTypesResult = Parse.Ref(() => QualifiedTypeName).DelimitedBy(Parse.Char(',').Token())(input); diff --git a/libs/UIX.Asm/Lexer.cs b/libs/UIX.Asm/Lexer.cs index 3854283..98af3c1 100644 --- a/libs/UIX.Asm/Lexer.cs +++ b/libs/UIX.Asm/Lexer.cs @@ -99,6 +99,12 @@ public static partial class Lexer } } + // Capture arrays + var arrayMarkerResult = Parse.String("[]")(input); + input = arrayMarkerResult.Remainder; + if (arrayMarkerResult.WasSuccessful) + typeName += "[]"; + QualifiedTypeName qualifiedName = new(typePrefix, typeName) { Line = line, diff --git a/libs/UIX.Asm/Models/Imports.cs b/libs/UIX.Asm/Models/Imports.cs index 8dfde84..dec42a2 100644 --- a/libs/UIX.Asm/Models/Imports.cs +++ b/libs/UIX.Asm/Models/Imports.cs @@ -59,7 +59,7 @@ public record ConstructorImport : ImportDirective public IEnumerable ParameterTypes { get; init; } - public override string ToString() => $"{base.ToString()} {QualifiedName}.({string.Join(", ", ParameterTypes)})"; + public override string ToString() => $"{base.ToString()} {QualifiedName}({string.Join(", ", ParameterTypes)})"; } public record MethodImport : ImportDirective diff --git a/libs/UIX.Asm/UIX.Asm.csproj b/libs/UIX.Asm/UIX.Asm.csproj index f8d7049..1fc6b0a 100644 --- a/libs/UIX.Asm/UIX.Asm.csproj +++ b/libs/UIX.Asm/UIX.Asm.csproj @@ -23,8 +23,8 @@ - - + +