Skip to content

Commit 3381169

Browse files
committed
updates
1 parent f1cc009 commit 3381169

File tree

7 files changed

+150
-119
lines changed

7 files changed

+150
-119
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using clojure.clr.api;
7+
using CljLang = clojure.lang;
8+
9+
namespace cljr.runtime
10+
{
11+
public static class Main
12+
{
13+
public static void Run ( string entryPoint, string [] args )
14+
{
15+
CljLang.Symbol CLOJURE_MAIN = CljLang.Symbol.intern( "clojure.main" );
16+
CljLang.Var REQUIRE = CljLang.RT.var( "clojure.core", "require" );
17+
CljLang.Var MAIN = CljLang.RT.var( "clojure.main", "main" );
18+
CljLang.RT.Init ();
19+
REQUIRE.invoke ( CLOJURE_MAIN );
20+
21+
List<String> actualArgs = new List<String> ();
22+
actualArgs.Add ( "-m" );
23+
actualArgs.Add ( entryPoint );
24+
actualArgs.AddRange ( args );
25+
MAIN.applyTo ( CljLang.RT.seq ( actualArgs.ToArray () ) );
26+
}
27+
28+
public static void REPL ( string [] args )
29+
{
30+
CljLang.Symbol CLOJURE_MAIN = CljLang.Symbol.intern( "clojure.main" );
31+
CljLang.Var REQUIRE = CljLang.RT.var( "clojure.core", "require" );
32+
CljLang.Var MAIN = CljLang.RT.var( "clojure.main", "main" );
33+
restart:
34+
try
35+
{
36+
CljLang.RT.Init ();
37+
REQUIRE.invoke ( CLOJURE_MAIN );
38+
MAIN.applyTo ( CljLang.RT.seq ( args ) );
39+
}
40+
catch ( Exception ex )
41+
{
42+
Console.WriteLine ( ex.ToString () );
43+
Console.WriteLine ( "Restarting the REPL..." );
44+
goto restart;
45+
}
46+
}
47+
48+
public static void Compile ( string [] libs )
49+
{
50+
#if NET5_0_OR_GREATER
51+
Console.WriteLine ( "Compiling is not supported on .NET 5.0 or greater ...yet." );
52+
#else
53+
const string PATH_PROP = "CLOJURE_COMPILE_PATH";
54+
const string REFLECTION_WARNING_PROP = "CLOJURE_COMPILE_WARN_ON_REFLECTION";
55+
const string UNCHECKED_MATH_PROP = "CLOJURE_COMPILE_UNCHECKED_MATH";
56+
57+
CljLang.RT.Init ();
58+
59+
TextWriter outTW = (TextWriter)CljLang.RT.OutVar.deref();
60+
TextWriter errTW = CljLang.RT.errPrintWriter();
61+
62+
string path = Environment.GetEnvironmentVariable(PATH_PROP);
63+
64+
path = path ?? ".";
65+
66+
string warnVal = Environment.GetEnvironmentVariable(REFLECTION_WARNING_PROP);
67+
bool warnOnReflection = warnVal == null ? false : warnVal.Equals("true");
68+
string mathVal = Environment.GetEnvironmentVariable(UNCHECKED_MATH_PROP);
69+
object uncheckedMath = false;
70+
71+
if ( "true".Equals ( mathVal ) )
72+
uncheckedMath = true;
73+
else if ( "warn-on-boxed".Equals ( mathVal ) )
74+
uncheckedMath = CljLang.Keyword.intern ( "warn-on-boxed" );
75+
76+
77+
// Force load to avoid transitive compilation during lazy load
78+
CljLang.Compiler.EnsureMacroCheck ();
79+
80+
try
81+
{
82+
CljLang.Var.pushThreadBindings ( CljLang.RT.map (
83+
CljLang.Compiler.CompilePathVar, path,
84+
CljLang.RT.WarnOnReflectionVar, warnOnReflection,
85+
CljLang.RT.UncheckedMathVar, uncheckedMath
86+
) );
87+
88+
Stopwatch sw = new Stopwatch();
89+
90+
if ( libs.Length > 0 )
91+
{
92+
foreach ( string lib in libs )
93+
{
94+
sw.Reset ();
95+
sw.Start ();
96+
outTW.Write ( "Compiling {0} to {1}", lib, path );
97+
outTW.Flush ();
98+
CljLang.Compiler.CompileVar.invoke ( CljLang.Symbol.intern ( lib ) );
99+
sw.Stop ();
100+
outTW.WriteLine ( " -- {0} milliseconds.", sw.ElapsedMilliseconds );
101+
}
102+
}
103+
else
104+
{
105+
Console.WriteLine ( "ERROR: No input provided." );
106+
// TODO: consult ndeps.edn file if it exists in the current
107+
// working directory.
108+
}
109+
}
110+
catch ( Exception e )
111+
{
112+
errTW.WriteLine ( e.ToString () );
113+
errTW.Flush ();
114+
Environment.Exit ( 1 );
115+
}
116+
finally
117+
{
118+
CljLang.Var.popThreadBindings ();
119+
try
120+
{
121+
outTW.Flush ();
122+
}
123+
catch ( IOException e )
124+
{
125+
errTW.WriteLine ( e.StackTrace );
126+
errTW.Flush ();
127+
}
128+
}
129+
130+
#endif
131+
132+
133+
}
134+
}
135+
}

