Neue Architektur

This commit is contained in:
2025-10-12 19:06:28 +02:00
commit bdee19419d
120 changed files with 2706 additions and 0 deletions

View File

@ -0,0 +1,76 @@
using System;
using System.IO;
using System.Text;
using STCompiler.Common;
using System.Collections.Generic;
class Program {
static int Main(string[] args) {
if (args.Length < 1) {
Console.WriteLine("Usage: StDisasm <file.stbc>");
return 1;
}
var path = args[0];
if (!File.Exists(path)) { Console.WriteLine("File not found: " + path); return 2; }
var data = File.ReadAllBytes(path);
try { Disasm(data); } catch(Exception ex) { Console.WriteLine("Error: " + ex.Message); return 3; }
return 0;
}
static void Disasm(byte[] data) {
using var ms = new MemoryStream(data);
using var r = new BinaryReader(ms);
string magic = Encoding.ASCII.GetString(r.ReadBytes(4));
Console.WriteLine($"Magic: {magic}");
ushort ver = r.ReadUInt16();
Console.WriteLine($"Version: {ver}");
ushort nConsts = r.ReadUInt16();
Console.WriteLine($"Consts: {nConsts}");
var consts = new List<object>();
for (int i = 0; i < nConsts; i++) {
byte t = r.ReadByte();
switch(t) {
case 1: { long v = r.ReadInt64(); consts.Add(v); Console.WriteLine($" [{i}] (long) = {v}"); break; }
case 2: { double v = r.ReadDouble(); consts.Add(v); Console.WriteLine($" [{i}] (double) = {v}"); break; }
case 3: { float v = r.ReadSingle(); consts.Add(v); Console.WriteLine($" [{i}] (float) = {v}"); break; }
case 4: { int v = r.ReadInt32(); consts.Add(v); Console.WriteLine($" [{i}] (int) = {v}"); break; }
default: { Console.WriteLine($" [{i}] Unknown const type {t}"); break; }
}
}
ushort nVars = r.ReadUInt16();
Console.WriteLine($"Vars: {nVars}");
var varTypes = new byte[nVars];
for (int i = 0; i < nVars; i++) { varTypes[i] = r.ReadByte(); Console.WriteLine($" Var[{i}] type = {varTypes[i]}"); }
ushort codeLen = r.ReadUInt16();
Console.WriteLine($"CodeLen: {codeLen} bytes");
var code = r.ReadBytes(codeLen);
Console.WriteLine("\n--- Disassembly ---");
int ip = 0;
while (ip < code.Length) {
int addr = ip;
byte op = code[ip++];
Console.Write($"{addr:0000}: 0x{op:X2} {Bytecode.OpName(op)} ");
switch (op) {
case Bytecode.OpCodes.NOP: Console.WriteLine("NOP"); break;
case Bytecode.OpCodes.PUSH_CONST: { ushort ci = ReadU16(code, ref ip); Console.WriteLine($"PUSH_CONST {ci} ({consts[ci]})"); break; }
case Bytecode.OpCodes.PUSH_REAL_CONST: { ushort ci = ReadU16(code, ref ip); Console.WriteLine($"PUSH_REAL_CONST {ci} ({consts[ci]})"); break; }
case Bytecode.OpCodes.LOAD_VAR: { ushort vi = ReadU16(code, ref ip); Console.WriteLine($"LOAD_VAR {vi}"); break; }
case Bytecode.OpCodes.STORE_VAR: { ushort vi = ReadU16(code, ref ip); Console.WriteLine($"STORE_VAR {vi}"); break; }
case Bytecode.OpCodes.JZ: { ushort target = ReadU16(code, ref ip); Console.WriteLine($"JZ addr={target}"); break; }
case Bytecode.OpCodes.JMP: { ushort target = ReadU16(code, ref ip); Console.WriteLine($"JMP addr={target}"); break; }
case Bytecode.OpCodes.HALT: Console.WriteLine("HALT"); break;
default: Console.WriteLine($"{Bytecode.OpName(op)}"); break;
}
}
}
static ushort ReadU16(byte[] a, ref int ip) {
ushort v = (ushort)(a[ip] | (a[ip+1] << 8));
ip += 2;
return v;
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\STCompiler.Common\STCompiler.Common.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,36 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v8.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v8.0": {
"STCompiler.Disassembler/1.0.0": {
"dependencies": {
"STCompiler.Common": "1.0.0"
},
"runtime": {
"STCompiler.Disassembler.dll": {}
}
},
"STCompiler.Common/1.0.0": {
"runtime": {
"STCompiler.Common.dll": {}
}
}
}
},
"libraries": {
"STCompiler.Disassembler/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"STCompiler.Common/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

View File

@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net8.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "8.0.0"
},
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]

