Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/kevinoneill/clojure-contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
arohner committed Apr 19, 2009
2 parents cb5808f d4fc9be commit efccd84
Show file tree
Hide file tree
Showing 291 changed files with 57,498 additions and 1,149 deletions.
7 changes: 7 additions & 0 deletions ClojureCLR/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 1,7 @@
#Visual Studio artifacts
bin
obj
*.user
*.suo
# Emacs artifacts
*~
82 changes: 82 additions & 0 deletions ClojureCLR/Clojure/Clojure.Console/Clojure.Console.csproj
Original file line number Diff line number Diff line change
@@ -0,0 1,82 @@
<?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>{4AFFC540-543E-4F56-9F49-14210D6C143A}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Clojure.Console</RootNamespace>
<AssemblyName>Clojure.Console</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkSubset>
</TargetFrameworkSubset>
</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\Runtime\src\Microsoft.Scripting.Core\Microsoft.Scripting.Core.csproj">
<Project>{2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}</Project>
<Name>Microsoft.Scripting.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\DLR_Main\Runtime\src\Microsoft.Scripting.Core\Microsoft.Scripting.ExtensionAttribute.csproj">
<Project>{8B0F1074-750E-4D64-BF23-A1E0F54261E5}</Project>
<Name>Microsoft.Scripting.ExtensionAttribute</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\DLR_Main\Runtime\src\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>
<ItemGroup>
<None Include="app.config" />
</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>
222 changes: 222 additions & 0 deletions ClojureCLR/Clojure/Clojure.Console/ClojureConsole.cs
Original file line number Diff line number Diff line change
@@ -0,0 1,222 @@
/**
* 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 = false;

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);
ScriptCode code = new ScriptCode(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(), false);
}

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 = Generator.Generate(form, addPrint);
ast = new GlobalLookupRewriter().RewriteLambda(ast);

ScriptCode code = new ScriptCode(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
}
}
36 changes: 36 additions & 0 deletions ClojureCLR/Clojure/Clojure.Console/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Clojure.Console")]
[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("64eccb33-4ad4-49b4-944c-ff486ccb5ea0")]

// 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")]
3 changes: 3 additions & 0 deletions ClojureCLR/Clojure/Clojure.Console/app.config
Original file line number Diff line number Diff line change
@@ -0,0 1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
Loading

0 comments on commit efccd84

Please sign in to comment.