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.Action;
24 import org.millscript.millscript.alert.Alerts;
25 import org.millscript.millscript.functions.SlotFunction;
26 import org.millscript.millscript.vm.CompilerState;
27
28 /**
29 * This class represents a <code>class</code> <code>slot</code> initialisation
30 * expression.
31 *
32 * @see org.millscript.millscript.expr.SpiceClassExpr
33 * @see org.millscript.millscript.action.SpiceClassSlotAction
34 */
35 public final class SpiceClassSlotExpr extends Expr< Action > {
36
37 /**
38 * The accessor function for this slot.
39 */
40 private final SlotFunction slotFunction;
41
42 /**
43 * The slots initial value expression.
44 */
45 private final Expr< ? > slotValue;
46
47 /**
48 * Constructs a new <code>class</code> <code>slot</code> initialisation
49 * expression.
50 *
51 * @param sf the accessor function for this slot
52 * @param sv the initial value expression for this slot
53 */
54 public SpiceClassSlotExpr( final SlotFunction sf, final Expr< ? > sv ) {
55 this.slotFunction = sf;
56 this.slotValue = CheckExpr.make( sv );
57 }
58
59 /**
60 * @see org.millscript.millscript.expr.Expr#compileIt()
61 */
62 @Override
63 public Action compileIt() {
64 throw(
65 Alerts.fault( "Trying to compile a naked SlotExpr" ).mishap()
66 );
67 }
68
69 /**
70 * Returns the slot function which accesses this slot.
71 *
72 * @return the SlotFunction to access this slot
73 */
74 public SlotFunction getSlotFunction() {
75 return slotFunction;
76 }
77
78 /**
79 * Returns the expression for the initial value of this slot.
80 *
81 * @return the Expr for the initial value of this slot
82 */
83 public Expr< ? > getSlotValue() {
84 return slotValue;
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.slotValue.resolve( state );
93 }
94
95 /**
96 * @see org.millscript.millscript.expr.Expr#showComponents(int)
97 */
98 @Override
99 void showComponents( final int n ) {
100 this.slotValue.show( n );
101 }
102
103 }