Permalink
Browse files

AdventureSample - support CLS

  • Loading branch information...
bobbymcr committed Apr 22, 2018
1 parent e4581f0 commit 7037cf19dd47ff8d555b9012d490f632977a2217
@@ -110,7 +110,14 @@ public void Remark(string text)
public void Void(string name)
{
throw new NotImplementedException();
switch (name)
{
case "Cls":
this.AddCls();
break;
default:
throw new NotImplementedException("Void:" + name);
}
}
private void Usings(IList<SyntaxNode> declarations)
@@ -196,17 +203,34 @@ private void AddPrint(BasicExpression expr)
{
ExpressionNode node = new ExpressionNode(this.generator, this.vars, this.methods);
expr.Accept(node);
var callPrint = this.generator.InvocationExpression(SyntaxFactory.IdentifierName("PRINT"), node.Value);
string name = "PRINT";
var callPrint = this.generator.InvocationExpression(SyntaxFactory.IdentifierName(name), node.Value);
this.lines.Add(this.lineNumber, callPrint);
var output = this.generator.MemberAccessExpression(this.generator.ThisExpression(), this.generator.IdentifierName("output"));
var callConsoleWriteLine = this.generator.MemberAccessExpression(output, "WriteLine");
SyntaxNode[] printStatements = new SyntaxNode[] { this.generator.InvocationExpression(callConsoleWriteLine, this.generator.IdentifierName("expression")) };
var callWriteLine = this.generator.MemberAccessExpression(output, "WriteLine");
SyntaxNode[] printStatements = new SyntaxNode[] { this.generator.InvocationExpression(callWriteLine, this.generator.IdentifierName("expression")) };
SyntaxNode[] parameters = new SyntaxNode[] { this.generator.ParameterDeclaration("expression", type: this.generator.TypeExpression(SpecialType.System_String)) };
string name = "PRINT";
var printMethod = this.generator.MethodDeclaration(name, accessibility: Accessibility.Private, parameters: parameters, statements: printStatements);
this.methods.Add(name, printMethod);
}
private void AddCls()
{
string name = "CLS";
var callCls = this.generator.InvocationExpression(SyntaxFactory.IdentifierName(name));
this.lines.Add(this.lineNumber, callCls);
var output = this.generator.MemberAccessExpression(this.generator.ThisExpression(), this.generator.IdentifierName("output"));
var callWrite = this.generator.MemberAccessExpression(output, "Write");
var callClear = this.generator.MemberAccessExpression(this.generator.IdentifierName("Console"), "Clear");
SyntaxNode[] clsStatements = new SyntaxNode[]
{
this.generator.InvocationExpression(callWrite, this.generator.LiteralExpression('\f')),
this.generator.InvocationExpression(callClear),
};
var clsMethod = this.generator.MethodDeclaration(name, accessibility: Accessibility.Private, statements: clsStatements);
this.methods.Add(name, clsMethod);
}
private void AddDim(BasicExpression expr)
{
ExpressionNode node = new ExpressionNode(this.generator, this.vars, this.methods);
@@ -22,13 +22,14 @@ private static int Main(string[] args)
return 0;
}
private static Task MainAsync(string inputPath, string outputPath)
private static async Task MainAsync(string inputPath, string outputPath)
{
string name = Path.GetFileNameWithoutExtension(inputPath);
return BasicProgram.TranslateAsync(
name,
Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read),
Open(outputPath, FileMode.Create, FileAccess.Write, FileShare.None));
using (Stream output = Open(outputPath, FileMode.Create, FileAccess.Write, FileShare.None))
{
Stream input = Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read);
await BasicProgram.TranslateAsync(name, input, output);
}
}
private static Stream Open(string path, FileMode mode, FileAccess access, FileShare share)
@@ -24,7 +24,8 @@ public void FullClass()
100 DIM B1$(6)
110 DIM A(7)
120 DIM B1(8)
200 GOTO 20";
130 CLS
1000 GOTO 20";
const string Expected = @"using System;
using System.IO;
@@ -77,6 +78,12 @@ private void DIM_na(out float[] a, float d1)
a = (new float[((int)(d1)) + (1)]);
}
private void CLS()
{
this.output.Write('\f');
Console.Clear();
}
private bool Main()
{
this.Init();
@@ -94,6 +101,7 @@ private bool Main()
DIM_sa(out B1_sa, 6);
DIM_na(out A_na, 7);
DIM_na(out B1_na, 8);
CLS();
goto L20;
return false;
}

0 comments on commit 7037cf1

Please sign in to comment.