projects/net6.0/cljr.Net60/cljr.runtime/Source.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,15 @@ public static Object EvalAsClojure ( this string src )
4747
{
4848
return Eval ( src );
4949
}
50+
51+
public static void CompileNamespace ( string nameSpace )
52+
{
53+
54+
}
55+
56+
public static void CompileFile ( string fileName )
57+
{
58+
59+
}
5060
}
5161
}

projects/net6.0/cljr.Net60/cljr.runtime/cljr.runtime.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>

projects/net6.0/cljr.Net60/cljr/cljr.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<BaseOutputPath>C:\projects\dotnet\cljr\build\bin</BaseOutputPath>

src/cs/cljr/Commands/CompileCommand.cs

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Text;
55
using System.Threading.Tasks;
66
using System.CommandLine;
7-
using CljLang = clojure.lang;
87
using System.IO;
98
using System.Diagnostics;
109

@@ -30,89 +29,7 @@ Command compileCommand
3029

3130
public static void HandleCompileRequest ( string [] libs )
3231
{
33-
#if NET5_0_OR_GREATER
34-
Console.WriteLine ( "Compiling is not supported on .NET 5.0 or greater yet." );
35-
#else
36-
const string PATH_PROP = "CLOJURE_COMPILE_PATH";
37-
const string REFLECTION_WARNING_PROP = "CLOJURE_COMPILE_WARN_ON_REFLECTION";
38-
const string UNCHECKED_MATH_PROP = "CLOJURE_COMPILE_UNCHECKED_MATH";
39-
40-
CljLang.RT.Init ();
41-
42-
TextWriter outTW = (TextWriter)CljLang.RT.OutVar.deref();
43-
TextWriter errTW = CljLang.RT.errPrintWriter();
44-
45-
string path = Environment.GetEnvironmentVariable(PATH_PROP);
46-
47-
path = path ?? ".";
48-
49-
string warnVal = Environment.GetEnvironmentVariable(REFLECTION_WARNING_PROP);
50-
bool warnOnReflection = warnVal == null ? false : warnVal.Equals("true");
51-
string mathVal = Environment.GetEnvironmentVariable(UNCHECKED_MATH_PROP);
52-
object uncheckedMath = false;
53-
54-
if ( "true".Equals ( mathVal ) )
55-
uncheckedMath = true;
56-
else if ( "warn-on-boxed".Equals ( mathVal ) )
57-
uncheckedMath = CljLang.Keyword.intern ( "warn-on-boxed" );
58-
59-
60-
// Force load to avoid transitive compilation during lazy load
61-
CljLang.Compiler.EnsureMacroCheck ();
62-
63-
try
64-
{
65-
CljLang.Var.pushThreadBindings ( CljLang.RT.map (
66-
CljLang.Compiler.CompilePathVar, path,
67-
CljLang.RT.WarnOnReflectionVar, warnOnReflection,
68-
CljLang.RT.UncheckedMathVar, uncheckedMath
69-
) );
70-
71-
Stopwatch sw = new Stopwatch();
72-
73-
if ( libs.Length > 0 )
74-
{
75-
foreach ( string lib in libs )
76-
{
77-
sw.Reset ();
78-
sw.Start ();
79-
outTW.Write ( "Compiling {0} to {1}", lib, path );
80-
outTW.Flush ();
81-
CljLang.Compiler.CompileVar.invoke ( CljLang.Symbol.intern ( lib ) );
82-
sw.Stop ();
83-
outTW.WriteLine ( " -- {0} milliseconds.", sw.ElapsedMilliseconds );
84-
}
85-
}
86-
else
87-
{
88-
Console.WriteLine ( "ERROR: No input provided." );
89-
// TODO: consult ndeps.edn file if it exists in the current
90-
// working directory.
91-
}
92-
}
93-
catch ( Exception e )
94-
{
95-
errTW.WriteLine ( e.ToString () );
96-
errTW.Flush ();
97-
Environment.Exit ( 1 );
98-
}
99-
finally
100-
{
101-
CljLang.Var.popThreadBindings ();
102-
try
103-
{
104-
outTW.Flush ();
105-
}
106-
catch ( IOException e )
107-
{
108-
errTW.WriteLine ( e.StackTrace );
109-
errTW.Flush ();
110-
}
111-
}
112-
113-
#endif
114-
115-
32+
cljr.runtime.Main.Compile ( libs );
11633
}
11734
}
11835
}

