-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathCompile.cs
More file actions
110 lines (91 loc) · 3.46 KB
/
Compile.cs
File metadata and controls
110 lines (91 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Copyright (c) Rich Hickey. 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.
**/
/**
* Author: David Miller
**/
using clojure.lang;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
namespace BootstrapCompile
{
static class Compile
{
const string PATH_PROP = "CLOJURE_COMPILE_PATH";
const string REFLECTION_WARNING_PROP = "CLOJURE_COMPILE_WARN_ON_REFLECTION";
const string UNCHECKED_MATH_PROP = "CLOJURE_COMPILE_UNCHECKED_MATH";
static void Main(string[] args)
{
RT.Init();
TextWriter outTW = (TextWriter)RT.OutVar.deref();
TextWriter errTW = RT.errPrintWriter();
string path = Environment.GetEnvironmentVariable(PATH_PROP);
path = path ?? ".";
string warnVal = Environment.GetEnvironmentVariable(REFLECTION_WARNING_PROP);
bool warnOnReflection = warnVal == null ? false : warnVal.Equals("true");
string mathVal = Environment.GetEnvironmentVariable(UNCHECKED_MATH_PROP);
object uncheckedMath = false;
if ("true".Equals(mathVal))
uncheckedMath = true;
else if ("warn-on-boxed".Equals(mathVal))
uncheckedMath = Keyword.intern("warn-on-boxed");
// Force load to avoid transitive compilation during lazy load
Compiler.EnsureMacroCheck();
#if NETFRAMEWORK
//Console.WriteLine("BootstrapCompile: .NET Framework detected.");
var which = "Framework";
#else
//Console.WriteLine("BootstrapCompile: .NET Core detected.");
var which = "Core";
#endif
Console.WriteLine($"Runtime: {RuntimeInformation.FrameworkDescription}");
Console.WriteLine($"CLR Version: {Environment.Version}");
try
{
Var.pushThreadBindings(RT.map(
Compiler.CompilePathVar, path,
RT.WarnOnReflectionVar, warnOnReflection,
RT.UncheckedMathVar, uncheckedMath
));
Stopwatch sw = new Stopwatch();
foreach (string lib in args)
{
sw.Reset();
sw.Start();
outTW.Write($"{which}: Compiling {lib} to {path}");
outTW.Flush();
Compiler.CompileVar.invoke(Symbol.intern(lib));
sw.Stop();
outTW.WriteLine(" -- {0} milliseconds.", sw.ElapsedMilliseconds);
}
}
catch (Exception e)
{
errTW.WriteLine(e.ToString());
errTW.Flush();
Environment.Exit(1);
}
finally
{
Var.popThreadBindings();
try
{
outTW.Flush();
}
catch (IOException e)
{
errTW.WriteLine(e.StackTrace);
errTW.Flush();
}
}
}
}
}