Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/Neo.VM/EvaluationStack.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (C) 2016-2023 The Neo Project.
//
// The neo-vm is free software distributed under the MIT software license,
//
// The neo-vm is free software distributed under the MIT software license,
// see the accompanying file LICENSE in the main directory of the
// project or http://www.opensource.org/licenses/mit-license.php
// project or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

Expand Down Expand Up @@ -35,6 +35,26 @@ internal EvaluationStack(ReferenceCounter referenceCounter)
/// </summary>
public int Count => innerList.Count;

public override string ToString()
{
return $@"[{string.Join(", ", innerList.Select(p =>
{
var value = p.Type switch
{
StackItemType.Pointer => $"({((Pointer)p).Position})",
StackItemType.Boolean => $"({p.GetBoolean()})",
StackItemType.Integer => $"({p.GetInteger()})",
Comment thread
shargon marked this conversation as resolved.
StackItemType.ByteString => $"(\"{p.GetString()}\")",
StackItemType.Array
or StackItemType.Map
or StackItemType.Struct => $"({((CompoundType)p).Count})",
_ => ""
Comment thread
Jim8y marked this conversation as resolved.
};
return $"{p.Type.ToString()}{value}";
}
))}]";
}

internal void Clear()
{
foreach (StackItem item in innerList)
Expand Down
13 changes: 13 additions & 0 deletions tests/Neo.VM.Tests/UtEvaluationStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,18 @@ public void TestReverse()
Assert.IsTrue(stack.Pop<Integer>().Equals(1));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stack.Pop<Integer>().Equals(0));
}

[TestMethod]
public void TestToString()
{
var stack = new EvaluationStack(new ReferenceCounter());

stack.Insert(0, 3);
stack.Insert(1, 1);
stack.Insert(2, "test");
stack.Insert(3, true);

Assert.AreEqual("[Boolean(True), ByteString(\"test\"), Integer(1), Integer(3)]", stack.ToString());
}
}
}