Opcodes massiv erweitert
This commit is contained in:
@ -30,16 +30,25 @@ public static class Bytecode {
|
|||||||
public const byte ADD_REAL = 0x40; public const byte SUB_REAL = 0x41; public const byte MUL_REAL = 0x42; public const byte DIV_REAL = 0x43;
|
public const byte ADD_REAL = 0x40; public const byte SUB_REAL = 0x41; public const byte MUL_REAL = 0x42; public const byte DIV_REAL = 0x43;
|
||||||
public const byte ADD_LREAL = 0x44; public const byte SUB_LREAL = 0x45; public const byte MUL_LREAL = 0x46; public const byte DIV_LREAL = 0x47;
|
public const byte ADD_LREAL = 0x44; public const byte SUB_LREAL = 0x45; public const byte MUL_LREAL = 0x46; public const byte DIV_LREAL = 0x47;
|
||||||
|
|
||||||
// Comparisons signed
|
// Signed integer comparisons
|
||||||
public const byte LT_S = 0x50; public const byte GT_S = 0x51; public const byte LE_S = 0x52; public const byte GE_S = 0x53; public const byte EQ_S = 0x54; public const byte NEQ_S = 0x55;
|
public const byte LT_SINT = 0x50; public const byte GT_SINT = 0x51; public const byte LE_SINT = 0x52; public const byte GE_SINT = 0x53; public const byte EQ_SINT = 0x54; public const byte NEQ_SINT = 0x55;
|
||||||
// Comparisons unsigned
|
public const byte LT_INT = 0x56; public const byte GT_INT = 0x57; public const byte LE_INT = 0x58; public const byte GE_INT = 0x59; public const byte EQ_INT = 0x5A; public const byte NEQ_INT = 0x5B;
|
||||||
public const byte LT_U = 0x56; public const byte GT_U = 0x57; public const byte LE_U = 0x58; public const byte GE_U = 0x59; public const byte EQ_U = 0x5A; public const byte NEQ_U = 0x5B;
|
public const byte LT_DINT = 0x5C; public const byte GT_DINT = 0x5D; public const byte LE_DINT = 0x5E; public const byte GE_DINT = 0x5F; public const byte EQ_DINT = 0x60; public const byte NEQ_DINT = 0x61;
|
||||||
// Comparisons floating
|
public const byte LT_LINT = 0x62; public const byte GT_LINT = 0x63; public const byte LE_LINT = 0x64; public const byte GE_LINT = 0x65; public const byte EQ_LINT = 0x66; public const byte NEQ_LINT = 0x67;
|
||||||
public const byte LT_F = 0x5C; public const byte GT_F = 0x5D; public const byte LE_F = 0x5E; public const byte GE_F = 0x5F; public const byte EQ_F = 0x60; public const byte NEQ_F = 0x61;
|
|
||||||
|
// Unsigned integer comparisons
|
||||||
|
public const byte LT_USINT = 0x70; public const byte GT_USINT = 0x71; public const byte LE_USINT = 0x72; public const byte GE_USINT = 0x73; public const byte EQ_USINT = 0x74; public const byte NEQ_USINT = 0x75;
|
||||||
|
public const byte LT_UINT = 0x76; public const byte GT_UINT = 0x77; public const byte LE_UINT = 0x78; public const byte GE_UINT = 0x79; public const byte EQ_UINT = 0x7A; public const byte NEQ_UINT = 0x7B;
|
||||||
|
public const byte LT_UDINT = 0x7C; public const byte GT_UDINT = 0x7D; public const byte LE_UDINT = 0x7E; public const byte GE_UDINT = 0x7F; public const byte EQ_UDINT = 0x80; public const byte NEQ_UDINT = 0x81;
|
||||||
|
public const byte LT_ULINT = 0x82; public const byte GT_ULINT = 0x83; public const byte LE_ULINT = 0x84; public const byte GE_ULINT = 0x85; public const byte EQ_ULINT = 0x86; public const byte NEQ_ULINT = 0x87;
|
||||||
|
|
||||||
|
// Floating point comparisons
|
||||||
|
public const byte LT_REAL = 0x90; public const byte GT_REAL = 0x91; public const byte LE_REAL = 0x92; public const byte GE_REAL = 0x93; public const byte EQ_REAL = 0x94; public const byte NEQ_REAL = 0x95;
|
||||||
|
public const byte LT_LREAL = 0x96; public const byte GT_LREAL = 0x97; public const byte LE_LREAL = 0x98; public const byte GE_LREAL = 0x99; public const byte EQ_LREAL = 0x9A; public const byte NEQ_LREAL = 0x9B;
|
||||||
|
|
||||||
// Control flow
|
// Control flow
|
||||||
public const byte JZ = 0x70;
|
public const byte JZ = 0xA0;
|
||||||
public const byte JMP = 0x71;
|
public const byte JMP = 0xA1;
|
||||||
|
|
||||||
// Array operations
|
// Array operations
|
||||||
public const byte ARRAY_BOUNDS_CHECK = 0xE0;
|
public const byte ARRAY_BOUNDS_CHECK = 0xE0;
|
||||||
@ -63,9 +72,16 @@ public static class Bytecode {
|
|||||||
{ OpCodes.ADD_ULINT, "ADD_ULINT" }, { OpCodes.SUB_ULINT, "SUB_ULINT" }, { OpCodes.MUL_ULINT, "MUL_ULINT" }, { OpCodes.DIV_ULINT, "DIV_ULINT" },
|
{ OpCodes.ADD_ULINT, "ADD_ULINT" }, { OpCodes.SUB_ULINT, "SUB_ULINT" }, { OpCodes.MUL_ULINT, "MUL_ULINT" }, { OpCodes.DIV_ULINT, "DIV_ULINT" },
|
||||||
{ OpCodes.ADD_REAL, "ADD_REAL" }, { OpCodes.SUB_REAL, "SUB_REAL" }, { OpCodes.MUL_REAL, "MUL_REAL" }, { OpCodes.DIV_REAL, "DIV_REAL" },
|
{ OpCodes.ADD_REAL, "ADD_REAL" }, { OpCodes.SUB_REAL, "SUB_REAL" }, { OpCodes.MUL_REAL, "MUL_REAL" }, { OpCodes.DIV_REAL, "DIV_REAL" },
|
||||||
{ OpCodes.ADD_LREAL, "ADD_LREAL" }, { OpCodes.SUB_LREAL, "SUB_LREAL" }, { OpCodes.MUL_LREAL, "MUL_LREAL" }, { OpCodes.DIV_LREAL, "DIV_LREAL" },
|
{ OpCodes.ADD_LREAL, "ADD_LREAL" }, { OpCodes.SUB_LREAL, "SUB_LREAL" }, { OpCodes.MUL_LREAL, "MUL_LREAL" }, { OpCodes.DIV_LREAL, "DIV_LREAL" },
|
||||||
{ OpCodes.LT_S, "LT_S" }, { OpCodes.GT_S, "GT_S" }, { OpCodes.LE_S, "LE_S" }, { OpCodes.GE_S, "GE_S" }, { OpCodes.EQ_S, "EQ_S" }, { OpCodes.NEQ_S, "NEQ_S" },
|
{ OpCodes.LT_SINT, "LT_SINT" }, { OpCodes.GT_SINT, "GT_SINT" }, { OpCodes.LE_SINT, "LE_SINT" }, { OpCodes.GE_SINT, "GE_SINT" }, { OpCodes.EQ_SINT, "EQ_SINT" }, { OpCodes.NEQ_SINT, "NEQ_SINT" },
|
||||||
{ OpCodes.LT_U, "LT_U" }, { OpCodes.GT_U, "GT_U" }, { OpCodes.LE_U, "LE_U" }, { OpCodes.GE_U, "GE_U" }, { OpCodes.EQ_U, "EQ_U" }, { OpCodes.NEQ_U, "NEQ_U" },
|
{ OpCodes.LT_INT, "LT_INT" }, { OpCodes.GT_INT, "GT_INT" }, { OpCodes.LE_INT, "LE_INT" }, { OpCodes.GE_INT, "GE_INT" }, { OpCodes.EQ_INT, "EQ_INT" }, { OpCodes.NEQ_INT, "NEQ_INT" },
|
||||||
{ OpCodes.LT_F, "LT_F" }, { OpCodes.GT_F, "GT_F" }, { OpCodes.LE_F, "LE_F" }, { OpCodes.GE_F, "GE_F" }, { OpCodes.EQ_F, "EQ_F" }, { OpCodes.NEQ_F, "NEQ_F" },
|
{ OpCodes.LT_DINT, "LT_DINT" }, { OpCodes.GT_DINT, "GT_DINT" }, { OpCodes.LE_DINT, "LE_DINT" }, { OpCodes.GE_DINT, "GE_DINT" }, { OpCodes.EQ_DINT, "EQ_DINT" }, { OpCodes.NEQ_DINT, "NEQ_DINT" },
|
||||||
|
{ OpCodes.LT_LINT, "LT_LINT" }, { OpCodes.GT_LINT, "GT_LINT" }, { OpCodes.LE_LINT, "LE_LINT" }, { OpCodes.GE_LINT, "GE_LINT" }, { OpCodes.EQ_LINT, "EQ_LINT" }, { OpCodes.NEQ_LINT, "NEQ_LINT" },
|
||||||
|
{ OpCodes.LT_USINT, "LT_USINT" }, { OpCodes.GT_USINT, "GT_USINT" }, { OpCodes.LE_USINT, "LE_USINT" }, { OpCodes.GE_USINT, "GE_USINT" }, { OpCodes.EQ_USINT, "EQ_USINT" }, { OpCodes.NEQ_USINT, "NEQ_USINT" },
|
||||||
|
{ OpCodes.LT_UINT, "LT_UINT" }, { OpCodes.GT_UINT, "GT_UINT" }, { OpCodes.LE_UINT, "LE_UINT" }, { OpCodes.GE_UINT, "GE_UINT" }, { OpCodes.EQ_UINT, "EQ_UINT" }, { OpCodes.NEQ_UINT, "NEQ_UINT" },
|
||||||
|
{ OpCodes.LT_UDINT, "LT_UDINT" }, { OpCodes.GT_UDINT, "GT_UDINT" }, { OpCodes.LE_UDINT, "LE_UDINT" }, { OpCodes.GE_UDINT, "GE_UDINT" }, { OpCodes.EQ_UDINT, "EQ_UDINT" }, { OpCodes.NEQ_UDINT, "NEQ_UDINT" },
|
||||||
|
{ OpCodes.LT_ULINT, "LT_ULINT" }, { OpCodes.GT_ULINT, "GT_ULINT" }, { OpCodes.LE_ULINT, "LE_ULINT" }, { OpCodes.GE_ULINT, "GE_ULINT" }, { OpCodes.EQ_ULINT, "EQ_ULINT" }, { OpCodes.NEQ_ULINT, "NEQ_ULINT" },
|
||||||
|
{ OpCodes.LT_REAL, "LT_REAL" }, { OpCodes.GT_REAL, "GT_REAL" }, { OpCodes.LE_REAL, "LE_REAL" }, { OpCodes.GE_REAL, "GE_REAL" }, { OpCodes.EQ_REAL, "EQ_REAL" }, { OpCodes.NEQ_REAL, "NEQ_REAL" },
|
||||||
|
{ OpCodes.LT_LREAL, "LT_LREAL" }, { OpCodes.GT_LREAL, "GT_LREAL" }, { OpCodes.LE_LREAL, "LE_LREAL" }, { OpCodes.GE_LREAL, "GE_LREAL" }, { OpCodes.EQ_LREAL, "EQ_LREAL" }, { OpCodes.NEQ_LREAL, "NEQ_LREAL" },
|
||||||
{ OpCodes.JZ, "JZ" }, { OpCodes.JMP, "JMP" },
|
{ OpCodes.JZ, "JZ" }, { OpCodes.JMP, "JMP" },
|
||||||
{ OpCodes.ARRAY_BOUNDS_CHECK, "ARRAY_BOUNDS_CHECK" },
|
{ OpCodes.ARRAY_BOUNDS_CHECK, "ARRAY_BOUNDS_CHECK" },
|
||||||
{ OpCodes.HALT, "HALT" }
|
{ OpCodes.HALT, "HALT" }
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Common")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Common")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+74f256efb2d90ae0bc878111d497ee146327bb51")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5a002806a9ee3a7389c5a14069c534271a20a9ac")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Common")]
|
[assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Common")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Common")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Common")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
4f685d6f74184ca56c8bdd109d64fc681695ed4155cb24ff44ab2c139f8eee14
|
47a06821b3855b1302f973341d27a55ee26f60ac14ed88a286a0d4a4b2a812d1
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -127,40 +127,40 @@ public class BytecodeEmitter {
|
|||||||
{(TokType.MUL, VarType.LREAL), Bytecode.OpCodes.MUL_LREAL}, {(TokType.DIV, VarType.LREAL), Bytecode.OpCodes.DIV_LREAL},
|
{(TokType.MUL, VarType.LREAL), Bytecode.OpCodes.MUL_LREAL}, {(TokType.DIV, VarType.LREAL), Bytecode.OpCodes.DIV_LREAL},
|
||||||
|
|
||||||
// Comparisons signed
|
// Comparisons signed
|
||||||
{(TokType.LT, VarType.SINT), Bytecode.OpCodes.LT_S}, {(TokType.GT, VarType.SINT), Bytecode.OpCodes.GT_S},
|
{(TokType.LT, VarType.SINT), Bytecode.OpCodes.LT_SINT}, {(TokType.GT, VarType.SINT), Bytecode.OpCodes.GT_SINT},
|
||||||
{(TokType.LE, VarType.SINT), Bytecode.OpCodes.LE_S}, {(TokType.GE, VarType.SINT), Bytecode.OpCodes.GE_S},
|
{(TokType.LE, VarType.SINT), Bytecode.OpCodes.LE_SINT}, {(TokType.GE, VarType.SINT), Bytecode.OpCodes.GE_SINT},
|
||||||
{(TokType.EQ, VarType.SINT), Bytecode.OpCodes.EQ_S}, {(TokType.NEQ, VarType.SINT), Bytecode.OpCodes.NEQ_S},
|
{(TokType.EQ, VarType.SINT), Bytecode.OpCodes.EQ_SINT}, {(TokType.NEQ, VarType.SINT), Bytecode.OpCodes.NEQ_SINT},
|
||||||
{(TokType.LT, VarType.INT), Bytecode.OpCodes.LT_S}, {(TokType.GT, VarType.INT), Bytecode.OpCodes.GT_S},
|
{(TokType.LT, VarType.INT), Bytecode.OpCodes.LT_INT}, {(TokType.GT, VarType.INT), Bytecode.OpCodes.GT_INT},
|
||||||
{(TokType.LE, VarType.INT), Bytecode.OpCodes.LE_S}, {(TokType.GE, VarType.INT), Bytecode.OpCodes.GE_S},
|
{(TokType.LE, VarType.INT), Bytecode.OpCodes.LE_INT}, {(TokType.GE, VarType.INT), Bytecode.OpCodes.GE_INT},
|
||||||
{(TokType.EQ, VarType.INT), Bytecode.OpCodes.EQ_S}, {(TokType.NEQ, VarType.INT), Bytecode.OpCodes.NEQ_S},
|
{(TokType.EQ, VarType.INT), Bytecode.OpCodes.EQ_INT}, {(TokType.NEQ, VarType.INT), Bytecode.OpCodes.NEQ_INT},
|
||||||
{(TokType.LT, VarType.DINT), Bytecode.OpCodes.LT_S}, {(TokType.GT, VarType.DINT), Bytecode.OpCodes.GT_S},
|
{(TokType.LT, VarType.DINT), Bytecode.OpCodes.LT_DINT}, {(TokType.GT, VarType.DINT), Bytecode.OpCodes.GT_DINT},
|
||||||
{(TokType.LE, VarType.DINT), Bytecode.OpCodes.LE_S}, {(TokType.GE, VarType.DINT), Bytecode.OpCodes.GE_S},
|
{(TokType.LE, VarType.DINT), Bytecode.OpCodes.LE_DINT}, {(TokType.GE, VarType.DINT), Bytecode.OpCodes.GE_DINT},
|
||||||
{(TokType.EQ, VarType.DINT), Bytecode.OpCodes.EQ_S}, {(TokType.NEQ, VarType.DINT), Bytecode.OpCodes.NEQ_S},
|
{(TokType.EQ, VarType.DINT), Bytecode.OpCodes.EQ_DINT}, {(TokType.NEQ, VarType.DINT), Bytecode.OpCodes.NEQ_DINT},
|
||||||
{(TokType.LT, VarType.LINT), Bytecode.OpCodes.LT_S}, {(TokType.GT, VarType.LINT), Bytecode.OpCodes.GT_S},
|
{(TokType.LT, VarType.LINT), Bytecode.OpCodes.LT_LINT}, {(TokType.GT, VarType.LINT), Bytecode.OpCodes.GT_LINT},
|
||||||
{(TokType.LE, VarType.LINT), Bytecode.OpCodes.LE_S}, {(TokType.GE, VarType.LINT), Bytecode.OpCodes.GE_S},
|
{(TokType.LE, VarType.LINT), Bytecode.OpCodes.LE_LINT}, {(TokType.GE, VarType.LINT), Bytecode.OpCodes.GE_LINT},
|
||||||
{(TokType.EQ, VarType.LINT), Bytecode.OpCodes.EQ_S}, {(TokType.NEQ, VarType.LINT), Bytecode.OpCodes.NEQ_S},
|
{(TokType.EQ, VarType.LINT), Bytecode.OpCodes.EQ_LINT}, {(TokType.NEQ, VarType.LINT), Bytecode.OpCodes.NEQ_LINT},
|
||||||
|
|
||||||
// Comparisons unsigned
|
// Comparisons unsigned
|
||||||
{(TokType.LT, VarType.USINT), Bytecode.OpCodes.LT_U}, {(TokType.GT, VarType.USINT), Bytecode.OpCodes.GT_U},
|
{(TokType.LT, VarType.USINT), Bytecode.OpCodes.LT_USINT}, {(TokType.GT, VarType.USINT), Bytecode.OpCodes.GT_USINT},
|
||||||
{(TokType.LE, VarType.USINT), Bytecode.OpCodes.LE_U}, {(TokType.GE, VarType.USINT), Bytecode.OpCodes.GE_U},
|
{(TokType.LE, VarType.USINT), Bytecode.OpCodes.LE_USINT}, {(TokType.GE, VarType.USINT), Bytecode.OpCodes.GE_USINT},
|
||||||
{(TokType.EQ, VarType.USINT), Bytecode.OpCodes.EQ_U}, {(TokType.NEQ, VarType.USINT), Bytecode.OpCodes.NEQ_U},
|
{(TokType.EQ, VarType.USINT), Bytecode.OpCodes.EQ_USINT}, {(TokType.NEQ, VarType.USINT), Bytecode.OpCodes.NEQ_USINT},
|
||||||
{(TokType.LT, VarType.UINT), Bytecode.OpCodes.LT_U}, {(TokType.GT, VarType.UINT), Bytecode.OpCodes.GT_U},
|
{(TokType.LT, VarType.UINT), Bytecode.OpCodes.LT_UINT}, {(TokType.GT, VarType.UINT), Bytecode.OpCodes.GT_UINT},
|
||||||
{(TokType.LE, VarType.UINT), Bytecode.OpCodes.LE_U}, {(TokType.GE, VarType.UINT), Bytecode.OpCodes.GE_U},
|
{(TokType.LE, VarType.UINT), Bytecode.OpCodes.LE_UINT}, {(TokType.GE, VarType.UINT), Bytecode.OpCodes.GE_UINT},
|
||||||
{(TokType.EQ, VarType.UINT), Bytecode.OpCodes.EQ_U}, {(TokType.NEQ, VarType.UINT), Bytecode.OpCodes.NEQ_U},
|
{(TokType.EQ, VarType.UINT), Bytecode.OpCodes.EQ_UINT}, {(TokType.NEQ, VarType.UINT), Bytecode.OpCodes.NEQ_UINT},
|
||||||
{(TokType.LT, VarType.UDINT), Bytecode.OpCodes.LT_U}, {(TokType.GT, VarType.UDINT), Bytecode.OpCodes.GT_U},
|
{(TokType.LT, VarType.UDINT), Bytecode.OpCodes.LT_UDINT}, {(TokType.GT, VarType.UDINT), Bytecode.OpCodes.GT_UDINT},
|
||||||
{(TokType.LE, VarType.UDINT), Bytecode.OpCodes.LE_U}, {(TokType.GE, VarType.UDINT), Bytecode.OpCodes.GE_U},
|
{(TokType.LE, VarType.UDINT), Bytecode.OpCodes.LE_UDINT}, {(TokType.GE, VarType.UDINT), Bytecode.OpCodes.GE_UDINT},
|
||||||
{(TokType.EQ, VarType.UDINT), Bytecode.OpCodes.EQ_U}, {(TokType.NEQ, VarType.UDINT), Bytecode.OpCodes.NEQ_U},
|
{(TokType.EQ, VarType.UDINT), Bytecode.OpCodes.EQ_UDINT}, {(TokType.NEQ, VarType.UDINT), Bytecode.OpCodes.NEQ_UDINT},
|
||||||
{(TokType.LT, VarType.ULINT), Bytecode.OpCodes.LT_U}, {(TokType.GT, VarType.ULINT), Bytecode.OpCodes.GT_U},
|
{(TokType.LT, VarType.ULINT), Bytecode.OpCodes.LT_ULINT}, {(TokType.GT, VarType.ULINT), Bytecode.OpCodes.GT_ULINT},
|
||||||
{(TokType.LE, VarType.ULINT), Bytecode.OpCodes.LE_U}, {(TokType.GE, VarType.ULINT), Bytecode.OpCodes.GE_U},
|
{(TokType.LE, VarType.ULINT), Bytecode.OpCodes.LE_ULINT}, {(TokType.GE, VarType.ULINT), Bytecode.OpCodes.GE_ULINT},
|
||||||
{(TokType.EQ, VarType.ULINT), Bytecode.OpCodes.EQ_U}, {(TokType.NEQ, VarType.ULINT), Bytecode.OpCodes.NEQ_U},
|
{(TokType.EQ, VarType.ULINT), Bytecode.OpCodes.EQ_ULINT}, {(TokType.NEQ, VarType.ULINT), Bytecode.OpCodes.NEQ_ULINT},
|
||||||
|
|
||||||
// Comparisons floating
|
// Comparisons floating
|
||||||
{(TokType.LT, VarType.REAL), Bytecode.OpCodes.LT_F}, {(TokType.GT, VarType.REAL), Bytecode.OpCodes.GT_F},
|
{(TokType.LT, VarType.REAL), Bytecode.OpCodes.LT_REAL}, {(TokType.GT, VarType.REAL), Bytecode.OpCodes.GT_REAL},
|
||||||
{(TokType.LE, VarType.REAL), Bytecode.OpCodes.LE_F}, {(TokType.GE, VarType.REAL), Bytecode.OpCodes.GE_F},
|
{(TokType.LE, VarType.REAL), Bytecode.OpCodes.LE_REAL}, {(TokType.GE, VarType.REAL), Bytecode.OpCodes.GE_REAL},
|
||||||
{(TokType.EQ, VarType.REAL), Bytecode.OpCodes.EQ_F}, {(TokType.NEQ, VarType.REAL), Bytecode.OpCodes.NEQ_F},
|
{(TokType.EQ, VarType.REAL), Bytecode.OpCodes.EQ_REAL}, {(TokType.NEQ, VarType.REAL), Bytecode.OpCodes.NEQ_REAL},
|
||||||
{(TokType.LT, VarType.LREAL), Bytecode.OpCodes.LT_F}, {(TokType.GT, VarType.LREAL), Bytecode.OpCodes.GT_F},
|
{(TokType.LT, VarType.LREAL), Bytecode.OpCodes.LT_LREAL}, {(TokType.GT, VarType.LREAL), Bytecode.OpCodes.GT_LREAL},
|
||||||
{(TokType.LE, VarType.LREAL), Bytecode.OpCodes.LE_F}, {(TokType.GE, VarType.LREAL), Bytecode.OpCodes.GE_F},
|
{(TokType.LE, VarType.LREAL), Bytecode.OpCodes.LE_LREAL}, {(TokType.GE, VarType.LREAL), Bytecode.OpCodes.GE_LREAL},
|
||||||
{(TokType.EQ, VarType.LREAL), Bytecode.OpCodes.EQ_F}, {(TokType.NEQ, VarType.LREAL), Bytecode.OpCodes.NEQ_F}
|
{(TokType.EQ, VarType.LREAL), Bytecode.OpCodes.EQ_LREAL}, {(TokType.NEQ, VarType.LREAL), Bytecode.OpCodes.NEQ_LREAL}
|
||||||
};
|
};
|
||||||
|
|
||||||
void EmitStmt(Stmt s){
|
void EmitStmt(Stmt s){
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -49,3 +49,14 @@ END_FOR;
|
|||||||
x := x + y / 2.0;
|
x := x + y / 2.0;
|
||||||
|
|
||||||
END_PROGRAM
|
END_PROGRAM
|
||||||
|
|
||||||
|
//=== Variable summary ===
|
||||||
|
//Index Type Value
|
||||||
|
//0 UINT 1
|
||||||
|
//1 UINT 12
|
||||||
|
//2 UINT 1
|
||||||
|
//3 DINT 25
|
||||||
|
//4 BOOL 1
|
||||||
|
//5 REAL 16,25
|
||||||
|
//6 LREAL 25
|
||||||
|
//7 INT 3
|
||||||
@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Compiler")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Compiler")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+74f256efb2d90ae0bc878111d497ee146327bb51")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5a002806a9ee3a7389c5a14069c534271a20a9ac")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Compiler")]
|
[assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Compiler")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Compiler")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Compiler")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
9e103a7c6db7d257367fcb8e4dc976fb31f0875136636fa357927991b9ce9ddc
|
d47a514fbef951d9157ec77bff6b43f7e588943a6cbc9cdecac26e64e892fcea
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -98,6 +98,112 @@ class Program {
|
|||||||
if (ip < code.Length) ip++;
|
if (ip < code.Length) ip++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// Signed integer arithmetic
|
||||||
|
case Bytecode.OpCodes.ADD_SINT: Console.WriteLine("ADD_SINT"); break;
|
||||||
|
case Bytecode.OpCodes.SUB_SINT: Console.WriteLine("SUB_SINT"); break;
|
||||||
|
case Bytecode.OpCodes.MUL_SINT: Console.WriteLine("MUL_SINT"); break;
|
||||||
|
case Bytecode.OpCodes.DIV_SINT: Console.WriteLine("DIV_SINT"); break;
|
||||||
|
case Bytecode.OpCodes.ADD_INT: Console.WriteLine("ADD_INT"); break;
|
||||||
|
case Bytecode.OpCodes.SUB_INT: Console.WriteLine("SUB_INT"); break;
|
||||||
|
case Bytecode.OpCodes.MUL_INT: Console.WriteLine("MUL_INT"); break;
|
||||||
|
case Bytecode.OpCodes.DIV_INT: Console.WriteLine("DIV_INT"); break;
|
||||||
|
case Bytecode.OpCodes.ADD_DINT: Console.WriteLine("ADD_DINT"); break;
|
||||||
|
case Bytecode.OpCodes.SUB_DINT: Console.WriteLine("SUB_DINT"); break;
|
||||||
|
case Bytecode.OpCodes.MUL_DINT: Console.WriteLine("MUL_DINT"); break;
|
||||||
|
case Bytecode.OpCodes.DIV_DINT: Console.WriteLine("DIV_DINT"); break;
|
||||||
|
case Bytecode.OpCodes.ADD_LINT: Console.WriteLine("ADD_LINT"); break;
|
||||||
|
case Bytecode.OpCodes.SUB_LINT: Console.WriteLine("SUB_LINT"); break;
|
||||||
|
case Bytecode.OpCodes.MUL_LINT: Console.WriteLine("MUL_LINT"); break;
|
||||||
|
case Bytecode.OpCodes.DIV_LINT: Console.WriteLine("DIV_LINT"); break;
|
||||||
|
// Unsigned integer arithmetic
|
||||||
|
case Bytecode.OpCodes.ADD_USINT: Console.WriteLine("ADD_USINT"); break;
|
||||||
|
case Bytecode.OpCodes.SUB_USINT: Console.WriteLine("SUB_USINT"); break;
|
||||||
|
case Bytecode.OpCodes.MUL_USINT: Console.WriteLine("MUL_USINT"); break;
|
||||||
|
case Bytecode.OpCodes.DIV_USINT: Console.WriteLine("DIV_USINT"); break;
|
||||||
|
case Bytecode.OpCodes.ADD_UINT: Console.WriteLine("ADD_UINT"); break;
|
||||||
|
case Bytecode.OpCodes.SUB_UINT: Console.WriteLine("SUB_UINT"); break;
|
||||||
|
case Bytecode.OpCodes.MUL_UINT: Console.WriteLine("MUL_UINT"); break;
|
||||||
|
case Bytecode.OpCodes.DIV_UINT: Console.WriteLine("DIV_UINT"); break;
|
||||||
|
case Bytecode.OpCodes.ADD_UDINT: Console.WriteLine("ADD_UDINT"); break;
|
||||||
|
case Bytecode.OpCodes.SUB_UDINT: Console.WriteLine("SUB_UDINT"); break;
|
||||||
|
case Bytecode.OpCodes.MUL_UDINT: Console.WriteLine("MUL_UDINT"); break;
|
||||||
|
case Bytecode.OpCodes.DIV_UDINT: Console.WriteLine("DIV_UDINT"); break;
|
||||||
|
case Bytecode.OpCodes.ADD_ULINT: Console.WriteLine("ADD_ULINT"); break;
|
||||||
|
case Bytecode.OpCodes.SUB_ULINT: Console.WriteLine("SUB_ULINT"); break;
|
||||||
|
case Bytecode.OpCodes.MUL_ULINT: Console.WriteLine("MUL_ULINT"); break;
|
||||||
|
case Bytecode.OpCodes.DIV_ULINT: Console.WriteLine("DIV_ULINT"); break;
|
||||||
|
// Floating point arithmetic
|
||||||
|
case Bytecode.OpCodes.ADD_REAL: Console.WriteLine("ADD_REAL"); break;
|
||||||
|
case Bytecode.OpCodes.SUB_REAL: Console.WriteLine("SUB_REAL"); break;
|
||||||
|
case Bytecode.OpCodes.MUL_REAL: Console.WriteLine("MUL_REAL"); break;
|
||||||
|
case Bytecode.OpCodes.DIV_REAL: Console.WriteLine("DIV_REAL"); break;
|
||||||
|
case Bytecode.OpCodes.ADD_LREAL: Console.WriteLine("ADD_LREAL"); break;
|
||||||
|
case Bytecode.OpCodes.SUB_LREAL: Console.WriteLine("SUB_LREAL"); break;
|
||||||
|
case Bytecode.OpCodes.MUL_LREAL: Console.WriteLine("MUL_LREAL"); break;
|
||||||
|
case Bytecode.OpCodes.DIV_LREAL: Console.WriteLine("DIV_LREAL"); break;
|
||||||
|
// Signed integer comparisons
|
||||||
|
case Bytecode.OpCodes.LT_SINT: Console.WriteLine("LT_SINT"); break;
|
||||||
|
case Bytecode.OpCodes.GT_SINT: Console.WriteLine("GT_SINT"); break;
|
||||||
|
case Bytecode.OpCodes.LE_SINT: Console.WriteLine("LE_SINT"); break;
|
||||||
|
case Bytecode.OpCodes.GE_SINT: Console.WriteLine("GE_SINT"); break;
|
||||||
|
case Bytecode.OpCodes.EQ_SINT: Console.WriteLine("EQ_SINT"); break;
|
||||||
|
case Bytecode.OpCodes.NEQ_SINT: Console.WriteLine("NEQ_SINT"); break;
|
||||||
|
case Bytecode.OpCodes.LT_INT: Console.WriteLine("LT_INT"); break;
|
||||||
|
case Bytecode.OpCodes.GT_INT: Console.WriteLine("GT_INT"); break;
|
||||||
|
case Bytecode.OpCodes.LE_INT: Console.WriteLine("LE_INT"); break;
|
||||||
|
case Bytecode.OpCodes.GE_INT: Console.WriteLine("GE_INT"); break;
|
||||||
|
case Bytecode.OpCodes.EQ_INT: Console.WriteLine("EQ_INT"); break;
|
||||||
|
case Bytecode.OpCodes.NEQ_INT: Console.WriteLine("NEQ_INT"); break;
|
||||||
|
case Bytecode.OpCodes.LT_DINT: Console.WriteLine("LT_DINT"); break;
|
||||||
|
case Bytecode.OpCodes.GT_DINT: Console.WriteLine("GT_DINT"); break;
|
||||||
|
case Bytecode.OpCodes.LE_DINT: Console.WriteLine("LE_DINT"); break;
|
||||||
|
case Bytecode.OpCodes.GE_DINT: Console.WriteLine("GE_DINT"); break;
|
||||||
|
case Bytecode.OpCodes.EQ_DINT: Console.WriteLine("EQ_DINT"); break;
|
||||||
|
case Bytecode.OpCodes.NEQ_DINT: Console.WriteLine("NEQ_DINT"); break;
|
||||||
|
case Bytecode.OpCodes.LT_LINT: Console.WriteLine("LT_LINT"); break;
|
||||||
|
case Bytecode.OpCodes.GT_LINT: Console.WriteLine("GT_LINT"); break;
|
||||||
|
case Bytecode.OpCodes.LE_LINT: Console.WriteLine("LE_LINT"); break;
|
||||||
|
case Bytecode.OpCodes.GE_LINT: Console.WriteLine("GE_LINT"); break;
|
||||||
|
case Bytecode.OpCodes.EQ_LINT: Console.WriteLine("EQ_LINT"); break;
|
||||||
|
case Bytecode.OpCodes.NEQ_LINT: Console.WriteLine("NEQ_LINT"); break;
|
||||||
|
// Unsigned integer comparisons
|
||||||
|
case Bytecode.OpCodes.LT_USINT: Console.WriteLine("LT_USINT"); break;
|
||||||
|
case Bytecode.OpCodes.GT_USINT: Console.WriteLine("GT_USINT"); break;
|
||||||
|
case Bytecode.OpCodes.LE_USINT: Console.WriteLine("LE_USINT"); break;
|
||||||
|
case Bytecode.OpCodes.GE_USINT: Console.WriteLine("GE_USINT"); break;
|
||||||
|
case Bytecode.OpCodes.EQ_USINT: Console.WriteLine("EQ_USINT"); break;
|
||||||
|
case Bytecode.OpCodes.NEQ_USINT: Console.WriteLine("NEQ_USINT"); break;
|
||||||
|
case Bytecode.OpCodes.LT_UINT: Console.WriteLine("LT_UINT"); break;
|
||||||
|
case Bytecode.OpCodes.GT_UINT: Console.WriteLine("GT_UINT"); break;
|
||||||
|
case Bytecode.OpCodes.LE_UINT: Console.WriteLine("LE_UINT"); break;
|
||||||
|
case Bytecode.OpCodes.GE_UINT: Console.WriteLine("GE_UINT"); break;
|
||||||
|
case Bytecode.OpCodes.EQ_UINT: Console.WriteLine("EQ_UINT"); break;
|
||||||
|
case Bytecode.OpCodes.NEQ_UINT: Console.WriteLine("NEQ_UINT"); break;
|
||||||
|
case Bytecode.OpCodes.LT_UDINT: Console.WriteLine("LT_UDINT"); break;
|
||||||
|
case Bytecode.OpCodes.GT_UDINT: Console.WriteLine("GT_UDINT"); break;
|
||||||
|
case Bytecode.OpCodes.LE_UDINT: Console.WriteLine("LE_UDINT"); break;
|
||||||
|
case Bytecode.OpCodes.GE_UDINT: Console.WriteLine("GE_UDINT"); break;
|
||||||
|
case Bytecode.OpCodes.EQ_UDINT: Console.WriteLine("EQ_UDINT"); break;
|
||||||
|
case Bytecode.OpCodes.NEQ_UDINT: Console.WriteLine("NEQ_UDINT"); break;
|
||||||
|
case Bytecode.OpCodes.LT_ULINT: Console.WriteLine("LT_ULINT"); break;
|
||||||
|
case Bytecode.OpCodes.GT_ULINT: Console.WriteLine("GT_ULINT"); break;
|
||||||
|
case Bytecode.OpCodes.LE_ULINT: Console.WriteLine("LE_ULINT"); break;
|
||||||
|
case Bytecode.OpCodes.GE_ULINT: Console.WriteLine("GE_ULINT"); break;
|
||||||
|
case Bytecode.OpCodes.EQ_ULINT: Console.WriteLine("EQ_ULINT"); break;
|
||||||
|
case Bytecode.OpCodes.NEQ_ULINT: Console.WriteLine("NEQ_ULINT"); break;
|
||||||
|
// Floating point comparisons
|
||||||
|
case Bytecode.OpCodes.LT_REAL: Console.WriteLine("LT_REAL"); break;
|
||||||
|
case Bytecode.OpCodes.GT_REAL: Console.WriteLine("GT_REAL"); break;
|
||||||
|
case Bytecode.OpCodes.LE_REAL: Console.WriteLine("LE_REAL"); break;
|
||||||
|
case Bytecode.OpCodes.GE_REAL: Console.WriteLine("GE_REAL"); break;
|
||||||
|
case Bytecode.OpCodes.EQ_REAL: Console.WriteLine("EQ_REAL"); break;
|
||||||
|
case Bytecode.OpCodes.NEQ_REAL: Console.WriteLine("NEQ_REAL"); break;
|
||||||
|
case Bytecode.OpCodes.LT_LREAL: Console.WriteLine("LT_LREAL"); break;
|
||||||
|
case Bytecode.OpCodes.GT_LREAL: Console.WriteLine("GT_LREAL"); break;
|
||||||
|
case Bytecode.OpCodes.LE_LREAL: Console.WriteLine("LE_LREAL"); break;
|
||||||
|
case Bytecode.OpCodes.GE_LREAL: Console.WriteLine("GE_LREAL"); break;
|
||||||
|
case Bytecode.OpCodes.EQ_LREAL: Console.WriteLine("EQ_LREAL"); break;
|
||||||
|
case Bytecode.OpCodes.NEQ_LREAL: Console.WriteLine("NEQ_LREAL"); break;
|
||||||
default: Console.WriteLine($"{Bytecode.OpName(op)}"); break;
|
default: Console.WriteLine($"{Bytecode.OpName(op)}"); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Disassembler")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Disassembler")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+74f256efb2d90ae0bc878111d497ee146327bb51")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5a002806a9ee3a7389c5a14069c534271a20a9ac")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Disassembler")]
|
[assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Disassembler")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Disassembler")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Disassembler")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
3d4adf0bd5b0dc0665a784bf64e53bbaf5e4ba59d3c539d15229580b865800e1
|
127117f0342214ac98d3bad7b812bb24f45bbb46074eff037772675e34d8b027
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,67 +2,76 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using STCompiler.Common;
|
using STCompiler.Common;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
static int Main(string[] args) {
|
static int Main(string[] args) {
|
||||||
|
bool verbose = true; // Default to verbose mode
|
||||||
|
if (args.Length > 0 && args[0] == "--verbose") {
|
||||||
|
verbose = true;
|
||||||
|
args = args[1..]; // Remove the --verbose argument from further processing
|
||||||
|
} else {
|
||||||
|
verbose = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (args.Length < 1) {
|
if (args.Length < 1) {
|
||||||
Console.WriteLine("Usage: StSim <file.stbc>");
|
Console.WriteLine("Usage: StSim [--verbose|--quiet] <file.stbc>");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
var path = args[0];
|
var path = args[0];
|
||||||
if (!File.Exists(path)) { Console.WriteLine("File not found: " + path); return 2; }
|
if (!File.Exists(path)) { Console.WriteLine("File not found: " + path); return 2; }
|
||||||
var data = File.ReadAllBytes(path);
|
var data = File.ReadAllBytes(path);
|
||||||
try { Simulate(data); } catch(Exception ex) { Console.WriteLine("Error: " + ex.Message); return 3; }
|
try { Simulate(data, verbose); } catch(Exception ex) { Console.WriteLine("Error: " + ex.Message); return 3; }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Simulate(byte[] data) {
|
static void Simulate(byte[] data, bool verbose) {
|
||||||
using var ms = new MemoryStream(data);
|
using var ms = new MemoryStream(data);
|
||||||
using var r = new BinaryReader(ms);
|
using var r = new BinaryReader(ms);
|
||||||
|
|
||||||
string magic = System.Text.Encoding.ASCII.GetString(r.ReadBytes(4));
|
string magic = System.Text.Encoding.ASCII.GetString(r.ReadBytes(4));
|
||||||
if (magic != Bytecode.Magic) throw new Exception("Invalid magic");
|
if (magic != Bytecode.Magic) throw new Exception("Invalid magic");
|
||||||
ushort ver = r.ReadUInt16();
|
ushort ver = r.ReadUInt16();
|
||||||
Console.WriteLine($"Version: {ver}");
|
if (verbose) Console.WriteLine($"Version: {ver}");
|
||||||
bool oldFormat = ver < Bytecode.Version;
|
bool oldFormat = ver < Bytecode.Version;
|
||||||
ushort cycletime = r.ReadUInt16();
|
ushort cycletime = r.ReadUInt16();
|
||||||
Console.WriteLine($"Cycle: {cycletime} ms");
|
if (verbose) Console.WriteLine($"Cycle: {cycletime} ms");
|
||||||
ushort nConsts = r.ReadUInt16();
|
ushort nConsts = r.ReadUInt16();
|
||||||
Console.WriteLine($"Consts: {nConsts}");
|
if (verbose) Console.WriteLine($"Consts: {nConsts}");
|
||||||
var consts = new List<object>();
|
var consts = new List<object>();
|
||||||
if (oldFormat) {
|
if (oldFormat) {
|
||||||
// old format: constants stored as 4-byte ints
|
// 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}"); }
|
for (int i = 0; i < nConsts; i++) { int v = r.ReadInt32(); consts.Add(v); if (verbose) Console.WriteLine($" [{i}] = {v}"); }
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < nConsts; i++) {
|
for (int i = 0; i < nConsts; i++) {
|
||||||
byte t = r.ReadByte();
|
byte t = r.ReadByte();
|
||||||
switch(t) {
|
switch(t) {
|
||||||
case 1: { long v = r.ReadInt64(); consts.Add(v); Console.WriteLine($" [{i}] (long) = {v}"); break; }
|
case 1: { long v = r.ReadInt64(); consts.Add(v); if (verbose) Console.WriteLine($" [{i}] (long) = {v}"); break; }
|
||||||
case 2: { double v = r.ReadDouble(); consts.Add(v); Console.WriteLine($" [{i}] (double) = {v}"); break; }
|
case 2: { double v = r.ReadDouble(); consts.Add(v); if (verbose) Console.WriteLine($" [{i}] (double) = {v}"); break; }
|
||||||
case 3: { float v = r.ReadSingle(); consts.Add(v); Console.WriteLine($" [{i}] (float) = {v}"); break; }
|
case 3: { float v = r.ReadSingle(); consts.Add(v); if (verbose) Console.WriteLine($" [{i}] (float) = {v}"); break; }
|
||||||
case 4: { int v = r.ReadInt32(); consts.Add(v); Console.WriteLine($" [{i}] (int) = {v}"); break; }
|
case 4: { int v = r.ReadInt32(); consts.Add(v); if (verbose) Console.WriteLine($" [{i}] (int) = {v}"); break; }
|
||||||
default: { Console.WriteLine($" [{i}] Unknown const type {t}"); break; }
|
default: { if (verbose) Console.WriteLine($" [{i}] Unknown const type {t}"); break; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ushort nVars = r.ReadUInt16();
|
ushort nVars = r.ReadUInt16();
|
||||||
Console.WriteLine($"Vars: {nVars}");
|
if (verbose) Console.WriteLine($"Vars: {nVars}");
|
||||||
var varTypes = new byte[nVars];
|
var varTypes = new byte[nVars];
|
||||||
for (int i = 0; i < nVars; i++) { varTypes[i] = r.ReadByte(); Console.WriteLine($" Var[{i}] type = {varTypes[i]}"); }
|
for (int i = 0; i < nVars; i++) { varTypes[i] = r.ReadByte(); if (verbose) Console.WriteLine($" Var[{i}] type = {varTypes[i]}"); }
|
||||||
|
|
||||||
ushort codeLen = r.ReadUInt16();
|
ushort codeLen = r.ReadUInt16();
|
||||||
Console.WriteLine($"CodeLen: {codeLen} bytes");
|
if (verbose) Console.WriteLine($"CodeLen: {codeLen} bytes");
|
||||||
var code = r.ReadBytes(codeLen);
|
var code = r.ReadBytes(codeLen);
|
||||||
|
|
||||||
// Initialize arrays for element type tracking
|
// Initialize arrays for element type tracking
|
||||||
var arrayRanges = new Dictionary<int, (int start, int length, VarType elementType)>();
|
var arrayRanges = new Dictionary<int, (int start, int length, VarType elementType)>();
|
||||||
Console.WriteLine("\nAnalyzing variable types:");
|
if (verbose) Console.WriteLine("\nAnalyzing variable types:");
|
||||||
for (int i = 0; i < nVars; i++) {
|
for (int i = 0; i < nVars; i++) {
|
||||||
Console.WriteLine($" [{i}] = {(VarType)varTypes[i]}");
|
if (verbose) Console.WriteLine($" [{i}] = {(VarType)varTypes[i]}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("\nDetecting arrays:");
|
if (verbose) Console.WriteLine("\nDetecting arrays:");
|
||||||
for (int i = 0; i < nVars; i++) {
|
for (int i = 0; i < nVars; i++) {
|
||||||
if (varTypes[i] == (byte)VarType.ARRAY && i + 2 <= nVars) {
|
if (varTypes[i] == (byte)VarType.ARRAY && i + 2 <= nVars) {
|
||||||
// An array consists of:
|
// An array consists of:
|
||||||
@ -81,10 +90,12 @@ class Program {
|
|||||||
}
|
}
|
||||||
|
|
||||||
arrayRanges[arrayStart] = (startOfElements, length, elementType);
|
arrayRanges[arrayStart] = (startOfElements, length, elementType);
|
||||||
|
if (verbose) {
|
||||||
Console.WriteLine($"Found array at index {arrayStart}:");
|
Console.WriteLine($"Found array at index {arrayStart}:");
|
||||||
Console.WriteLine($" - Element type: {elementType}");
|
Console.WriteLine($" - Element type: {elementType}");
|
||||||
Console.WriteLine($" - Elements start at: {startOfElements}");
|
Console.WriteLine($" - Elements start at: {startOfElements}");
|
||||||
Console.WriteLine($" - Length: {length}");
|
Console.WriteLine($" - Length: {length}");
|
||||||
|
}
|
||||||
|
|
||||||
// Skip past the array definition (ARRAY marker + element type)
|
// Skip past the array definition (ARRAY marker + element type)
|
||||||
i = startOfElements - 1;
|
i = startOfElements - 1;
|
||||||
@ -94,28 +105,36 @@ class Program {
|
|||||||
var stack = new Stack<object>();
|
var stack = new Stack<object>();
|
||||||
var vars = new object[nVars];
|
var vars = new object[nVars];
|
||||||
int ip = 0;
|
int ip = 0;
|
||||||
Console.WriteLine("\n--- Disassembly / Simulation ---");
|
var opcodeExecutionTimes = new Dictionary<byte, long>();
|
||||||
|
var opcodeCounts = new Dictionary<byte, int>();
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
|
||||||
|
if (verbose) Console.WriteLine("\n--- Disassembly / Simulation ---");
|
||||||
while (ip < code.Length) {
|
while (ip < code.Length) {
|
||||||
int addr = ip;
|
int addr = ip;
|
||||||
byte op = code[ip++];
|
byte op = code[ip++];
|
||||||
Console.Write($"{addr:0000}: 0x{op:X2} ");
|
if (verbose) Console.Write($"{addr:0000}: 0x{op:X2} ");
|
||||||
|
|
||||||
|
// Track opcode execution time
|
||||||
|
stopwatch.Restart();
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case Bytecode.OpCodes.NOP: Console.WriteLine("NOP"); break;
|
case Bytecode.OpCodes.NOP: if (verbose) Console.WriteLine("NOP"); break;
|
||||||
case Bytecode.OpCodes.PUSH_CONST: {
|
case Bytecode.OpCodes.PUSH_CONST: {
|
||||||
ushort ci = (ushort)(code[ip++] | (code[ip++] << 8));
|
ushort ci = (ushort)(code[ip++] | (code[ip++] << 8));
|
||||||
if (oldFormat) { byte typeMarker = code[ip++]; /* skip legacy type byte */ }
|
if (oldFormat) { byte typeMarker = code[ip++]; /* skip legacy type byte */ }
|
||||||
Console.WriteLine($"PUSH_CONST {ci} ({consts[ci]})");
|
if (verbose) Console.WriteLine($"PUSH_CONST {ci} ({consts[ci]})");
|
||||||
stack.Push(consts[ci]);
|
stack.Push(consts[ci]);
|
||||||
break; }
|
break; }
|
||||||
case Bytecode.OpCodes.PUSH_REAL_CONST: {
|
case Bytecode.OpCodes.PUSH_REAL_CONST: {
|
||||||
ushort ci = (ushort)(code[ip++] | (code[ip++] << 8));
|
ushort ci = (ushort)(code[ip++] | (code[ip++] << 8));
|
||||||
if (oldFormat) { byte typeMarker = code[ip++]; /* skip legacy type byte */ }
|
if (oldFormat) { byte typeMarker = code[ip++]; /* skip legacy type byte */ }
|
||||||
Console.WriteLine($"PUSH_REAL_CONST {ci} ({consts[ci]})");
|
if (verbose) Console.WriteLine($"PUSH_REAL_CONST {ci} ({consts[ci]})");
|
||||||
stack.Push(consts[ci]);
|
stack.Push(consts[ci]);
|
||||||
break; }
|
break; }
|
||||||
case Bytecode.OpCodes.LOAD_VAR: {
|
case Bytecode.OpCodes.LOAD_VAR: {
|
||||||
ushort vi = (ushort)(code[ip++] | (code[ip++] << 8));
|
ushort vi = (ushort)(code[ip++] | (code[ip++] << 8));
|
||||||
Console.WriteLine($"LOAD_VAR {vi}");
|
if (verbose) Console.WriteLine($"LOAD_VAR {vi}");
|
||||||
|
|
||||||
// Check if the variable index is within bounds
|
// Check if the variable index is within bounds
|
||||||
if (vi >= vars.Length) {
|
if (vi >= vars.Length) {
|
||||||
@ -134,7 +153,7 @@ class Program {
|
|||||||
}
|
}
|
||||||
case Bytecode.OpCodes.STORE_VAR: {
|
case Bytecode.OpCodes.STORE_VAR: {
|
||||||
ushort vi = (ushort)(code[ip++] | (code[ip++] << 8));
|
ushort vi = (ushort)(code[ip++] | (code[ip++] << 8));
|
||||||
Console.WriteLine($"STORE_VAR {vi}");
|
if (verbose) Console.WriteLine($"STORE_VAR {vi}");
|
||||||
|
|
||||||
// Check if the variable index is within bounds
|
// Check if the variable index is within bounds
|
||||||
if (vi >= vars.Length) {
|
if (vi >= vars.Length) {
|
||||||
@ -147,7 +166,7 @@ class Program {
|
|||||||
if (value is object[] arr) {
|
if (value is object[] arr) {
|
||||||
Array.Copy(arr, 0, vars, start, Math.Min(arr.Length, arrayLength));
|
Array.Copy(arr, 0, vars, start, Math.Min(arr.Length, arrayLength));
|
||||||
} else {
|
} else {
|
||||||
Console.WriteLine($"Warning: Attempting to store non-array value in array variable at index {vi}");
|
if (verbose) Console.WriteLine($"Warning: Attempting to store non-array value in array variable at index {vi}");
|
||||||
vars[vi] = value;
|
vars[vi] = value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -155,15 +174,15 @@ class Program {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Bytecode.OpCodes.JZ: { ushort target = (ushort)(code[ip++] | (code[ip++] << 8)); Console.WriteLine($"JZ addr={target:0000}"); 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.JZ: { ushort target = (ushort)(code[ip++] | (code[ip++] << 8)); if (verbose) Console.WriteLine($"JZ addr={target:0000}"); 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: {
|
case Bytecode.OpCodes.JMP: {
|
||||||
ushort target = (ushort)(code[ip++] | (code[ip++] << 8));
|
ushort target = (ushort)(code[ip++] | (code[ip++] << 8));
|
||||||
Console.WriteLine($"JMP addr={target:0000}");
|
if (verbose) Console.WriteLine($"JMP addr={target:0000}");
|
||||||
ip = target;
|
ip = target;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Bytecode.OpCodes.HALT:
|
case Bytecode.OpCodes.HALT:
|
||||||
Console.WriteLine("HALT");
|
if (verbose) Console.WriteLine("HALT");
|
||||||
ip = code.Length;
|
ip = code.Length;
|
||||||
break;
|
break;
|
||||||
case Bytecode.OpCodes.ARRAY_BOUNDS_CHECK:
|
case Bytecode.OpCodes.ARRAY_BOUNDS_CHECK:
|
||||||
@ -176,11 +195,11 @@ class Program {
|
|||||||
|
|
||||||
// Check if this variable is actually an array
|
// Check if this variable is actually an array
|
||||||
if (!arrayRanges.ContainsKey(arrayIndex)) {
|
if (!arrayRanges.ContainsKey(arrayIndex)) {
|
||||||
Console.WriteLine($"Warning: ARRAY_BOUNDS_CHECK instruction for non-array variable {arrayIndex}");
|
if (verbose) Console.WriteLine($"Warning: ARRAY_BOUNDS_CHECK instruction for non-array variable {arrayIndex}");
|
||||||
continue; // Skip this instruction
|
continue; // Skip this instruction
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"ARRAY_BOUNDS_CHECK for array at index {arrayIndex}");
|
if (verbose) Console.WriteLine($"ARRAY_BOUNDS_CHECK for array at index {arrayIndex}");
|
||||||
|
|
||||||
if (stack.Count < 1) {
|
if (stack.Count < 1) {
|
||||||
throw new Exception("Stack underflow during array bounds check");
|
throw new Exception("Stack underflow during array bounds check");
|
||||||
@ -206,73 +225,453 @@ class Program {
|
|||||||
|
|
||||||
// Calculate the actual element address
|
// Calculate the actual element address
|
||||||
stack.Push(elementsStart + adjustedIndex);
|
stack.Push(elementsStart + adjustedIndex);
|
||||||
Console.WriteLine($"Accessing element {index} of array, mapped to variable index {elementsStart + adjustedIndex}");
|
if (verbose) Console.WriteLine($"Accessing element {index} of array, mapped to variable index {elementsStart + adjustedIndex}");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
;
|
|
||||||
// fallback handlers
|
// fallback handlers
|
||||||
if (Bytecode.OpName(op).StartsWith("ADD_") || Bytecode.OpName(op).StartsWith("SUB_") || Bytecode.OpName(op).StartsWith("MUL_") || Bytecode.OpName(op).StartsWith("DIV_")) {
|
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);
|
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;
|
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_")) {
|
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_")) {
|
||||||
dynamic rVal = stack.Pop(); dynamic lVal = stack.Pop();
|
dynamic rVal = stack.Pop(); dynamic lVal = stack.Pop();
|
||||||
bool res = Bytecode.OpName(op).StartsWith("LT_") ? (lVal < rVal) :
|
// Optimized comparison handler with type-specific operations
|
||||||
Bytecode.OpName(op).StartsWith("GT_") ? (lVal > rVal) :
|
switch (op) {
|
||||||
Bytecode.OpName(op).StartsWith("LE_") ? (lVal <= rVal) :
|
// Signed comparisons
|
||||||
Bytecode.OpName(op).StartsWith("GE_") ? (lVal >= rVal) :
|
case Bytecode.OpCodes.LT_SINT:
|
||||||
Bytecode.OpName(op).StartsWith("EQ_") ? (lVal == rVal) :
|
if (lVal is byte lb_s && rVal is byte rb_s) stack.Push(lb_s < rb_s ? 1 : 0);
|
||||||
(lVal != rVal);
|
else if (lVal is short ls_s && rVal is short rs_s) stack.Push(ls_s < rs_s ? 1 : 0);
|
||||||
stack.Push(res ? 1 : 0);
|
else if (lVal is int li1_s && rVal is int ri1_s) stack.Push(li1_s < ri1_s ? 1 : 0);
|
||||||
|
else if (lVal is long ll_s && rVal is long rl_s) stack.Push(ll_s < rl_s ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) < Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GT_SINT:
|
||||||
|
if (lVal is byte lb_gt && rVal is byte rb_gt) stack.Push(lb_gt > rb_gt ? 1 : 0);
|
||||||
|
else if (lVal is short ls_gt && rVal is short rs_gt) stack.Push(ls_gt > rs_gt ? 1 : 0);
|
||||||
|
else if (lVal is int li2_gt && rVal is int ri2_gt) stack.Push(li2_gt > ri2_gt ? 1 : 0);
|
||||||
|
else if (lVal is long ll_gt && rVal is long rl_gt) stack.Push(ll_gt > rl_gt ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) > Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LE_SINT:
|
||||||
|
if (lVal is byte lb_le && rVal is byte rb_le) stack.Push(lb_le <= rb_le ? 1 : 0);
|
||||||
|
else if (lVal is short ls_le && rVal is short rs_le) stack.Push(ls_le <= rs_le ? 1 : 0);
|
||||||
|
else if (lVal is int li3_le && rVal is int ri3_le) stack.Push(li3_le <= ri3_le ? 1 : 0);
|
||||||
|
else if (lVal is long ll_le && rVal is long rl_le) stack.Push(ll_le <= rl_le ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) <= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GE_SINT:
|
||||||
|
if (lVal is byte lb_ge && rVal is byte rb_ge) stack.Push(lb_ge >= rb_ge ? 1 : 0);
|
||||||
|
else if (lVal is short ls_ge && rVal is short rs_ge) stack.Push(ls_ge >= rs_ge ? 1 : 0);
|
||||||
|
else if (lVal is int li4_ge && rVal is int ri4_ge) stack.Push(li4_ge >= ri4_ge ? 1 : 0);
|
||||||
|
else if (lVal is long ll_ge && rVal is long rl_ge) stack.Push(ll_ge >= rl_ge ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) >= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.EQ_SINT:
|
||||||
|
if (lVal is byte lb_eq && rVal is byte rb_eq) stack.Push(lb_eq == rb_eq ? 1 : 0);
|
||||||
|
else if (lVal is short ls_eq && rVal is short rs_eq) stack.Push(ls_eq == rs_eq ? 1 : 0);
|
||||||
|
else if (lVal is int li5_eq && rVal is int ri5_eq) stack.Push(li5_eq == ri5_eq ? 1 : 0);
|
||||||
|
else if (lVal is long ll_eq && rVal is long rl_eq) stack.Push(ll_eq == rl_eq ? 1 : 0);
|
||||||
|
else stack.Push(Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.NEQ_SINT:
|
||||||
|
if (lVal is byte lb_ne && rVal is byte rb_ne) stack.Push(lb_ne != rb_ne ? 1 : 0);
|
||||||
|
else if (lVal is short ls_ne && rVal is short rs_ne) stack.Push(ls_ne != rs_ne ? 1 : 0);
|
||||||
|
else if (lVal is int li6_ne && rVal is int ri6_ne) stack.Push(li6_ne != ri6_ne ? 1 : 0);
|
||||||
|
else if (lVal is long ll_ne && rVal is long rl_ne) stack.Push(ll_ne != rl_ne ? 1 : 0);
|
||||||
|
else stack.Push(!Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LT_INT:
|
||||||
|
if (lVal is byte lb_lt && rVal is byte rb_lt) stack.Push(lb_lt < rb_lt ? 1 : 0);
|
||||||
|
else if (lVal is short ls_lt && rVal is short rs_lt) stack.Push(ls_lt < rs_lt ? 1 : 0);
|
||||||
|
else if (lVal is int li1_lt && rVal is int ri1_lt) stack.Push(li1_lt < ri1_lt ? 1 : 0);
|
||||||
|
else if (lVal is long ll_lt && rVal is long rl_lt) stack.Push(ll_lt < rl_lt ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) < Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GT_INT:
|
||||||
|
if (lVal is byte lb_gt2 && rVal is byte rb_gt2) stack.Push(lb_gt2 > rb_gt2 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_gt2 && rVal is short rs_gt2) stack.Push(ls_gt2 > rs_gt2 ? 1 : 0);
|
||||||
|
else if (lVal is int li2_gt2 && rVal is int ri2_gt2) stack.Push(li2_gt2 > ri2_gt2 ? 1 : 0);
|
||||||
|
else if (lVal is long ll_gt2 && rVal is long rl_gt2) stack.Push(ll_gt2 > rl_gt2 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) > Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LE_INT:
|
||||||
|
if (lVal is byte lb_le2 && rVal is byte rb_le2) stack.Push(lb_le2 <= rb_le2 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_le2 && rVal is short rs_le2) stack.Push(ls_le2 <= rs_le2 ? 1 : 0);
|
||||||
|
else if (lVal is int li3_le2 && rVal is int ri3_le2) stack.Push(li3_le2 <= ri3_le2 ? 1 : 0);
|
||||||
|
else if (lVal is long ll_le2 && rVal is long rl_le2) stack.Push(ll_le2 <= rl_le2 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) <= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GE_INT:
|
||||||
|
if (lVal is byte lb_ge2 && rVal is byte rb_ge2) stack.Push(lb_ge2 >= rb_ge2 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_ge2 && rVal is short rs_ge2) stack.Push(ls_ge2 >= rs_ge2 ? 1 : 0);
|
||||||
|
else if (lVal is int li4_ge2 && rVal is int ri4_ge2) stack.Push(li4_ge2 >= ri4_ge2 ? 1 : 0);
|
||||||
|
else if (lVal is long ll_ge2 && rVal is long rl_ge2) stack.Push(ll_ge2 >= rl_ge2 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) >= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.EQ_INT:
|
||||||
|
if (lVal is byte lb_eq2 && rVal is byte rb_eq2) stack.Push(lb_eq2 == rb_eq2 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_eq2 && rVal is short rs_eq2) stack.Push(ls_eq2 == rs_eq2 ? 1 : 0);
|
||||||
|
else if (lVal is int li5_eq2 && rVal is int ri5_eq2) stack.Push(li5_eq2 == ri5_eq2 ? 1 : 0);
|
||||||
|
else if (lVal is long ll_eq2 && rVal is long rl_eq2) stack.Push(ll_eq2 == rl_eq2 ? 1 : 0);
|
||||||
|
else stack.Push(Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.NEQ_INT:
|
||||||
|
if (lVal is byte lb_ne2 && rVal is byte rb_ne2) stack.Push(lb_ne2 != rb_ne2 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_ne2 && rVal is short rs_ne2) stack.Push(ls_ne2 != rs_ne2 ? 1 : 0);
|
||||||
|
else if (lVal is int li6_ne2 && rVal is int ri6_ne2) stack.Push(li6_ne2 != ri6_ne2 ? 1 : 0);
|
||||||
|
else if (lVal is long ll_ne2 && rVal is long rl_ne2) stack.Push(ll_ne2 != rl_ne2 ? 1 : 0);
|
||||||
|
else stack.Push(!Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LT_DINT:
|
||||||
|
if (lVal is byte lb_dint && rVal is byte rb_dint) stack.Push(lb_dint < rb_dint ? 1 : 0);
|
||||||
|
else if (lVal is short ls_dint && rVal is short rs_dint) stack.Push(ls_dint < rs_dint ? 1 : 0);
|
||||||
|
else if (lVal is int li1_dint && rVal is int ri1_dint) stack.Push(li1_dint < ri1_dint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_dint && rVal is long rl_dint) stack.Push(ll_dint < rl_dint ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) < Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GT_DINT:
|
||||||
|
if (lVal is byte lb_dint2 && rVal is byte rb_dint2) stack.Push(lb_dint2 > rb_dint2 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_dint2 && rVal is short rs_dint2) stack.Push(ls_dint2 > rs_dint2 ? 1 : 0);
|
||||||
|
else if (lVal is int li2_dint && rVal is int ri2_dint) stack.Push(li2_dint > ri2_dint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_dint2 && rVal is long rl_dint2) stack.Push(ll_dint2 > rl_dint2 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) > Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LE_DINT:
|
||||||
|
if (lVal is byte lb_dint3 && rVal is byte rb_dint3) stack.Push(lb_dint3 <= rb_dint3 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_dint3 && rVal is short rs_dint3) stack.Push(ls_dint3 <= rs_dint3 ? 1 : 0);
|
||||||
|
else if (lVal is int li3_dint && rVal is int ri3_dint) stack.Push(li3_dint <= ri3_dint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_dint3 && rVal is long rl_dint3) stack.Push(ll_dint3 <= rl_dint3 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) <= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GE_DINT:
|
||||||
|
if (lVal is byte lb_dint4 && rVal is byte rb_dint4) stack.Push(lb_dint4 >= rb_dint4 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_dint4 && rVal is short rs_dint4) stack.Push(ls_dint4 >= rs_dint4 ? 1 : 0);
|
||||||
|
else if (lVal is int li4_dint && rVal is int ri4_dint) stack.Push(li4_dint >= ri4_dint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_dint4 && rVal is long rl_dint4) stack.Push(ll_dint4 >= rl_dint4 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) >= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.EQ_DINT:
|
||||||
|
if (lVal is byte lb_dint5 && rVal is byte rb_dint5) stack.Push(lb_dint5 == rb_dint5 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_dint5 && rVal is short rs_dint5) stack.Push(ls_dint5 == rs_dint5 ? 1 : 0);
|
||||||
|
else if (lVal is int li5_dint && rVal is int ri5_dint) stack.Push(li5_dint == ri5_dint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_dint5 && rVal is long rl_dint5) stack.Push(ll_dint5 == rl_dint5 ? 1 : 0);
|
||||||
|
else stack.Push(Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.NEQ_DINT:
|
||||||
|
if (lVal is byte lb_dint6 && rVal is byte rb_dint6) stack.Push(lb_dint6 != rb_dint6 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_dint6 && rVal is short rs_dint6) stack.Push(ls_dint6 != rs_dint6 ? 1 : 0);
|
||||||
|
else if (lVal is int li6_dint && rVal is int ri6_dint) stack.Push(li6_dint != ri6_dint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_dint6 && rVal is long rl_dint6) stack.Push(ll_dint6 != rl_dint6 ? 1 : 0);
|
||||||
|
else stack.Push(!Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LT_LINT:
|
||||||
|
if (lVal is byte lb_lint && rVal is byte rb_lint) stack.Push(lb_lint < rb_lint ? 1 : 0);
|
||||||
|
else if (lVal is short ls_lint && rVal is short rs_lint) stack.Push(ls_lint < rs_lint ? 1 : 0);
|
||||||
|
else if (lVal is int li1_lint && rVal is int ri1_lint) stack.Push(li1_lint < ri1_lint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_lint && rVal is long rl_lint) stack.Push(ll_lint < rl_lint ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) < Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GT_LINT:
|
||||||
|
if (lVal is byte lb_lint2 && rVal is byte rb_lint2) stack.Push(lb_lint2 > rb_lint2 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_lint2 && rVal is short rs_lint2) stack.Push(ls_lint2 > rs_lint2 ? 1 : 0);
|
||||||
|
else if (lVal is int li2_lint && rVal is int ri2_lint) stack.Push(li2_lint > ri2_lint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_lint2 && rVal is long rl_lint2) stack.Push(ll_lint2 > rl_lint2 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) > Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LE_LINT:
|
||||||
|
if (lVal is byte lb_lint3 && rVal is byte rb_lint3) stack.Push(lb_lint3 <= rb_lint3 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_lint3 && rVal is short rs_lint3) stack.Push(ls_lint3 <= rs_lint3 ? 1 : 0);
|
||||||
|
else if (lVal is int li3_lint && rVal is int ri3_lint) stack.Push(li3_lint <= ri3_lint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_lint3 && rVal is long rl_lint3) stack.Push(ll_lint3 <= rl_lint3 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) <= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GE_LINT:
|
||||||
|
if (lVal is byte lb_lint4 && rVal is byte rb_lint4) stack.Push(lb_lint4 >= rb_lint4 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_lint4 && rVal is short rs_lint4) stack.Push(ls_lint4 >= rs_lint4 ? 1 : 0);
|
||||||
|
else if (lVal is int li4_lint && rVal is int ri4_lint) stack.Push(li4_lint >= ri4_lint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_lint4 && rVal is long rl_lint4) stack.Push(ll_lint4 >= rl_lint4 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) >= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.EQ_LINT:
|
||||||
|
if (lVal is byte lb_lint5 && rVal is byte rb_lint5) stack.Push(lb_lint5 == rb_lint5 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_lint5 && rVal is short rs_lint5) stack.Push(ls_lint5 == rs_lint5 ? 1 : 0);
|
||||||
|
else if (lVal is int li5_lint && rVal is int ri5_lint) stack.Push(li5_lint == ri5_lint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_lint5 && rVal is long rl_lint5) stack.Push(ll_lint5 == rl_lint5 ? 1 : 0);
|
||||||
|
else stack.Push(Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.NEQ_LINT:
|
||||||
|
if (lVal is byte lb_lint6 && rVal is byte rb_lint6) stack.Push(lb_lint6 != rb_lint6 ? 1 : 0);
|
||||||
|
else if (lVal is short ls_lint6 && rVal is short rs_lint6) stack.Push(ls_lint6 != rs_lint6 ? 1 : 0);
|
||||||
|
else if (lVal is int li6_lint && rVal is int ri6_lint) stack.Push(li6_lint != ri6_lint ? 1 : 0);
|
||||||
|
else if (lVal is long ll_lint6 && rVal is long rl_lint6) stack.Push(ll_lint6 != rl_lint6 ? 1 : 0);
|
||||||
|
else stack.Push(!Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Unsigned comparisons
|
||||||
|
case Bytecode.OpCodes.LT_USINT:
|
||||||
|
if (lVal is byte lb_us && rVal is byte rb_us) stack.Push(lb_us < rb_us ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_us && rVal is ushort rus_us) stack.Push(lus_us < rus_us ? 1 : 0);
|
||||||
|
else if (lVal is uint lu1_us && rVal is uint ru1_us) stack.Push(lu1_us < ru1_us ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_us && rVal is ulong rlu_us) stack.Push(llu_us < rlu_us ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) < Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GT_USINT:
|
||||||
|
if (lVal is byte lb_us2 && rVal is byte rb_us2) stack.Push(lb_us2 > rb_us2 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_us2 && rVal is ushort rus_us2) stack.Push(lus_us2 > rus_us2 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu2_us && rVal is uint ru2_us) stack.Push(lu2_us > ru2_us ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_us2 && rVal is ulong rlu_us2) stack.Push(llu_us2 > rlu_us2 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) > Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LE_USINT:
|
||||||
|
if (lVal is byte lb_us3 && rVal is byte rb_us3) stack.Push(lb_us3 <= rb_us3 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_us3 && rVal is ushort rus_us3) stack.Push(lus_us3 <= rus_us3 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu3_us && rVal is uint ru3_us) stack.Push(lu3_us <= ru3_us ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_us3 && rVal is ulong rlu_us3) stack.Push(llu_us3 <= rlu_us3 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) <= Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GE_USINT:
|
||||||
|
if (lVal is byte lb_us4 && rVal is byte rb_us4) stack.Push(lb_us4 >= rb_us4 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_us4 && rVal is ushort rus_us4) stack.Push(lus_us4 >= rus_us4 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu4_us && rVal is uint ru4_us) stack.Push(lu4_us >= ru4_us ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_us4 && rVal is ulong rlu_us4) stack.Push(llu_us4 >= rlu_us4 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) >= Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.EQ_USINT:
|
||||||
|
if (lVal is byte lb_us5 && rVal is byte rb_us5) stack.Push(lb_us5 == rb_us5 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_us5 && rVal is ushort rus_us5) stack.Push(lus_us5 == rus_us5 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu5_us && rVal is uint ru5_us) stack.Push(lu5_us == ru5_us ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_us5 && rVal is ulong rlu_us5) stack.Push(llu_us5 == rlu_us5 ? 1 : 0);
|
||||||
|
else stack.Push(Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.NEQ_USINT:
|
||||||
|
if (lVal is byte lb_us6 && rVal is byte rb_us6) stack.Push(lb_us6 != rb_us6 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_us6 && rVal is ushort rus_us6) stack.Push(lus_us6 != rus_us6 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu6_us && rVal is uint ru6_us) stack.Push(lu6_us != ru6_us ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_us6 && rVal is ulong rlu_us6) stack.Push(llu_us6 != rlu_us6 ? 1 : 0);
|
||||||
|
else stack.Push(!Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LT_UINT:
|
||||||
|
if (lVal is byte lb_uint && rVal is byte rb_uint) stack.Push(lb_uint < rb_uint ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_uint && rVal is ushort rus_uint) stack.Push(lus_uint < rus_uint ? 1 : 0);
|
||||||
|
else if (lVal is uint lu1_uint && rVal is uint ru1_uint) stack.Push(lu1_uint < ru1_uint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_uint && rVal is ulong rlu_uint) stack.Push(llu_uint < rlu_uint ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) < Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GT_UINT:
|
||||||
|
if (lVal is byte lb_uint2 && rVal is byte rb_uint2) stack.Push(lb_uint2 > rb_uint2 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_uint2 && rVal is ushort rus_uint2) stack.Push(lus_uint2 > rus_uint2 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu2_uint && rVal is uint ru2_uint) stack.Push(lu2_uint > ru2_uint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_uint2 && rVal is ulong rlu_uint2) stack.Push(llu_uint2 > rlu_uint2 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) > Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LE_UINT:
|
||||||
|
if (lVal is byte lb_uint3 && rVal is byte rb_uint3) stack.Push(lb_uint3 <= rb_uint3 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_uint3 && rVal is ushort rus_uint3) stack.Push(lus_uint3 <= rus_uint3 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu3_uint && rVal is uint ru3_uint) stack.Push(lu3_uint <= ru3_uint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_uint3 && rVal is ulong rlu_uint3) stack.Push(llu_uint3 <= rlu_uint3 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) <= Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GE_UINT:
|
||||||
|
if (lVal is byte lb_uint4 && rVal is byte rb_uint4) stack.Push(lb_uint4 >= rb_uint4 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_uint4 && rVal is ushort rus_uint4) stack.Push(lus_uint4 >= rus_uint4 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu4_uint && rVal is uint ru4_uint) stack.Push(lu4_uint >= ru4_uint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_uint4 && rVal is ulong rlu_uint4) stack.Push(llu_uint4 >= rlu_uint4 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) >= Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.EQ_UINT:
|
||||||
|
if (lVal is byte lb_uint5 && rVal is byte rb_uint5) stack.Push(lb_uint5 == rb_uint5 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_uint5 && rVal is ushort rus_uint5) stack.Push(lus_uint5 == rus_uint5 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu5_uint && rVal is uint ru5_uint) stack.Push(lu5_uint == ru5_uint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_uint5 && rVal is ulong rlu_uint5) stack.Push(llu_uint5 == rlu_uint5 ? 1 : 0);
|
||||||
|
else stack.Push(Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.NEQ_UINT:
|
||||||
|
if (lVal is byte lb_uint6 && rVal is byte rb_uint6) stack.Push(lb_uint6 != rb_uint6 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_uint6 && rVal is ushort rus_uint6) stack.Push(lus_uint6 != rus_uint6 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu6_uint && rVal is uint ru6_uint) stack.Push(lu6_uint != ru6_uint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_uint6 && rVal is ulong rlu_uint6) stack.Push(llu_uint6 != rlu_uint6 ? 1 : 0);
|
||||||
|
else stack.Push(!Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LT_UDINT:
|
||||||
|
if (lVal is byte lb_udint && rVal is byte rb_udint) stack.Push(lb_udint < rb_udint ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_udint && rVal is ushort rus_udint) stack.Push(lus_udint < rus_udint ? 1 : 0);
|
||||||
|
else if (lVal is uint lu1_udint && rVal is uint ru1_udint) stack.Push(lu1_udint < ru1_udint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_udint && rVal is ulong rlu_udint) stack.Push(llu_udint < rlu_udint ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) < Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GT_UDINT:
|
||||||
|
if (lVal is byte lb_udint2 && rVal is byte rb_udint2) stack.Push(lb_udint2 > rb_udint2 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_udint2 && rVal is ushort rus_udint2) stack.Push(lus_udint2 > rus_udint2 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu2_udint && rVal is uint ru2_udint) stack.Push(lu2_udint > ru2_udint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_udint2 && rVal is ulong rlu_udint2) stack.Push(llu_udint2 > rlu_udint2 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) > Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LE_UDINT:
|
||||||
|
if (lVal is byte lb_udint3 && rVal is byte rb_udint3) stack.Push(lb_udint3 <= rb_udint3 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_udint3 && rVal is ushort rus_udint3) stack.Push(lus_udint3 <= rus_udint3 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu3_udint && rVal is uint ru3_udint) stack.Push(lu3_udint <= ru3_udint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_udint3 && rVal is ulong rlu_udint3) stack.Push(llu_udint3 <= rlu_udint3 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) <= Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GE_UDINT:
|
||||||
|
if (lVal is byte lb_udint4 && rVal is byte rb_udint4) stack.Push(lb_udint4 >= rb_udint4 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_udint4 && rVal is ushort rus_udint4) stack.Push(lus_udint4 >= rus_udint4 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu4_udint && rVal is uint ru4_udint) stack.Push(lu4_udint >= ru4_udint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_udint4 && rVal is ulong rlu_udint4) stack.Push(llu_udint4 >= rlu_udint4 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) >= Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.EQ_UDINT:
|
||||||
|
if (lVal is byte lb_udint5 && rVal is byte rb_udint5) stack.Push(lb_udint5 == rb_udint5 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_udint5 && rVal is ushort rus_udint5) stack.Push(lus_udint5 == rus_udint5 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu5_udint && rVal is uint ru5_udint) stack.Push(lu5_udint == ru5_udint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_udint5 && rVal is ulong rlu_udint5) stack.Push(llu_udint5 == rlu_udint5 ? 1 : 0);
|
||||||
|
else stack.Push(Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.NEQ_UDINT:
|
||||||
|
if (lVal is byte lb_udint6 && rVal is byte rb_udint6) stack.Push(lb_udint6 != rb_udint6 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_udint6 && rVal is ushort rus_udint6) stack.Push(lus_udint6 != rus_udint6 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu6_udint && rVal is uint ru6_udint) stack.Push(lu6_udint != ru6_udint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_udint6 && rVal is ulong rlu_udint6) stack.Push(llu_udint6 != rlu_udint6 ? 1 : 0);
|
||||||
|
else stack.Push(!Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LT_ULINT:
|
||||||
|
if (lVal is byte lb_ulint && rVal is byte rb_ulint) stack.Push(lb_ulint < rb_ulint ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_ulint && rVal is ushort rus_ulint) stack.Push(lus_ulint < rus_ulint ? 1 : 0);
|
||||||
|
else if (lVal is uint lu1_ulint && rVal is uint ru1_ulint) stack.Push(lu1_ulint < ru1_ulint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_ulint && rVal is ulong rlu_ulint) stack.Push(llu_ulint < rlu_ulint ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) < Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GT_ULINT:
|
||||||
|
if (lVal is byte lb_ulint2 && rVal is byte rb_ulint2) stack.Push(lb_ulint2 > rb_ulint2 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_ulint2 && rVal is ushort rus_ulint2) stack.Push(lus_ulint2 > rus_ulint2 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu2_ulint && rVal is uint ru2_ulint) stack.Push(lu2_ulint > ru2_ulint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_ulint2 && rVal is ulong rlu_ulint2) stack.Push(llu_ulint2 > rlu_ulint2 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) > Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LE_ULINT:
|
||||||
|
if (lVal is byte lb_ulint3 && rVal is byte rb_ulint3) stack.Push(lb_ulint3 <= rb_ulint3 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_ulint3 && rVal is ushort rus_ulint3) stack.Push(lus_ulint3 <= rus_ulint3 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu3_ulint && rVal is uint ru3_ulint) stack.Push(lu3_ulint <= ru3_ulint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_ulint3 && rVal is ulong rlu_ulint3) stack.Push(llu_ulint3 <= rlu_ulint3 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) <= Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GE_ULINT:
|
||||||
|
if (lVal is byte lb_ulint4 && rVal is byte rb_ulint4) stack.Push(lb_ulint4 >= rb_ulint4 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_ulint4 && rVal is ushort rus_ulint4) stack.Push(lus_ulint4 >= rus_ulint4 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu4_ulint && rVal is uint ru4_ulint) stack.Push(lu4_ulint >= ru4_ulint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_ulint4 && rVal is ulong rlu_ulint4) stack.Push(llu_ulint4 >= rlu_ulint4 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToUInt64(lVal) >= Convert.ToUInt64(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.EQ_ULINT:
|
||||||
|
if (lVal is byte lb_ulint5 && rVal is byte rb_ulint5) stack.Push(lb_ulint5 == rb_ulint5 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_ulint5 && rVal is ushort rus_ulint5) stack.Push(lus_ulint5 == rus_ulint5 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu5_ulint && rVal is uint ru5_ulint) stack.Push(lu5_ulint == ru5_ulint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_ulint5 && rVal is ulong rlu_ulint5) stack.Push(llu_ulint5 == rlu_ulint5 ? 1 : 0);
|
||||||
|
else stack.Push(Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.NEQ_ULINT:
|
||||||
|
if (lVal is byte lb_ulint6 && rVal is byte rb_ulint6) stack.Push(lb_ulint6 != rb_ulint6 ? 1 : 0);
|
||||||
|
else if (lVal is ushort lus_ulint6 && rVal is ushort rus_ulint6) stack.Push(lus_ulint6 != rus_ulint6 ? 1 : 0);
|
||||||
|
else if (lVal is uint lu6_ulint && rVal is uint ru6_ulint) stack.Push(lu6_ulint != ru6_ulint ? 1 : 0);
|
||||||
|
else if (lVal is ulong llu_ulint6 && rVal is ulong rlu_ulint6) stack.Push(llu_ulint6 != rlu_ulint6 ? 1 : 0);
|
||||||
|
else stack.Push(!Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Floating point comparisons
|
||||||
|
case Bytecode.OpCodes.LT_REAL:
|
||||||
|
if (lVal is float lf1_real && rVal is float rf1_real) stack.Push(lf1_real < rf1_real ? 1 : 0);
|
||||||
|
else if (lVal is double ld_real && rVal is double rd_real) stack.Push(ld_real < rd_real ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) < Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GT_REAL:
|
||||||
|
if (lVal is float lf2_real && rVal is float rf2_real) stack.Push(lf2_real > rf2_real ? 1 : 0);
|
||||||
|
else if (lVal is double ld_real2 && rVal is double rd_real2) stack.Push(ld_real2 > rd_real2 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) > Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LE_REAL:
|
||||||
|
if (lVal is float lf3_real && rVal is float rf3_real) stack.Push(lf3_real <= rf3_real ? 1 : 0);
|
||||||
|
else if (lVal is double ld_real3 && rVal is double rd_real3) stack.Push(ld_real3 <= rd_real3 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) <= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GE_REAL:
|
||||||
|
if (lVal is float lf4_real && rVal is float rf4_real) stack.Push(lf4_real >= rf4_real ? 1 : 0);
|
||||||
|
else if (lVal is double ld_real4 && rVal is double rd_real4) stack.Push(ld_real4 >= rd_real4 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) >= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.EQ_REAL:
|
||||||
|
if (lVal is float lf5_real && rVal is float rf5_real) stack.Push(lf5_real == rf5_real ? 1 : 0);
|
||||||
|
else if (lVal is double ld_real5 && rVal is double rd_real5) stack.Push(ld_real5 == rd_real5 ? 1 : 0);
|
||||||
|
else stack.Push(Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.NEQ_REAL:
|
||||||
|
if (lVal is float lf6_real && rVal is float rf6_real) stack.Push(lf6_real != rf6_real ? 1 : 0);
|
||||||
|
else if (lVal is double ld_real6 && rVal is double rd_real6) stack.Push(ld_real6 != rd_real6 ? 1 : 0);
|
||||||
|
else stack.Push(!Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LT_LREAL:
|
||||||
|
if (lVal is float lf1_lreal && rVal is float rf1_lreal) stack.Push(lf1_lreal < rf1_lreal ? 1 : 0);
|
||||||
|
else if (lVal is double ld_lreal && rVal is double rd_lreal) stack.Push(ld_lreal < rd_lreal ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) < Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GT_LREAL:
|
||||||
|
if (lVal is float lf2_lreal && rVal is float rf2_lreal) stack.Push(lf2_lreal > rf2_lreal ? 1 : 0);
|
||||||
|
else if (lVal is double ld_lreal2 && rVal is double rd_lreal2) stack.Push(ld_lreal2 > rd_lreal2 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) > Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.LE_LREAL:
|
||||||
|
if (lVal is float lf3_lreal && rVal is float rf3_lreal) stack.Push(lf3_lreal <= rf3_lreal ? 1 : 0);
|
||||||
|
else if (lVal is double ld_lreal3 && rVal is double rd_lreal3) stack.Push(ld_lreal3 <= rd_lreal3 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) <= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.GE_LREAL:
|
||||||
|
if (lVal is float lf4_lreal && rVal is float rf4_lreal) stack.Push(lf4_lreal >= rf4_lreal ? 1 : 0);
|
||||||
|
else if (lVal is double ld_lreal4 && rVal is double rd_lreal4) stack.Push(ld_lreal4 >= rd_lreal4 ? 1 : 0);
|
||||||
|
else stack.Push(Convert.ToDouble(lVal) >= Convert.ToDouble(rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.EQ_LREAL:
|
||||||
|
if (lVal is float lf5_lreal && rVal is float rf5_lreal) stack.Push(lf5_lreal == rf5_lreal ? 1 : 0);
|
||||||
|
else if (lVal is double ld_lreal5 && rVal is double rd_lreal5) stack.Push(ld_lreal5 == rd_lreal5 ? 1 : 0);
|
||||||
|
else stack.Push(Equals(lVal, rVal) ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case Bytecode.OpCodes.NEQ_LREAL:
|
||||||
|
if (lVal is float lf6_lreal && rVal is float rf6_lreal) stack.Push(lf6_lreal != rf6_lreal ? 1 : 0);
|
||||||
|
else if (lVal is double ld_lreal6 && rVal is double rd_lreal6) stack.Push(ld_lreal6 != rd_lreal6 ? 1 : 0);
|
||||||
|
else stack.Push(!Equals(lVal, rVal) ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Array operations
|
|
||||||
if (op == Bytecode.OpCodes.ARRAY_BOUNDS_CHECK) {
|
|
||||||
// Extract the array index from the instruction
|
|
||||||
byte arrayIndexInner = 0;
|
|
||||||
if (ip < code.Length) {
|
|
||||||
arrayIndexInner = code[ip];
|
|
||||||
ip++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if this variable is actually an array
|
|
||||||
if (!arrayRanges.ContainsKey(arrayIndexInner)) {
|
|
||||||
Console.WriteLine($"Warning: ARRAY_BOUNDS_CHECK instruction for non-array variable {arrayIndexInner}");
|
|
||||||
continue; // Skip this instruction
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"ARRAY_BOUNDS_CHECK for array at index {arrayIndexInner}");
|
|
||||||
|
|
||||||
if (stack.Count < 1) {
|
|
||||||
throw new Exception("Stack underflow during array bounds check");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert index value safely
|
|
||||||
var indexObjInner = stack.Pop();
|
|
||||||
int indexInner = Convert.ToInt32(indexObjInner);
|
|
||||||
|
|
||||||
// The arrayStart from the instruction should be the array marker directly
|
|
||||||
if (!arrayRanges.TryGetValue(arrayIndexInner, out var arrayInfoInner)) {
|
|
||||||
// This should not happen since we checked above
|
|
||||||
throw new Exception($"Array metadata missing for index {arrayIndexInner}");
|
|
||||||
}
|
|
||||||
|
|
||||||
var (elementsStartInner, lengthInner, elementTypeInner) = arrayInfoInner;
|
|
||||||
if (indexInner < 0 || indexInner >= lengthInner) {
|
|
||||||
throw new Exception($"Array index {indexInner} out of bounds [0..{lengthInner-1}]");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the actual element address
|
|
||||||
stack.Push(elementsStartInner + indexInner);
|
|
||||||
Console.WriteLine($"Accessing element {indexInner} of array, mapped to variable index {elementsStartInner + indexInner}");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception($"Unknown opcode 0x{op:X2}");
|
throw new Exception($"Unknown opcode 0x{op:X2}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop the stopwatch and record execution time
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
// Update execution time and count for this opcode
|
||||||
|
if (opcodeExecutionTimes.ContainsKey(op)) {
|
||||||
|
opcodeExecutionTimes[op] += stopwatch.ElapsedTicks;
|
||||||
|
opcodeCounts[op]++;
|
||||||
|
} else {
|
||||||
|
opcodeExecutionTimes[op] = stopwatch.ElapsedTicks;
|
||||||
|
opcodeCounts[op] = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Execution finished\n");
|
if (verbose) Console.WriteLine("Execution finished\n");
|
||||||
// Detailed variable summary
|
|
||||||
|
// Calculate total execution time in milliseconds
|
||||||
|
long totalTicks = 0;
|
||||||
|
foreach (var ticks in opcodeExecutionTimes.Values) {
|
||||||
|
totalTicks += ticks;
|
||||||
|
}
|
||||||
|
double totalMs = totalTicks * 1000.0 / Stopwatch.Frequency;
|
||||||
|
|
||||||
|
// Detailed variable summary - always show this
|
||||||
Console.WriteLine("=== Variable summary ===");
|
Console.WriteLine("=== Variable summary ===");
|
||||||
Console.WriteLine("Index\tType\t\tValue");
|
Console.WriteLine("Index\tType\t\tValue");
|
||||||
for (int i = 0; i < vars.Length; i++) {
|
for (int i = 0; i < vars.Length; i++) {
|
||||||
@ -280,5 +679,26 @@ class Program {
|
|||||||
var value = vars[i] ?? "null";
|
var value = vars[i] ?? "null";
|
||||||
Console.WriteLine($"{i}\t{typeName.PadRight(8)}\t{value}");
|
Console.WriteLine($"{i}\t{typeName.PadRight(8)}\t{value}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Performance summary
|
||||||
|
Console.WriteLine("\n=== Performance summary ===");
|
||||||
|
Console.WriteLine($"Total execution time: {totalMs:F4} ms");
|
||||||
|
Console.WriteLine($"Target cycle time: {cycletime} ms");
|
||||||
|
|
||||||
|
if (totalMs > cycletime) {
|
||||||
|
Console.WriteLine($"⚠️ Execution time exceeds target cycle time by {totalMs - cycletime:F4} ms");
|
||||||
|
} else {
|
||||||
|
Console.WriteLine($"✅ Execution time is within target cycle time by {cycletime - totalMs:F4} ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show opcode execution statistics
|
||||||
|
Console.WriteLine("\nOpcode execution statistics:");
|
||||||
|
Console.WriteLine("Opcode\t\tCount\tAvg Time (ms)\tTotal Time (ms)");
|
||||||
|
foreach (var opcode in opcodeExecutionTimes.Keys) {
|
||||||
|
double avgTicks = (double)opcodeExecutionTimes[opcode] / opcodeCounts[opcode];
|
||||||
|
double avgMs = avgTicks * 1000.0 / Stopwatch.Frequency;
|
||||||
|
double totalMsForOpcode = opcodeExecutionTimes[opcode] * 1000.0 / Stopwatch.Frequency;
|
||||||
|
Console.WriteLine($"{Bytecode.OpName(opcode).PadRight(16)}\t{opcodeCounts[opcode]}\t{avgMs:F6}\t\t{totalMsForOpcode:F6}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Simulator")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("STCompiler.Simulator")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+74f256efb2d90ae0bc878111d497ee146327bb51")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5a002806a9ee3a7389c5a14069c534271a20a9ac")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Simulator")]
|
[assembly: System.Reflection.AssemblyProductAttribute("STCompiler.Simulator")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Simulator")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("STCompiler.Simulator")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
504856d607c12c0216f0b660a4485f4825b01e58f9f0bf1be4eb0f07ce5141ce
|
90805d3298b5e0050cfdc234b2564634379d8ea402d74f5ae50bf935d29242fc
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user