Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit 9a813e4

Browse files
committed
Some expression tree work with Bonsai serialization support.
1 parent 27a1316 commit 9a813e4

File tree

14 files changed

+2520
-748
lines changed

14 files changed

+2520
-748
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<ProjectGuid>{9286B3D5-AAB5-41FB-B205-ED0ACADBDB98}</ProjectGuid>
7+
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
8+
<OutputType>Library</OutputType>
9+
<OutputPath>bin</OutputPath>
10+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
11+
<DebugType>full</DebugType>
12+
<DebugSymbols>true</DebugSymbols>
13+
<TypeScriptToolsVersion>1.4</TypeScriptToolsVersion>
14+
<UseIISExpress>true</UseIISExpress>
15+
<IISExpressSSLPort />
16+
<IISExpressAnonymousAuthentication />
17+
<IISExpressWindowsAuthentication />
18+
<IISExpressUseClassicPipelineMode />
19+
<UseGlobalApplicationHostFile />
20+
</PropertyGroup>
21+
<ItemGroup>
22+
<Service Include="{4A0DDDB5-7A95-4FBF-97CC-616D07737A77}" />
23+
</ItemGroup>
24+
<ItemGroup>
25+
<Content Include="app.css" />
26+
<Content Include="index.html" />
27+
<Content Include="web.config" />
28+
</ItemGroup>
29+
<ItemGroup>
30+
<TypeScriptCompile Include="app.ts" />
31+
<TypeScriptCompile Include="compiler.ts" />
32+
</ItemGroup>
33+
<ItemGroup>
34+
<None Include="web.Debug.config">
35+
<DependentUpon>web.config</DependentUpon>
36+
</None>
37+
<None Include="web.Release.config">
38+
<DependentUpon>web.config</DependentUpon>
39+
</None>
40+
</ItemGroup>
41+
<PropertyGroup>
42+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion>
43+
</PropertyGroup>
44+
<PropertyGroup>
45+
<RootNamespace>ExpressionTrees</RootNamespace>
46+
</PropertyGroup>
47+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
48+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets')" />
49+
<ProjectExtensions>
50+
<VisualStudio>
51+
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
52+
<WebProjectProperties>
53+
<UseIIS>True</UseIIS>
54+
<AutoAssignPort>True</AutoAssignPort>
55+
<DevelopmentServerPort>18636</DevelopmentServerPort>
56+
<DevelopmentServerVPath>/</DevelopmentServerVPath>
57+
<IISUrl>http://localhost:18636/</IISUrl>
58+
<NTLMAuthentication>False</NTLMAuthentication>
59+
<UseCustomServer>False</UseCustomServer>
60+
<CustomServerUrl>
61+
</CustomServerUrl>
62+
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
63+
</WebProjectProperties>
64+
</FlavorProperties>
65+
</VisualStudio>
66+
</ProjectExtensions>
67+
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
68+
<TypeScriptRemoveComments>false</TypeScriptRemoveComments>
69+
<TypeScriptSourceMap>true</TypeScriptSourceMap>
70+
</PropertyGroup>
71+
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
72+
<TypeScriptRemoveComments>true</TypeScriptRemoveComments>
73+
<TypeScriptSourceMap>false</TypeScriptSourceMap>
74+
</PropertyGroup>
75+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
76+
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ProjectExtensions>
4+
<VisualStudio>
5+
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
6+
<WebProjectProperties>
7+
<StartPageUrl>
8+
</StartPageUrl>
9+
<StartAction>CurrentPage</StartAction>
10+
<AspNetDebugging>True</AspNetDebugging>
11+
<SilverlightDebugging>False</SilverlightDebugging>
12+
<NativeDebugging>False</NativeDebugging>
13+
<SQLDebugging>False</SQLDebugging>
14+
<ExternalProgram>
15+
</ExternalProgram>
16+
<StartExternalURL>
17+
</StartExternalURL>
18+
<StartCmdLineArguments>
19+
</StartCmdLineArguments>
20+
<StartWorkingDirectory>
21+
</StartWorkingDirectory>
22+
<EnableENC>True</EnableENC>
23+
<AlwaysStartWebServerOnDebug>True</AlwaysStartWebServerOnDebug>
24+
</WebProjectProperties>
25+
</FlavorProperties>
26+
</VisualStudio>
27+
</ProjectExtensions>
28+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.22823.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExpressionTrees", "ExpressionTrees.csproj", "{9286B3D5-AAB5-41FB-B205-ED0ACADBDB98}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9286B3D5-AAB5-41FB-B205-ED0ACADBDB98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9286B3D5-AAB5-41FB-B205-ED0ACADBDB98}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9286B3D5-AAB5-41FB-B205-ED0ACADBDB98}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9286B3D5-AAB5-41FB-B205-ED0ACADBDB98}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

