Skip to content

Commit 5c96910

Browse files
committed
A few more compiler updates.
1 parent 8364fa3 commit 5c96910

File tree

5 files changed

+63
-89
lines changed

5 files changed

+63
-89
lines changed

Clojure/Clojure/CljCompiler/Ast/EmptyExpr.cs

Lines changed: 31 additions & 31 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;
1713
using System.Reflection.Emit;
@@ -23,7 +19,7 @@ public class EmptyExpr : Expr
2319
#region Data
2420

2521
readonly object _coll;
26-
public object Coll { get { return _coll; } }
22+
public object Coll => _coll;
2723

2824
#endregion
2925

@@ -38,24 +34,20 @@ public EmptyExpr(object coll)
3834

3935
#region Type mangling
4036

41-
public bool HasClrType
42-
{
43-
get { return true; }
44-
}
37+
public bool HasClrType => true;
4538

4639
public Type ClrType
4740
{
48-
get {
49-
if (_coll is IPersistentList)
50-
return typeof(IPersistentList);
51-
else if (_coll is IPersistentVector)
52-
return typeof(IPersistentVector);
53-
else if (_coll is IPersistentMap)
54-
return typeof(IPersistentMap);
55-
else if (_coll is IPersistentSet)
56-
return typeof(IPersistentSet);
57-
else
58-
throw new InvalidOperationException("Unknown Collection type.");
41+
get
42+
{
43+
return _coll switch
44+
{
45+
IPersistentList => typeof(IPersistentList),
46+
IPersistentVector => typeof(IPersistentVector),
47+
IPersistentMap => typeof(IPersistentMap),
48+
IPersistentSet => typeof(IPersistentSet),
49+
_ => throw new InvalidOperationException("Unknown Collection type.")
50+
};
5951
}
6052
}
6153

@@ -79,21 +71,29 @@ public object Eval()
7971

8072
public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
8173
{
82-
if (_coll is IPersistentList || _coll is LazySeq) // JVM does not include LazySeq test. I'm getting it in some places. LazySeq of 0 size got us here, we'll treat as an empty list
83-
ilg.EmitFieldGet(ListEmptyFI);
84-
else if (_coll is IPersistentVector)
85-
ilg.EmitFieldGet(VectorEmptyFI);
86-
else if (_coll is IPersistentMap)
87-
ilg.EmitFieldGet(HashMapEmptyFI);
88-
else if (_coll is IPersistentSet)
89-
ilg.EmitFieldGet(HashSetEmptyFI);
90-
else
91-
throw new InvalidOperationException("Unknown collection type.");
74+
switch (_coll)
75+
{
76+
case IPersistentList:
77+
case LazySeq:
78+
ilg.EmitFieldGet(ListEmptyFI);
79+
break;
80+
case IPersistentVector:
81+
ilg.EmitFieldGet(VectorEmptyFI);
82+
break;
83+
case IPersistentMap:
84+
ilg.EmitFieldGet(HashMapEmptyFI);
85+
break;
86+
case IPersistentSet:
87+
ilg.EmitFieldGet(HashSetEmptyFI);
88+
break;
89+
default:
90+
throw new InvalidOperationException("Unknown collection type.");
91+
}
9292
if (rhc == RHC.Statement)
9393
ilg.Emit(OpCodes.Pop);
9494
}
9595

96-
public bool HasNormalExit() { return true; }
96+
public bool HasNormalExit() => true;
9797

9898
#endregion
9999
}

Clojure/Clojure/CljCompiler/Ast/KeywordInvokeExpr.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ public sealed class KeywordInvokeExpr : Expr
1919
#region Data
2020

2121
readonly KeywordExpr _kw;
22-
public KeywordExpr KWExpr { get { return _kw; } }
22+
public KeywordExpr KWExpr => _kw;
2323

2424
readonly Object _tag;
25-
public object Tag { get { return _tag; } }
26-
25+
public object Tag => _tag;
26+
2727
readonly Expr _target;
28-
public Expr Target { get { return _target; } }
29-
28+
public Expr Target => _target;
29+
3030
readonly string _source;
31-
public string Source { get { return _source; } }
32-
31+
public string Source => _source;
32+
3333
readonly IPersistentMap _spanMap;
34-
public IPersistentMap SpanMap { get { return _spanMap; } }
35-
34+
public IPersistentMap SpanMap => _spanMap;
35+
3636
readonly int _siteIndex;
37-
public int SiteIndex { get { return _siteIndex; } }
37+
public int SiteIndex => _siteIndex;
3838

3939
Type _cachedType;
40-
40+
4141
#endregion
4242

4343
#region C-tors
@@ -56,10 +56,7 @@ public KeywordInvokeExpr(string source, IPersistentMap spanMap, Symbol tag, Keyw
5656

5757
#region Type mangling
5858

59-
public bool HasClrType
60-
{
61-
get { return _tag != null; }
62-
}
59+
public bool HasClrType => _tag is not null;
6360

6461
public Type ClrType
6562
{
@@ -158,7 +155,7 @@ public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
158155
ilg.Emit(OpCodes.Pop);
159156
}
160157

161-
public bool HasNormalExit() { return true; }
158+
public bool HasNormalExit() => true;
162159

163160
#endregion
164161
}

