Skip to content

Commit 8364fa3

Browse files
committed
Doing some compiler code cleanup while looking for missed updates.
1 parent 1d48e7b commit 8364fa3

25 files changed

+205
-377
lines changed

Clojure/Clojure/CljCompiler/Ast/AssignExpr.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
* You must not remove this notice, or any other, from this software.
99
**/
1010

11-
/**
12-
* Author: David Miller
13-
**/
14-
1511
using System;
1612

1713
namespace clojure.lang.CljCompiler.Ast
@@ -21,10 +17,10 @@ public class AssignExpr : Expr
2117
#region Data
2218

2319
readonly AssignableExpr _target;
24-
public AssignableExpr Target { get { return _target; } }
20+
public AssignableExpr Target => _target;
2521

2622
readonly Expr _val;
27-
public Expr Val { get { return _val; } }
23+
public Expr Val => _val;
2824

2925
#endregion
3026

@@ -40,15 +36,9 @@ public AssignExpr(AssignableExpr target, Expr val)
4036

4137
#region Type mangling
4238

43-
public bool HasClrType
44-
{
45-
get { return Val.HasClrType; }
46-
}
39+
public bool HasClrType => Val.HasClrType;
4740

48-
public Type ClrType
49-
{
50-
get { return Val.ClrType; }
51-
}
41+
public Type ClrType => Val.ClrType;
5242

5343
#endregion
5444

@@ -61,12 +51,13 @@ public Expr Parse(ParserContext pcon, object frm)
6151
ISeq form = (ISeq)frm;
6252
if (RT.Length(form) != 3)
6353
throw new ParseException("Malformed assignment, expecting (set! target val)");
54+
6455
Expr target = Compiler.Analyze(new ParserContext(RHC.Expression, true), RT.second(form));
6556

66-
if (!(target is AssignableExpr ae))
57+
if (target is not AssignableExpr ae)
6758
throw new ParseException("Invalid assignment target");
6859

69-
return new AssignExpr(ae, Compiler.Analyze(pcon.SetRhc(RHC.Expression),RT.third(form)));
60+
return new AssignExpr(ae, Compiler.Analyze(pcon.SetRhc(RHC.Expression), RT.third(form)));
7061
}
7162
}
7263

Clojure/Clojure/CljCompiler/Ast/AssignableExpr.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@
88
* You must not remove this notice, or any other, from this software.
99
**/
1010

11-
/**
12-
* Author: David Miller
13-
**/
14-
15-
1611
namespace clojure.lang.CljCompiler.Ast
1712
{
1813
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "ClojureJVM name match")]
1914
public interface AssignableExpr
2015
{
2116
object EvalAssign(Expr val);
2217
void EmitAssign(RHC rhc, ObjExpr objx, CljILGen ilg, Expr val);
23-
2418
}
2519
}

Clojure/Clojure/CljCompiler/Ast/BooleanExpr.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
* You must not remove this notice, or any other, from this software.
99
**/
1010

11-
/**
12-
* Author: David Miller
13-
**/
14-
1511
using System;
1612
using System.Reflection.Emit;
1713

@@ -22,7 +18,7 @@ public class BooleanExpr : LiteralExpr // , MaybePrimitiveExpr TODO: No reason
2218
#region Data
2319

2420
readonly bool _val;
25-
public override object Val { get { return _val; } }
21+
public override object Val => _val;
2622

2723
#endregion
2824

@@ -37,15 +33,9 @@ public BooleanExpr(bool val)
3733

3834
#region Type mangling
3935

40-
public override bool HasClrType
41-
{
42-
get { return true; }
43-
}
36+
public override bool HasClrType => true;
4437

45-
public override Type ClrType
46-
{
47-
get { return typeof(Boolean); }
48-
}
38+
public override Type ClrType => typeof(bool);
4939

5040
#endregion
5141

@@ -54,7 +44,7 @@ public override Type ClrType
5444
public override void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
5545
{
5646
ilg.EmitBoolean(_val);
57-
ilg.Emit(OpCodes.Box,typeof(bool));
47+
ilg.Emit(OpCodes.Box, typeof(bool));
5848
if (rhc == RHC.Statement)
5949
ilg.Emit(OpCodes.Pop);
6050
}

Clojure/Clojure/CljCompiler/Ast/ConstantExpr.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public class ConstantExpr : LiteralExpr
1818
#region Data
1919

2020
readonly object _v;
21-
public override object Val { get { return _v; } }
21+
public override object Val => _v;
2222

