@@ -7,9 +7,10 @@ import scala.language.higherKinds
7
7
8
8
// Core Embedding
9
9
private [parsley] abstract class Singleton [A ](pretty : String , instr : => instructions.Instr ) extends Parsley [A ] {
10
+ final override def findLetsAux [Cont [_, + _]: ContOps ]
11
+ (implicit seen : Set [Parsley [_]], state : LetFinderState , label : UnsafeOption [String ]): Cont [Unit , Unit ] = result(())
10
12
final override def preprocess [Cont [_, + _]: ContOps , A_ >: A ](implicit seen : Set [Parsley [_]], sub : SubMap ,
11
13
label : UnsafeOption [String ]): Cont [Unit , Parsley [A_ ]] = result(this )
12
- final override def findLetsAux [Cont [_, + _]: ContOps ](implicit seen : Set [Parsley [_]], state : LetFinderState ): Cont [Unit , Unit ] = result(())
13
14
final override def codeGen [Cont [_, + _]: ContOps ](implicit instrs : InstrBuffer , state : CodeGenState ): Cont [Unit , Unit ] = {
14
15
result(instrs += instr)
15
16
}
@@ -20,12 +21,13 @@ private [parsley] abstract class Singleton[A](pretty: String, instr: =>instructi
20
21
21
22
private [deepembedding] abstract class SingletonExpect [A ](pretty : String , builder : UnsafeOption [String ] => SingletonExpect [A ], instr : instructions.Instr )
22
23
extends Parsley [A ] {
24
+ final override def findLetsAux [Cont [_, + _]: ContOps ]
25
+ (implicit seen : Set [Parsley [_]], state : LetFinderState , label : UnsafeOption [String ]): Cont [Unit , Unit ] = result(())
23
26
final override def preprocess [Cont [_, + _]: ContOps , A_ >: A ](implicit seen : Set [Parsley [_]], sub : SubMap ,
24
- label : UnsafeOption [String ]): Cont [Unit , Parsley [A ]] = {
27
+ label : UnsafeOption [String ]): Cont [Unit , Parsley [A ]] = {
25
28
if (label == null ) result(this )
26
29
else result(builder(label))
27
30
}
28
- final override def findLetsAux [Cont [_, + _]: ContOps ](implicit seen : Set [Parsley [_]], state : LetFinderState ): Cont [Unit , Unit ] = result(())
29
31
final override def codeGen [Cont [_, + _]: ContOps ](implicit instrs : InstrBuffer , state : CodeGenState ): Cont [Unit , Unit ] = {
30
32
result(instrs += instr)
31
33
}
@@ -34,22 +36,17 @@ private [deepembedding] abstract class SingletonExpect[A](pretty: String, builde
34
36
// $COVERAGE-ON$
35
37
}
36
38
37
- private [deepembedding] abstract class Unary [A , B ](_p : => Parsley [A ])(pretty : String => String , empty : String => Unary [A , B ]) extends Parsley [B ] {
39
+ private [deepembedding] abstract class Unary [A , B ](__p : => Parsley [A ])(pretty : String => String , empty : String => Unary [A , B ]) extends Parsley [B ] {
40
+ private lazy val _p = __p
38
41
private [deepembedding] var p : Parsley [A ] = _
39
42
protected val childRepeats : Int = 1
40
43
protected val numInstrs : Int
41
- final override def findLetsAux [Cont [_, + _]: ContOps ](implicit seen : Set [Parsley [_]], state : LetFinderState ): Cont [Unit ,Unit ] = this .synchronized {
42
- processed = false
43
- p = _p
44
- p.findLets
45
- }
44
+ final override def findLetsAux [Cont [_, + _]: ContOps ]
45
+ (implicit seen : Set [Parsley [_]], state : LetFinderState , label : UnsafeOption [String ]): Cont [Unit ,Unit ] = _p.findLets
46
46
override def preprocess [Cont [_, + _]: ContOps , B_ >: B ](implicit seen : Set [Parsley [_]], sub : SubMap ,
47
- label : UnsafeOption [String ]): Cont [Unit , Parsley [B_ ]] =
48
- if (label == null && processed) result(this ) else for (p <- this .p.optimised) yield {
49
- val self = /* if (label == null) this else*/ empty(label)
50
- self.ready(p)
51
- }
52
- private [deepembedding] def ready (p : Parsley [A ]): this .type = this .synchronized {
47
+ label : UnsafeOption [String ]): Cont [Unit , Parsley [B_ ]] =
48
+ for (p <- _p.optimised) yield empty(label).ready(p)
49
+ private [deepembedding] def ready (p : Parsley [A ]): this .type = {
53
50
processed = true
54
51
this .p = p
55
52
size = p.size + numInstrs
@@ -60,26 +57,23 @@ private [deepembedding] abstract class Unary[A, B](_p: =>Parsley[A])(pretty: Str
60
57
// $COVERAGE-ON$
61
58
}
62
59
63
- private [deepembedding] abstract class Binary [A , B , C ](_left : => Parsley [A ], _right : => Parsley [B ])(pretty : (String , String ) => String , empty : => Binary [A , B , C ])
64
- extends Parsley [C ] {
60
+ private [deepembedding] abstract class Binary [A , B , C ](__left : => Parsley [A ], __right : => Parsley [B ])
61
+ (pretty : (String , String ) => String , empty : => Binary [A , B , C ]) extends Parsley [C ] {
62
+ private lazy val _left = __left
63
+ private lazy val _right = __right
65
64
private [deepembedding] var left : Parsley [A ] = _
66
65
private [deepembedding] var right : Parsley [B ] = _
67
66
protected val numInstrs : Int
68
67
protected val leftRepeats : Int = 1
69
68
protected val rightRepeats : Int = 1
70
- final override def findLetsAux [Cont [_, + _]: ContOps ](implicit seen : Set [Parsley [_]], state : LetFinderState ): Cont [Unit ,Unit ] = this .synchronized {
71
- processed = false
72
- left = _left
73
- right = _right
74
- left.findLets >> right.findLets
75
- }
69
+ final override def findLetsAux [Cont [_, + _]: ContOps ]
70
+ (implicit seen : Set [Parsley [_]], state : LetFinderState , label : UnsafeOption [String ]): Cont [Unit ,Unit ] = _left.findLets >> _right.findLets
76
71
final override def preprocess [Cont [_, + _]: ContOps , C_ >: C ](implicit seen : Set [Parsley [_]], sub : SubMap ,
77
72
label : UnsafeOption [String ]): Cont [Unit , Parsley [C_ ]] =
78
- if (label == null && processed) result(this ) else for (left <- this .left.optimised; right <- this .right.optimised) yield {
79
- val self = /* if (label == null) this else*/ empty
80
- self.ready(left, right)
73
+ for (left <- _left.optimised; right <- _right.optimised) yield {
74
+ empty.ready(left, right)
81
75
}
82
- private [deepembedding] def ready (left : Parsley [A ], right : Parsley [B ]): this .type = this . synchronized {
76
+ private [deepembedding] def ready (left : Parsley [A ], right : Parsley [B ]): this .type = {
83
77
processed = true
84
78
this .left = left
85
79
this .right = right
@@ -93,34 +87,32 @@ private [deepembedding] abstract class Binary[A, B, C](_left: =>Parsley[A], _rig
93
87
// $COVERAGE-ON$
94
88
}
95
89
96
- private [deepembedding] abstract class Ternary [A , B , C , D ](_first : => Parsley [A ], _second : => Parsley [B ], _third : => Parsley [C ])
90
+ private [deepembedding] abstract class Ternary [A , B , C , D ](__first : => Parsley [A ], __second : => Parsley [B ], __third : => Parsley [C ])
97
91
(pretty : (String , String , String ) => String , empty : => Ternary [A , B , C , D ]) extends Parsley [D ] {
92
+ private lazy val _first : Parsley [A ] = __first
93
+ private lazy val _second : Parsley [B ] = __second
94
+ private lazy val _third : Parsley [C ] = __third
98
95
private [deepembedding] var first : Parsley [A ] = _
99
96
private [deepembedding] var second : Parsley [B ] = _
100
97
private [deepembedding] var third : Parsley [C ] = _
101
98
protected val numInstrs : Int
99
+ final override def findLetsAux [Cont [_, + _]: ContOps ]
100
+ (implicit seen : Set [Parsley [_]], state : LetFinderState , label : UnsafeOption [String ]): Cont [Unit , Unit ] = {
101
+ _first.findLets >> _second.findLets >> _third.findLets
102
+ }
102
103
final override def preprocess [Cont [_, + _]: ContOps , D_ >: D ](implicit seen : Set [Parsley [_]], sub : SubMap ,
103
104
label : UnsafeOption [String ]): Cont [Unit , Parsley [D_ ]] =
104
- if (label == null && processed) result(this ) else
105
- for (first <- this .first.optimised; second <- this .second.optimised; third <- this .third.optimised) yield {
106
- val self = /* if (label == null) this else*/ empty
107
- self.ready(first, second, third)
108
- }
109
- private [deepembedding] def ready (first : Parsley [A ], second : Parsley [B ], third : Parsley [C ]): this .type = this .synchronized {
105
+ for (first <- _first.optimised; second <- _second.optimised; third <- _third.optimised) yield {
106
+ empty.ready(first, second, third)
107
+ }
108
+ private [deepembedding] def ready (first : Parsley [A ], second : Parsley [B ], third : Parsley [C ]): this .type = {
110
109
processed = true
111
110
this .first = first
112
111
this .second = second
113
112
this .third = third
114
113
size = first.size + second.size + third.size + numInstrs
115
114
this
116
115
}
117
- final override def findLetsAux [Cont [_, + _]: ContOps ](implicit seen : Set [Parsley [_]], state : LetFinderState ): Cont [Unit , Unit ] = this .synchronized {
118
- processed = false
119
- first = _first
120
- second = _second
121
- third = _third
122
- first.findLets >> second.findLets >> third.findLets
123
- }
124
116
// $COVERAGE-OFF$
125
117
final override def prettyASTAux [Cont [_, + _]: ContOps ]: Cont [String , String ] =
126
118
for (f <- first.prettyASTAux; s <- second.prettyASTAux; t <- third.prettyASTAux) yield pretty(f, s, t)
0 commit comments