Skip to content

Commit 8bd49e8

Browse files
committed
remove return address from Frame.cs
1 parent 619abd7 commit 8bd49e8

File tree

6 files changed

+8
-10
lines changed

6 files changed

+8
-10
lines changed

src/Domain/HydraScript.Domain.BackEnd/Frame.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
namespace HydraScript.Domain.BackEnd;
22

3-
public class Frame(IAddress returnAddress, Frame? parentFrame = null)
3+
public class Frame(Frame? parentFrame = null)
44
{
55
private readonly Dictionary<string, object?> _variables = new();
66

7-
public IAddress ReturnAddress { get; } = returnAddress;
8-
97
public object? this[string id]
108
{
119
get => _variables.TryGetValue(id, out var value)

src/Domain/HydraScript.Domain.BackEnd/Impl/Instructions/Return.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace HydraScript.Domain.BackEnd.Impl.Instructions;
22

33
public class Return(IValue? value = null) : Instruction
44
{
5-
public override IAddress Execute(IExecuteParams executeParams)
5+
public override IAddress? Execute(IExecuteParams executeParams)
66
{
77
var frame = executeParams.Frames.Pop();
88
var call = executeParams.CallStack.Pop();
@@ -11,7 +11,7 @@ public override IAddress Execute(IExecuteParams executeParams)
1111
executeParams.Frames.Peek()[call.Where] = value.Get(frame);
1212
}
1313

14-
return frame.ReturnAddress;
14+
return call.From.Next;
1515
}
1616

1717
protected override string ToStringInternal() =>

src/Domain/HydraScript.Domain.BackEnd/Impl/Instructions/WithAssignment/CallFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ protected override void OnSetOfAddress(IAddress address)
1212

1313
public override IAddress Execute(IExecuteParams executeParams)
1414
{
15-
var frame = new Frame(Address.Next!, executeParams.Frames.Peek());
15+
var frame = new Frame(executeParams.Frames.Peek());
1616
executeParams.CallStack.Push(new Call(Address, function, Left));
1717
executeParams.Frames.Push(frame);
1818
return function.Start;

src/Domain/HydraScript.Domain.BackEnd/Impl/VirtualMachine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class VirtualMachine(IOutputWriter writer) : IVirtualMachine
66

77
public void Run(AddressedInstructions instructions)
88
{
9-
ExecuteParams.Frames.Push(new Frame(instructions.Start));
9+
ExecuteParams.Frames.Push(new Frame());
1010

1111
var address = instructions.Start;
1212
while (address is not null)

tests/HydraScript.UnitTests/Domain/BackEnd/AsStringTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void Execute_String_NoQuotes(VirtualMachine vm)
1212
{
1313
// Arrange
1414
AddressedInstructions program = [new AsString(new Constant("string"))];
15-
vm.ExecuteParams.Frames.Push(new Frame(program.Start));
15+
vm.ExecuteParams.Frames.Push(new Frame());
1616

1717
// Act
1818
program[program.Start].Execute(vm.ExecuteParams);

tests/HydraScript.UnitTests/Domain/BackEnd/VirtualMachineTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class VirtualMachineTests
1717
public void CorrectPrintToOutTest([Frozen] IOutputWriter writer, IExecuteParams exParams)
1818
{
1919
exParams.CallStack.Returns(new Stack<Call>());
20-
exParams.Frames.Returns(new Stack<Frame>([new Frame(new HashAddress(0))]));
20+
exParams.Frames.Returns(new Stack<Frame>([new Frame()]));
2121
exParams.Arguments.Returns(new Queue<object?>());
2222

2323
var print = new Print(new Constant(223))
@@ -95,7 +95,7 @@ public void VirtualMachineHandlesRecursionTest(VirtualMachine vm)
9595
[Theory, AutoHydraScriptData]
9696
public void CreateArrayReservesCertainSpaceTest(ExecuteParams vm)
9797
{
98-
vm.Frames.Push(new Frame(new HashAddress(0)));
98+
vm.Frames.Push(new Frame());
9999

100100
var createArray = new CreateArray("arr", 6)
101101
{

0 commit comments

Comments
 (0)