View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2001-2005 Open World Ltd
4   //
5   // This file is part of MillScript.
6   //
7   // MillScript is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.millscript.expr;
22  
23  import org.millscript.millscript.action.InitAction;
24  import org.millscript.millscript.vm.CompilerState;
25  
26  /**
27   * This class implements a <code>init</code> expression. This expression will
28   * never return any results, as we are running the initialiser on an object,
29   * not constructing a new one.
30   *
31   * @see org.millscript.millscript.syntax.InitSyntax
32   * @see org.millscript.millscript.action.InitAction
33   */
34  public final class InitExpr extends Expr< InitAction > implements ZeroResults {
35  
36      /**
37       * The expression generating the arguments to apply the function with.
38       */
39      private final Expr< ? > args;
40  
41      /**
42       * The expression generating a function to apply.
43       */
44      private final Expr< ? > fun;
45  
46      /**
47       * Creates a new init  expression for the specified function and arguments
48       * expressions.
49       *
50       * @param   f   the function expression, which must return a function as a
51       *              single result
52       * @param   a   the arguments expression, which can return zero or more
53       *              results
54       */
55      public InitExpr( final Expr< ? > f, final Expr< ? > a ) {
56          this.fun = CheckExpr.make( f );
57          this.args = a;
58      }
59  
60      /**
61       * @see org.millscript.millscript.expr.Expr#compileIt()
62       */
63      @Override
64      public InitAction compileIt() {
65          return new InitAction( this.fun.compile(), this.args.compile() );
66      }
67  
68      /**
69       * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
70       */
71      @Override
72      public void resolve( final CompilerState state ) {
73          this.fun.resolve( state );
74          this.args.resolve( state );
75      }
76  
77      /**
78       * @see org.millscript.millscript.expr.Expr#showComponents(int)
79       */
80      @Override
81      void showComponents( final int n ) {
82          this.fun.show( n );
83          this.args.show( n );
84      }
85  
86  }