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.ApplyUpdaterAction;
24 import org.millscript.millscript.vm.CompilerState;
25
26 /**
27 * This class implements an apply updater expression.
28 *
29 * @see org.millscript.millscript.syntax.DotSyntax
30 * @see org.millscript.millscript.syntax.ParenSyntax
31 * @see org.millscript.millscript.functions.Function
32 * @see ApplyUpdaterAction
33 */
34 public final class ApplyUpdaterExpr extends Expr< ApplyUpdaterAction > {
35
36 /**
37 * The expression generating an updateable function to apply.
38 */
39 private final Expr< ? > fun;
40
41 /**
42 * The expression generating the arguments to apply the function with.
43 */
44 private final Expr< ? > args;
45
46 /**
47 * The expression generating the results to update with.
48 */
49 private final Expr< ? > uargs;
50
51 /**
52 * Creates a new apply updater expression for the specified function,
53 * arguments and update arguments expressions.
54 *
55 * @param f the function expression, which must return an updateable
56 * funtion as a single result
57 * @param a the arguments expression, which can return zero or more
58 * results
59 * @param u the expression generating the results to update with
60 */
61 public ApplyUpdaterExpr( final Expr< ? > f, final Expr< ? > a, final Expr< ? > u ) {
62 fun = f;
63 args = a;
64 uargs = u;
65 }
66
67 /**
68 * @see org.millscript.millscript.expr.Expr#compileIt()
69 */
70 @Override
71 public ApplyUpdaterAction compileIt() {
72 return (
73 new ApplyUpdaterAction(
74 fun.compile(),
75 args.compile(),
76 uargs.compile()
77 )
78 );
79 }
80
81 /**
82 * Returns the function expression this apply updater expression will apply.
83 *
84 * @return the expression returning a single function
85 */
86 Expr getFun() { return fun; }
87
88 /**
89 * Returns the arguments expression this apply updater expression will apply
90 * the function with.
91 *
92 * @return the expression returning the arguments for the function
93 */
94 Expr getArgs() { return args; }
95
96 /**
97 * Returns the update expression this apply updater expression will update
98 * with.
99 *
100 * @return the expression returning the results to update with
101 */
102 Expr getUArgs() { return uargs; }
103
104 /**
105 * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
106 */
107 @Override
108 public void resolve( final CompilerState state ) {
109 this.fun.resolve( state );
110 this.args.resolve( state );
111 this.uargs.resolve( state );
112 }
113
114 /**
115 * @see org.millscript.millscript.expr.Expr#showComponents(int)
116 */
117 @Override
118 void showComponents( final int n ) {
119 this.fun.show( n );
120 this.args.show( n );
121 this.uargs.show( n );
122 }
123
124 }