@@ -32,21 +32,21 @@ internal class ExpressionInstructionProvider : VisitorBase<IAbstractSyntaxTreeNo
3232 IVisitor < IndexAccess , AddressedInstructions > ,
3333 IVisitor < CallExpression , AddressedInstructions >
3434{
35- private readonly IValueDtoConverter _valueDtoConverter ;
35+ private readonly IValueFactory _valueFactory ;
3636
37- public ExpressionInstructionProvider ( IValueDtoConverter valueDtoConverter ) =>
38- _valueDtoConverter = valueDtoConverter ;
37+ public ExpressionInstructionProvider ( IValueFactory valueFactory ) =>
38+ _valueFactory = valueFactory ;
3939
4040 public override AddressedInstructions Visit ( IAbstractSyntaxTreeNode visitable ) => [ ] ;
4141
4242 public AddressedInstructions Visit ( PrimaryExpression visitable ) =>
43- [ new Simple ( _valueDtoConverter . Convert ( visitable . ToValueDto ( ) ) ) ] ;
43+ [ new Simple ( _valueFactory . Create ( visitable . ToValueDto ( ) ) ) ] ;
4444
4545 public AddressedInstructions Visit ( ArrayLiteral visitable )
4646 {
4747 var arraySize = visitable . Expressions . Count ;
4848
49- var arrayName = new Name ( visitable . Id ) ;
49+ var arrayName = _valueFactory . CreateName ( visitable . Id ) ;
5050 var createArray = new CreateArray ( arrayName , arraySize ) ;
5151
5252 var result = new AddressedInstructions { createArray } ;
@@ -60,7 +60,7 @@ public AddressedInstructions Visit(ArrayLiteral visitable)
6060 result . Add ( new IndexAssignment (
6161 arrayName ,
6262 index ,
63- _valueDtoConverter . Convert ( primary . ToValueDto ( ) ) ) ) ;
63+ _valueFactory . Create ( primary . ToValueDto ( ) ) ) ) ;
6464 else
6565 {
6666 result . AddRange ( expression . Accept ( This ) ) ;
@@ -74,8 +74,8 @@ public AddressedInstructions Visit(ArrayLiteral visitable)
7474
7575 public AddressedInstructions Visit ( ObjectLiteral visitable )
7676 {
77- var objectId = visitable . Id ;
78- var createObject = new CreateObject ( new Name ( objectId ) ) ;
77+ var objectId = _valueFactory . CreateName ( visitable . Id ) ;
78+ var createObject = new CreateObject ( objectId ) ;
7979
8080 var result = new AddressedInstructions { createObject } ;
8181
@@ -89,7 +89,7 @@ public AddressedInstructions Visit(ObjectLiteral visitable)
8989
9090 public AddressedInstructions Visit ( Property visitable )
9191 {
92- var objectId = new Name ( visitable . Object . Id ) ;
92+ var objectId = _valueFactory . CreateName ( visitable . Object . Id ) ;
9393
9494 var ( id , expression ) = visitable ;
9595 var propertyId = new Constant ( id ) ;
@@ -98,7 +98,7 @@ public AddressedInstructions Visit(Property visitable)
9898 return [ new DotAssignment (
9999 objectId ,
100100 propertyId ,
101- _valueDtoConverter . Convert ( primary . ToValueDto ( ) ) ) ] ;
101+ _valueFactory . Create ( primary . ToValueDto ( ) ) ) ] ;
102102
103103 var instructions = expression . Accept ( This ) ;
104104 var last = instructions . OfType < Simple > ( ) . Last ( ) . Left ! ;
@@ -110,7 +110,7 @@ public AddressedInstructions Visit(Property visitable)
110110 public AddressedInstructions Visit ( UnaryExpression visitable )
111111 {
112112 if ( visitable . Expression is PrimaryExpression primary )
113- return [ new Simple ( visitable . Operator , _valueDtoConverter . Convert ( primary . ToValueDto ( ) ) ) ] ;
113+ return [ new Simple ( visitable . Operator , _valueFactory . Create ( primary . ToValueDto ( ) ) ) ] ;
114114
115115 var result = visitable . Expression . Accept ( This ) ;
116116 var last = result . OfType < Simple > ( ) . Last ( ) . Left ! ;
@@ -122,21 +122,21 @@ public AddressedInstructions Visit(UnaryExpression visitable)
122122 public AddressedInstructions Visit ( BinaryExpression visitable )
123123 {
124124 if ( visitable is { Left : IdentifierReference arr , Right : PrimaryExpression primary , Operator : "::" } )
125- return [ new RemoveFromArray ( new Name ( arr ) , index : _valueDtoConverter . Convert ( primary . ToValueDto ( ) ) ) ] ;
125+ return [ new RemoveFromArray ( _valueFactory . CreateName ( arr ) , index : _valueFactory . Create ( primary . ToValueDto ( ) ) ) ] ;
126126
127127 var result = new AddressedInstructions ( ) ;
128128 IValue left , right ;
129129
130130 if ( visitable . Left is PrimaryExpression primaryLeft )
131- left = _valueDtoConverter . Convert ( primaryLeft . ToValueDto ( ) ) ;
131+ left = _valueFactory . Create ( primaryLeft . ToValueDto ( ) ) ;
132132 else
133133 {
134134 result . AddRange ( visitable . Left . Accept ( This ) ) ;
135135 left = result . OfType < Simple > ( ) . Last ( ) . Left ! ;
136136 }
137137
138138 if ( visitable . Right is PrimaryExpression primaryRight )
139- right = _valueDtoConverter . Convert ( primaryRight . ToValueDto ( ) ) ;
139+ right = _valueFactory . Create ( primaryRight . ToValueDto ( ) ) ;
140140 else
141141 {
142142 result . AddRange ( visitable . Right . Accept ( This ) ) ;
@@ -151,7 +151,7 @@ public AddressedInstructions Visit(BinaryExpression visitable)
151151 public AddressedInstructions Visit ( CastAsExpression visitable )
152152 {
153153 if ( visitable . Expression is PrimaryExpression primary )
154- return [ new AsString ( _valueDtoConverter . Convert ( primary . ToValueDto ( ) ) ) ] ;
154+ return [ new AsString ( _valueFactory . Create ( primary . ToValueDto ( ) ) ) ] ;
155155
156156 var result = visitable . Expression . Accept ( This ) ;
157157 var last = result . OfType < Simple > ( ) . Last ( ) . Left ! ;
@@ -162,7 +162,7 @@ public AddressedInstructions Visit(CastAsExpression visitable)
162162
163163 public AddressedInstructions Visit ( WithExpression visitable )
164164 {
165- var objectId = new Name ( visitable . ObjectLiteral . Id ) ;
165+ var objectId = _valueFactory . CreateName ( visitable . ObjectLiteral . Id ) ;
166166 var createObject = new CreateObject ( objectId ) ;
167167
168168 var result = new AddressedInstructions { createObject } ;
@@ -187,15 +187,15 @@ public AddressedInstructions Visit(WithExpression visitable)
187187 result . AddRange ( visitable . Expression is PrimaryExpression ? [ ] : visitable. Expression . Accept ( This ) ) ;
188188
189189 var copyFrom = visitable . Expression is IdentifierReference objectIdent
190- ? new Name ( objectIdent )
190+ ? _valueFactory . CreateName ( objectIdent )
191191 : result . OfType < Simple > ( ) . Last ( ) . Left ! ;
192192
193193 for ( var i = 0 ; i < visitable . ComputedCopiedProperties . Count ; i ++ )
194194 {
195195 var property = new Constant ( visitable . ComputedCopiedProperties [ i ] ) ;
196196 result . Add ( new DotRead ( copyFrom , property ) ) ;
197197 var read = result [ result . End ] . Address . Name ;
198- result . Add ( new DotAssignment ( objectId , property , new Name ( read ) ) ) ;
198+ result . Add ( new DotAssignment ( objectId , property , _valueFactory . CreateName ( read ) ) ) ;
199199 }
200200
201201 return result ;
@@ -210,7 +210,7 @@ public AddressedInstructions Visit(ConditionalExpression visitable)
210210 var result = new AddressedInstructions ( ) ;
211211
212212 if ( visitable . Test is PrimaryExpression primary )
213- result . Add ( new IfNotGoto ( test : _valueDtoConverter . Convert ( primary . ToValueDto ( ) ) , startBlockLabel ) ) ;
213+ result . Add ( new IfNotGoto ( test : _valueFactory . Create ( primary . ToValueDto ( ) ) , startBlockLabel ) ) ;
214214 else
215215 {
216216 result . AddRange ( visitable . Test . Accept ( This ) ) ;
@@ -245,7 +245,7 @@ public AddressedInstructions Visit(AssignmentExpression visitable)
245245 }
246246
247247 if ( visitable . Destination . Empty ( ) )
248- result . OfType < Simple > ( ) . Last ( ) . Left = new Name ( visitable . Destination . Id ) ;
248+ result . OfType < Simple > ( ) . Last ( ) . Left = _valueFactory . CreateName ( visitable . Destination . Id ) ;
249249 else
250250 {
251251 var last = result . OfType < Simple > ( ) . Last ( ) . Left ! ;
@@ -267,7 +267,7 @@ public AddressedInstructions Visit(DotAccess visitable)
267267 var right = new Constant ( visitable . Property . Name ) ;
268268
269269 if ( ! visitable . HasPrev ( ) && visitable . Parent is LeftHandSideExpression lhs )
270- return [ new DotRead ( new Name ( lhs . Id ) , right ) ] ;
270+ return [ new DotRead ( _valueFactory . CreateName ( lhs . Id ) , right ) ] ;
271271
272272 var result = visitable . Prev ? . Accept ( This ) ?? [ ] ;
273273 var left = result . OfType < Simple > ( ) . Last ( ) . Left ! ;
@@ -283,15 +283,15 @@ public AddressedInstructions Visit(IndexAccess visitable)
283283 IValue right ;
284284
285285 if ( visitable . Index is PrimaryExpression primary )
286- right = _valueDtoConverter . Convert ( primary . ToValueDto ( ) ) ;
286+ right = _valueFactory . Create ( primary . ToValueDto ( ) ) ;
287287 else
288288 {
289289 result . AddRange ( visitable . Index . Accept ( This ) ) ;
290290 right = result . OfType < Simple > ( ) . Last ( ) . Left ! ;
291291 }
292292
293293 if ( ! visitable . HasPrev ( ) && visitable . Parent is LeftHandSideExpression lhs )
294- result . Add ( new IndexRead ( new Name ( lhs . Id ) , right ) ) ;
294+ result . Add ( new IndexRead ( _valueFactory . CreateName ( lhs . Id ) , right ) ) ;
295295 else
296296 {
297297 result . AddRange ( visitable . Prev ? . Accept ( This ) ?? [ ] ) ;
@@ -320,15 +320,17 @@ public AddressedInstructions Visit(CallExpression visitable)
320320
321321 if ( methodCall )
322322 {
323- var caller = result . Count > 0 ? result . OfType < Simple > ( ) . Last ( ) . Left ! : new Name ( visitable . Id ) ;
323+ var caller = result . Count > 0
324+ ? result . OfType < Simple > ( ) . Last ( ) . Left !
325+ : _valueFactory . CreateName ( visitable . Id ) ;
324326 result . Add ( new PushParameter ( caller ) ) ;
325327 }
326328
327329 for ( var i = 0 ; i < visitable . Parameters . Count ; i ++ )
328330 {
329331 var expr = visitable . Parameters [ i ] ;
330332 if ( expr is PrimaryExpression primary )
331- result . Add ( new PushParameter ( _valueDtoConverter . Convert ( primary . ToValueDto ( ) ) ) ) ;
333+ result . Add ( new PushParameter ( _valueFactory . Create ( primary . ToValueDto ( ) ) ) ) ;
332334 else
333335 {
334336 result . AddRange ( expr . Accept ( This ) ) ;
0 commit comments