1 /*
2 * Copyright (c) 2001, Zoltan Farkas All Rights Reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 package net.sf.zel.vm;
20
21 import net.sf.zel.math.ExtendedMathContext;
22
23
24 public final class CompileContext implements ParsingContext
25 {
26
27 private final ProgramBuilder prog;
28
29 public CompileContext()
30 {
31 this.prog = new ProgramBuilder();
32 }
33
34 @SuppressWarnings("unchecked")
35 @Override
36 public void generateCode(Object... args)
37 {
38 if (args == null)
39 prog.add(null);
40 else
41 prog.addAll(args);
42 }
43
44 @Override
45 public void generateCodeAt(int address, Object... args)
46 {
47 if (args == null)
48 prog.set(address, null);
49 else
50 prog.setAll(address, args);
51 }
52
53
54
55 @Override
56 public void generateCodeAll(ParsingContext parsingContext)
57 {
58 prog.addAll(parsingContext.getProgramBuilder());
59 }
60
61
62
63 public int getAddress()
64 {
65 return prog.size();
66 }
67
68 /**
69 * Do no aditional processing
70 * @param obj Object
71 */
72 @Override
73 public void process(Object obj)
74 {
75 }
76
77 /**
78 * get the code generated in this context
79 * @return Object[]
80 */
81 @Override
82 public ProgramBuilder getProgramBuilder()
83 {
84 return prog;
85 }
86
87 /**
88 * Add code to this context
89 * @param code Object[]
90 */
91
92 @Override
93 public CompileContext createSubContext()
94 {
95 return new CompileContext();
96 }
97
98 @Override
99 public ExtendedMathContext getMathContext()
100 {
101 return ExtendedMathContext.CURRENT_EXTENDED_MATH_CONTEXT.get();
102 }
103
104 }