src/core/expressions/app.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
body {
2+
font-family: 'Segoe UI', sans-serif;
3+
}
4+
5+
span {
6+
font-style: italic;
7+
}

src/core/expressions/app.js

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/expressions/app.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/expressions/app.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/// <reference path="compiler.ts" />
2+
3+
class Tests {
4+
element: HTMLElement;
5+
6+
constructor(element: HTMLElement) {
7+
this.element = element;
8+
}
9+
10+
start() {
11+
var e = Expression.Add(Expression.Constant(1), Expression.Constant(2));
12+
var l = Expression.Lambda<() => number>(e);
13+
var c = l.CompileToFunction();
14+
var f = l.Compile();
15+
var b = l.toBonsai();
16+
var x = f();
17+
this.element.innerHTML = "Eval(" + l + ") = Eval(" + c + ") = Eval(" + JSON.stringify(b) + ") = " + x;
18+
}
19+
}
20+
21+
window.onload = () => {
22+
var el = document.getElementById('content');
23+
var tests = new Tests(el);
24+
tests.start();
25+
};
26+
27+
/*
28+
var resources =
29+
{
30+
"my://xs": [1, 2, 3, 4, 5],
31+
"my://ss": ["bar", "foo", "qux"],
32+
"rx://operators/filter": function (xs: any[], f: (any) => boolean) { return xs.filter(f); },
33+
"rx://operators/map": function (xs: any[], f: (any) => any) { return xs.map(f); },
34+
};
35+
36+
var x = Expression.Parameter("x");
37+
var f1 =
38+
Expression.Invoke(
39+
Expression.Parameter("rx://operators/map"),
40+
Expression.Invoke(
41+
Expression.Parameter("rx://operators/filter"),
42+
Expression.Parameter("my://xs"),
43+
Expression.Lambda<(number) => boolean>(
44+
Expression.Equal(
45+
Expression.Modulo(
46+
x,
47+
Expression.Constant(2)
48+
),
49+
Expression.Constant(0)
50+
),
51+
x
52+
)
53+
),
54+
Expression.Lambda<(number) => boolean>(
55+
Expression.Multiply(
56+
x,
57+
x
58+
),
59+
x
60+
)
61+
);
62+
63+
var f2 =
64+
Expression.Invoke(
65+
Expression.Parameter("rx://operators/map"),
66+
Expression.Parameter("my://ss"),
67+
Expression.Lambda<(string) => string>(
68+
Expression.Call(
69+
x,
70+
"substring",
71+
Expression.Constant(1)
72+
),
73+
x
74+
)
75+
);
76+
77+
var binder = new Binder(resources);
78+
79+
var b1 = Expression.Lambda<() => number[]>(binder.Visit(f1));
80+
var c1 = b1.Compile();
81+
var r1 = c1();
82+
alert(r1.join(", "));
83+
84+
var b2 = Expression.Lambda<() => string[]>(binder.Visit(f2));
85+
var c2 = b2.Compile();
86+
var r2 = c2();
87+
alert(r2.join(", "));
88+
*/

0 commit comments

Comments
 (0)