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">
|
<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_005Cexpressionsyntax/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=parser_005Cstatementsyntax/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<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 System.Text;
|
||||||
using Upsilon.BaseTypes.Number;
|
using Upsilon.BaseTypes.Number;
|
||||||
using Upsilon.Binder;
|
using Upsilon.Binder;
|
||||||
using System.Collections.Immutable;
|
|
||||||
using Type = Upsilon.BaseTypes.Type;
|
using Type = Upsilon.BaseTypes.Type;
|
||||||
|
|
||||||
namespace UpsilonCompiler
|
namespace UpsilonCompiler
|
||||||
{
|
{
|
||||||
public class Compiler
|
public class Transpiler
|
||||||
{
|
{
|
||||||
public string CompileToCSharp(BoundScript script)
|
public string TranspilerToCSharp(BoundScript script)
|
||||||
{
|
{
|
||||||
var s = script.Statement;
|
var s = script.Statement;
|
||||||
return Compile(s);
|
return Transpile(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string Compile(BoundNode e)
|
private string Transpile(BoundNode e)
|
||||||
{
|
{
|
||||||
switch (e.Kind)
|
switch (e.Kind)
|
||||||
{
|
{
|
||||||
case BoundKind.BoundScript:
|
case BoundKind.BoundScript:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
case BoundKind.BoundLiteralExpression:
|
case BoundKind.BoundLiteralExpression:
|
||||||
return CompileLiteralExpression((BoundLiteralExpression) e);
|
return TranspileLiteralExpression((BoundLiteralExpression) e);
|
||||||
case BoundKind.BoundBinaryExpression:
|
case BoundKind.BoundBinaryExpression:
|
||||||
return CompileBinaryExpression((BoundBinaryExpression) e);
|
return TranspileBinaryExpression((BoundBinaryExpression) e);
|
||||||
case BoundKind.BoundUnaryExpression:
|
case BoundKind.BoundUnaryExpression:
|
||||||
case BoundKind.VariableExpression:
|
case BoundKind.VariableExpression:
|
||||||
case BoundKind.BoundAssignmentStatement:
|
case BoundKind.BoundAssignmentStatement:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
case BoundKind.BoundExpressionStatement:
|
case BoundKind.BoundExpressionStatement:
|
||||||
return Compile(((BoundExpressionStatement)e).Expression);
|
return Transpile(((BoundExpressionStatement)e).Expression);
|
||||||
case BoundKind.BoundBlockStatement:
|
case BoundKind.BoundBlockStatement:
|
||||||
return CompileBlockStatement((BoundBlockStatement) e);
|
return TranspileBlockStatement((BoundBlockStatement) e);
|
||||||
case BoundKind.BoundIfStatement:
|
case BoundKind.BoundIfStatement:
|
||||||
return CompileIfStatement((BoundIfStatement) e);
|
return TranspileIfStatement((BoundIfStatement) e);
|
||||||
case BoundKind.BoundElseStatement:
|
case BoundKind.BoundElseStatement:
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException(e.Kind.ToString());
|
throw new ArgumentOutOfRangeException(e.Kind.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string CompileBlockStatement(BoundBlockStatement s)
|
private string TranspileBlockStatement(BoundBlockStatement s)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
foreach (var sStatement in s.Statements)
|
foreach (var sStatement in s.Statements)
|
||||||
{
|
{
|
||||||
var compile = Compile(sStatement);
|
var compile = Transpile(sStatement);
|
||||||
sb.Append(compile);
|
sb.Append(compile);
|
||||||
sb.Append(";\n");
|
sb.Append(";\n");
|
||||||
}
|
}
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string CompileLiteralExpression(BoundLiteralExpression e)
|
private static string TranspileLiteralExpression(BoundLiteralExpression e)
|
||||||
{
|
{
|
||||||
switch (e.Type)
|
switch (e.Type)
|
||||||
{
|
{
|
||||||
|
@ -73,12 +72,12 @@ namespace UpsilonCompiler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string CompileBinaryExpression(BoundBinaryExpression e)
|
private string TranspileBinaryExpression(BoundBinaryExpression e)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("(");
|
sb.Append("(");
|
||||||
var compiledLeft = Compile(e.LeftExpression);
|
var compiledLeft = Transpile(e.LeftExpression);
|
||||||
var compiledRight = Compile(e.RightExpression);
|
var compiledRight = Transpile(e.RightExpression);
|
||||||
sb.Append(compiledLeft);
|
sb.Append(compiledLeft);
|
||||||
switch (e.Operator.Kind)
|
switch (e.Operator.Kind)
|
||||||
{
|
{
|
||||||
|
@ -109,15 +108,15 @@ namespace UpsilonCompiler
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string CompileIfStatement(BoundIfStatement s, bool isElseIf = false)
|
private string TranspileIfStatement(BoundIfStatement s, bool isElseIf = false)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
var openToken = isElseIf ? "else if(" : "if(";
|
var openToken = isElseIf ? "else if(" : "if(";
|
||||||
sb.Append(openToken);
|
sb.Append(openToken);
|
||||||
var compiledCondition = Compile(s.Condition);
|
var compiledCondition = Transpile(s.Condition);
|
||||||
sb.Append(compiledCondition);
|
sb.Append(compiledCondition);
|
||||||
sb.Append("){\n");
|
sb.Append("){\n");
|
||||||
var compiledBlock = Compile(s.Block);
|
var compiledBlock = Transpile(s.Block);
|
||||||
sb.Append(compiledBlock);
|
sb.Append(compiledBlock);
|
||||||
sb.Append("}");
|
sb.Append("}");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
|
|
|
@ -35,8 +35,8 @@ namespace Yc
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var compiler = new Compiler();
|
var compiler = new Transpiler();
|
||||||
var compiled = compiler.CompileToCSharp(parsed.Bind());
|
var compiled = compiler.TranspilerToCSharp(parsed.Bind());
|
||||||
Console.WriteLine(compiled);
|
Console.WriteLine(compiled);
|
||||||
/*
|
/*
|
||||||
var evaluate = parsed.Evaluate();
|
var evaluate = parsed.Evaluate();
|
||||||
|
|
Loading…
Reference in New Issue