src/cs/cljr/Commands/REPLCommand.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
using System.CommandLine;
88

9-
using CljLang = clojure.lang;
10-
using clojure.clr.api;
11-
129
namespace cljr.Commands
1310
{
1411
internal static class REPLCommand
@@ -34,22 +31,7 @@ Command replCommand
3431

3532
public static void HandleREPLRequest ( string [] args )
3633
{
37-
CljLang.Symbol CLOJURE_MAIN = CljLang.Symbol.intern( "clojure.main" );
38-
CljLang.Var REQUIRE = CljLang.RT.var( "clojure.core", "require" );
39-
CljLang.Var MAIN = CljLang.RT.var( "clojure.main", "main" );
40-
restart:
41-
try
42-
{
43-
CljLang.RT.Init ();
44-
REQUIRE.invoke ( CLOJURE_MAIN );
45-
MAIN.applyTo ( CljLang.RT.seq ( args ) );
46-
}
47-
catch ( Exception ex )
48-
{
49-
Console.WriteLine ( ex.ToString () );
50-
Console.WriteLine ( "Restarting the REPL..." );
51-
goto restart;
52-
}
34+
cljr.runtime.Main.REPL ( args );
5335
}
5436
}
5537
}

src/cs/cljr/Commands/RunCommand.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
using System.CommandLine;
77
using System.IO;
88
using System.Reflection;
9-
using clojure.clr.api;
10-
using CljLang = clojure.lang;
119

1210
namespace cljr.Commands
1311
{
@@ -50,18 +48,7 @@ Command runCommand
5048

5149
public static void HandleRunCommand ( string entryPoint, string [] args )
5250
{
53-
CljLang.Symbol CLOJURE_MAIN = CljLang.Symbol.intern( "clojure.main" );
54-
CljLang.Var REQUIRE = CljLang.RT.var( "clojure.core", "require" );
55-
CljLang.Var MAIN = CljLang.RT.var( "clojure.main", "main" );
56-
CljLang.RT.Init ();
57-
REQUIRE.invoke ( CLOJURE_MAIN );
58-
59-
List<String> actualArgs = new List<String> ();
60-
actualArgs.Add ( "-m" );
61-
actualArgs.Add ( entryPoint );
62-
actualArgs.AddRange ( args );
63-
MAIN.applyTo ( CljLang.RT.seq ( actualArgs.ToArray() ) );
64-
51+
cljr.runtime.Main.Run ( entryPoint, args );
6552
}
6653
}
6754
}

0 commit comments

Comments
 (0)