2323
readonly int _id;
24-
public int Id { get { return _id; } }
24+
public int Id => _id;
2525

2626
#endregion
2727

@@ -31,16 +31,16 @@ public ConstantExpr(object v)
3131
{
3232
_v = v;
3333
_id = Compiler.RegisterConstant(v);
34-
}
34+
}
3535

3636
#endregion
3737

3838
#region Type mangling
3939

4040
public override bool HasClrType
4141
{
42-
get
43-
{
42+
get
43+
{
4444
return _v.GetType().IsPublic
4545
|| _v.GetType().IsNestedPublic
4646
|| typeof(Type).IsInstanceOfType(_v); // This bit of hackery is due to the fact that RuntimeType is not public.
@@ -86,7 +86,8 @@ public Expr Parse(ParserContext pcon, object form)
8686
}
8787

8888
object v = RT.second(form);
89-
if (v == null)
89+
90+
if (v is null)
9091
return Compiler.NilExprInstance;
9192
else if (v is Boolean)
9293
{
@@ -101,7 +102,7 @@ public Expr Parse(ParserContext pcon, object form)
101102
return new StringExpr((String)v);
102103
else if (v is IPersistentCollection collection
103104
&& collection.count() == 0
104-
&& (!(v is IObj ov) || (ov.meta() == null)))
105+
&& (!(v is IObj ov) || (ov.meta() == null)))
105106
return new EmptyExpr(v);
106107
else
107108
return new ConstantExpr(v);

Clojure/Clojure/CljCompiler/Ast/DefExpr.cs

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,39 @@
88
* You must not remove this notice, or any other, from this software.
99
**/
1010

11-
/**
12-
* Author: David Miller
13-
**/
14-
1511
using System;
1612
using System.Reflection;
1713
using System.Reflection.Emit;
1814

19-
2015
namespace clojure.lang.CljCompiler.Ast
2116
{
2217
public class DefExpr : Expr
2318
{
2419
#region Data
2520

2621
readonly Var _var;
27-
public Var Var { get { return _var; } }
22+
public Var Var => _var;
2823

2924
readonly Expr _init;
30-
public Expr Init { get { return _init; } }
25+
public Expr Init => _init;
3126

3227
readonly Expr _meta;
33-
public Expr Meta { get { return _meta; } }
28+
public Expr Meta => _meta;
3429

3530
readonly bool _initProvided;
36-
public bool InitProvided { get { return _initProvided; } }
37-
31+
public bool InitProvided => _initProvided;
32+
3833
readonly bool _isDynamic;
39-
public bool IsDynamic { get { return _isDynamic; } }
40-
34+
public bool IsDynamic => _isDynamic;
35+
4136
readonly string _source;
42-
public string Source { get { return _source; } }
43-
37+
public string Source => _source;
38+
4439
readonly int _line;
45-
public int Line { get { return _line; } }
46-
40+
public int Line => _line;
41+
4742
readonly int _column;
48-
public int Column { get { return _column; } }
43+
public int Column => _column;
4944

5045
#endregion
5146

@@ -67,15 +62,9 @@ public DefExpr(string source, int line, int column, Var var, Expr init, Expr met
6762

6863
#region Type mangling
6964

70-
public bool HasClrType
71-
{
72-
get { return true; }
73-
}
65+
public bool HasClrType => true;
7466

75-
public Type ClrType
76-
{
77-
get { return typeof(Var); }
78-
}
67+
public Type ClrType => typeof(Var);
7968

8069
#endregion
8170

@@ -101,19 +90,19 @@ public Expr Parse(ParserContext pcon, object form)
10190

10291
Symbol sym = RT.second(form) as Symbol;
10392

104-
if (sym == null)
93+
if (sym is null)
10594
throw new ParseException("First argument to def must be a Symbol.");
10695

10796
//Console.WriteLine("Def {0}", sym.Name);
108-
97+
10998
Var v = Compiler.LookupVar(sym, true);
11099

111-
if (v == null)
100+
if (v is null)
112101
throw new ParseException("Can't refer to qualified var that doesn't exist");
113102

114103
if (!v.Namespace.Equals(Compiler.CurrentNamespace))
115104
{
116-
if (sym.Namespace == null)
105+
if (sym.Namespace is null)
117106
{
118107
v = Compiler.CurrentNamespace.intern(sym);
119108
Compiler.RegisterVar(v);
@@ -133,7 +122,7 @@ public Expr Parse(ParserContext pcon, object form)
133122
{
134123
RT.errPrintWriter().WriteLine("Warning: {0} not declared dynamic and thus is not dynamically rebindable, "
135124
+ "but its name suggests otherwise. Please either indicate ^:dynamic {0} or change the name. ({1}:{2}\n",
136-
sym,Compiler.SourcePathVar.get(),Compiler.LineVar.get());
125+
sym, Compiler.SourcePathVar.get(), Compiler.LineVar.get());
137126
RT.errPrintWriter().Flush();
138127
}
139128

@@ -148,10 +137,10 @@ public Expr Parse(ParserContext pcon, object form)
148137

149138
Object source_path = Compiler.SourcePathVar.get();
150139
source_path = source_path ?? "NO_SOURCE_FILE";
151-
mm = (IPersistentMap)RT.assoc(mm,RT.LineKey, Compiler.LineVar.get())
152-
.assoc(RT.ColumnKey,Compiler.ColumnVar.get())
140+
mm = (IPersistentMap)RT.assoc(mm, RT.LineKey, Compiler.LineVar.get())
141+
.assoc(RT.ColumnKey, Compiler.ColumnVar.get())
153142
.assoc(RT.FileKey, source_path);
154-
//.assoc(RT.SOURCE_SPAN_KEY,Compiler.SOURCE_SPAN.deref());
143+
//.assoc(RT.SOURCE_SPAN_KEY,Compiler.SOURCE_SPAN.deref());
155144
if (docstring != null)
156145
mm = (IPersistentMap)RT.assoc(mm, RT.DocKey, docstring);
157146

@@ -168,15 +157,15 @@ public Expr Parse(ParserContext pcon, object form)
168157

169158
mm = (IPersistentMap)Compiler.ElideMeta(mm);
170159

171-
Expr meta = mm == null || mm.count() == 0 ? null : Compiler.Analyze(pcon.EvalOrExpr(),mm);
172-
Expr init = Compiler.Analyze(pcon.EvalOrExpr(),RT.third(form), v.Symbol.Name);
160+
Expr meta = mm is null || mm.count() == 0 ? null : Compiler.Analyze(pcon.EvalOrExpr(), mm);
161+
Expr init = Compiler.Analyze(pcon.EvalOrExpr(), RT.third(form), v.Symbol.Name);
173162
bool initProvided = RT.count(form) == 3;
174163

175164
return new DefExpr(
176165
(string)Compiler.SourceVar.deref(),
177166
Compiler.LineVarDeref(),
178167
Compiler.ColumnVarDeref(),
179-
v, init, meta, initProvided,isDynamic);
168+
v, init, meta, initProvided, isDynamic);
180169
}
181170
}
182171

@@ -190,10 +179,10 @@ public object Eval()
190179
{
191180
if (_initProvided)
192181
_var.bindRoot(_init.Eval());
193-
if (_meta != null)
182+
if (_meta is not null)
194183
{
195-
if (_initProvided || true) // includesExplicitMetadata((MapExpr)_meta))
196-
_var.setMeta((IPersistentMap)_meta.Eval());
184+
//if (InitProvided || true) // includesExplicitMetadata((MapExpr)_meta)) -- the last time I checked X || true is always true
185+
_var.setMeta((IPersistentMap)_meta.Eval());
197186
}
198187
return _var.setDynamic(_isDynamic);
199188
}
@@ -231,12 +220,12 @@ public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
231220
expr.EmitForDefn(objx, ilg);
232221
else
233222
_init.Emit(RHC.Expression, objx, ilg);
234-
ilg.Emit(OpCodes.Call,Compiler.Method_Var_bindRoot);
223+
ilg.Emit(OpCodes.Call, Compiler.Method_Var_bindRoot);
235224
}
236225

237-
if (_meta != null)
226+
if (_meta is not null)
238227
{
239-
if (_initProvided || true) //IncludesExplicitMetadata((MapExpr)_meta))
228+
// if (InitProvided || true) //IncludesExplicitMetadata((MapExpr)_meta)) -- the last time I checked X || true is always true
240229
{
241230
ilg.Emit(OpCodes.Dup);
242231
_meta.Emit(RHC.Expression, objx, ilg);
@@ -255,6 +244,7 @@ public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
255244

256245
#region Misc
257246

247+
// This is in the JVM code, but all uses are commented out.
258248
//private static bool IncludesExplicitMetadata(MapExpr expr)
259249
//{
260250
// for (int i = 0; i < expr.KeyVals.count(); i += 2)

0 commit comments

Comments
 (0)