Skip to content

Commit dd5e013

Browse files
committed
#200 - codegen
1 parent 124d583 commit dd5e013

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Application/HydraScript.Application.CodeGeneration/Visitors/InstructionProvider.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ internal class InstructionProvider : VisitorBase<IAbstractSyntaxTreeNode, Addres
2424
IVisitor<FunctionDeclaration, AddressedInstructions>,
2525
IVisitor<WhileStatement, AddressedInstructions>,
2626
IVisitor<IfStatement, AddressedInstructions>,
27-
IVisitor<OutputStatement, AddressedInstructions>
27+
IVisitor<OutputStatement, AddressedInstructions>,
28+
IVisitor<InputStatement, AddressedInstructions>
2829
{
2930
private readonly IValueFactory _valueFactory;
3031
private readonly IVisitor<IAbstractSyntaxTreeNode, AddressedInstructions> _expressionVisitor;
@@ -255,4 +256,7 @@ public AddressedInstructions Visit(OutputStatement visitable)
255256

256257
return result;
257258
}
259+
260+
public AddressedInstructions Visit(InputStatement visitable) =>
261+
[new Input(_valueFactory.Create(visitable.Destination))];
258262
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using HydraScript.Domain.BackEnd.Impl.Values;
2+
3+
namespace HydraScript.Domain.BackEnd.Impl.Instructions;
4+
5+
public class Input(Name name) : Instruction
6+
{
7+
public override IAddress? Execute(IExecuteParams executeParams)
8+
{
9+
var input = executeParams.Console.ReadLine();
10+
name.Set(input);
11+
return Address.Next;
12+
}
13+
14+
protected override string ToStringInternal() =>
15+
$"Input {name}";
16+
}

0 commit comments

Comments
 (0)