diff --git a/STCompiler.Common/bin/Debug/net8.0/STCompiler.Common.dll b/STCompiler.Common/bin/Debug/net8.0/STCompiler.Common.dll index 14398bb..2f833e8 100644 Binary files a/STCompiler.Common/bin/Debug/net8.0/STCompiler.Common.dll and b/STCompiler.Common/bin/Debug/net8.0/STCompiler.Common.dll differ diff --git a/STCompiler.Common/bin/Debug/net8.0/STCompiler.Common.pdb b/STCompiler.Common/bin/Debug/net8.0/STCompiler.Common.pdb index 1976021..e31bac4 100644 Binary files a/STCompiler.Common/bin/Debug/net8.0/STCompiler.Common.pdb and b/STCompiler.Common/bin/Debug/net8.0/STCompiler.Common.pdb differ diff --git a/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.AssemblyInfo.cs b/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.AssemblyInfo.cs index 6fdd837..7a4d92f 100644 --- a/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.AssemblyInfo.cs +++ b/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.AssemblyInfo.cs @@ -13,10 +13,10 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Common")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+bdee19419dc879274e82afdd621b54e1923e0940")] [assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Common")] [assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Common")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Generated by the MSBuild WriteCodeFragment class. +// Von der MSBuild WriteCodeFragment-Klasse generiert. diff --git a/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.AssemblyInfoInputs.cache b/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.AssemblyInfoInputs.cache index dc208ce..220b771 100644 --- a/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.AssemblyInfoInputs.cache +++ b/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.AssemblyInfoInputs.cache @@ -1 +1 @@ -47f7f9783b0890c01839d6f882aac21cc3b1825ebf07d1532f3ffeb6d47e1764 +003d3c09b7e8f7918fbf4cdaa8090fdb095851afe383470e725a487d784f9416 diff --git a/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.dll b/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.dll index 14398bb..2f833e8 100644 Binary files a/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.dll and b/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.dll differ diff --git a/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.pdb b/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.pdb index 1976021..e31bac4 100644 Binary files a/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.pdb and b/STCompiler.Common/obj/Debug/net8.0/STCompiler.Common.pdb differ diff --git a/STCompiler.Common/obj/Debug/net8.0/ref/STCompiler.Common.dll b/STCompiler.Common/obj/Debug/net8.0/ref/STCompiler.Common.dll index 7718b6b..e65a8d4 100644 Binary files a/STCompiler.Common/obj/Debug/net8.0/ref/STCompiler.Common.dll and b/STCompiler.Common/obj/Debug/net8.0/ref/STCompiler.Common.dll differ diff --git a/STCompiler.Common/obj/Debug/net8.0/refint/STCompiler.Common.dll b/STCompiler.Common/obj/Debug/net8.0/refint/STCompiler.Common.dll index 7718b6b..e65a8d4 100644 Binary files a/STCompiler.Common/obj/Debug/net8.0/refint/STCompiler.Common.dll and b/STCompiler.Common/obj/Debug/net8.0/refint/STCompiler.Common.dll differ diff --git a/STCompiler.Compiler/Program.cs b/STCompiler.Compiler/Program.cs index 2b53f9a..54cffee 100644 --- a/STCompiler.Compiler/Program.cs +++ b/STCompiler.Compiler/Program.cs @@ -622,12 +622,12 @@ public class BytecodeEmitter { syms[v.Name]=new Symbol{Name=v.Name,Type=v.Type,Index=idx++}; foreach(var v in p.Vars) - if(v.Init!=null){EmitExpr(v.Init);EmitByte(0x03);EmitU16((ushort)syms[v.Name].Index);} + if(v.Init!=null){EmitExpr(v.Init);EmitByte(Bytecode.OpCodes.STORE_VAR);EmitU16((ushort)syms[v.Name].Index);} foreach(var s in p.Stmts) EmitStmt(s); - EmitByte(0xF0); // Program End + EmitByte(Bytecode.OpCodes.HALT); // Program End } // Operationscodes für verschiedene Datentypen @@ -779,14 +779,14 @@ public class BytecodeEmitter { int ci = AddConst(ie.Value); EmitByte(Bytecode.OpCodes.PUSH_CONST); // PUSH_CONST EmitU16((ushort)ci); - EmitByte((byte)ie.Type); // Typ der Konstante + // removed emitting the type byte into code stream; type is stored with constant table break; case RealExpr re: int cri = AddConst(re.Value); EmitByte(Bytecode.OpCodes.PUSH_REAL_CONST); // PUSH_REAL_CONST EmitU16((ushort)cri); - EmitByte((byte)re.Type); // REAL oder LREAL + // removed emitting the type byte into code stream; type is stored with constant table break; case VarExpr ve: @@ -808,10 +808,11 @@ public class BytecodeEmitter { } // Wenn nötig, Typenkonvertierung vor der Operation - if (be.L.Type != be.Type) - EmitByte((byte)(0x50 + (int)be.Type)); // CONVERT_TO_* - if (be.R.Type != be.Type) - EmitByte((byte)(0x50 + (int)be.Type)); // CONVERT_TO_* + // Conversion opcodes removed - runtime will handle type differences using constant type markers and operation opcodes + // if (be.L.Type != be.Type) + // EmitByte((byte)(0x50 + (int)be.Type)); // CONVERT_TO_* + // if (be.R.Type != be.Type) + // EmitByte((byte)(0x50 + (int)be.Type)); // CONVERT_TO_* EmitByte(opCodes[key]); break; diff --git a/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Common.dll b/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Common.dll index 14398bb..2f833e8 100644 Binary files a/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Common.dll and b/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Common.dll differ diff --git a/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Common.pdb b/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Common.pdb index 1976021..e31bac4 100644 Binary files a/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Common.pdb and b/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Common.pdb differ diff --git a/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Compiler.dll b/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Compiler.dll index 96199dd..9df4131 100644 Binary files a/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Compiler.dll and b/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Compiler.dll differ diff --git a/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Compiler.pdb b/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Compiler.pdb index 439a2fb..8a45371 100644 Binary files a/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Compiler.pdb and b/STCompiler.Compiler/bin/Debug/net8.0/STCompiler.Compiler.pdb differ diff --git a/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.AssemblyInfo.cs b/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.AssemblyInfo.cs index 96b3af7..f3a7144 100644 --- a/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.AssemblyInfo.cs +++ b/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.AssemblyInfo.cs @@ -13,10 +13,10 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Compiler")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+bdee19419dc879274e82afdd621b54e1923e0940")] [assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Compiler")] [assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Compiler")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Generated by the MSBuild WriteCodeFragment class. +// Von der MSBuild WriteCodeFragment-Klasse generiert. diff --git a/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.AssemblyInfoInputs.cache b/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.AssemblyInfoInputs.cache index 2f2f6fc..111b2d9 100644 --- a/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.AssemblyInfoInputs.cache +++ b/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.AssemblyInfoInputs.cache @@ -1 +1 @@ -62e0a705d77d04812d8911688545c821288c02824251ca71c994335e8a831b77 +46a6144e75588781017434fbf53d108cb421bb266942aa9aa55b1dd432b3b750 diff --git a/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.csproj.AssemblyReference.cache b/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.csproj.AssemblyReference.cache index 9b81881..32cebfd 100644 Binary files a/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.csproj.AssemblyReference.cache and b/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.csproj.AssemblyReference.cache differ diff --git a/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.dll b/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.dll index 96199dd..9df4131 100644 Binary files a/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.dll and b/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.dll differ diff --git a/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.pdb b/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.pdb index 439a2fb..8a45371 100644 Binary files a/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.pdb and b/STCompiler.Compiler/obj/Debug/net8.0/STCompiler.Compiler.pdb differ diff --git a/STCompiler.Compiler/obj/Debug/net8.0/ref/STCompiler.Compiler.dll b/STCompiler.Compiler/obj/Debug/net8.0/ref/STCompiler.Compiler.dll index ac5a523..a0f0572 100644 Binary files a/STCompiler.Compiler/obj/Debug/net8.0/ref/STCompiler.Compiler.dll and b/STCompiler.Compiler/obj/Debug/net8.0/ref/STCompiler.Compiler.dll differ diff --git a/STCompiler.Compiler/obj/Debug/net8.0/refint/STCompiler.Compiler.dll b/STCompiler.Compiler/obj/Debug/net8.0/refint/STCompiler.Compiler.dll index ac5a523..a0f0572 100644 Binary files a/STCompiler.Compiler/obj/Debug/net8.0/refint/STCompiler.Compiler.dll and b/STCompiler.Compiler/obj/Debug/net8.0/refint/STCompiler.Compiler.dll differ diff --git a/STCompiler.Compiler/output.bin b/STCompiler.Compiler/output.bin index a480aa0..34a8490 100644 Binary files a/STCompiler.Compiler/output.bin and b/STCompiler.Compiler/output.bin differ diff --git a/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Common.dll b/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Common.dll index 14398bb..2f833e8 100644 Binary files a/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Common.dll and b/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Common.dll differ diff --git a/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Common.pdb b/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Common.pdb index 1976021..e31bac4 100644 Binary files a/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Common.pdb and b/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Common.pdb differ diff --git a/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.dll b/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.dll index 3605db3..3adf22d 100644 Binary files a/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.dll and b/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.dll differ diff --git a/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.pdb b/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.pdb index 9984f44..b5c604f 100644 Binary files a/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.pdb and b/STCompiler.Disassembler/bin/Debug/net8.0/STCompiler.Disassembler.pdb differ diff --git a/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.AssemblyInfo.cs b/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.AssemblyInfo.cs index 7884c82..c076f49 100644 --- a/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.AssemblyInfo.cs +++ b/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.AssemblyInfo.cs @@ -13,10 +13,10 @@ 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.AssemblyInformationalVersionAttribute("1.0.0+bdee19419dc879274e82afdd621b54e1923e0940")] [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. +// Von der MSBuild WriteCodeFragment-Klasse generiert. diff --git a/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.AssemblyInfoInputs.cache b/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.AssemblyInfoInputs.cache index 8c30dea..2f53faa 100644 --- a/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.AssemblyInfoInputs.cache +++ b/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.AssemblyInfoInputs.cache @@ -1 +1 @@ -dc637a389172b7c1d98556c8fdb0f7e6b7d0182cadc40b75d2a802cc3145ba46 +e512ea89251f2295a76007dc4f99ce92f19bc2813739fd32e9bf7233cc288310 diff --git a/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.csproj.AssemblyReference.cache b/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.csproj.AssemblyReference.cache index 9b81881..32cebfd 100644 Binary files a/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.csproj.AssemblyReference.cache and b/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.csproj.AssemblyReference.cache differ diff --git a/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.dll b/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.dll index 3605db3..3adf22d 100644 Binary files a/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.dll and b/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.dll differ diff --git a/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.pdb b/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.pdb index 9984f44..b5c604f 100644 Binary files a/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.pdb and b/STCompiler.Disassembler/obj/Debug/net8.0/STCompiler.Disassembler.pdb differ diff --git a/STCompiler.Disassembler/obj/Debug/net8.0/ref/STCompiler.Disassembler.dll b/STCompiler.Disassembler/obj/Debug/net8.0/ref/STCompiler.Disassembler.dll index 18f4033..62cf6ba 100644 Binary files a/STCompiler.Disassembler/obj/Debug/net8.0/ref/STCompiler.Disassembler.dll and b/STCompiler.Disassembler/obj/Debug/net8.0/ref/STCompiler.Disassembler.dll differ diff --git a/STCompiler.Disassembler/obj/Debug/net8.0/refint/STCompiler.Disassembler.dll b/STCompiler.Disassembler/obj/Debug/net8.0/refint/STCompiler.Disassembler.dll index 18f4033..62cf6ba 100644 Binary files a/STCompiler.Disassembler/obj/Debug/net8.0/refint/STCompiler.Disassembler.dll and b/STCompiler.Disassembler/obj/Debug/net8.0/refint/STCompiler.Disassembler.dll differ diff --git a/STCompiler.Simulator/Program.cs b/STCompiler.Simulator/Program.cs index 7fe13a2..9b990ee 100644 --- a/STCompiler.Simulator/Program.cs +++ b/STCompiler.Simulator/Program.cs @@ -23,86 +23,71 @@ class Program { string magic = System.Text.Encoding.ASCII.GetString(r.ReadBytes(4)); if (magic != Bytecode.Magic) throw new Exception("Invalid magic"); ushort ver = r.ReadUInt16(); - if (ver != Bytecode.Version) throw new Exception($"Unsupported version {ver}"); + Console.WriteLine($"Version: {ver}"); + bool oldFormat = ver < Bytecode.Version; ushort nConsts = r.ReadUInt16(); + Console.WriteLine($"Consts: {nConsts}"); var consts = new List(); - for (int i = 0; i < nConsts; i++) { - byte t = r.ReadByte(); - switch(t) { - case 1: consts.Add(r.ReadInt64()); break; - case 2: consts.Add(r.ReadDouble()); break; - case 3: consts.Add(r.ReadSingle()); break; - case 4: consts.Add(r.ReadInt32()); break; - default: throw new Exception($"Unknown const type {t}"); + if (oldFormat) { + // old format: constants stored as 4-byte ints + for (int i = 0; i < nConsts; i++) { int v = r.ReadInt32(); consts.Add(v); Console.WriteLine($" [{i}] = {v}"); } + } else { + 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(); - var varTypes = new VarType[nVars]; - for (int i = 0; i < nVars; i++) varTypes[i] = (VarType)r.ReadByte(); + 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); var stack = new Stack(); var vars = new object[nVars]; int ip = 0; + Console.WriteLine("\n--- Disassembly / Simulation ---"); while (ip < code.Length) { + int addr = ip; byte op = code[ip++]; - switch(op) { - case Bytecode.OpCodes.NOP: break; + 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 = (ushort)(code[ip++] | (code[ip++] << 8)); + if (oldFormat) { byte typeMarker = code[ip++]; /* skip legacy type byte */ } + Console.WriteLine($"PUSH_CONST {ci} ({consts[ci]})"); stack.Push(consts[ci]); - break; - } + break; } case Bytecode.OpCodes.PUSH_REAL_CONST: { ushort ci = (ushort)(code[ip++] | (code[ip++] << 8)); + if (oldFormat) { byte typeMarker = code[ip++]; /* skip legacy type byte */ } + Console.WriteLine($"PUSH_REAL_CONST {ci} ({consts[ci]})"); stack.Push(consts[ci]); - break; - } - case Bytecode.OpCodes.LOAD_VAR: { - ushort vi = (ushort)(code[ip++] | (code[ip++] << 8)); - stack.Push(vars[vi]); - break; - } - case Bytecode.OpCodes.STORE_VAR: { - ushort vi = (ushort)(code[ip++] | (code[ip++] << 8)); - vars[vi] = stack.Pop(); - break; - } - case Bytecode.OpCodes.JZ: { - ushort target = (ushort)(code[ip++] | (code[ip++] << 8)); - var cond = stack.Pop(); - bool isFalse = cond is int ci ? ci == 0 : cond is long cl ? cl == 0L : cond is double cd ? cd == 0.0 : cond == null; - if (isFalse) ip = target; - break; - } - case Bytecode.OpCodes.JMP: { - ushort target = (ushort)(code[ip++] | (code[ip++] << 8)); - ip = target; - break; - } - case Bytecode.OpCodes.HALT: - Console.WriteLine("HALT"); - return; - default: - // Simple arithmetic handlers for some opcodes - if (Bytecode.OpName(op).StartsWith("ADD_")) { - dynamic b = stack.Pop(); dynamic a = stack.Pop(); stack.Push(a + b); break; - } - if (Bytecode.OpName(op).StartsWith("SUB_")) { - dynamic b = stack.Pop(); dynamic a = stack.Pop(); stack.Push(a - b); break; - } - if (Bytecode.OpName(op).StartsWith("MUL_")) { - dynamic b = stack.Pop(); dynamic a = stack.Pop(); stack.Push(a * b); break; - } - if (Bytecode.OpName(op).StartsWith("DIV_")) { - dynamic b = stack.Pop(); dynamic a = stack.Pop(); stack.Push(a / b); break; + break; } + case Bytecode.OpCodes.LOAD_VAR: { ushort vi = (ushort)(code[ip++] | (code[ip++] << 8)); Console.WriteLine($"LOAD_VAR {vi}"); stack.Push(vars[vi]); break; } + case Bytecode.OpCodes.STORE_VAR: { ushort vi = (ushort)(code[ip++] | (code[ip++] << 8)); Console.WriteLine($"STORE_VAR {vi}"); vars[vi] = stack.Pop(); break; } + case Bytecode.OpCodes.JZ: { ushort target = (ushort)(code[ip++] | (code[ip++] << 8)); Console.WriteLine($"JZ addr={target}"); var cond = stack.Pop(); bool isFalse = cond is int ci ? ci == 0 : cond is long cl ? cl == 0L : cond is double cd ? cd == 0.0 : cond == null; if (isFalse) ip = target; break; } + case Bytecode.OpCodes.JMP: { ushort target = (ushort)(code[ip++] | (code[ip++] << 8)); Console.WriteLine($"JMP addr={target}"); ip = target; break; } + case Bytecode.OpCodes.HALT: Console.WriteLine("HALT"); ip = code.Length; break; + default: Console.WriteLine(); + // fallback handlers + if (Bytecode.OpName(op).StartsWith("ADD_") || Bytecode.OpName(op).StartsWith("SUB_") || Bytecode.OpName(op).StartsWith("MUL_") || Bytecode.OpName(op).StartsWith("DIV_")) { + dynamic b = stack.Pop(); dynamic a = stack.Pop(); if (Bytecode.OpName(op).StartsWith("ADD_")) stack.Push(a + b); else if (Bytecode.OpName(op).StartsWith("SUB_")) stack.Push(a - b); else if (Bytecode.OpName(op).StartsWith("MUL_")) stack.Push(a * b); else stack.Push(a / b); + break; } if (Bytecode.OpName(op).StartsWith("LT_") || Bytecode.OpName(op).StartsWith("GT_") || Bytecode.OpName(op).StartsWith("LE_") || Bytecode.OpName(op).StartsWith("GE_") || Bytecode.OpName(op).StartsWith("EQ_") || Bytecode.OpName(op).StartsWith("NEQ_")) { - // comparisons: pop r, pop l, push int 0/1 dynamic rVal = stack.Pop(); dynamic lVal = stack.Pop(); bool res = Bytecode.OpName(op).StartsWith("LT_") ? (lVal < rVal) : Bytecode.OpName(op).StartsWith("GT_") ? (lVal > rVal) : @@ -117,7 +102,14 @@ class Program { } } - Console.WriteLine("Execution finished"); - for (int i = 0; i < vars.Length; i++) Console.WriteLine($"Var[{i}] = {vars[i]}"); + Console.WriteLine("Execution finished\n"); + // Detailed variable summary + Console.WriteLine("=== Variable summary ==="); + Console.WriteLine("Index\tType\t\tValue"); + for (int i = 0; i < vars.Length; i++) { + string typeName = (i < varTypes.Length) ? ((VarType)varTypes[i]).ToString() : "Unknown"; + var value = vars[i] ?? "null"; + Console.WriteLine($"{i}\t{typeName.PadRight(8)}\t{value}"); + } } } diff --git a/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Common.dll b/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Common.dll index 14398bb..2f833e8 100644 Binary files a/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Common.dll and b/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Common.dll differ diff --git a/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Common.pdb b/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Common.pdb index 1976021..e31bac4 100644 Binary files a/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Common.pdb and b/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Common.pdb differ diff --git a/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Simulator.dll b/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Simulator.dll index c61cbf4..8959c75 100644 Binary files a/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Simulator.dll and b/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Simulator.dll differ diff --git a/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Simulator.pdb b/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Simulator.pdb index 9dc9620..7af0505 100644 Binary files a/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Simulator.pdb and b/STCompiler.Simulator/bin/Debug/net8.0/STCompiler.Simulator.pdb differ diff --git a/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.AssemblyInfo.cs b/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.AssemblyInfo.cs index 6bf35d1..d507ab4 100644 --- a/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.AssemblyInfo.cs +++ b/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.AssemblyInfo.cs @@ -13,10 +13,10 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Simulator")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+bdee19419dc879274e82afdd621b54e1923e0940")] [assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Simulator")] [assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Simulator")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Generated by the MSBuild WriteCodeFragment class. +// Von der MSBuild WriteCodeFragment-Klasse generiert. diff --git a/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.AssemblyInfoInputs.cache b/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.AssemblyInfoInputs.cache index 89c0bcf..c12e849 100644 --- a/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.AssemblyInfoInputs.cache +++ b/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.AssemblyInfoInputs.cache @@ -1 +1 @@ -e68c3397a6969111aabee6432e0447cb372a6ba9ca289ded0d01796be53dbb16 +d8b8419173d413df3b338b6f12782609e7ef0c8712b509b4a4bb6869e65f93af diff --git a/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.csproj.AssemblyReference.cache b/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.csproj.AssemblyReference.cache index 9b81881..32cebfd 100644 Binary files a/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.csproj.AssemblyReference.cache and b/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.csproj.AssemblyReference.cache differ diff --git a/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.dll b/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.dll index c61cbf4..8959c75 100644 Binary files a/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.dll and b/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.dll differ diff --git a/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.pdb b/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.pdb index 9dc9620..7af0505 100644 Binary files a/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.pdb and b/STCompiler.Simulator/obj/Debug/net8.0/STCompiler.Simulator.pdb differ diff --git a/STCompiler.Simulator/obj/Debug/net8.0/ref/STCompiler.Simulator.dll b/STCompiler.Simulator/obj/Debug/net8.0/ref/STCompiler.Simulator.dll index 35146d5..3d64003 100644 Binary files a/STCompiler.Simulator/obj/Debug/net8.0/ref/STCompiler.Simulator.dll and b/STCompiler.Simulator/obj/Debug/net8.0/ref/STCompiler.Simulator.dll differ diff --git a/STCompiler.Simulator/obj/Debug/net8.0/refint/STCompiler.Simulator.dll b/STCompiler.Simulator/obj/Debug/net8.0/refint/STCompiler.Simulator.dll index 35146d5..3d64003 100644 Binary files a/STCompiler.Simulator/obj/Debug/net8.0/refint/STCompiler.Simulator.dll and b/STCompiler.Simulator/obj/Debug/net8.0/refint/STCompiler.Simulator.dll differ