1 ////////////////////////////////////////////////////////////////////////////////
2 // MillScript: an Open Spice interpreter and batch website creation tool
3 // Copyright (C) 2001-2004 Open World Ltd
4 // Copyright (C) 2005 Kevin Rogers
5 //
6 // This file is part of MillScript.
7 //
8 // MillScript is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
11 // any later version.
12 //
13 // MillScript is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 // more details.
17 //
18 // You should have received a copy of the GNU General Public License along with
19 // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
20 // Place, Suite 330, Boston, MA 02111-1307 USA
21 ////////////////////////////////////////////////////////////////////////////////
22 package org.millscript.millscript.action;
23
24 import org.millscript.millscript.alert.Alerts;
25 import org.millscript.millscript.expr.Ident;
26 import org.millscript.millscript.vm.Machine;
27 import org.millscript.millscript.vm.Ref;
28
29 /**
30 * This class is the base of all variable assignment actions, for a
31 * <code>:=</code> expression.
32 *
33 * @see org.millscript.millscript.expr.AssignExpr
34 * @see org.millscript.millscript.syntax.AssignSyntax
35 */
36 public abstract class AssignAction extends Action {
37
38 /**
39 * The reference for the value of the ident.
40 */
41 Ref ref;
42
43 /**
44 * The action for the value we want to assign to the variable.
45 */
46 Action rhs;
47
48 /**
49 * Constructs a new assignment action, to assign to the specified ident,
50 * with the specified action to generate the value to assign.
51 *
52 * @param i the ident for the variable we want to assign to
53 * @param r the action for the value we want to assign
54 */
55 AssignAction( final Ident i, final Action r ) {
56 if ( i.getIsConst() ) {
57 throw(
58 Alerts.compile(
59 "Trying to assign to a const",
60 "Const variables cannot be assigned to"
61 ).culprit( "name", i.getName() ).mishap()
62 );
63 }
64 // Get the reference from the ident
65 this.ref = i.getRef();
66 this.rhs = r;
67 }
68
69 /**
70 * @see org.millscript.millscript.action.Action#action(org.millscript.millscript.vm.Machine)
71 */
72 @Override
73 public void action( final Machine mc ) {
74 // Update the references value with the result of performing the value
75 // action
76 ref.value = rhs.act1( mc );
77 }
78
79 }