1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.millscript.expr;
22
23 import org.millscript.millscript.action.BindingListAction;
24 import org.millscript.millscript.vm.CompilerState;
25
26 import java.util.Stack;
27
28 /**
29 * This class represents a for loop list binding expression. A list binding
30 * expression binds successive items from a list to a name.
31 */
32 public final class BindingListExpr extends BindingExpr< BindingListAction > {
33
34 /**
35 * The expression that generates the list of items to bind elements from.
36 */
37 private final Expr< ? > inExpr;
38
39 /**
40 * The name expression to bind successive list items to.
41 */
42 private final NameExpr name;
43
44 /**
45 * Constructs a new list binding expression, with the supplied name and list
46 * expressions.
47 *
48 * @param a the name expression to bind to
49 * @param b the list expression to bind elements from
50 */
51 public BindingListExpr( final NameExpr a, final Expr< ? > b ) {
52 name = a;
53 inExpr = CheckExpr.make( b );
54 }
55
56 /**
57 * @see org.millscript.millscript.expr.Expr#compileIt()
58 */
59 @Override
60 public BindingListAction compileIt() {
61 return new BindingListAction( name.getIdent(), inExpr.compile() );
62 }
63
64 /**
65 * @see org.millscript.millscript.expr.BindingExpr#pushNames(java.util.Stack)
66 */
67 @Override
68 void pushNames( final Stack< Expr > s ) {
69 s.push( name );
70 }
71
72 /**
73 * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
74 */
75 @Override
76 public void resolve( final CompilerState state ) {
77 this.inExpr.resolve( state );
78 }
79
80 /**
81 * @see org.millscript.millscript.expr.Expr#showComponents(int)
82 */
83 @Override
84 void showComponents( final int n ) {
85 this.inExpr.show( n );
86 }
87
88 }