View File

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Disassembler")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Disassembler")]
[assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Disassembler")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@ -0,0 +1 @@
dc637a389172b7c1d98556c8fdb0f7e6b7d0182cadc40b75d2a802cc3145ba46

View File

@ -0,0 +1,13 @@
is_global = true
build_property.TargetFramework = net8.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = STCompiler.Disassembler
build_property.ProjectDir = /home/martin/Projects/STCompiler/STCompiler.Disassembler/
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

View File

@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

View File

@ -0,0 +1 @@
fed524f70924a7a6242fb1ec88f1925ce6879f83c899f8ed3dffe3ffd15c88b0

View File

@ -0,0 +1,18 @@
/home/martin/Projects/STCompiler/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler
/home/martin/Projects/STCompiler/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.deps.json
/home/martin/Projects/STCompiler/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.runtimeconfig.json
/home/martin/Projects/STCompiler/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.dll
/home/martin/Projects/STCompiler/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.pdb
/home/martin/Projects/STCompiler/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Common.dll
/home/martin/Projects/STCompiler/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Common.pdb
/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.csproj.AssemblyReference.cache
/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.GeneratedMSBuildEditorConfig.editorconfig
/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.AssemblyInfoInputs.cache
/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.AssemblyInfo.cs
/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.csproj.CoreCompileInputs.cache
/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.csproj.CopyComplete
/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.dll
/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/Debug/net8.0/refint/STCompiler.Disassembler.dll
/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.pdb
/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.genruntimeconfig.cache
/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/Debug/net8.0/ref/STCompiler.Disassembler.dll

View File

@ -0,0 +1 @@
0f919aa6f48480752187acc6336f3dd954d81be64b7f977f5e7455370c6b0417

Binary file not shown.

View File

@ -0,0 +1,130 @@
{
"format": 1,
"restore": {
"/home/martin/Projects/STCompiler/STCompiler.Disassembler/STCompiler.Disassembler.csproj": {}
},
"projects": {
"/home/martin/Projects/STCompiler/STCompiler.Common/STCompiler.Common.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/martin/Projects/STCompiler/STCompiler.Common/STCompiler.Common.csproj",
"projectName": "STCompiler.Common",
"projectPath": "/home/martin/Projects/STCompiler/STCompiler.Common/STCompiler.Common.csproj",
"packagesPath": "/home/martin/.nuget/packages/",
"outputPath": "/home/martin/Projects/STCompiler/STCompiler.Common/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/martin/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[8.0.20, 8.0.20]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.120/PortableRuntimeIdentifierGraph.json"
}
}
},
"/home/martin/Projects/STCompiler/STCompiler.Disassembler/STCompiler.Disassembler.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/martin/Projects/STCompiler/STCompiler.Disassembler/STCompiler.Disassembler.csproj",
"projectName": "STCompiler.Disassembler",
"projectPath": "/home/martin/Projects/STCompiler/STCompiler.Disassembler/STCompiler.Disassembler.csproj",
"packagesPath": "/home/martin/.nuget/packages/",
"outputPath": "/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/martin/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {
"/home/martin/Projects/STCompiler/STCompiler.Common/STCompiler.Common.csproj": {
"projectPath": "/home/martin/Projects/STCompiler/STCompiler.Common/STCompiler.Common.csproj"
}
}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[8.0.20, 8.0.20]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.120/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/martin/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/martin/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.8.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/home/martin/.nuget/packages/" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@ -0,0 +1,95 @@
{
"version": 3,
"targets": {
"net8.0": {
"STCompiler.Common/1.0.0": {
"type": "project",
"framework": ".NETCoreApp,Version=v8.0",
"compile": {
"bin/placeholder/STCompiler.Common.dll": {}
},
"runtime": {
"bin/placeholder/STCompiler.Common.dll": {}
}
}
}
},
"libraries": {
"STCompiler.Common/1.0.0": {
"type": "project",
"path": "../STCompiler.Common/STCompiler.Common.csproj",
"msbuildProject": "../STCompiler.Common/STCompiler.Common.csproj"
}
},
"projectFileDependencyGroups": {
"net8.0": [
"STCompiler.Common >= 1.0.0"
]
},
"packageFolders": {
"/home/martin/.nuget/packages/": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/martin/Projects/STCompiler/STCompiler.Disassembler/STCompiler.Disassembler.csproj",
"projectName": "STCompiler.Disassembler",
"projectPath": "/home/martin/Projects/STCompiler/STCompiler.Disassembler/STCompiler.Disassembler.csproj",
"packagesPath": "/home/martin/.nuget/packages/",
"outputPath": "/home/martin/Projects/STCompiler/STCompiler.Disassembler/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/martin/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {
"/home/martin/Projects/STCompiler/STCompiler.Common/STCompiler.Common.csproj": {
"projectPath": "/home/martin/Projects/STCompiler/STCompiler.Common/STCompiler.Common.csproj"
}
}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[8.0.20, 8.0.20]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.120/PortableRuntimeIdentifierGraph.json"
}
}
}
}

View File

@ -0,0 +1,10 @@
{
"version": 2,
"dgSpecHash": "s0tj8ngaSHf4PEU0x7K1E9bEHGayTmYwySGUMOEav8+YNokCEe1HNBdMoO+cEMLuxPCm3+TQcBxCGTSvXq6UBQ==",
"success": true,
"projectFilePath": "/home/martin/Projects/STCompiler/STCompiler.Disassembler/STCompiler.Disassembler.csproj",
"expectedPackageFiles": [
"/home/martin/.nuget/packages/microsoft.aspnetcore.app.ref/8.0.20/microsoft.aspnetcore.app.ref.8.0.20.nupkg.sha512"
],
"logs": []
}