Clojure/Clojure/CljCompiler/Ast/MapExpr.cs

Lines changed: 6 additions & 17 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 MapExpr : Expr
2218
#region Data
2319

2420
readonly IPersistentVector _keyvals;
25-
public IPersistentVector KeyVals { get { return _keyvals; } }
21+
public IPersistentVector KeyVals => _keyvals;
2622

2723
#endregion
2824

@@ -37,15 +33,9 @@ public MapExpr(IPersistentVector keyvals)
3733

3834
#region Type mangling
3935

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

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

5040
#endregion
5141

@@ -79,7 +69,7 @@ public static Expr Parse(ParserContext pcon, IPersistentMap form)
7969
}
8070
else
8171
keysConstant = false;
82-
if (!(v is LiteralExpr))
72+
if (v is not LiteralExpr)
8373
valsConstant = false;
8474
}
8575

@@ -133,7 +123,6 @@ public object Eval()
133123
return RT.map(ret);
134124
}
135125

136-
137126
#endregion
138127

139128
#region Code generation
@@ -169,10 +158,10 @@ public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
169158
ilg.EmitCall(Compiler.Method_RT_map);
170159

171160
if (rhc == RHC.Statement)
172-
ilg.Emit(OpCodes.Pop);
161+
ilg.Emit(OpCodes.Pop);
173162
}
174163

175-
public bool HasNormalExit() { return true; }
164+
public bool HasNormalExit() => true;
176165

177166
#endregion
178167
}

Clojure/Clojure/CljCompiler/Ast/SetExpr.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class SetExpr : Expr
2222
#region Data
2323

2424
readonly IPersistentVector _keys;
25-
public IPersistentVector Keys { get { return _keys; } }
25+
public IPersistentVector Keys => _keys;
2626

2727
#endregion
2828

@@ -37,18 +37,12 @@ public SetExpr(IPersistentVector keys)
3737

3838
#region Type mangling
3939

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

45-
public Type ClrType
46-
{
47-
get { return typeof(IPersistentSet); }
48-
}
42+
public Type ClrType => typeof(IPersistentSet);
4943

5044
#endregion
51-
45+
5246
#region Parsing
5347

5448
public static Expr Parse(ParserContext pcon, IPersistentSet form)
@@ -62,12 +56,12 @@ public static Expr Parse(ParserContext pcon, IPersistentSet form)
6256
object e = s.first();
6357
Expr expr = Compiler.Analyze(pconToUse, e);
6458
keys = (IPersistentVector)keys.cons(expr);
65-
if (!(expr is LiteralExpr))
59+
if (expr is not LiteralExpr)
6660
constant = false;
6761
}
6862
Expr ret = new SetExpr(keys);
6963

70-
if (form is IObj iobjForm && iobjForm.meta() != null)
64+
if (form is IObj iobjForm && iobjForm.meta() is not null)
7165
return Compiler.OptionallyGenerateMetaInit(pcon, form, ret);
7266
else if (constant)
7367
{
@@ -107,7 +101,7 @@ public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
107101
ilg.Emit(OpCodes.Pop);
108102
}
109103

110-
public bool HasNormalExit() { return true; }
104+
public bool HasNormalExit() => true;
111105

112106
#endregion
113107
}

Clojure/Clojure/CljCompiler/Ast/VectorExpr.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class VectorExpr : Expr
2222
#region Data
2323

2424
readonly IPersistentVector _args;
25-
public IPersistentVector Args { get { return _args; } }
25+
public IPersistentVector Args => _args;
2626

2727
#endregion
2828

@@ -37,15 +37,9 @@ public VectorExpr(IPersistentVector args)
3737

3838
#region Type mangling
3939

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

45-
public Type ClrType
46-
{
47-
get { return typeof(IPersistentVector); }
48-
}
42+
public Type ClrType => typeof(IPersistentVector);
4943

5044
#endregion
5145

@@ -57,11 +51,11 @@ public static Expr Parse(ParserContext pcon, IPersistentVector form)
5751
bool constant = true;
5852

5953
IPersistentVector args = PersistentVector.EMPTY;
60-
for (int i = 0; i < form.count(); i++ )
54+
for (int i = 0; i < form.count(); i++)
6155
{
6256
Expr v = Compiler.Analyze(pconToUse, form.nth(i));
6357
args = (IPersistentVector)args.cons(v);
64-
if ( !(v is LiteralExpr) )
58+
if (v is not LiteralExpr)
6559
constant = false;
6660
}
6761

@@ -115,7 +109,7 @@ public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
115109
ilg.Emit(OpCodes.Pop);
116110
}
117111

118-
public bool HasNormalExit() { return true; }
112+
public bool HasNormalExit() => true;
119113

120114
#endregion
121115
}

0 commit comments

Comments
 (0)