Permalink
Browse files

Back to a working compiler, slow as hell.

  • Loading branch information...
1 parent daaadb2 commit 87ef51af3cad3a3de1d995e026cf6c54bb54f062 @dmiller dmiller committed May 2, 2009
Showing with 1,038 additions and 214 deletions.
  1. BIN Bin/Debug/ipy.vshost.exe
  2. +18 −0 Bin/Debug/ipy.vshost.exe.config
  3. +11 −0 Bin/Debug/ipy.vshost.exe.manifest
  4. +73 −0 Clojure/Clojure.Console.Old/Clojure.Console.Old.csproj
  5. +230 −0 Clojure/Clojure.Console.Old/ClojureConsole.cs
  6. +36 −0 Clojure/Clojure.Console.Old/Properties/AssemblyInfo.cs
  7. +19 −161 Clojure/Clojure.Console/ClojureConsole.cs
  8. +1 −1 Clojure/Clojure/Bootstrap/core.clj
  9. +81 −0 Clojure/Clojure/CljCompiler/Ast/AFnImplGenerator.cs
  10. +1 −1 Clojure/Clojure/CljCompiler/Ast/ConstantExpr.cs
  11. +1 −1 Clojure/Clojure/CljCompiler/Ast/DefExpr.cs
  12. +129 −8 Clojure/Clojure/CljCompiler/Ast/FnExpr.cs
  13. +80 −6 Clojure/Clojure/CljCompiler/Ast/FnMethod.cs
  14. +16 −2 Clojure/Clojure/CljCompiler/Ast/GenContext.cs
  15. +1 −1 Clojure/Clojure/CljCompiler/Ast/InstanceMethodExpr.cs
  16. +1 −1 Clojure/Clojure/CljCompiler/Ast/KeywordExpr.cs
  17. +1 −1 Clojure/Clojure/CljCompiler/Ast/TheVarExpr.cs
  18. +1 −1 Clojure/Clojure/CljCompiler/Ast/UnresolvedVarExpr.cs
  19. +1 −1 Clojure/Clojure/CljCompiler/Ast/VarExpr.cs
  20. +5 −4 Clojure/Clojure/CljCompiler/Compiler.cs
  21. +7 −0 Clojure/Clojure/Clojure.csproj
  22. +7 −0 Clojure/Clojure/Lib/AFn.cs
  23. +5 −0 Clojure/Clojure/Lib/Util.cs
  24. +13 −0 Clojure/Clojure/Runtime/ClojureConsoleOptions.cs
  25. +31 −25 Clojure/Clojure/Runtime/ClojureContext.cs
  26. +37 −0 Clojure/Clojure/Runtime/ClojureHostUtils.cs
  27. +12 −0 Clojure/Clojure/Runtime/ClojureOptionsParser.cs
  28. +36 −0 Clojure/ClojureCLR.sln
  29. +36 −0 Clojure/Simple.Console/Properties/AssemblyInfo.cs
  30. +73 −0 Clojure/Simple.Console/Simple.Console.csproj
  31. +75 −0 Clojure/Simple.Console/SimpleConsole.cs
