Skip to content

Commit

Permalink
#31 - tuple -> dto
Browse files Browse the repository at this point in the history
  • Loading branch information
Stepami committed Jul 26, 2024
1 parent 27c5975 commit 12ed0d5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/HydraScript.Lib/BackEnd/Instructions/PushParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public class PushParameter(string parameter, IValue value) : Instruction
{
public override IAddress Execute(VirtualMachine vm)
{
vm.Arguments.Push((parameter, value.Get(vm.Frames.Peek())));
vm.Arguments.Push(new CallArgument(
parameter,
value.Get(vm.Frames.Peek())));
return Address.Next;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override IAddress Execute(VirtualMachine vm)
var frame = new Frame(Address.Next, vm.Frames.Peek());

var i = 0;
var args = new List<(string Id, object? Value)>();
var args = new List<CallArgument>();
while (i < _numberOfArguments)
{
args.Add(vm.Arguments.Pop());
Expand Down
11 changes: 8 additions & 3 deletions src/HydraScript.Lib/BackEnd/VirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace HydraScript.Lib.BackEnd;

public record VirtualMachine(
Stack<Call> CallStack, Stack<Frame> Frames,
Stack<(string Id, object? Value)> Arguments,
Stack<CallArgument> Arguments,
TextWriter Writer
)
{
Expand All @@ -29,11 +29,16 @@ public void Run(AddressedInstructions instructions)

public record Call(
IAddress From, FunctionInfo To,
List<(string Id, object? Value)> Parameters,
List<CallArgument> Arguments,
string? Where = null)
{
public override string ToString() =>
$"{From} => {To.Start}: {To.Id}({string.Join(", ", Parameters.Select(x => $"{x.Id}: {x.Value}"))})";
$"{From} => {To.Start}: {To.Id}({string.Join(", ", Arguments)})";
}

public record CallArgument(string Id, object? Value)
{
public override string ToString() => $"{Id}: {Value}";
}

public record FunctionInfo(string Id)
Expand Down
2 changes: 1 addition & 1 deletion tests/HydraScript.Tests/Unit/BackEnd/CallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void ToStringCorrect()
var call = new Call(
new Label("9"),
new FunctionInfo("func"),
[("arg", 1)]);
[new CallArgument("arg", 1)]);
const string expected = "9:\n\t => Start_func:\n\t: func(arg: 1)";
Assert.Equal(expected, call.ToString());
}
Expand Down

0 comments on commit 12ed0d5

Please sign in to comment.