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.ApplyAction;
24 import org.millscript.millscript.vm.CompilerState;
25
26 /**
27 * This class implements an apply 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 ApplyAction
33 */
34 public final class ApplyExpr extends Expr< ApplyAction > {
35
36 /**
37 * The expression generating the arguments to apply the function with.
38 */
39 private final Expr< ? > args;
40
41 /**
42 * The expression generating a function to apply.
43 */
44 private final Expr< ? > fun;
45
46 /**
47 * Creates a new apply expression for the specified function and arguments
48 * expressions.
49 *
50 * @param f the function expression, which must return a function as a
51 * single result
52 * @param a the arguments expression, which can return zero or more
53 * results
54 */
55 public ApplyExpr( final Expr< ? > f, final Expr< ? > a ) {
56 fun = CheckExpr.make( f );
57 args = a;
58 }
59
60 /**
61 * @see org.millscript.millscript.expr.Expr#compileIt()
62 */
63 @Override
64 public ApplyAction compileIt() {
65 return new ApplyAction( fun.compile(), args.compile() );
66 }
67
68 /**
69 * Returns the arguments expression this apply expression will apply the
70 * function with.
71 *
72 * @return the expression returning the arguments for the function
73 */
74 public Expr getArgs() {
75 return args;
76 }
77
78 /**
79 * Returns the function expression this apply expression will apply.
80 *
81 * @return the expression returning a single function
82 */
83 public Expr getFun() {
84 return fun;
85 }
86
87 /**
88 * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
89 */
90 @Override
91 public void resolve( final CompilerState state ) {
92 this.fun.resolve( state );
93 this.args.resolve( state );
94 }
95
96 /**
97 * @see org.millscript.millscript.expr.Expr#showComponents(int)
98 */
99 @Override
100 void showComponents( final int n ) {
101 this.fun.show( n );
102 this.args.show( n );
103 }
104
105 }