View
Binary file not shown.
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <configSections>
+ <section name="microsoft.scripting" type="Microsoft.Scripting.Hosting.Configuration.Section, Microsoft.Scripting, Version=0.9.5.1, Culture=neutral, PublicKeyToken=null" requirePermission="false" />
+ </configSections>
+
+ <microsoft.scripting>
+ <languages>
+ <language names="IronPython;Python;py" extensions=".py" displayName="IronPython 2.6 Alpha" type="IronPython.Runtime.PythonContext, IronPython, Version=2.6.0.1, Culture=neutral, PublicKeyToken=null" />
+ <language names="IronRuby;Ruby;rb" extensions=".rb" displayName="IronRuby 0.3" type="IronRuby.Runtime.RubyContext, IronRuby, Version=0.3.0.0, Culture=neutral, PublicKeyToken=null" />
+ <language names="ToyScript;ts" extensions=".ts" type="ToyScript.ToyLanguageContext, ToyScript, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
+ </languages>
+
+ <options>
+ <set language="Ruby" option="LibraryPaths" value="..\..\Languages\Ruby\libs\;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\site_ruby\1.8\;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8\" />
+ </options>
+ </microsoft.scripting>
+</configuration>
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
+ <security>
+ <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
+ <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
+ </requestedPrivileges>
+ </security>
+ </trustInfo>
+</assembly>
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{1B343DCA-03EF-406E-B35A-59AD878C6A5A}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Clojure.Console.Old</RootNamespace>
+ <AssemblyName>Clojure.Console.Old</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ClojureConsole.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\DLR_Main\Src\Runtime\Microsoft.Scripting.Core\Microsoft.Scripting.Core.csproj">
+ <Project>{2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}</Project>
+ <Name>Microsoft.Scripting.Core</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\DLR_Main\Src\Runtime\Microsoft.Scripting\Microsoft.Scripting.csproj">
+ <Project>{EB66B766-6354-4208-A3D4-AACBDCB5C3B3}</Project>
+ <Name>Microsoft.Scripting</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Clojure\Clojure.csproj">
+ <Project>{B8089F66-DFBD-4906-BEE0-B317689C2524}</Project>
+ <Name>Clojure</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,230 @@
+/**
+ * Copyright (c) David Miller. All rights reserved.
+ * The use and distribution terms for this software are covered by the
+ * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+ * which can be found in the file epl-v10.html at the root of this distribution.
+ * By using this software in any fashion, you are agreeing to be bound by
+ * the terms of this license.
+ * You must not remove this notice, or any other, from this software.
+ **/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Scripting.Hosting.Shell;
+using clojure.lang;
+using System.IO;
+using Microsoft.Linq.Expressions;
+using Microsoft.Scripting.Generation;
+using Microsoft.Scripting;
+using Microsoft.Scripting.Runtime;
+using Microsoft.Scripting.Hosting;
+using Microsoft.Scripting.Hosting.Providers;
+using System.Diagnostics;
+using System.Resources;
+using System.Threading;
+
+
+using clojure.runtime;
+using clojure.compiler;
+
+
+namespace clojure.console
+{
+ class ClojureConsole : ConsoleHost, Compiler.EEHooks
+ {
+ #region Data
+
+ private bool _isInitialized = false;
+
+ #endregion
+
+ #region Convenience accessors
+
+ private ClojureContext GetLanguageContext()
+ {
+ return (ClojureContext)HostingHelpers.GetLanguageContext(Engine);
+ }
+
+
+ private static SourceUnit GetSourceUnit(ScriptSource scriptSource)
+ {
+ return HostingHelpers.GetSourceUnit(scriptSource);
+ }
+
+ #endregion
+
+ #region Basic overrides
+
+ protected override Type Provider
+ {
+ get
+ {
+ return typeof(ClojureContext);
+ }
+ }
+
+ protected override CommandLine CreateCommandLine()
+ {
+ return new ClojureCommandLine();
+ }
+
+ protected override ScriptRuntimeSetup CreateRuntimeSetup()
+ {
+ ScriptRuntimeSetup setup = base.CreateRuntimeSetup();
+
+ // Set this to true to force snippets to be written out.
+ // Or you can put -D on the command line.
+ setup.DebugMode = true;
+
+ return setup;
+ }
+
+ #endregion
+
+ #region Main routine
+
+ [STAThread]
+ static int Main(string[] args)
+ {
+ ClojureConsole cc = new ClojureConsole();
+
+ int ret = cc.Run(args);
+
+ Console.ReadLine();
+ return ret;
+ }
+
+ #endregion
+
+ #region Execution override
+
+ protected override void ExecuteInternal()
+ {
+ Debug.Assert(Engine != null);
+
+ Var.pushThreadBindings(
+ RT.map(RT.CURRENT_NS, RT.CURRENT_NS.deref()));
+ try
+ {
+ //Snippets.SetSaveAssemblies(true, ".");
+ MaybeInitialize();
+ //RT.PostBootstrapInit();
+ //Snippets.SaveAndVerifyAssemblies();
+ base.ExecuteInternal();
+ }
+ catch (Exception e)
+ {
+ UnhandledException(Engine, e);
+ }
+
+ finally
+ {
+ //Snippets.SaveAndVerifyAssemblies();
+ Var.popThreadBindings();
+ }
+ }
+
+
+ #endregion
+
+ #region Initialization
+
+ private void MaybeInitialize()
+ {
+ if (_isInitialized)
+ return;
+
+ _isInitialized = true;
+
+ Compiler.SetHooks(this);
+
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+
+ LoadFromStream(new StringReader(clojure.properties.Resources.core));
+ //LoadFromStream(new StringReader(clojure.properties.Resources.core_print));
+ //LoadFromStream(new StringReader(clojure.properties.Resources.test));
+
+ sw.Stop();
+ Console.WriteLine("Loading took {0} milliseconds.", sw.ElapsedMilliseconds);
+
+ }
+
+ #endregion
+
+ #region EEHooks Members
+
+ public object Eval(object form)
+ {
+ ScriptSource scriptSource = Engine.CreateScriptSourceFromString("<internal>");
+
+ Expression expr = Generator.Eval(GetLanguageContext(), form);
+ //LambdaExpression ast = Expression.Lambda(expr);
+ //ast = new GlobalLookupRewriter().RewriteLambda(ast);
+ LambdaExpression ast = Expression.Lambda(expr,
+ Expression.Parameter(typeof(Scope), "#scope"),
+ Expression.Parameter(typeof(LanguageContext), "#context"));
+
+ ScriptCode code = new LegacyScriptCode(ast, GetSourceUnit(scriptSource));
+ return code.Run();
+ }
+
+ public object Macroexpand1(object form)
+ {
+ return Generator.Macroexpand1(GetLanguageContext(), form);
+ }
+
+ public object LoadFromStream(TextReader rdr)
+ {
+ ScriptSource scriptSource = Engine.CreateScriptSourceFromString("<already opened TextReader>",".");
+ //PushbackReader pbr = new PushbackReader(rdr);
+
+ return LoadFromPushbackReader(scriptSource, rdr, false );
+ }
+
+ public object LoadFile(string filename)
+ {
+ ScriptSource scriptSource = Engine.CreateScriptSourceFromFile(filename);
+
+ return LoadFromPushbackReader(scriptSource, scriptSource.GetReader(), true); // debug -- should be false for real
+ }
+
+ private static object LoadFromPushbackReader(ScriptSource scriptSource, TextReader pbr, bool addPrint)
+ {
+ object ret = null;
+ object eofVal = new object();
+ object form;
+ while ((form = LispReader.read(pbr, false, eofVal, false)) != eofVal)
+ {
+ LambdaExpression ast = Compiler.GenerateLambda(form, addPrint);
+ //ast = new GlobalLookupRewriter().RewriteLambda(ast);
+ ast = Expression.Lambda(ast,
+ Expression.Parameter(typeof(Scope), "#scope"),
+ Expression.Parameter(typeof(LanguageContext), "#context"));
+
+
+
+ ScriptCode code = new LegacyScriptCode(ast, GetSourceUnit(scriptSource));
+ ret = code.Run();
+ }
+
+ return ret;
+ }
+
+ public Delegate GenerateTypedDelegate(Type delegateType, Symbol optName, IPersistentVector argList, ISeq body)
+ {
+ ScriptSource scriptSource = Engine.CreateScriptSourceFromString("<internal>");
+
+ LambdaExpression ast = Generator.GenerateTypedDelegateExpression(GetLanguageContext(), delegateType, optName, argList, body);
+ return ast.Compile();
+
+ //ast = new GlobalLookupRewriter().RewriteLambda(ast); -- doesn't work unless no args
+ //ScriptCode code = new ScriptCode(ast, GetSourceUnit(scriptSource));
+ //return code;
+ }
+
+ #endregion
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Clojure.Console.Old")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Clojure.Console.Old")]
+[assembly: AssemblyCopyright("Copyright © 2009")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("72f2f013-9b8a-497e-9bea-ac0083c5c146")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
Oops, something went wrong.

0 comments on commit 87ef51a

Please sign in to comment.