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.SpiceClassConstructorFunction;
26 import org.millscript.millscript.vm.Machine;
27
28 /**
29 * This class implements the action used when initialising a class. This action
30 * returns a new function which can then be bound to the relevant variable.
31 *
32 * @see org.millscript.millscript.expr.SpiceClassInitExpr
33 * @see org.millscript.millscript.syntax.DefineSyntax
34 */
35 public final class SpiceClassInitAction extends Action {
36
37 /**
38 * The action that returns the Function this initiaiser is based on.
39 */
40 private final Action initialiserFunction;
41
42 /**
43 * The action that returns the Spice class we are initialising.
44 */
45 private final Action enclosingSpiceClass;
46
47 /**
48 * Constructs a new init action, using the specified actions to obtain
49 * the type we are initialising and associated initialiser.
50 *
51 * @param sc the action that generates the Spice class we are
52 * initialising
53 * @param mf the action, which generates the Function for the
54 * initialiser body
55 */
56 public SpiceClassInitAction( final Action sc, final Action mf ) {
57 this.enclosingSpiceClass = sc;
58 this.initialiserFunction = mf;
59 }
60
61 /**
62 * @see org.millscript.millscript.action.Action#action(org.millscript.millscript.vm.Machine)
63 */
64 @Override
65 public void action( final Machine mc ) {
66
67 mc.pushObject(
68 new SpiceClassConstructorFunction(
69
70
71 (SpiceClass) enclosingSpiceClass.act1( mc ),
72
73
74 (Function)initialiserFunction.act1( mc )
75 )
76 );
77 }
78
79 }