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.BindingMapAction;
24 import org.millscript.millscript.vm.CompilerState;
25
26 import java.util.Stack;
27
28 /**
29 * This class represents a for loop map binding expression. A map binding
30 * expression binds successive key-value pairs from a map to given names.
31 */
32 public final class BindingMapExpr extends BindingExpr< BindingMapAction > {
33
34 /**
35 * The expression that generates the map to bind elements from.
36 */
37 private final Expr< ? > inExpr;
38
39 /**
40 * The name expression to bind successive keys to.
41 */
42 private final NameExpr key;
43
44 /**
45 * The name expression to bind successive values to.
46 */
47 private final NameExpr val;
48
49 /**
50 * Constructs a new map binding expression, with the supplied key and value
51 * name expressions and map expression.
52 *
53 * @param k the name expression for the key to bind to
54 * @param v the name expression for the value to bind to
55 * @param i the expression to generate the map to bind from
56 */
57 public BindingMapExpr( final NameExpr k, final NameExpr v, final Expr< ? > i ) {
58 key = k;
59 val = v;
60 inExpr = CheckExpr.make( i );
61 }
62
63 /**
64 * @see org.millscript.millscript.expr.Expr#compileIt()
65 */
66 @Override
67 public BindingMapAction compileIt() {
68 return new BindingMapAction(
69 key.getIdent(),
70 val.getIdent(),
71 inExpr.compile()
72 );
73 }
74
75 /**
76 * @see org.millscript.millscript.expr.BindingExpr#pushNames(java.util.Stack)
77 */
78 @Override
79 void pushNames( final Stack< Expr > s ) {
80 s.push( key );
81 s.push( val );
82 }
83
84 /**
85 * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
86 */
87 @Override
88 public void resolve( final CompilerState state ) {
89 this.inExpr.resolve( state );
90 }
91
92 /**
93 * @see org.millscript.millscript.expr.Expr#showComponents(int)
94 */
95 @Override
96 void showComponents( final int n ) {
97 this.inExpr.show( n );
98 }
99
100 }