Disammbler und Simulator angepasst. Arrays begonnen (defunct)
This commit is contained in:
@ -46,10 +46,29 @@ class Program {
|
||||
byte tb = r.ReadByte();
|
||||
var vt = (VarType)tb;
|
||||
varTypes[i] = vt;
|
||||
if (Enum.IsDefined(typeof(VarType), vt))
|
||||
|
||||
if (vt == VarType.ARRAY) {
|
||||
// Look ahead to find array length and element type
|
||||
int arrayStart = i;
|
||||
int length = 1;
|
||||
VarType elementType = 0; // Initialize to INT as default
|
||||
|
||||
if (i + 1 < nVars) {
|
||||
elementType = (VarType)varTypes[i + 1];
|
||||
while (i + length < nVars && varTypes[i + length] == varTypes[i + 1]) {
|
||||
length++;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($" Var[{i}] type = ARRAY[{length}] OF {elementType}");
|
||||
i += length - 1; // Skip array elements
|
||||
}
|
||||
else if (Enum.IsDefined(typeof(VarType), vt)) {
|
||||
Console.WriteLine($" Var[{i}] type = {vt}");
|
||||
else
|
||||
}
|
||||
else {
|
||||
Console.WriteLine($" Var[{i}] type = {tb} (unknown)");
|
||||
}
|
||||
}
|
||||
|
||||
ushort codeLen = r.ReadUInt16();
|
||||
@ -71,6 +90,12 @@ class Program {
|
||||
case Bytecode.OpCodes.JZ: { ushort target = ReadU16(code, ref ip); Console.WriteLine($"JZ addr={target:0000}"); break; }
|
||||
case Bytecode.OpCodes.JMP: { ushort target = ReadU16(code, ref ip); Console.WriteLine($"JMP addr={target:0000}"); break; }
|
||||
case Bytecode.OpCodes.HALT: Console.WriteLine("HALT"); break;
|
||||
case Bytecode.OpCodes.ARRAY_BOUNDS_CHECK: {
|
||||
Console.WriteLine("ARRAY_BOUNDS_CHECK");
|
||||
// Skip the next byte as it's part of the array bounds check instruction
|
||||
if (ip < code.Length) ip++;
|
||||
break;
|
||||
}
|
||||
default: Console.WriteLine($"{Bytecode.OpName(op)}"); break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user