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.action;
22
23 import org.millscript.millscript.datatypes.SpiceClass;
24 import org.millscript.millscript.functions.Function;
25 import org.millscript.millscript.functions.ManyBodyFunction;
26 import org.millscript.millscript.vm.Machine;
27
28 /**
29 * This class implements the action used when defining a new method. This
30 * action returns a new many body function which can then be bound to the
31 * relevant variable.
32 *
33 * @see org.millscript.millscript.expr.MethodExpr
34 * @see org.millscript.millscript.syntax.DefineSyntax
35 */
36 public final class MethodOverrideAction extends Action {
37
38 /**
39 * The action that generates the ManyBodyFunction we are making
40 * a new override for.
41 */
42 private final Action manyBodyAction;
43
44 /**
45 * The action that returns the Function for the new overrides body.
46 */
47 private final Action methodFunction;
48
49 /**
50 * The action that returns the enclosing Spice class, to dispatch on.
51 */
52 private final Action enclosingSpiceClass;
53
54 /**
55 * Constructs a new method override action, to introduce a method override
56 * for the specified method, using the specified dispatch type and body
57 *
58 * @param mba the action that generates the ManyBodyFunction we are
59 * adding an override to
60 * @param sc the action that generates the enclosing Spice class to
61 * dispatch on
62 * @param mfa the action that generates the Function for the new
63 * overrides body
64 */
65 public MethodOverrideAction( final Action mba, final Action sc, final Action mfa ) {
66 this.enclosingSpiceClass = sc;
67 this.manyBodyAction = mba;
68 this.methodFunction = mfa;
69 }
70
71 /**
72 * @see org.millscript.millscript.action.Action#action(org.millscript.millscript.vm.Machine)
73 */
74 @Override
75 public void action( final Machine mc ) {
76
77
78 final ManyBodyFunction mbf = (ManyBodyFunction) manyBodyAction.act1( mc );
79
80 final Function fn = (Function) methodFunction.act1( mc );
81
82
83 final SpiceClass sc = (SpiceClass) enclosingSpiceClass.act1( mc );
84
85 mbf.setMethodEntry( mc, sc, fn );
86 }
87
88 }