Merge remote-tracking branch 'redux/master' into sh4-pool
[tamarin-stm.git] / eval / eval.h
blob7ddb3e78df59ccd004249916454216f39c5befc9
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2008
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Adobe AS3 Team
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 // This file provides common, private APIs for the eval implementation.
42 // About the coding style used in eval:
44 // - eval.h is included into every cpp file in the eval subdirectory.
46 // - Inline functions are almost never in-line in the class definition, but
47 // are placed in a separate file and declared 'inline' explicitly. This
48 // helps separate definition from implementation and reduces clutter, and
49 // it resolves circular dependencies between classes in that two class
50 // definitions will be visible to both classes' inline functions. The main
51 // exception to the rule is trivial constructors, especially in eval-parse.h.
53 // - Class members are 'const' whenever possible.
55 // - All eval code is placed in the namespace avmplus::RTC ("run-time compiler")
56 // so that it is clearly segregated from the rest of the VM; no part of the
57 // VM code should need to open that namespace at all.
59 // - Reasonably standard C++ is assumed, the intent is not for this code to
60 // be portable to the most feeble compilers for embedded systems.
62 // - Almost all allocation is off a private heap of header-less objects that
63 // has minimal allocation cost, very low fragmentation, and which can be
64 // freed in bulk very quickly. See eval-util.h.
66 // - The code is almost entirely independent of avmplus, so that it can be
67 // easily incorporated into a standalone compiler. As a consequence, there
68 // is no use of String, AvmCore, GC, or other central data structures of
69 // avmplus; the necessary functionality (not much) is implemented inside
70 // eval or made available through an abstract HostContext class provided
71 // to the Compiler instance when the latter is created.
73 // Still, a few dependencies remain:
75 // - avmplus.h is included everywhere, so there's a dependency on that name,
76 // if nothing else
78 // - ActionBlockConstants data, both opcode definitions and the instruction
79 // attribute table
81 // - MathUtils, for isNaN (in one case, can be factored into HostContext)
83 // - AvmAssert (can be mapped trivially to ISO C "assert")
85 // - wchar (can be mapped trivially to uint16_t)
87 // A prototype standalone compiler exists in utils/avmc and demonstrates that
88 // the independence works pretty well in practice; all the dependencies are
89 // resolved by implementations in that shell code.
91 #ifdef VMCFG_EVAL
93 #ifdef _MSC_VER
94 #pragma warning(disable:4355) // 'this' : used in base member initializer list
95 #pragma warning(disable:4345) // behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
96 #endif
98 #ifdef DEBUG
99 # define DEBUG_ONLY(x) x
100 #else
101 # define DEBUG_ONLY(x)
102 #endif
104 namespace avmplus
106 namespace RTC
108 using namespace ActionBlockConstants;
110 // Types.
112 // egrep '^class ' *.h | awk '{ print $2 }' | sort | awk '{ print "class " $1 ";" }'
114 class ABCChunk;
115 class ABCClassInfo;
116 class ABCExceptionInfo;
117 class ABCExceptionTable;
118 class ABCFile;
119 class ABCInstanceInfo;
120 class ABCMetadataInfo;
121 class ABCMethodBodyInfo;
122 class ABCMethodInfo;
123 class ABCMethodTrait;
124 class ABCMultinameInfo;
125 class ABCNamespaceInfo;
126 class ABCNamespaceSetInfo;
127 class ABCScriptInfo;
128 class ABCSlotTrait;
129 class ABCTrait;
130 class ABCTraitsTable;
131 class ActivationCtx;
132 class Allocator;
133 class AssignExpr;
134 class BinaryExpr;
135 class Binding;
136 class BlockStmt;
137 class BreakCtx;
138 class BreakStmt;
139 class ByteBuffer;
140 class CVAnonNS;
141 class CVNamespace;
142 class CVValue;
143 class CallExpr;
144 class CaseClause;
145 class CatchClause;
146 class ClassDefn;
147 class CodeBlock;
148 class Cogen;
149 class CommonNamespace;
150 class Compiler;
151 class ComputedName;
152 class ConditionalExpr;
153 class ConstValue;
154 class ContinueCtx;
155 class ContinueStmt;
156 class ControlFlowCtx;
157 class Ctx;
158 class DefaultValue;
159 class DefaultXmlNamespaceStmt;
160 class DescendantsExpr;
161 class DoWhileStmt;
162 class EmptyStmt;
163 class EscapeExpr;
164 class Expr;
165 class ExprStmt;
166 class FilterExpr;
167 class FinallyCtx;
168 class ForInStmt;
169 class ForStmt;
170 class FunctionCtx;
171 class FunctionDefn;
172 class FunctionParam;
173 class IfStmt;
174 class InterfaceDefn;
175 class Label;
176 class LabelSetStmt;
177 class LabeledStmt;
178 class Lexer;
179 class LiteralArray;
180 class LiteralBoolean;
181 class LiteralDouble;
182 class LiteralField;
183 class LiteralFunction;
184 class LiteralInt;
185 class LiteralNull;
186 class LiteralObject;
187 class LiteralRegExp;
188 class LiteralString;
189 class LiteralUInt;
190 class LiteralUndefined;
191 class NameComponent;
192 class NameExpr;
193 class Namespace;
194 class NamespaceDefn;
195 class NamespaceRef;
196 class NewExpr;
197 class ObjectRef;
198 class Parser;
199 class Program;
200 class ProgramCtx;
201 class QualifiedName;
202 class Qualifier;
203 class RefLocalExpr;
204 class ReturnStmt;
205 class SBChunk;
206 class ScopeCtx;
207 class SimpleName;
208 class Stmt;
209 class Str;
210 class StringBuilder;
211 class SwitchStmt;
212 class ThisExpr;
213 class ThrowStmt;
214 class TryStmt;
215 class UnaryExpr;
216 class VarScopeCtx;
217 class WhileStmt;
218 class WildcardName;
219 class WithCtx;
220 class WithStmt;
221 class XmlInitializer;
223 // some special cases
225 class XmlContext;
228 * Symbolic names for syntax error messages / format strings (localizable). See
229 * eval-compile.cpp for the actual contents, the English language strings define
230 * the meaning of the symbols.
232 enum SyntaxError {
233 SYNTAXERR_EOT_IN_REGEXP = 0,
234 SYNTAXERR_NEWLINE_IN_REGEXP = 1,
235 SYNTAXERR_XML_UNEXPECTED_TOKEN = 2,
236 SYNTAXERR_NATIVE_NOT_SUPPORTED = 3,
237 SYNTAXERR_DEFAULT_NOT_EXPECTED = 4,
238 SYNTAXERR_ILLEGAL_QNAME = 5,
239 SYNTAXERR_IMPOSSIBLE_DEFAULT = 6,
240 SYNTAXERR_ILLEGAL_TYPENAME = 7,
241 SYNTAXERR_ILLEGAL_FIELDNAME = 8,
242 SYNTAXERR_ILLEGAL_PROPNAME = 9,
243 SYNTAXERR_QUALIFIER_NOT_ALLOWED = 10,
244 SYNTAXERR_ILLEGAL_INCLUDE = 11,
245 SYNTAXERR_ILLEGAL_NAMESPACE = 12,
246 SYNTAXERR_ILLEGAL_IN_INTERFACE = 13,
247 SYNTAXERR_ONE_ARGUMENT_REQUIRED = 14,
248 SYNTAXERR_NO_FUNCTIONS_IN_BLOCKS = 15,
249 SYNTAXERR_SEMICOLON_OR_NEWLINE = 16,
250 SYNTAXERR_CONST_INIT_REQD = 17,
251 SYNTAXERR_ILLEGAL_USE = 18,
252 SYNTAXERR_RETURN_OUTSIDE_FN = 19,
253 SYNTAXERR_VOIDFN_RETURNS_VALUE = 20,
254 SYNTAXERR_EXPECT_DXNS = 21,
255 SYNTAXERR_FOR_IN_ONEBINDING = 22,
256 SYNTAXERR_FOR_EACH_REQS_IN = 23,
257 SYNTAXERR_DUPLICATE_DEFAULT = 24,
258 SYNTAXERR_EXPECT_CASE_OR_DEFAULT = 25,
259 SYNTAXERR_CLASS_NOT_ALLOWED = 26,
260 SYNTAXERR_XML_ILLEGAL_CHARS = 27,
261 SYNTAXERR_INTERFACE_NOT_ALLOWED = 28,
262 SYNTAXERR_PROPERTY_OPERATOR_REQUIRED = 29,
263 SYNTAXERR_STMT_IN_INTERFACE = 30,
264 SYNTAXERR_ILLEGAL_STMT = 31,
265 SYNTAXERR_KWD_NOT_ALLOWED = 32,
266 SYNTAXERR_INCLUDE_ORIGIN = 33,
267 SYNTAXERR_INCLUDE_INACCESSIBLE = 34,
268 SYNTAXERR_REDEFINITION = 35,
269 SYNTAXERR_REDEFINITION_TYPE = 36,
270 SYNTAXERR_REDUNDANT_CONST = 37,
271 SYNTAXERR_REDUNDANT_METHOD = 38,
272 SYNTAXERR_REDUNDANT_NAMESPACE = 39,
273 SYNTAXERR_DEFAULT_VALUE_REQD = 40,
274 SYNTAXERR_WRONG_TOKEN = 41,
275 SYNTAXERR_EXPECTED_IDENT = 42,
276 SYNTAXERR_ILLEGALCHAR_NUL = 43,
277 SYNTAXERR_ILLEGAL_NUMBER = 44,
278 SYNTAXERR_ILLEGALCHAR_POSTNUMBER = 45,
279 SYNTAXERR_EOI_IN_COMMENT = 46,
280 SYNTAXERR_ILLEGALCHAR = 47,
281 SYNTAXERR_UNTERMINATED_STRING = 48,
282 SYNTAXERR_EOI_IN_ESC = 49,
283 SYNTAXERR_XML_UNTERMINATED = 50,
284 SYNTAXERR_XML_INVALID_SLASH = 51,
285 SYNTAXERR_XML_INVALID_LEFTBANG = 52,
286 SYNTAXERR_IDENT_IS_KWD = 53,
287 SYNTAXERR_EOL_IN_ESC = 54,
288 SYNTAXERR_INVALID_VAR_ESC = 55,
289 SYNTAXERR_ILLEGAL_BREAK = 56,
290 SYNTAXERR_BREAK_LABEL_UNDEF = 57,
291 SYNTAXERR_ILLEGAL_CONTINUE = 58,
292 SYNTAXERR_CONTINUE_LABEL_UNDEF = 59,
293 SYNTAXERR_XML_EOI_IN_MARKUP = 60,
294 SYNTAXERR_UNBOUND_CONST_NAME = 61,
295 SYNTAXERR_ILLEGAL_OP_IN_CONSTEXPR = 62,
296 SYNTAXERR_CONFIG_NAMESPACE_SHADOWING = 63,
297 SYNTAXERR_ILLEGAL_METADATA = 64,
298 SYNTAXERR_KWD_NAMESPACE_REQUIRED = 65,
299 SYNTAXERR_CONFIG_NAMESPACE_NOT_ALLOWED = 66,
300 SYNTAXERR_CONFIG_NAMESPACE_MUST_BE_UNQUALIFIED = 67,
301 SYNTAXERR_DUPLICATE_CONFIG = 68,
302 SYNTAXERR_DIRECTIVE_REQUIRED = 69,
303 SYNTAXERR_METADATA_NOT_ALLOWED = 70,
304 SYNTAXERR_NEWLINE_NOT_ALLOWED = 71,
305 SYNTAXERR_DUPLICATE_QUALIFIER = 72,
306 SYNTAXERR_CONFIG_REQUIRED = 73,
307 SYNTAXERR_CONFIG_PROHIBITED = 74,
310 // The HostContext must be implemented by the embedder of eval. 'wchar' is a 16-bit unsigned value always.
312 class HostContext {
313 public:
314 #ifndef AVMC_STANDALONE
315 // AvmCore is used for VMPI_alloca.
316 HostContext(AvmCore* core) : core(core), stopAfterParse(false) {}
317 AvmCore * const core;
318 #else
319 HostContext() : stopAfterParse(false) {}
320 #endif
321 bool stopAfterParse;
323 virtual ~HostContext() {};
324 virtual uint8_t* obtainStorageForResult(uint32_t nbytes) = 0;
325 virtual const wchar* readFileForEval(const wchar* basename, const wchar* filename, uint32_t* inputlen) = 0;
326 virtual void freeInput(const wchar* input) = 0;
327 virtual void doubleToString(double d, char* buf, size_t bufsiz) = 0;
328 virtual bool stringToDouble(const char* s, double* d) = 0;
329 virtual void throwInternalError(const char* msgz) = 0;
330 virtual void throwSyntaxError(const char* msgz) = 0;
337 // type definitions
339 #include "eval-util.h"
340 #include "eval-lex.h"
341 #include "eval-parse.h"
342 #include "eval-cogen.h"
343 #include "eval-abc.h"
344 #include "eval-compile.h"
345 #include "eval-unicode.h"
347 // all inline functions for those types
349 #include "eval-util-inlines.h"
350 #include "eval-abc-inlines.h"
351 #include "eval-lex-inlines.h"
352 #include "eval-parse-inlines.h"
353 #include "eval-cogen-inlines.h"
355 #endif // VMCFG_EVAL