Cleanup and reorganization
This commit is contained in:
parent
bb5d8140e4
commit
dff1ddc0ba
|
@ -1,3 +1,5 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=binder_005Cboundexpressions/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=binder_005Cboundstatements/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=parser_005Cexpressionsyntax/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=parser_005Cstatementsyntax/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
|
@ -2,58 +2,57 @@ using System;
|
|||
using System.Text;
|
||||
using Upsilon.BaseTypes.Number;
|
||||
using Upsilon.Binder;
|
||||
using System.Collections.Immutable;
|
||||
using Type = Upsilon.BaseTypes.Type;
|
||||
|
||||
namespace UpsilonCompiler
|
||||
{
|
||||
public class Compiler
|
||||
public class Transpiler
|
||||
{
|
||||
public string CompileToCSharp(BoundScript script)
|
||||
public string TranspilerToCSharp(BoundScript script)
|
||||
{
|
||||
var s = script.Statement;
|
||||
return Compile(s);
|
||||
return Transpile(s);
|
||||
}
|
||||
|
||||
private string Compile(BoundNode e)
|
||||
private string Transpile(BoundNode e)
|
||||
{
|
||||
switch (e.Kind)
|
||||
{
|
||||
case BoundKind.BoundScript:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
case BoundKind.BoundLiteralExpression:
|
||||
return CompileLiteralExpression((BoundLiteralExpression) e);
|
||||
return TranspileLiteralExpression((BoundLiteralExpression) e);
|
||||
case BoundKind.BoundBinaryExpression:
|
||||
return CompileBinaryExpression((BoundBinaryExpression) e);
|
||||
return TranspileBinaryExpression((BoundBinaryExpression) e);
|
||||
case BoundKind.BoundUnaryExpression:
|
||||
case BoundKind.VariableExpression:
|
||||
case BoundKind.BoundAssignmentStatement:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
case BoundKind.BoundExpressionStatement:
|
||||
return Compile(((BoundExpressionStatement)e).Expression);
|
||||
return Transpile(((BoundExpressionStatement)e).Expression);
|
||||
case BoundKind.BoundBlockStatement:
|
||||
return CompileBlockStatement((BoundBlockStatement) e);
|
||||
return TranspileBlockStatement((BoundBlockStatement) e);
|
||||
case BoundKind.BoundIfStatement:
|
||||
return CompileIfStatement((BoundIfStatement) e);
|
||||
return TranspileIfStatement((BoundIfStatement) e);
|
||||
case BoundKind.BoundElseStatement:
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(e.Kind.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private string CompileBlockStatement(BoundBlockStatement s)
|
||||
private string TranspileBlockStatement(BoundBlockStatement s)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (var sStatement in s.Statements)
|
||||
{
|
||||
var compile = Compile(sStatement);
|
||||
var compile = Transpile(sStatement);
|
||||
sb.Append(compile);
|
||||
sb.Append(";\n");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private string CompileLiteralExpression(BoundLiteralExpression e)
|
||||
private static string TranspileLiteralExpression(BoundLiteralExpression e)
|
||||
{
|
||||
switch (e.Type)
|
||||
{
|
||||
|
@ -73,12 +72,12 @@ namespace UpsilonCompiler
|
|||
}
|
||||
}
|
||||
|
||||
private string CompileBinaryExpression(BoundBinaryExpression e)
|
||||
private string TranspileBinaryExpression(BoundBinaryExpression e)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("(");
|
||||
var compiledLeft = Compile(e.LeftExpression);
|
||||
var compiledRight = Compile(e.RightExpression);
|
||||
var compiledLeft = Transpile(e.LeftExpression);
|
||||
var compiledRight = Transpile(e.RightExpression);
|
||||
sb.Append(compiledLeft);
|
||||
switch (e.Operator.Kind)
|
||||
{
|
||||
|
@ -109,15 +108,15 @@ namespace UpsilonCompiler
|
|||
return sb.ToString();
|
||||
}
|
||||
|
||||
private string CompileIfStatement(BoundIfStatement s, bool isElseIf = false)
|
||||
private string TranspileIfStatement(BoundIfStatement s, bool isElseIf = false)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var openToken = isElseIf ? "else if(" : "if(";
|
||||
sb.Append(openToken);
|
||||
var compiledCondition = Compile(s.Condition);
|
||||
var compiledCondition = Transpile(s.Condition);
|
||||
sb.Append(compiledCondition);
|
||||
sb.Append("){\n");
|
||||
var compiledBlock = Compile(s.Block);
|
||||
var compiledBlock = Transpile(s.Block);
|
||||
sb.Append(compiledBlock);
|
||||
sb.Append("}");
|
||||
return sb.ToString();
|
||||
|
|
|
@ -35,8 +35,8 @@ namespace Yc
|
|||
continue;
|
||||
}
|
||||
|
||||
var compiler = new Compiler();
|
||||
var compiled = compiler.CompileToCSharp(parsed.Bind());
|
||||
var compiler = new Transpiler();
|
||||
var compiled = compiler.TranspilerToCSharp(parsed.Bind());
|
||||
Console.WriteLine(compiled);
|
||||
/*
|
||||
var evaluate = parsed.Evaluate();
|
||||
|
|
Loading…
Reference in New Issue