Skip to content

Commit

Permalink
AdventureSample - support RUN
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Apr 23, 2018
1 parent 428cee7 commit b55b896
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions projects/AdventureSample/src/GWBas2CS/BasicVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public void Void(string name)
case "Return":
this.AddReturn();
break;
case "Run":
this.AddRun();
break;
default:
throw new NotImplementedException("Void:" + name);
}
Expand Down Expand Up @@ -248,6 +251,12 @@ private void AddReturn()
this.lines.AddReturn(this.lineNumber);
}

private void AddRun()
{
var ret = this.generator.ReturnStatement(this.generator.LiteralExpression(1));
this.lines.Add(this.lineNumber, ret);
}

private void AddCls()
{
string name = "CLS";
Expand Down
50 changes: 50 additions & 0 deletions projects/AdventureSample/test/GWBas2CS.Test/Subroutines.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// <copyright file="Subroutines.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace GWBas2CS.Test
{
using FluentAssertions;
using Xunit;

public sealed class Subroutines
{
[Fact]
public void WithRun()
{
const string Input =
@"10 GOSUB 30
20 GOTO 10
30 RUN
40 RETURN";
const string Expected = @"*
private int Sub_30()
{
return 1;
return 0;
}
private int Main()
{
this.Init();
L10:
;
switch (Sub_30())
{
case 1:
return 1;
case 2:
return 2;
}
goto L10;
return 2;
}
*";

string actual = Test.Translate("MyProg", Input);

actual.Should().Match(Expected);
}
}
}

0 comments on commit b55b896

Please sign in to comment.