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.vm.CompilerState;
25
26 /**
27 * This class represents binary opereration syntax. A binary operation is one
28 * which returns a single result, from two single inputs. This means the left
29 * and right hand side expressions must produce single results, and that the
30 * expression as a whole will return a single result.
31 *
32 * @see AppendExpr
33 * @see org.millscript.millscript.action.BinaryOpAction
34 */
35 public abstract class UnaryOpExpr< A extends Action > extends Expr< A > implements OneResult {
36
37 /**
38 * The single expression
39 */
40 private final Expr< ? > expr;
41
42 /**
43 * Creates a new unary operation expression for the specified expression.
44 *
45 * @param a the single expression, which must return a single result
46 */
47 public UnaryOpExpr( final Expr< ? > a ) {
48 this.expr = CheckExpr.make( a );
49 }
50
51 /**
52 * @see org.millscript.millscript.expr.Expr#compileIt()
53 */
54 @Override
55 public final A compileIt() {
56
57
58
59
60 return newAction( expr.compile() );
61 }
62
63 /**
64 * Compiles this expression into an action. This is method performs the
65 * expression specific compilation, but does not need to handle the single
66 * expression compilation.
67 *
68 * @param a the compiled single expression
69 * @return the {@link Action} for this expression
70 */
71 public abstract A newAction( final Action a );
72
73 /**
74 * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
75 */
76 @Override
77 public void resolve( final CompilerState state ) {
78 this.expr.resolve( state );
79 }
80
81 /**
82 * @see org.millscript.millscript.expr.Expr#showComponents(int)
83 */
84 @Override
85 void showComponents( final int n ) {
86 this.expr.show( n );
87 }
88
89 }