Separate decode and execute steps

This commit is contained in:
Yoshi Askharoun
2023-10-09 14:46:51 -05:00
parent be78b55a30
commit b5837bd3b8
8 changed files with 191 additions and 47 deletions
@@ -1,5 +1,4 @@
using Microsoft.Iris.Markup; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
@@ -15,27 +14,26 @@ public class InterpreterEntry : IComparable<InterpreterEntry>
Instruction = instruction; Instruction = instruction;
} }
public InterpreterInstruction Instruction { get; } public InterpreterInstruction Instruction { get; set; }
public List<InterpreterObject> Parameters { get; } = new(); public List<InterpreterObject> Parameters { get; } = new();
public List<InterpreterObject> ReturnValues { get; } = new(); public List<InterpreterObject> ReturnValues { get; } = new();
public string InstructionString => ToInstructionString();
public override string ToString() public override string ToString()
{ {
StringBuilder sb = new($"[{LoadUri} @ 0x{Offset:X}] {OpCode}({string.Join(", ", Parameters)})"); StringBuilder sb = new($"[{Instruction.LoadUri} @ 0x{Instruction.Offset:X}] " +
$"{Instruction.OpCode}({string.Join(", ", Parameters)})");
if (ReturnValues.Count > 0) if (ReturnValues.Count <= 0)
{ return sb.ToString();
sb.Append(" -> ");
sb.Append(" -> ");
if (ReturnValues.Count == 1) if (ReturnValues.Count == 1)
sb.Append(ReturnValues[0]); sb.Append(ReturnValues[0]);
else else
sb.Append($"[{string.Join(", ", ReturnValues)}]"); sb.Append($"[{string.Join(", ", ReturnValues)}]");
}
return sb.ToString(); return sb.ToString();
} }
@@ -1,11 +1,14 @@
using Microsoft.Iris.Markup; using Microsoft.Iris.Markup;
using System; using System;
using System.Collections.Generic;
namespace Microsoft.Iris.Debug.Data; namespace Microsoft.Iris.Debug.Data;
[Serializable] [Serializable]
public class InterpreterInstruction : IComparable<InterpreterInstruction> public class InterpreterInstruction : IComparable<InterpreterInstruction>
{ {
public InterpreterInstruction() { }
public InterpreterInstruction(OpCode opCode, uint offset, string loadUri) public InterpreterInstruction(OpCode opCode, uint offset, string loadUri)
{ {
OpCode = opCode; OpCode = opCode;
@@ -19,11 +22,15 @@ public class InterpreterInstruction : IComparable<InterpreterInstruction>
public string LoadUri { get; set; } public string LoadUri { get; set; }
public List<object> Operands { get; } = new();
public int CompareTo(InterpreterInstruction other) public int CompareTo(InterpreterInstruction other)
{ {
int stringCmp = LoadUri.CompareTo(other.LoadUri); var stringCmp = string.Compare(LoadUri, other.LoadUri, StringComparison.Ordinal);
return stringCmp != 0 return stringCmp != 0
? stringCmp ? stringCmp
: Offset.CompareTo(other.Offset); : Offset.CompareTo(other.Offset);
} }
public override string ToString() => $"[0x{Offset:X}] {OpCode} {string.Join(", ", Operands)}";
} }
@@ -4,7 +4,8 @@ public enum DebuggerMessageType : int
{ {
Null = 0, Null = 0,
InterpreterOpCode, InterpreterDecode,
InterpreterExecute,
DispatcherStep, DispatcherStep,
UpdateBreakpoint, UpdateBreakpoint,
+7 -2
View File
@@ -15,9 +15,14 @@ public interface IDebuggerClient
event Action<InterpreterCommand> InterpreterStateChanged; event Action<InterpreterCommand> InterpreterStateChanged;
/// <summary> /// <summary>
/// Fired when the UIX interpreter steps forward. /// Fired when the UIX interpreter decodes an instruction.
/// </summary> /// </summary>
event EventHandler<InterpreterEntry> InterpreterStep; event EventHandler<InterpreterInstruction> InterpreterDecode;
/// <summary>
/// Fired when the UIX interpreter executes an instruction.
/// </summary>
event EventHandler<InterpreterEntry> InterpreterExecute;
/// <summary> /// <summary>
/// Fired when the UIX dispatcher executes another call from the queue. /// Fired when the UIX dispatcher executes another call from the queue.
+8 -2
View File
@@ -7,10 +7,16 @@ internal interface IDebuggerServer
InterpreterCommand DebuggerCommand { get; set; } InterpreterCommand DebuggerCommand { get; set; }
/// <summary> /// <summary>
/// Logs the context, opcode, and arguments of an instruction /// Logs the context, opcode, and operands of an instruction
/// decoded by <c>Microsoft.Iris.Markup.Interpreter</c>.
/// </summary>
void LogInterpreterDecode(object context, InterpreterInstruction instruction);
/// <summary>
/// Logs the context, opcode, arguments, and results of an instruction
/// executed by <c>Microsoft.Iris.Markup.Interpreter</c>. /// executed by <c>Microsoft.Iris.Markup.Interpreter</c>.
/// </summary> /// </summary>
void LogInterpreterOpCode(object context, InterpreterEntry entry); void LogInterpreterExecute(object context, InterpreterEntry entry);
/// <summary> /// <summary>
/// Logs the string representation of a dispatcher step. /// Logs the string representation of a dispatcher step.
@@ -27,7 +27,8 @@ public class NetDebuggerClient : IDebuggerClient, IDisposable
} }
} }
public event EventHandler<InterpreterEntry> InterpreterStep; public event EventHandler<InterpreterInstruction> InterpreterDecode;
public event EventHandler<InterpreterEntry> InterpreterExecute;
public event Action<string> DispatcherStep; public event Action<string> DispatcherStep;
public event Action<InterpreterCommand> InterpreterStateChanged; public event Action<InterpreterCommand> InterpreterStateChanged;
@@ -75,9 +76,14 @@ public class NetDebuggerClient : IDebuggerClient, IDisposable
switch (frame.Type) switch (frame.Type)
{ {
case DebuggerMessageType.InterpreterOpCode: case DebuggerMessageType.InterpreterDecode:
var entry = frame.DeserializeData<InterpreterEntry>(_formatter); var decEntry = frame.DeserializeData<InterpreterInstruction>(_formatter);
InterpreterStep?.Invoke(this, entry); InterpreterDecode?.Invoke(this, decEntry);
break;
case DebuggerMessageType.InterpreterExecute:
var execEntry = frame.DeserializeData<InterpreterEntry>(_formatter);
InterpreterExecute?.Invoke(this, execEntry);
break; break;
case DebuggerMessageType.DispatcherStep: case DebuggerMessageType.DispatcherStep:
@@ -91,7 +97,7 @@ public class NetDebuggerClient : IDebuggerClient, IDisposable
break; break;
default: default:
Trace.WriteLine(TraceCategory.MarkupDebug, "Recieved unknown debugger message of type '{0}'.", frame.Type); Trace.WriteLine(TraceCategory.MarkupDebug, "Received unknown debugger message of type '{0}'.", frame.Type);
break; break;
} }
} }
@@ -49,9 +49,14 @@ internal class NetDebuggerServer : IDebuggerServer, IDisposable
Current = this; Current = this;
} }
public void LogInterpreterOpCode(object context, InterpreterEntry entry) public void LogInterpreterDecode(object context, InterpreterInstruction instruction)
{ {
QueueDebuggerMessage(new(0, DebuggerMessageType.InterpreterOpCode, entry.Serialize(_formatter))); QueueDebuggerMessage(new(0, DebuggerMessageType.InterpreterDecode, instruction.Serialize(_formatter)));
}
public void LogInterpreterExecute(object context, InterpreterEntry entry)
{
QueueDebuggerMessage(new(0, DebuggerMessageType.InterpreterExecute, entry.Serialize(_formatter)));
} }
public void LogDispatcher(string message) public void LogDispatcher(string message)
+136 -20
View File
@@ -44,7 +44,7 @@ namespace Microsoft.Iris.Markup
} }
return result; return result;
} }
// Token: 0x06000F22 RID: 3874 RVA: 0x00029EF8 File Offset: 0x00028EF8 // Token: 0x06000F22 RID: 3874 RVA: 0x00029EF8 File Offset: 0x00028EF8
private static object Run(InterpreterContext context, ByteCodeReader reader) private static object Run(InterpreterContext context, ByteCodeReader reader)
{ {
@@ -68,6 +68,21 @@ namespace Microsoft.Iris.Markup
object result = null; object result = null;
bool wasInDebugState = false; bool wasInDebugState = false;
bool debugging = Application.Debugger != null; bool debugging = Application.Debugger != null;
void OnDecode(InterpreterEntry entry)
{
if (!debugging) return;
Application.Debugger.LogInterpreterDecode(context, entry.Instruction);
// Stop execution while the debugger is in break mode
while (Application.Debugger.DebuggerCommand == InterpreterCommand.Break) ;
// If the debugger requested a single step, immediately set the debugger
// to break again for the next instruction
if (Application.Debugger.DebuggerCommand == InterpreterCommand.Step)
Application.Debugger.DebuggerCommand = InterpreterCommand.Break;
}
while (!errorsDetected) while (!errorsDetected)
{ {
@@ -87,14 +102,6 @@ namespace Microsoft.Iris.Markup
if (shouldBreakHere) if (shouldBreakHere)
Application.Debugger.DebuggerCommand = InterpreterCommand.Break; Application.Debugger.DebuggerCommand = InterpreterCommand.Break;
} }
// Stop exeuction while the debugger is in break mode
while (Application.Debugger.DebuggerCommand == InterpreterCommand.Break) ;
// If the debugger requested a single step, immediately set the debugger
// to break again for the next instruction
if (Application.Debugger.DebuggerCommand == InterpreterCommand.Step)
Application.Debugger.DebuggerCommand = InterpreterCommand.Break;
} }
switch (opCode) switch (opCode)
@@ -102,6 +109,9 @@ namespace Microsoft.Iris.Markup
case OpCode.ConstructObject: case OpCode.ConstructObject:
{ {
int typeIndex = reader.ReadUInt16(); int typeIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(typeIndex);
OnDecode(entry);
TypeSchema typeSchema = importTables.TypeImports[typeIndex]; TypeSchema typeSchema = importTables.TypeImports[typeIndex];
entry.Parameters.Add(new InterpreterObject("type", typeof(TypeSchema), entry.Parameters.Add(new InterpreterObject("type", typeof(TypeSchema),
typeSchema, InstructionObjectSource.TypeImports, typeIndex)); typeSchema, InstructionObjectSource.TypeImports, typeIndex));
@@ -121,6 +131,9 @@ namespace Microsoft.Iris.Markup
case OpCode.ConstructObjectIndirect: case OpCode.ConstructObjectIndirect:
{ {
int assignmentTypeIndex = reader.ReadUInt16(); int assignmentTypeIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(assignmentTypeIndex);
OnDecode(entry);
TypeSchema assignmentTypeSchema = importTables.TypeImports[assignmentTypeIndex]; TypeSchema assignmentTypeSchema = importTables.TypeImports[assignmentTypeIndex];
entry.Parameters.Add(new("assignmentType", typeof(TypeSchema), entry.Parameters.Add(new("assignmentType", typeof(TypeSchema),
assignmentTypeSchema, InstructionObjectSource.TypeImports, assignmentTypeIndex)); assignmentTypeSchema, InstructionObjectSource.TypeImports, assignmentTypeIndex));
@@ -153,9 +166,13 @@ namespace Microsoft.Iris.Markup
case OpCode.ConstructObjectParam: case OpCode.ConstructObjectParam:
{ {
int targetTypeIndex = reader.ReadUInt16(); int targetTypeIndex = reader.ReadUInt16();
TypeSchema targetTypeSchema = importTables.TypeImports[targetTypeIndex];
int constructorIndex = reader.ReadUInt16(); int constructorIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(targetTypeIndex);
entry.Instruction.Operands.Add(constructorIndex);
OnDecode(entry);
TypeSchema targetTypeSchema = importTables.TypeImports[targetTypeIndex];
ConstructorSchema constructorSchema = importTables.ConstructorImports[constructorIndex]; ConstructorSchema constructorSchema = importTables.ConstructorImports[constructorIndex];
int parameterCount = constructorSchema.ParameterTypes.Length; int parameterCount = constructorSchema.ParameterTypes.Length;
@@ -182,11 +199,16 @@ namespace Microsoft.Iris.Markup
case OpCode.ConstructFromString: case OpCode.ConstructFromString:
{ {
int typeIndex = reader.ReadUInt16(); int typeIndex = reader.ReadUInt16();
int stringIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(typeIndex);
entry.Instruction.Operands.Add(stringIndex);
OnDecode(entry);
TypeSchema typeSchema = importTables.TypeImports[typeIndex]; TypeSchema typeSchema = importTables.TypeImports[typeIndex];
entry.Parameters.Add(new("type", typeof(TypeSchema), entry.Parameters.Add(new("type", typeof(TypeSchema),
typeSchema, InstructionObjectSource.TypeImports, typeIndex)); typeSchema, InstructionObjectSource.TypeImports, typeIndex));
int stringIndex = reader.ReadUInt16();
string fromString = (string)constantsTable.Get(stringIndex); string fromString = (string)constantsTable.Get(stringIndex);
entry.Parameters.Add(new("fromString", typeof(string), entry.Parameters.Add(new("fromString", typeof(string),
fromString, InstructionObjectSource.Constants, stringIndex)); fromString, InstructionObjectSource.Constants, stringIndex));
@@ -206,6 +228,9 @@ namespace Microsoft.Iris.Markup
case OpCode.ConstructFromBinary: case OpCode.ConstructFromBinary:
{ {
int typeIndex = reader.ReadUInt16(); int typeIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(typeIndex);
OnDecode(entry);
TypeSchema typeSchema = importTables.TypeImports[typeIndex]; TypeSchema typeSchema = importTables.TypeImports[typeIndex];
entry.Parameters.Add(new("type", typeof(TypeSchema), entry.Parameters.Add(new("type", typeof(TypeSchema),
typeSchema, InstructionObjectSource.TypeImports, typeIndex)); typeSchema, InstructionObjectSource.TypeImports, typeIndex));
@@ -240,6 +265,9 @@ namespace Microsoft.Iris.Markup
case OpCode.InitializeInstance: case OpCode.InitializeInstance:
{ {
int typeIndex = reader.ReadUInt16(); int typeIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(typeIndex);
OnDecode(entry);
TypeSchema typeSchema = importTables.TypeImports[typeIndex]; TypeSchema typeSchema = importTables.TypeImports[typeIndex];
entry.Parameters.Add(new("type", typeof(TypeSchema), entry.Parameters.Add(new("type", typeof(TypeSchema),
typeSchema, InstructionObjectSource.TypeImports, typeIndex)); typeSchema, InstructionObjectSource.TypeImports, typeIndex));
@@ -260,6 +288,8 @@ namespace Microsoft.Iris.Markup
} }
case OpCode.InitializeInstanceIndirect: case OpCode.InitializeInstanceIndirect:
{ {
OnDecode(entry);
TypeSchema typeSchema = (TypeSchema)stack.Pop(); TypeSchema typeSchema = (TypeSchema)stack.Pop();
entry.Parameters.Add(new("type", typeof(TypeSchema), entry.Parameters.Add(new("type", typeof(TypeSchema),
typeSchema, InstructionObjectSource.Stack)); typeSchema, InstructionObjectSource.Stack));
@@ -281,6 +311,9 @@ namespace Microsoft.Iris.Markup
case OpCode.LookupSymbol: case OpCode.LookupSymbol:
{ {
int symbolRefIndex = reader.ReadUInt16(); int symbolRefIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(symbolRefIndex);
OnDecode(entry);
SymbolReference symbolRef = symbolReferenceTable[symbolRefIndex]; SymbolReference symbolRef = symbolReferenceTable[symbolRefIndex];
entry.Parameters.Add(new("symbolRef", typeof(SymbolReference), entry.Parameters.Add(new("symbolRef", typeof(SymbolReference),
symbolRef, InstructionObjectSource.SymbolReference, symbolRefIndex)); symbolRef, InstructionObjectSource.SymbolReference, symbolRefIndex));
@@ -298,11 +331,14 @@ namespace Microsoft.Iris.Markup
case OpCode.WriteSymbol: case OpCode.WriteSymbol:
case OpCode.WriteSymbolPeek: case OpCode.WriteSymbolPeek:
{ {
int symbolRefIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(symbolRefIndex);
OnDecode(entry);
object symbol = (opCode == OpCode.WriteSymbolPeek) ? stack.Peek() : stack.Pop(); object symbol = (opCode == OpCode.WriteSymbolPeek) ? stack.Peek() : stack.Pop();
entry.Parameters.Add(new("symbol", typeof(object), entry.Parameters.Add(new("symbol", typeof(object),
symbol, InstructionObjectSource.Stack)); symbol, InstructionObjectSource.Stack));
int symbolRefIndex = reader.ReadUInt16();
SymbolReference symbolRef = symbolReferenceTable[symbolRefIndex]; SymbolReference symbolRef = symbolReferenceTable[symbolRefIndex];
entry.Parameters.Add(new("symbolRef", typeof(SymbolReference), entry.Parameters.Add(new("symbolRef", typeof(SymbolReference),
symbolRef, InstructionObjectSource.SymbolReference, symbolRefIndex)); symbolRef, InstructionObjectSource.SymbolReference, symbolRefIndex));
@@ -317,6 +353,9 @@ namespace Microsoft.Iris.Markup
case OpCode.ClearSymbol: case OpCode.ClearSymbol:
{ {
int symbolRefIndex = reader.ReadUInt16(); int symbolRefIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(symbolRefIndex);
OnDecode(entry);
SymbolReference symbolRef = symbolReferenceTable[symbolRefIndex]; SymbolReference symbolRef = symbolReferenceTable[symbolRefIndex];
entry.Parameters.Add(new("symbolRef", typeof(SymbolReference), entry.Parameters.Add(new("symbolRef", typeof(SymbolReference),
symbolRef, InstructionObjectSource.SymbolReference, symbolRefIndex)); symbolRef, InstructionObjectSource.SymbolReference, symbolRefIndex));
@@ -331,6 +370,10 @@ namespace Microsoft.Iris.Markup
case OpCode.PropertyInitialize: case OpCode.PropertyInitialize:
case OpCode.PropertyInitializeIndirect: case OpCode.PropertyInitializeIndirect:
{ {
int propertyIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(propertyIndex);
OnDecode(entry);
bool isIndirect = opCode == OpCode.PropertyInitializeIndirect; bool isIndirect = opCode == OpCode.PropertyInitializeIndirect;
TypeSchema parentTypeSchema = null; TypeSchema parentTypeSchema = null;
if (isIndirect) if (isIndirect)
@@ -340,7 +383,6 @@ namespace Microsoft.Iris.Markup
parentTypeSchema, InstructionObjectSource.Stack)); parentTypeSchema, InstructionObjectSource.Stack));
} }
int propertyIndex = reader.ReadUInt16();
PropertySchema propertySchema = importTables.PropertyImports[propertyIndex]; PropertySchema propertySchema = importTables.PropertyImports[propertyIndex];
entry.Parameters.Add(new("property", typeof(PropertySchema), entry.Parameters.Add(new("property", typeof(PropertySchema),
propertySchema, InstructionObjectSource.PropertyImports, propertyIndex)); propertySchema, InstructionObjectSource.PropertyImports, propertyIndex));
@@ -387,11 +429,14 @@ namespace Microsoft.Iris.Markup
} }
case OpCode.PropertyListAdd: case OpCode.PropertyListAdd:
{ {
int propertyIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(propertyIndex);
OnDecode(entry);
object objToAdd = stack.Pop(); object objToAdd = stack.Pop();
entry.Parameters.Add(new("objToAdd", typeof(object), entry.Parameters.Add(new("objToAdd", typeof(object),
objToAdd, InstructionObjectSource.Stack)); objToAdd, InstructionObjectSource.Stack));
int propertyIndex = reader.ReadUInt16();
object collection = GetCollection(stack.Peek(), importTables, propertyIndex, out var propertySchema); object collection = GetCollection(stack.Peek(), importTables, propertyIndex, out var propertySchema);
entry.Parameters.Add(new("collection", typeof(IList), entry.Parameters.Add(new("collection", typeof(IList),
collection, InstructionObjectSource.Dynamic)); collection, InstructionObjectSource.Dynamic));
@@ -412,8 +457,12 @@ namespace Microsoft.Iris.Markup
case OpCode.PropertyDictionaryAdd: case OpCode.PropertyDictionaryAdd:
{ {
int propertyIndex = reader.ReadUInt16(); int propertyIndex = reader.ReadUInt16();
int keyIndex = reader.ReadUInt16(); int keyIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(propertyIndex);
entry.Instruction.Operands.Add(keyIndex);
OnDecode(entry);
string key = (string)constantsTable.Get(keyIndex); string key = (string)constantsTable.Get(keyIndex);
entry.Parameters.Add(new("key", typeof(string), entry.Parameters.Add(new("key", typeof(string),
key, InstructionObjectSource.Constants, keyIndex)); key, InstructionObjectSource.Constants, keyIndex));
@@ -443,6 +492,9 @@ namespace Microsoft.Iris.Markup
case OpCode.PropertyAssignStatic: case OpCode.PropertyAssignStatic:
{ {
int propertyIndex = reader.ReadUInt16(); int propertyIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(propertyIndex);
OnDecode(entry);
PropertySchema propertySchema = importTables.PropertyImports[propertyIndex]; PropertySchema propertySchema = importTables.PropertyImports[propertyIndex];
entry.Parameters.Add(new("property", typeof(PropertySchema), entry.Parameters.Add(new("property", typeof(PropertySchema),
propertySchema, InstructionObjectSource.PropertyImports, propertyIndex)); propertySchema, InstructionObjectSource.PropertyImports, propertyIndex));
@@ -478,6 +530,9 @@ namespace Microsoft.Iris.Markup
case OpCode.PropertyGetStatic: case OpCode.PropertyGetStatic:
{ {
int propertyIndex = reader.ReadUInt16(); int propertyIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(propertyIndex);
OnDecode(entry);
PropertySchema propertySchema = importTables.PropertyImports[propertyIndex]; PropertySchema propertySchema = importTables.PropertyImports[propertyIndex];
entry.Parameters.Add(new("property", typeof(PropertySchema), entry.Parameters.Add(new("property", typeof(PropertySchema),
propertySchema, InstructionObjectSource.PropertyImports, propertyIndex)); propertySchema, InstructionObjectSource.PropertyImports, propertyIndex));
@@ -516,6 +571,9 @@ namespace Microsoft.Iris.Markup
case OpCode.MethodInvokeStaticPushLastParam: case OpCode.MethodInvokeStaticPushLastParam:
{ {
int methodIndex = reader.ReadUInt16(); int methodIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(methodIndex);
OnDecode(entry);
MethodSchema methodSchema = importTables.MethodImports[methodIndex]; MethodSchema methodSchema = importTables.MethodImports[methodIndex];
int parameterCount = methodSchema.ParameterTypes.Length; int parameterCount = methodSchema.ParameterTypes.Length;
@@ -566,6 +624,9 @@ namespace Microsoft.Iris.Markup
case OpCode.VerifyTypeCast: case OpCode.VerifyTypeCast:
{ {
int typeIndex = reader.ReadUInt16(); int typeIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(typeIndex);
OnDecode(entry);
TypeSchema typeSchema = importTables.TypeImports[typeIndex]; TypeSchema typeSchema = importTables.TypeImports[typeIndex];
entry.Parameters.Add(new("type", typeof(TypeSchema), entry.Parameters.Add(new("type", typeof(TypeSchema),
typeSchema, InstructionObjectSource.TypeImports, typeIndex)); typeSchema, InstructionObjectSource.TypeImports, typeIndex));
@@ -600,11 +661,16 @@ namespace Microsoft.Iris.Markup
case OpCode.ConvertType: case OpCode.ConvertType:
{ {
int toTypeIndex = reader.ReadUInt16(); int toTypeIndex = reader.ReadUInt16();
int fromTypeIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(toTypeIndex);
entry.Instruction.Operands.Add(fromTypeIndex);
OnDecode(entry);
TypeSchema toTypeSchema = importTables.TypeImports[toTypeIndex]; TypeSchema toTypeSchema = importTables.TypeImports[toTypeIndex];
entry.Parameters.Add(new("toType", typeof(TypeSchema), entry.Parameters.Add(new("toType", typeof(TypeSchema),
toTypeSchema, InstructionObjectSource.TypeImports, toTypeIndex)); toTypeSchema, InstructionObjectSource.TypeImports, toTypeIndex));
int fromTypeIndex = reader.ReadUInt16();
TypeSchema fromTypeSchema = importTables.TypeImports[fromTypeIndex]; TypeSchema fromTypeSchema = importTables.TypeImports[fromTypeIndex];
entry.Parameters.Add(new("fromType", typeof(TypeSchema), entry.Parameters.Add(new("fromType", typeof(TypeSchema),
fromTypeSchema, InstructionObjectSource.TypeImports, fromTypeIndex)); fromTypeSchema, InstructionObjectSource.TypeImports, fromTypeIndex));
@@ -631,11 +697,16 @@ namespace Microsoft.Iris.Markup
case OpCode.Operation: case OpCode.Operation:
{ {
int opHostIndex = reader.ReadUInt16(); int opHostIndex = reader.ReadUInt16();
OperationType op = (OperationType)reader.ReadByte();
entry.Instruction.Operands.Add(opHostIndex);
entry.Instruction.Operands.Add(op);
OnDecode(entry);
TypeSchema opHost = importTables.TypeImports[opHostIndex]; TypeSchema opHost = importTables.TypeImports[opHostIndex];
entry.Parameters.Add(new("opHost", typeof(TypeSchema), entry.Parameters.Add(new("opHost", typeof(TypeSchema),
opHost, InstructionObjectSource.TypeImports, opHostIndex)); opHost, InstructionObjectSource.TypeImports, opHostIndex));
OperationType op = (OperationType)reader.ReadByte();
entry.Parameters.Add(new("op", typeof(OperationType), entry.Parameters.Add(new("op", typeof(OperationType),
op, InstructionObjectSource.Inline)); op, InstructionObjectSource.Inline));
@@ -667,6 +738,9 @@ namespace Microsoft.Iris.Markup
case OpCode.IsCheck: case OpCode.IsCheck:
{ {
int targetTypeIndex = reader.ReadUInt16(); int targetTypeIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(targetTypeIndex);
OnDecode(entry);
TypeSchema targetTypeSchema = importTables.TypeImports[targetTypeIndex]; TypeSchema targetTypeSchema = importTables.TypeImports[targetTypeIndex];
entry.Parameters.Add(new("targetType", typeof(TypeSchema), entry.Parameters.Add(new("targetType", typeof(TypeSchema),
targetTypeSchema, InstructionObjectSource.TypeImports, targetTypeIndex)); targetTypeSchema, InstructionObjectSource.TypeImports, targetTypeIndex));
@@ -690,6 +764,9 @@ namespace Microsoft.Iris.Markup
case OpCode.As: case OpCode.As:
{ {
int targetTypeIndex = reader.ReadUInt16(); int targetTypeIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(targetTypeIndex);
OnDecode(entry);
TypeSchema targetTypeSchema = importTables.TypeImports[targetTypeIndex]; TypeSchema targetTypeSchema = importTables.TypeImports[targetTypeIndex];
entry.Parameters.Add(new("targetType", typeof(TypeSchema), entry.Parameters.Add(new("targetType", typeof(TypeSchema),
targetTypeSchema, InstructionObjectSource.TypeImports, targetTypeIndex)); targetTypeSchema, InstructionObjectSource.TypeImports, targetTypeIndex));
@@ -718,6 +795,9 @@ namespace Microsoft.Iris.Markup
case OpCode.TypeOf: case OpCode.TypeOf:
{ {
int typeIndex = reader.ReadUInt16(); int typeIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(typeIndex);
OnDecode(entry);
entry.Parameters.Add(new("typeIndex", typeof(ushort), entry.Parameters.Add(new("typeIndex", typeof(ushort),
typeIndex, InstructionObjectSource.Inline)); typeIndex, InstructionObjectSource.Inline));
@@ -728,12 +808,16 @@ namespace Microsoft.Iris.Markup
break; break;
} }
case OpCode.PushNull: case OpCode.PushNull:
OnDecode(entry);
stack.Push(null); stack.Push(null);
entry.ReturnValues.Add(new(null)); entry.ReturnValues.Add(new(null));
break; break;
case OpCode.PushConstant: case OpCode.PushConstant:
{ {
int constantIndex = reader.ReadUInt16(); int constantIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(constantIndex);
OnDecode(entry);
entry.Parameters.Add(new("constantIndex", typeof(ushort), entry.Parameters.Add(new("constantIndex", typeof(ushort),
constantIndex, InstructionObjectSource.Inline)); constantIndex, InstructionObjectSource.Inline));
@@ -744,14 +828,18 @@ namespace Microsoft.Iris.Markup
break; break;
} }
case OpCode.PushThis: case OpCode.PushThis:
OnDecode(entry);
stack.Push(instance); stack.Push(instance);
entry.ReturnValues.Add(new(instance)); entry.ReturnValues.Add(new(instance));
break; break;
case OpCode.DiscardValue: case OpCode.DiscardValue:
OnDecode(entry);
stack.Pop(); stack.Pop();
break; break;
case OpCode.ReturnValue: case OpCode.ReturnValue:
{ {
OnDecode(entry);
object thisResult = stack.Pop(); object thisResult = stack.Pop();
entry.ReturnValues.Add(new(thisResult)); entry.ReturnValues.Add(new(thisResult));
@@ -760,6 +848,7 @@ namespace Microsoft.Iris.Markup
break; break;
} }
case OpCode.ReturnVoid: case OpCode.ReturnVoid:
OnDecode(entry);
result = VoidReturnValue; result = VoidReturnValue;
errorsDetected = true; errorsDetected = true;
break; break;
@@ -768,6 +857,9 @@ namespace Microsoft.Iris.Markup
case OpCode.JumpIfTruePeek: case OpCode.JumpIfTruePeek:
{ {
uint jumpTo = reader.ReadUInt32(); uint jumpTo = reader.ReadUInt32();
entry.Instruction.Operands.Add(jumpTo);
OnDecode(entry);
entry.Parameters.Add(new("jumpTo", typeof(uint), entry.Parameters.Add(new("jumpTo", typeof(uint),
jumpTo, InstructionObjectSource.Inline)); jumpTo, InstructionObjectSource.Inline));
@@ -790,8 +882,13 @@ namespace Microsoft.Iris.Markup
{ {
ushort propertyIndex = reader.ReadUInt16(); ushort propertyIndex = reader.ReadUInt16();
ushort keyIndex = reader.ReadUInt16(); ushort keyIndex = reader.ReadUInt16();
uint jumpTo = reader.ReadUInt32(); uint jumpTo = reader.ReadUInt32();
entry.Instruction.Operands.Add(propertyIndex);
entry.Instruction.Operands.Add(keyIndex);
entry.Instruction.Operands.Add(jumpTo);
OnDecode(entry);
entry.Parameters.Add(new("jumpTo", typeof(uint), entry.Parameters.Add(new("jumpTo", typeof(uint),
jumpTo, InstructionObjectSource.Inline)); jumpTo, InstructionObjectSource.Inline));
@@ -826,6 +923,9 @@ namespace Microsoft.Iris.Markup
case OpCode.JumpIfNullPeek: case OpCode.JumpIfNullPeek:
{ {
uint jumpTo = reader.ReadUInt32(); uint jumpTo = reader.ReadUInt32();
entry.Instruction.Operands.Add(jumpTo);
OnDecode(entry);
entry.Parameters.Add(new("jumpTo", typeof(uint), entry.Parameters.Add(new("jumpTo", typeof(uint),
jumpTo, InstructionObjectSource.Inline)); jumpTo, InstructionObjectSource.Inline));
@@ -847,6 +947,9 @@ namespace Microsoft.Iris.Markup
case OpCode.Jump: case OpCode.Jump:
{ {
uint jumpTo = reader.ReadUInt32(); uint jumpTo = reader.ReadUInt32();
entry.Instruction.Operands.Add(jumpTo);
OnDecode(entry);
entry.Parameters.Add(new("jumpTo", typeof(uint), entry.Parameters.Add(new("jumpTo", typeof(uint),
jumpTo, InstructionObjectSource.Inline)); jumpTo, InstructionObjectSource.Inline));
@@ -860,6 +963,9 @@ namespace Microsoft.Iris.Markup
case OpCode.ConstructListenerStorage: case OpCode.ConstructListenerStorage:
{ {
int listenerCount = reader.ReadUInt16(); int listenerCount = reader.ReadUInt16();
entry.Instruction.Operands.Add(listenerCount);
OnDecode(entry);
entry.Parameters.Add(new("listenerCount", typeof(int), entry.Parameters.Add(new("listenerCount", typeof(int),
listenerCount, InstructionObjectSource.Inline)); listenerCount, InstructionObjectSource.Inline));
@@ -883,16 +989,20 @@ namespace Microsoft.Iris.Markup
case OpCode.DestructiveListen: case OpCode.DestructiveListen:
{ {
int listenerIndex = reader.ReadUInt16(); int listenerIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(listenerIndex);
entry.Parameters.Add(new("listenerIndex", typeof(int), entry.Parameters.Add(new("listenerIndex", typeof(int),
listenerIndex, InstructionObjectSource.Inline)); listenerIndex, InstructionObjectSource.Inline));
ListenerType listenerType = (ListenerType)reader.ReadByte(); ListenerType listenerType = (ListenerType)reader.ReadByte();
entry.Instruction.Operands.Add(listenerType);
entry.Parameters.Add(new("listenerType", typeof(ListenerType), entry.Parameters.Add(new("listenerType", typeof(ListenerType),
listenerType, InstructionObjectSource.Inline)); listenerType, InstructionObjectSource.Inline));
int watchIndex = reader.ReadUInt16(); int watchIndex = reader.ReadUInt16();
entry.Instruction.Operands.Add(watchIndex);
uint handlerOffset = reader.ReadUInt32(); uint handlerOffset = reader.ReadUInt32();
entry.Instruction.Operands.Add(handlerOffset);
entry.Parameters.Add(new("handlerOffset", typeof(uint), entry.Parameters.Add(new("handlerOffset", typeof(uint),
handlerOffset, InstructionObjectSource.Inline)); handlerOffset, InstructionObjectSource.Inline));
@@ -900,10 +1010,13 @@ namespace Microsoft.Iris.Markup
if (opCode == OpCode.DestructiveListen) if (opCode == OpCode.DestructiveListen)
{ {
refreshOffset = reader.ReadUInt32(); refreshOffset = reader.ReadUInt32();
entry.Instruction.Operands.Add(refreshOffset);
entry.Parameters.Add(new("refreshOffset", typeof(uint), entry.Parameters.Add(new("refreshOffset", typeof(uint),
refreshOffset, InstructionObjectSource.Inline)); refreshOffset, InstructionObjectSource.Inline));
} }
OnDecode(entry);
string watch = null; string watch = null;
InstructionObjectSource watchSource = InstructionObjectSource.Dynamic; InstructionObjectSource watchSource = InstructionObjectSource.Dynamic;
switch (listenerType) switch (listenerType)
@@ -942,6 +1055,9 @@ namespace Microsoft.Iris.Markup
case OpCode.EnterDebugState: case OpCode.EnterDebugState:
{ {
int breakpointIndex = reader.ReadInt32(); int breakpointIndex = reader.ReadInt32();
entry.Instruction.Operands.Add(breakpointIndex);
OnDecode(entry);
entry.Parameters.Add(new("breakpointIndex", typeof(int), entry.Parameters.Add(new("breakpointIndex", typeof(int),
breakpointIndex, InstructionObjectSource.Inline)); breakpointIndex, InstructionObjectSource.Inline));
@@ -953,7 +1069,7 @@ namespace Microsoft.Iris.Markup
} }
} }
Application.Debugger?.LogInterpreterOpCode(context, entry); Application.Debugger?.LogInterpreterExecute(context, entry);
} }
while (stack.Count > count) while (stack.Count > count)
{ {