Bug 607719 followup: deep tests that do not match the current config will run in...
[tamarin-stm.git] / shell / ShellCore.h
blob3fb7da63a9457687b580433b68062c2205aac3d9
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) 2004-2006
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 #ifndef __avmshell_core__
41 #define __avmshell_core__
43 using namespace avmplus;
45 namespace avmshell
47 /**
48 * Settings for ShellCore. The command line parser uses this, but the initial state
49 * is set in ShellCore.cpp, and it's propagated throughout various parts of the
50 * system. Partly duplicates the functionality in AvmCore::config, and some settings
51 * are copied from ShellCoreSettings into that structure when a new core is created.
53 * We try to avoid conditional compilation here, as there's only ever one of these
54 * structures floating around and the savings would be minuscule.
56 * FIXME: the naming of many fields could be much better, and they should be documented.
58 class ShellCoreSettings
60 public:
61 ShellCoreSettings();
63 char** arguments; // non-terminated array of argument values, never NULL
64 int numargs; // number of entries in 'arguments'
65 bool nodebugger;
66 int astrace_console;
67 uint32_t do_verbose; // copy to config
68 bool enter_debugger_on_launch;
69 bool interrupts; // copy to config
70 bool verifyall; // copy to config
71 bool verifyonly; // copy to config
72 bool greedy; // copy to each GC
73 bool nogc; // copy to each GC
74 bool incremental; // copy to each GC
75 bool exactgc; // copy to each GC
76 bool fixedcheck; // copy to each GC
77 int gcthreshold; // copy to each GC
78 int langID; // copy to ShellCore?
79 bool jitordie; // copy to config
80 Runmode runmode; // copy to config
81 #ifdef VMCFG_NANOJIT
82 nanojit::Config njconfig; // copy to config
83 #endif
84 AvmCore::CacheSizes cacheSizes; // Default to unlimited
85 const char* st_component;
86 const char* st_category;
87 const char* st_name;
88 ApiVersion api;
89 BugCompatibility::Version swfVersion;
91 MMgc::GC::GCMode gcMode()
93 if (nogc) return MMgc::GC::kDisableGC;
94 else if (greedy) return MMgc::GC::kGreedyGC;
95 else if (incremental) return MMgc::GC::kIncrementalGC;
96 else return MMgc::GC::kNonincrementalGC;
100 class ShellCodeContext : public CodeContext
102 public:
103 inline ShellCodeContext(DomainEnv* env, const BugCompatibility* bugCompatibility)
104 : CodeContext(env, bugCompatibility) { }
108 * ShellCore provides typical housekeeping tasks around an AvmCore, lightweight
109 * embedders may prefer to use this rather than to subclass AvmCore themselves
110 * and do all the housekeeping that results. The shell uses this; see the
111 * shell code for typical usage patterns.
113 class ShellCore : public AvmCore
115 friend class SystemClass;
116 friend class avmplus::DomainObject;
117 public:
119 * Create a new core with the given GC (one gc per core).
121 * Requires: MMGC_ENTER and MMGC_GCENTER(gc) on the stack.
123 ShellCore(MMgc::GC *gc);
126 * Initialize the new core from the settings. This creates a top-level
127 * environment and performs other housekeeping.
129 * Requires: MMGC_ENTER and MMGC_GCENTER(gc) on the stack.
131 bool setup(const ShellCoreSettings& settings);
134 * Load the contents from the file and run them in the context of this core's
135 * top level. The file may contain ABC bytecode, a SWF containing a single DoABC
136 * tag, or (if the run-time compiler is present) ActionScript source code.
138 * Requires: MMGC_ENTER and MMGC_GCENTER(gc) on the stack.
140 int evaluateFile(ShellCoreSettings& settings, const char* filename);
142 #ifdef VMCFG_EVAL
144 * Load ActionScript source code from the string and run it in the
145 * context of this core's top level. Note the string must have been
146 * created in the context of the GC in this ShellCore instance.
148 * Requires: MMGC_ENTER and MMGC_GCENTER(gc) on the stack.
150 void evaluateString(String* input, bool record_time=false);
151 #endif
153 #ifdef AVMSHELL_PROJECTOR_SUPPORT
154 int executeProjector(char *executablePath);
155 #endif
157 #ifdef VMCFG_SELFTEST
158 void executeSelftest(ShellCoreSettings& settings);
159 #endif
161 PoolObject* getShellPool() { return shellPool; }
163 SystemClass* getSystemClass() { return systemClass; }
165 #ifdef AVMSHELL_PROJECTOR_SUPPORT
166 static bool isValidProjectorFile(const char* filename);
167 #endif
169 inline int32_t getDefaultAPI() { return ApiUtils::toAPI(this, defaultAPIVersion); }
171 inline BugCompatibility::Version getDefaultBugCompatibilityVersion() const { return defaultBugCompatibilityVersion; }
173 protected:
174 virtual void setStackLimit() = 0;
176 virtual Toplevel* createToplevel(AbcEnv* abcEnv);
177 #ifdef DEBUGGER
178 virtual avmplus::Debugger* createDebugger(int tracelevel)
180 AvmAssert(allowDebugger >= 0);
181 return allowDebugger ? DebugCLI::create(GetGC(), this, (avmplus::Debugger::TraceLevel)tracelevel) : NULL;
184 #endif
185 #ifdef VMCFG_EVAL
186 virtual String* readFileForEval(String* referencing_filename, String* filename);
187 #endif
189 private:
190 static void interruptTimerCallback(void* data);
192 ShellToplevel* createShellToplevel();
194 void interrupt(Toplevel*, InterruptReason);
195 void stackOverflow(Toplevel *toplevel);
196 void setEnv(Toplevel *toplevel, int argc, char *argv[]);
197 void initShellPool();
198 int handleArbitraryExecutableContent(ScriptBuffer& code, const char * filename);
199 #ifdef VMCFG_EVAL
200 String* decodeBytesAsUTF16String(uint8_t* bytes, uint32_t nbytes, bool terminate=false);
201 #endif // VMCFG_EVAL
202 #ifdef DEBUGGER
203 DebugCLI* debugCLI() { return (DebugCLI*)debugger(); }
204 #endif
206 #ifdef AVMPLUS_VERBOSE
207 virtual const char* identifyDomain(Domain* domain);
208 #endif
209 SystemClass* systemClass;
210 PoolObject* shellPool;
211 OutputStream *consoleOutputStream;
212 bool gracePeriod;
213 bool inStackOverflow;
214 int allowDebugger;
215 ShellToplevel* shell_toplevel;
216 DomainEnv* shell_domainEnv;
217 Domain* shell_domain;
218 // Note that this has been renamed to emphasize the fact that it is
219 // the CodeContext/DomainEnv that user code will run in (as opposed
220 // to the Shell's builtin classes, eg System, File, Domain).
221 ShellCodeContext* user_codeContext;
222 ApiVersion defaultAPIVersion;
223 BugCompatibility::Version defaultBugCompatibilityVersion;
226 class GC_CPP_EXACT(ShellToplevel, avmplus::Toplevel)
228 friend class ShellCore;
230 private:
231 ShellToplevel(AbcEnv* abcEnv);
233 public:
234 REALLY_INLINE static ShellToplevel* create(MMgc::GC* gc, AbcEnv* abcEnv)
236 return MMgc::setExact(new (gc) ShellToplevel(abcEnv));
239 ShellCore* core() const {
240 return (ShellCore*)Toplevel::core();
243 virtual ClassClosure *getBuiltinExtensionClass(int class_id)
245 return shellClasses->list[class_id] ? shellClasses->list[class_id] : resolveShellClass(class_id);
248 private:
249 ClassClosure* resolveShellClass(int class_id)
251 ClassClosure* cc = findClassInScriptEnv(class_id, shellEntryPoint);
252 shellClasses->list.set(class_id, cc);
253 return cc;
256 GC_DATA_BEGIN(ShellToplevel)
258 DWB(ScriptEnv*) GC_POINTER(shellEntryPoint);
259 DWB(ExactHeapList< RCList<ClassClosure> >*) GC_POINTER(shellClasses);
261 GC_DATA_END(ShellToplevel)
265 #endif /* __avmshell_core__ */