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.InitAction;
24 import org.millscript.millscript.vm.CompilerState;
25
26 /**
27 * This class implements a <code>init</code> expression. This expression will
28 * never return any results, as we are running the initialiser on an object,
29 * not constructing a new one.
30 *
31 * @see org.millscript.millscript.syntax.InitSyntax
32 * @see org.millscript.millscript.action.InitAction
33 */
34 public final class InitExpr extends Expr< InitAction > implements ZeroResults {
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 init 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 InitExpr( final Expr< ? > f, final Expr< ? > a ) {
56 this.fun = CheckExpr.make( f );
57 this.args = a;
58 }
59
60 /**
61 * @see org.millscript.millscript.expr.Expr#compileIt()
62 */
63 @Override
64 public InitAction compileIt() {
65 return new InitAction( this.fun.compile(), this.args.compile() );
66 }
67
68 /**
69 * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
70 */
71 @Override
72 public void resolve( final CompilerState state ) {
73 this.fun.resolve( state );
74 this.args.resolve( state );
75 }
76
77 /**
78 * @see org.millscript.millscript.expr.Expr#showComponents(int)
79 */
80 @Override
81 void showComponents( final int n ) {
82 this.fun.show( n );
83 this.args.show( n );
84 }
85
86 }