use of com.github.anba.es6draft.ast.Script in project es6draft by anba.
the class Compiler method compile.
private <FUNCTION extends FunctionNode> CompiledFunction compile(FUNCTION function, String className, BiConsumer<CodeGenerator, FUNCTION> compiler) {
Script script = functionScript(function);
if (!isEnabled(Compiler.Option.NoByteCodeSizeValidation)) {
CodeSize.analyze(function);
}
long startCompile = 0;
if (MEASURE_COMPILE_TIME) {
startCompile = System.nanoTime();
}
Code code = new Code(Modifier.PUBLIC | Modifier.FINAL, className, ClassSignature.NONE, Types.CompiledFunction, Collections.<Type>emptyList(), NodeSourceInfo.create(function, isEnabled(Option.SourceMap)));
CodeGenerator codegen = new CodeGenerator(context, code, script);
try {
compiler.accept(codegen, function);
} catch (RuntimeException e) {
throw handleAsmError(e);
}
if (MEASURE_COMPILE_TIME) {
long time = System.nanoTime() - startCompile;
STATISTICS.compileTime.add(time);
STATISTICS.compileTimeFunction.add(time);
}
long startLoad = 0;
if (MEASURE_LOAD_TIME) {
startLoad = System.nanoTime();
}
CompiledFunction compiledFunction;
try {
if (useAnonymousLoader(code)) {
compiledFunction = defineAndLoad(script, code, AnonymousCodeLoader.FUNCTION);
} else {
compiledFunction = defineAndLoad(script, code, className);
}
} catch (RuntimeException e) {
throw handleAsmError(e);
}
if (MEASURE_LOAD_TIME) {
long time = System.nanoTime() - startLoad;
STATISTICS.loadTime.add(time);
STATISTICS.loadTimeFunction.add(time);
}
return compiledFunction;
}
use of com.github.anba.es6draft.ast.Script in project es6draft by anba.
the class ScriptCodeGenerator method generateGlobalScriptEvaluation.
/**
* 15.1.7 Runtime Semantics: ScriptEvaluation
*
* @param node
* the script node
* @param mv
* the instruction visitor
*/
private void generateGlobalScriptEvaluation(Script node, InstructionVisitor mv) {
Variable<ExecutionContext> callerContext = mv.getParameter(EXECUTION_CONTEXT, ExecutionContext.class);
Variable<com.github.anba.es6draft.Script> script = mv.getParameter(SCRIPT, com.github.anba.es6draft.Script.class);
Variable<Realm> realm = mv.newVariable("realm", Realm.class);
Variable<ExecutionContext> scriptCxt = mv.newVariable("scriptCxt", ExecutionContext.class);
Variable<ExecutionContext> oldScriptContext = mv.newVariable("oldScriptContext", ExecutionContext.class);
Variable<Object> result = mv.newVariable("result", Object.class);
Variable<Throwable> throwable = mv.newVariable("throwable", Throwable.class);
getRealm(callerContext, realm, mv);
/* steps 1-2 (not applicable) */
/* steps 3-7 */
newScriptExecutionContext(realm, script, scriptCxt, mv);
/* step 8 */
getScriptContext(realm, oldScriptContext, mv);
/* step 9 */
setScriptContext(realm, scriptCxt, mv);
TryCatchLabel startFinally = new TryCatchLabel(), endFinally = new TryCatchLabel();
TryCatchLabel handlerFinally = new TryCatchLabel();
mv.mark(startFinally);
{
/* step 10 */
mv.load(scriptCxt);
mv.invoke(codegen.methodDesc(node, ScriptName.Init));
/* steps 11-12 */
mv.load(scriptCxt);
mv.invoke(codegen.methodDesc(node, ScriptName.Code));
mv.store(result);
/* steps 13-15 */
setScriptContext(realm, oldScriptContext, mv);
/* step 16 */
mv.load(result);
mv._return();
}
mv.mark(endFinally);
// Exception: Restore script context and then rethrow exception
mv.finallyHandler(handlerFinally);
mv.store(throwable);
/* steps 13-15 */
setScriptContext(realm, oldScriptContext, mv);
mv.load(throwable);
mv.athrow();
mv.tryFinally(startFinally, endFinally, handlerFinally);
}
use of com.github.anba.es6draft.ast.Script in project es6draft by anba.
the class Compiler method compile.
private CompiledFunction compile(FunctionNode function, String className) {
Script script = functionScript(function);
if (!isEnabled(Compiler.Option.NoByteCodeSizeValidation)) {
try {
CodeSize.analyze(function);
} catch (CodeSizeException e) {
throw new CompilationException(e.getMessage());
}
}
Code code = new Code(Modifier.PUBLIC | Modifier.FINAL, className, ClassSignature.NONE, Types.CompiledFunction, Collections.<Type>emptyList(), NodeSourceInfo.create(function, compilerOptions));
CodeGenerator codegen = new CodeGenerator(code, script, executor, compilerOptions);
codegen.compileFunction(function);
return defineAndLoad(code, className);
}
use of com.github.anba.es6draft.ast.Script in project es6draft by anba.
the class ScriptCodeGenerator method generateGlobalScriptEvaluation.
/**
* 15.1.7 Runtime Semantics: ScriptEvaluation
*
* @param node
* the script node
* @param scriptInit
* the script declaration instantiation method
* @param scriptBody
* the script body method
* @param mv
* the instruction visitor
*/
private static void generateGlobalScriptEvaluation(Script node, MethodName scriptInit, MethodName scriptBody, ScriptEvalVisitor mv) {
Variable<ExecutionContext> callerContext = mv.getCallerContext();
Variable<com.github.anba.es6draft.Script> script = mv.getScript();
Variable<Realm> realm = mv.newVariable("realm", Realm.class);
Variable<ExecutionContext> scriptCxt = mv.newVariable("scriptCxt", ExecutionContext.class);
Variable<ExecutionContext> oldScriptContext = mv.newVariable("oldScriptContext", ExecutionContext.class);
Variable<Object> result = mv.newVariable("result", Object.class);
Variable<Throwable> throwable = mv.newVariable("throwable", Throwable.class);
getRealm(callerContext, realm, mv);
/* steps 1-2 (not applicable) */
/* steps 3-7 */
newScriptExecutionContext(realm, script, scriptCxt, mv);
/* step 8 */
getScriptContext(realm, oldScriptContext, mv);
/* step 9 */
setScriptContext(realm, scriptCxt, mv);
TryCatchLabel startFinally = new TryCatchLabel(), endFinally = new TryCatchLabel();
TryCatchLabel handlerFinally = new TryCatchLabel();
mv.mark(startFinally);
{
/* step 10 */
mv.load(scriptCxt);
mv.invoke(scriptInit);
/* steps 11-12 */
mv.load(scriptCxt);
mv.invoke(scriptBody);
mv.store(result);
/* steps 13-15 */
setScriptContext(realm, oldScriptContext, mv);
/* step 16 */
mv.load(result);
mv._return();
}
mv.mark(endFinally);
// Exception: Restore script context and then rethrow exception
mv.finallyHandler(handlerFinally);
mv.store(throwable);
/* steps 13-15 */
setScriptContext(realm, oldScriptContext, mv);
mv.load(throwable);
mv.athrow();
mv.tryFinally(startFinally, endFinally, handlerFinally);
}
Aggregations