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
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.
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
;
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
63 char** arguments
; // non-terminated array of argument values, never NULL
64 int numargs
; // number of entries in 'arguments'
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 fixedcheck
; // copy to each GC
76 int langID
; // copy to ShellCore?
77 bool jitordie
; // copy to config
78 Runmode runmode
; // copy to config
79 #ifdef FEATURE_NANOJIT
80 nanojit::Config njconfig
; // copy to config
82 AvmCore::CacheSizes cacheSizes
; // Default to unlimited
83 const char* st_component
;
84 const char* st_category
;
87 BugCompatibility::Version bugCompatibilityVersion
;
89 MMgc::GC::GCMode
gcMode()
91 if (nogc
) return MMgc::GC::kDisableGC
;
92 else if (greedy
) return MMgc::GC::kGreedyGC
;
93 else if (incremental
) return MMgc::GC::kIncrementalGC
;
94 else return MMgc::GC::kNonincrementalGC
;
98 class ShellCodeContext
: public CodeContext
101 inline ShellCodeContext(DomainEnv
* env
, const BugCompatibility
* bugCompatibility
)
102 : CodeContext(env
, bugCompatibility
) { }
106 * ShellCore provides typical housekeeping tasks around an AvmCore, lightweight
107 * embedders may prefer to use this rather than to subclass AvmCore themselves
108 * and do all the housekeeping that results. The shell uses this; see the
109 * shell code for typical usage patterns.
111 class ShellCore
: public AvmCore
113 friend class SystemClass
;
114 friend class DomainObject
;
117 * Create a new core with the given GC (one gc per core).
119 * Requires: MMGC_ENTER and MMGC_GCENTER(gc) on the stack.
121 ShellCore(MMgc::GC
*gc
);
124 * Initialize the new core from the settings. This creates a top-level
125 * environment and performs other housekeeping.
127 * Requires: MMGC_ENTER and MMGC_GCENTER(gc) on the stack.
129 bool setup(ShellCoreSettings
& settings
);
132 * Load the contents from the file and run them in the context of this core's
133 * top level. The file may contain ABC bytecode, a SWF containing a single DoABC
134 * tag, or (if the run-time compiler is present) ActionScript source code.
136 * Requires: MMGC_ENTER and MMGC_GCENTER(gc) on the stack.
138 int evaluateFile(ShellCoreSettings
& settings
, const char* filename
);
142 * Load ActionScript source code from the string and run it in the
143 * context of this core's top level. Note the string must have been
144 * created in the context of the GC in this ShellCore instance.
146 * Requires: MMGC_ENTER and MMGC_GCENTER(gc) on the stack.
148 void evaluateString(String
* input
, bool record_time
=false);
151 #ifdef AVMSHELL_PROJECTOR_SUPPORT
152 int executeProjector(char *executablePath
);
155 #ifdef VMCFG_SELFTEST
156 void executeSelftest(ShellCoreSettings
& settings
);
159 PoolObject
* getShellPool() { return shellPool
; }
161 SystemClass
* getSystemClass() { return systemClass
; }
163 #ifdef AVMSHELL_PROJECTOR_SUPPORT
164 static bool isValidProjectorFile(const char* filename
);
167 inline int32_t getDefaultAPI() { return ApiUtils::toAPI(this, defaultAPIVersion
); }
169 inline BugCompatibility::Version
getDefaultBugCompatibilityVersion() const { return defaultBugCompatibilityVersion
; }
172 virtual void setStackLimit() = 0;
174 virtual Toplevel
* createToplevel(AbcEnv
* abcEnv
);
176 virtual avmplus::Debugger
* createDebugger(int tracelevel
)
178 AvmAssert(allowDebugger
>= 0);
179 return allowDebugger
? new (GetGC()) DebugCLI(this, (avmplus::Debugger::TraceLevel
)tracelevel
) : NULL
;
181 virtual avmplus::Profiler
* createProfiler() { AvmAssert(allowDebugger
>= 0); return allowDebugger
? new (GetGC()) Profiler(this) : NULL
; }
184 virtual String
* readFileForEval(String
* referencing_filename
, String
* filename
);
188 static void interruptTimerCallback(void* data
);
190 ShellToplevel
* createShellToplevel();
192 void interrupt(Toplevel
*, InterruptReason
);
193 void stackOverflow(Toplevel
*toplevel
);
194 void setEnv(Toplevel
*toplevel
, int argc
, char *argv
[]);
195 void initShellPool();
196 int handleArbitraryExecutableContent(ScriptBuffer
& code
, const char * filename
);
198 String
* decodeBytesAsUTF16String(uint8_t* bytes
, uint32_t nbytes
, bool terminate
=false);
201 DebugCLI
* debugCLI() { return (DebugCLI
*)debugger(); }
204 #ifdef AVMPLUS_VERBOSE
205 virtual const char* identifyDomain(Domain
* domain
);
207 SystemClass
* systemClass
;
208 PoolObject
* shellPool
;
209 OutputStream
*consoleOutputStream
;
211 bool inStackOverflow
;
213 ShellToplevel
* shell_toplevel
;
214 // Note that this has been renamed to emphasize the fact that it is
215 // the CodeContext/DomainEnv that user code will run in (as opposed
216 // to the Shell's builtin classes, eg System, File, Domain).
217 ShellCodeContext
* user_codeContext
;
218 uint32_t defaultAPIVersion
;
219 BugCompatibility::Version defaultBugCompatibilityVersion
;
222 class ShellToplevel
: public Toplevel
225 ShellToplevel(AbcEnv
* abcEnv
);
227 ShellCore
* core() const {
228 return (ShellCore
*)Toplevel::core();
231 virtual ClassClosure
*getBuiltinExtensionClass(int class_id
)
233 return shellClasses
[class_id
] ? shellClasses
[class_id
] : resolveShellClass(class_id
);
237 ClassClosure
* resolveShellClass(int class_id
)
239 ClassClosure
* cc
= findClassInPool(class_id
, core()->getShellPool());
240 WBRC(core()->GetGC(), shellClasses
, &shellClasses
[class_id
], cc
);
244 DWB(ClassClosure
**) shellClasses
;
248 #endif /* __avmshell_core__ */