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.MethodAction;
24 import org.millscript.millscript.vm.CompilerState;
25
26 /**
27 * This class implements a method expression. This is used to define a new
28 * method.
29 *
30 * @see org.millscript.millscript.syntax.DefineSyntax
31 * @see org.millscript.millscript.action.MethodAction
32 */
33 public final class MethodExpr extends Expr< MethodAction > implements OneResult {
34
35 /**
36 * The name of the class this method belongs to, for the dispatch
37 * parameter.
38 */
39 private final NameExpr classNameExpr;
40
41 /**
42 * The lambda expression for the body of the method.
43 */
44 private final LambdaExpr lambda;
45
46 /**
47 * Creates a new method expression, for the specified lamba expression.
48 *
49 * @param name the name of the class this method dispatches on
50 * @param e the lamba expression, for the method body
51 */
52 public MethodExpr( final NameExpr name, final LambdaExpr e ) {
53 classNameExpr = name;
54 lambda = e;
55 }
56
57 /**
58 * @see org.millscript.millscript.expr.Expr#compileIt()
59 */
60 @Override
61 public MethodAction compileIt() {
62 return new MethodAction( classNameExpr.compileIt(), lambda.compileIt() );
63 }
64
65 /**
66 * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
67 */
68 @Override
69 public void resolve( final CompilerState state ) {
70 this.classNameExpr.resolve( state );
71 this.lambda.resolve( state );
72 }
73
74 /**
75 * @see org.millscript.millscript.expr.Expr#showComponents(int)
76 */
77 @Override
78 void showComponents( final int n ) {
79 this.classNameExpr.show( n );
80 this.lambda.show( n );
81 }
82
83 }