Always embed runtime into generated file. Remove 'runtime' build property

This commit is contained in:
Alexey Andreev 2018-10-28 00:15:36 +03:00
parent 63b2440e48
commit 4d2c075c07
40 changed files with 245 additions and 321 deletions

View File

@ -67,6 +67,10 @@
<artifactId>jackson-annotations</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -45,6 +45,7 @@ import org.teavm.backend.javascript.codegen.SourceWriter;
import org.teavm.backend.javascript.codegen.SourceWriterBuilder;
import org.teavm.backend.javascript.rendering.Renderer;
import org.teavm.backend.javascript.rendering.RenderingContext;
import org.teavm.backend.javascript.rendering.RuntimeRenderer;
import org.teavm.backend.javascript.spi.GeneratedBy;
import org.teavm.backend.javascript.spi.Generator;
import org.teavm.backend.javascript.spi.InjectedBy;
@ -292,6 +293,7 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
renderingContext.setMinifying(minifying);
Renderer renderer = new Renderer(sourceWriter, asyncMethods, asyncFamilyMethods,
controller.getDiagnostics(), renderingContext);
RuntimeRenderer runtimeRenderer = new RuntimeRenderer(naming, sourceWriter);
renderer.setProperties(controller.getProperties());
renderer.setMinifying(minifying);
if (debugEmitter != null) {
@ -319,7 +321,7 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
int start = sourceWriter.getOffset();
sourceWriter.append("\"use strict\";").newLine();
renderer.prepare(clsNodes);
renderer.renderRuntime();
runtimeRenderer.renderRuntime();
renderer.render(clsNodes);
renderer.renderStringPool();
renderer.renderStringConstants();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 Alexey Andreev.
* Copyright 2018 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.jso.impl;
package org.teavm.backend.javascript.rendering;
import java.io.IOException;
import java.util.Collections;
@ -276,6 +276,7 @@ public class AstWriter {
private void print(AstRoot node) throws IOException {
for (Node child : node) {
print((AstNode) child);
writer.softNewLine();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 Alexey Andreev.
* Copyright 2018 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.jso.impl;
package org.teavm.backend.javascript.rendering;
import org.mozilla.javascript.CompilerEnvirons;
import org.mozilla.javascript.ErrorReporter;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 Alexey Andreev.
* Copyright 2018 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.jso.impl;
package org.teavm.backend.javascript.rendering;
import java.io.IOException;
interface NameEmitter {
public interface NameEmitter {
void emit(int precedence) throws IOException;
}

View File

@ -193,106 +193,6 @@ public class Renderer implements RenderingManager {
sizeByClass.put(className, sizeByClass.getOrDefault(className, 0) + sz);
}
public void renderRuntime() throws RenderingException {
try {
renderSetCloneMethod();
renderRuntimeCls();
renderRuntimeString();
renderRuntimeUnwrapString();
renderRuntimeObjcls();
renderRuntimeNullCheck();
renderRuntimeIntern();
renderRuntimeThreads();
} catch (NamingException e) {
throw new RenderingException("Error rendering runtime methods. See a cause for details", e);
} catch (IOException e) {
throw new RenderingException("IO error", e);
}
}
private void renderSetCloneMethod() throws IOException {
writer.append("function $rt_setCloneMethod(target, f)").ws().append("{").softNewLine().indent();
writer.append("target.").appendMethod("clone", Object.class).ws().append('=').ws().append("f;").
softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeCls() throws IOException {
writer.append("function $rt_cls(cls)").ws().append("{").softNewLine().indent();
writer.append("return ").appendMethodBody("java.lang.Class", "getClass",
ValueType.object("org.teavm.platform.PlatformClass"),
ValueType.object("java.lang.Class")).append("(cls);")
.softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeString() throws IOException {
MethodReference stringCons = new MethodReference(String.class, "<init>", char[].class, void.class);
writer.append("function $rt_str(str) {").indent().softNewLine();
writer.append("if (str === null) {").indent().softNewLine();
writer.append("return null;").softNewLine();
writer.outdent().append("}").softNewLine();
writer.append("var characters = $rt_createCharArray(str.length);").softNewLine();
writer.append("var charsBuffer = characters.data;").softNewLine();
writer.append("for (var i = 0; i < str.length; i = (i + 1) | 0) {").indent().softNewLine();
writer.append("charsBuffer[i] = str.charCodeAt(i) & 0xFFFF;").softNewLine();
writer.outdent().append("}").softNewLine();
writer.append("return ").append(naming.getNameForInit(stringCons)).append("(characters);").softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeUnwrapString() throws IOException {
MethodReference stringLen = new MethodReference(String.class, "length", int.class);
MethodReference getChars = new MethodReference(String.class, "getChars", int.class, int.class,
char[].class, int.class, void.class);
writer.append("function $rt_ustr(str) {").indent().softNewLine();
writer.append("if (str === null) {").indent().softNewLine();
writer.append("return null;").softNewLine();
writer.outdent().append("}").softNewLine();
writer.append("var result = \"\";").softNewLine();
writer.append("var sz = ").appendMethodBody(stringLen).append("(str);").softNewLine();
writer.append("var array = $rt_createCharArray(sz);").softNewLine();
writer.appendMethodBody(getChars).append("(str, 0, sz, array, 0);").softNewLine();
writer.append("for (var i = 0; i < sz; i = (i + 1) | 0) {").indent().softNewLine();
writer.append("result += String.fromCharCode(array.data[i]);").softNewLine();
writer.outdent().append("}").softNewLine();
writer.append("return result;").softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeNullCheck() throws IOException {
writer.append("function $rt_nullCheck(val) {").indent().softNewLine();
writer.append("if (val === null) {").indent().softNewLine();
writer.append("$rt_throw(").append(naming.getNameForInit(new MethodReference(NullPointerException.class,
"<init>", void.class))).append("());").softNewLine();
writer.outdent().append("}").softNewLine();
writer.append("return val;").softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeIntern() throws IOException {
writer.append("function $rt_intern(str) {").indent().softNewLine();
writer.append("return ").appendMethodBody(new MethodReference(String.class, "intern", String.class))
.append("(str);").softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeObjcls() throws IOException {
writer.append("function $rt_objcls() { return ").appendClass("java.lang.Object").append("; }").newLine();
}
private void renderRuntimeThreads() throws IOException {
writer.append("function $rt_getThread()").ws().append("{").indent().softNewLine();
writer.append("return ").appendMethodBody(Thread.class, "currentThread", Thread.class).append("();")
.softNewLine();
writer.outdent().append("}").newLine();
writer.append("function $rt_setThread(t)").ws().append("{").indent().softNewLine();
writer.append("return ").appendMethodBody(Thread.class, "setCurrentThread", Thread.class, void.class)
.append("(t);").softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeAliases() throws IOException {
String[] names = { "$rt_throw", "$rt_compare", "$rt_nullCheck", "$rt_cls", "$rt_createArray",
"$rt_isInstance", "$rt_nativeThread", "$rt_suspending", "$rt_resuming", "$rt_invalidPointer",

View File

@ -0,0 +1,163 @@
/*
* Copyright 2018 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.backend.javascript.rendering;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import org.mozilla.javascript.CompilerEnvirons;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ast.AstRoot;
import org.teavm.backend.javascript.codegen.NamingException;
import org.teavm.backend.javascript.codegen.NamingStrategy;
import org.teavm.backend.javascript.codegen.SourceWriter;
import org.teavm.model.MethodReference;
import org.teavm.model.ValueType;
import org.teavm.vm.RenderingException;
public class RuntimeRenderer {
private final NamingStrategy naming;
private final SourceWriter writer;
public RuntimeRenderer(NamingStrategy naming, SourceWriter writer) {
this.naming = naming;
this.writer = writer;
}
public void renderRuntime() throws RenderingException {
try {
renderHandWrittenRuntime();
renderSetCloneMethod();
renderRuntimeCls();
renderRuntimeString();
renderRuntimeUnwrapString();
renderRuntimeObjcls();
renderRuntimeNullCheck();
renderRuntimeIntern();
renderRuntimeThreads();
} catch (NamingException e) {
throw new RenderingException("Error rendering runtime methods. See a cause for details", e);
} catch (IOException e) {
throw new RenderingException("IO error", e);
}
}
private void renderHandWrittenRuntime() throws IOException {
AstRoot ast = parseRuntime();
ast.visit(new StringConstantElimination());
AstWriter astWriter = new AstWriter(writer);
astWriter.hoist(ast);
astWriter.print(ast);
}
private AstRoot parseRuntime() throws IOException {
CompilerEnvirons env = new CompilerEnvirons();
env.setRecoverFromErrors(true);
env.setLanguageVersion(Context.VERSION_1_8);
JSParser factory = new JSParser(env);
ClassLoader loader = RuntimeRenderer.class.getClassLoader();
try (InputStream input = loader.getResourceAsStream("org/teavm/backend/javascript/runtime.js");
Reader reader = new InputStreamReader(input, StandardCharsets.UTF_8)) {
return factory.parse(reader, null, 0);
}
}
private void renderSetCloneMethod() throws IOException {
writer.append("function $rt_setCloneMethod(target, f)").ws().append("{").softNewLine().indent();
writer.append("target.").appendMethod("clone", Object.class).ws().append('=').ws().append("f;").
softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeCls() throws IOException {
writer.append("function $rt_cls(cls)").ws().append("{").softNewLine().indent();
writer.append("return ").appendMethodBody("java.lang.Class", "getClass",
ValueType.object("org.teavm.platform.PlatformClass"),
ValueType.object("java.lang.Class")).append("(cls);")
.softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeString() throws IOException {
MethodReference stringCons = new MethodReference(String.class, "<init>", char[].class, void.class);
writer.append("function $rt_str(str) {").indent().softNewLine();
writer.append("if (str === null) {").indent().softNewLine();
writer.append("return null;").softNewLine();
writer.outdent().append("}").softNewLine();
writer.append("var characters = $rt_createCharArray(str.length);").softNewLine();
writer.append("var charsBuffer = characters.data;").softNewLine();
writer.append("for (var i = 0; i < str.length; i = (i + 1) | 0) {").indent().softNewLine();
writer.append("charsBuffer[i] = str.charCodeAt(i) & 0xFFFF;").softNewLine();
writer.outdent().append("}").softNewLine();
writer.append("return ").append(naming.getNameForInit(stringCons)).append("(characters);").softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeUnwrapString() throws IOException {
MethodReference stringLen = new MethodReference(String.class, "length", int.class);
MethodReference getChars = new MethodReference(String.class, "getChars", int.class, int.class,
char[].class, int.class, void.class);
writer.append("function $rt_ustr(str) {").indent().softNewLine();
writer.append("if (str === null) {").indent().softNewLine();
writer.append("return null;").softNewLine();
writer.outdent().append("}").softNewLine();
writer.append("var result = \"\";").softNewLine();
writer.append("var sz = ").appendMethodBody(stringLen).append("(str);").softNewLine();
writer.append("var array = $rt_createCharArray(sz);").softNewLine();
writer.appendMethodBody(getChars).append("(str, 0, sz, array, 0);").softNewLine();
writer.append("for (var i = 0; i < sz; i = (i + 1) | 0) {").indent().softNewLine();
writer.append("result += String.fromCharCode(array.data[i]);").softNewLine();
writer.outdent().append("}").softNewLine();
writer.append("return result;").softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeNullCheck() throws IOException {
writer.append("function $rt_nullCheck(val) {").indent().softNewLine();
writer.append("if (val === null) {").indent().softNewLine();
writer.append("$rt_throw(").append(naming.getNameForInit(new MethodReference(NullPointerException.class,
"<init>", void.class))).append("());").softNewLine();
writer.outdent().append("}").softNewLine();
writer.append("return val;").softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeIntern() throws IOException {
writer.append("function $rt_intern(str) {").indent().softNewLine();
writer.append("return ").appendMethodBody(new MethodReference(String.class, "intern", String.class))
.append("(str);").softNewLine();
writer.outdent().append("}").newLine();
}
private void renderRuntimeObjcls() throws IOException {
writer.append("function $rt_objcls() { return ").appendClass("java.lang.Object").append("; }").newLine();
}
private void renderRuntimeThreads() throws IOException {
writer.append("function $rt_getThread()").ws().append("{").indent().softNewLine();
writer.append("return ").appendMethodBody(Thread.class, "currentThread", Thread.class).append("();")
.softNewLine();
writer.outdent().append("}").newLine();
writer.append("function $rt_setThread(t)").ws().append("{").indent().softNewLine();
writer.append("return ").appendMethodBody(Thread.class, "setCurrentThread", Thread.class, void.class)
.append("(t);").softNewLine();
writer.outdent().append("}").newLine();
}
}

View File

@ -0,0 +1,49 @@
/*
* Copyright 2018 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.backend.javascript.rendering;
import org.mozilla.javascript.Node;
import org.mozilla.javascript.ast.AstNode;
import org.mozilla.javascript.ast.AstRoot;
import org.mozilla.javascript.ast.Block;
import org.mozilla.javascript.ast.ExpressionStatement;
import org.mozilla.javascript.ast.NodeVisitor;
import org.mozilla.javascript.ast.Scope;
import org.mozilla.javascript.ast.StringLiteral;
public class StringConstantElimination implements NodeVisitor {
@Override
public boolean visit(AstNode astNode) {
if (astNode instanceof Block || astNode instanceof Scope || astNode instanceof AstRoot) {
handle(astNode);
}
return true;
}
private void handle(AstNode block) {
Node child = block.getFirstChild();
while (child != null) {
Node next = child.getNext();
if (child instanceof ExpressionStatement) {
ExpressionStatement statement = (ExpressionStatement) child;
if (statement.getExpression() instanceof StringLiteral) {
block.removeChild(child);
}
}
child = next;
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 Alexey Andreev.
* Copyright 2018 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.jso.plugin;
package org.teavm.backend.javascript.rendering;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.io.StringReader;
import org.junit.Test;
@ -25,8 +25,6 @@ import org.mozilla.javascript.Context;
import org.mozilla.javascript.ast.AstRoot;
import org.teavm.backend.javascript.codegen.SourceWriter;
import org.teavm.backend.javascript.codegen.SourceWriterBuilder;
import org.teavm.jso.impl.AstWriter;
import org.teavm.jso.impl.JSParser;
public class AstWriterTest {
private StringBuilder sb = new StringBuilder();

View File

@ -39,11 +39,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
<artifactId>teavm-jso-apis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@ -20,6 +20,7 @@ import org.mozilla.javascript.Node;
import org.mozilla.javascript.ast.AstNode;
import org.mozilla.javascript.ast.Block;
import org.teavm.backend.javascript.codegen.SourceWriter;
import org.teavm.backend.javascript.rendering.AstWriter;
import org.teavm.backend.javascript.rendering.Precedence;
import org.teavm.backend.javascript.spi.GeneratorContext;
import org.teavm.backend.javascript.spi.InjectorContext;
@ -30,7 +31,7 @@ class JSBodyAstEmitter implements JSBodyEmitter {
private AstNode ast;
private String[] parameterNames;
public JSBodyAstEmitter(boolean isStatic, AstNode ast, String[] parameterNames) {
JSBodyAstEmitter(boolean isStatic, AstNode ast, String[] parameterNames) {
this.isStatic = isStatic;
this.ast = ast;
this.parameterNames = parameterNames;

View File

@ -30,6 +30,7 @@ import org.mozilla.javascript.Context;
import org.mozilla.javascript.ast.AstNode;
import org.mozilla.javascript.ast.AstRoot;
import org.mozilla.javascript.ast.FunctionNode;
import org.teavm.backend.javascript.rendering.JSParser;
import org.teavm.cache.NoCache;
import org.teavm.diagnostics.Diagnostics;
import org.teavm.interop.Sync;

View File

@ -72,6 +72,7 @@
<jackson.version>2.6.2</jackson.version>
<idea.version>2017.3.5</idea.version>
<asm.version>6.1.1</asm.version>
<rhino.version>1.7.7</rhino.version>
<teavm.test.incremental>false</teavm.test.incremental>
<teavm.test.threads>1</teavm.test.threads>
@ -201,6 +202,11 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>${rhino.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -63,7 +63,6 @@
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.async.AsyncProgram</mainClass>
<runtime>SEPARATE</runtime>
<minifying>false</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>

View File

@ -18,7 +18,6 @@
<head>
<title>Continuation-passing style demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
<script type="text/javascript" charset="utf-8" src="teavm/stdout.js"></script>
<script type="text/javascript" charset="utf-8" src="highlight.pack.js"></script>

View File

@ -149,7 +149,6 @@
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.benchmark.teavm.BenchmarkStarter</mainClass>
<runtime>SEPARATE</runtime>
<minifying>true</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<optimizationLevel>FULL</optimizationLevel>

View File

@ -18,7 +18,6 @@
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>TeaVM jbox2d benchmark</title>
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
</head>
<body onload="main()">

View File

@ -76,7 +76,6 @@
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.hello.Client</mainClass>
<runtime>SEPARATE</runtime>
<minifying>false</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>

View File

@ -18,7 +18,6 @@
<head>
<title>Hello web application</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
</head>
<body onload="main()">

View File

@ -97,7 +97,6 @@
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.kotlin.HelloKt</mainClass>
<runtime>SEPARATE</runtime>
<minifying>false</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>

View File

@ -3,7 +3,6 @@
<head>
<title>Hello kotlin</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
</head>
<body onload="main()">

View File

@ -71,7 +71,6 @@
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.scala.Client</mainClass>
<runtime>SEPARATE</runtime>
<minifying>false</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>

View File

@ -3,7 +3,6 @@
<head>
<title>Hello Scala</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
<link rel="stylesheet" type="text/css" href="calculator.css">
</head>

View File

@ -18,7 +18,6 @@
<head>
<title>Web Storage web application</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
</head>
<body onload="main()">

View File

@ -76,7 +76,6 @@
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.video.Player</mainClass>
<runtime>SEPARATE</runtime>
<minifying>false</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>

View File

@ -18,7 +18,6 @@
<head>
<title>HTML5 Video web application</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

View File

@ -20,7 +20,6 @@ import * as http from "http";
import {server as WebSocketServer} from "websocket";
const TEST_FILE_NAME = "test.js";
const RUNTIME_FILE_NAME = "runtime.js";
const WASM_RUNTIME_FILE_NAME = "test.wasm-runtime.js";
const TEST_FILES = [
{ file: TEST_FILE_NAME, name: "simple", type: "js" },
@ -122,7 +121,7 @@ async function serveFile(path, response) {
async function walkDir(path, name, suite) {
const files = await fs.readdir(rootDir + "/" + path);
if (files.includes(WASM_RUNTIME_FILE_NAME) || files.includes(RUNTIME_FILE_NAME)) {
if (files.includes(WASM_RUNTIME_FILE_NAME) || files.includes("test.js")) {
for (const { file: fileName, name: profileName, type: type } of TEST_FILES) {
if (files.includes(fileName)) {
switch (type) {

View File

@ -46,7 +46,6 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.teavm.backend.wasm.render.WasmBinaryVersion;
import org.teavm.tooling.RuntimeCopyOperation;
import org.teavm.tooling.TeaVMTargetType;
import org.teavm.tooling.TeaVMTool;
import org.teavm.tooling.TeaVMToolException;
@ -231,22 +230,6 @@ public final class TeaVMRunner {
} else {
tool.setMinifying(false);
}
if (commandLine.hasOption("r")) {
switch (commandLine.getOptionValue("r")) {
case "separate":
tool.setRuntime(RuntimeCopyOperation.SEPARATE);
break;
case "merge":
tool.setRuntime(RuntimeCopyOperation.MERGED);
break;
case "none":
tool.setRuntime(RuntimeCopyOperation.NONE);
break;
default:
System.err.println("Wrong parameter for -r option specified");
printUsage();
}
}
}
private void parseDebugOptions() {

View File

@ -1,22 +0,0 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.tooling;
public enum RuntimeCopyOperation {
SEPARATE,
MERGED,
NONE
}

View File

@ -15,16 +15,14 @@
*/
package org.teavm.tooling;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -32,10 +30,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.io.IOUtils;
import org.teavm.backend.c.CTarget;
import org.teavm.backend.javascript.JavaScriptTarget;
import org.teavm.backend.javascript.rendering.RenderingManager;
import org.teavm.backend.wasm.WasmTarget;
import org.teavm.backend.wasm.render.WasmBinaryVersion;
import org.teavm.cache.DiskCachedClassHolderSource;
@ -65,7 +61,6 @@ import org.teavm.vm.TeaVMBuilder;
import org.teavm.vm.TeaVMOptimizationLevel;
import org.teavm.vm.TeaVMProgressListener;
import org.teavm.vm.TeaVMTarget;
import org.teavm.vm.spi.AbstractRendererListener;
public class TeaVMTool implements BaseTeaVMTool {
private File targetDirectory = new File(".");
@ -73,7 +68,6 @@ public class TeaVMTool implements BaseTeaVMTool {
private String targetFileName = "";
private boolean minifying = true;
private String mainClass;
private RuntimeCopyOperation runtime = RuntimeCopyOperation.SEPARATE;
private Properties properties = new Properties();
private boolean debugInformationGenerated;
private boolean sourceMapsFileGenerated;
@ -145,14 +139,6 @@ public class TeaVMTool implements BaseTeaVMTool {
this.mainClass = mainClass;
}
public RuntimeCopyOperation getRuntime() {
return runtime;
}
public void setRuntime(RuntimeCopyOperation runtime) {
this.runtime = runtime;
}
public boolean isDebugInformationGenerated() {
return debugInformationGenerated;
}
@ -407,9 +393,6 @@ public class TeaVMTool implements BaseTeaVMTool {
}
targetDirectory.mkdirs();
if (runtime == RuntimeCopyOperation.MERGED) {
javaScriptTarget.add(runtimeInjector);
}
BuildTarget buildTarget = new DirectoryBuildTarget(targetDirectory);
String outputName = getResolvedTargetFileName();
vm.build(buildTarget, outputName);
@ -495,7 +478,8 @@ public class TeaVMTool implements BaseTeaVMTool {
String sourceMapsFileName = getResolvedTargetFileName() + ".map";
writer.append("\n//# sourceMappingURL=").append(sourceMapsFileName);
File sourceMapsFile = new File(targetDirectory, sourceMapsFileName);
try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(sourceMapsFile), "UTF-8")) {
try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(sourceMapsFile),
StandardCharsets.UTF_8)) {
debugInfo.writeAsSourceMaps(sourceMapsOut, "src", getResolvedTargetFileName());
}
generatedFiles.add(sourceMapsFile);
@ -505,10 +489,6 @@ public class TeaVMTool implements BaseTeaVMTool {
copySourceFiles();
log.info("Source files successfully written");
}
if (runtime == RuntimeCopyOperation.SEPARATE) {
resourceToFile("org/teavm/backend/javascript/runtime.js", "runtime.js");
}
}
private void printStats() {
@ -536,30 +516,4 @@ public class TeaVMTool implements BaseTeaVMTool {
copier.setLog(log);
copier.copy(new File(targetDirectory, "src"));
}
private AbstractRendererListener runtimeInjector = new AbstractRendererListener() {
@Override
public void begin(RenderingManager manager, BuildTarget buildTarget) throws IOException {
StringWriter writer = new StringWriter();
resourceToWriter("org/teavm/backend/javascript/runtime.js", writer);
writer.close();
manager.getWriter().append(writer.toString()).newLine();
}
};
private void resourceToFile(String resource, String fileName) throws IOException {
try (InputStream input = TeaVMTool.class.getClassLoader().getResourceAsStream(resource)) {
File outputFile = new File(targetDirectory, fileName);
try (OutputStream output = new BufferedOutputStream(new FileOutputStream(outputFile))) {
IOUtils.copy(new BufferedInputStream(input), output);
}
generatedFiles.add(outputFile);
}
}
private void resourceToWriter(String resource, Writer writer) throws IOException {
try (InputStream input = TeaVMTool.class.getClassLoader().getResourceAsStream(resource)) {
IOUtils.copy(new BufferedInputStream(input), writer, "UTF-8");
}
}
}

View File

@ -23,7 +23,6 @@ import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
import org.teavm.eclipse.TeaVMEclipsePlugin;
import org.teavm.eclipse.TeaVMProfile;
import org.teavm.eclipse.TeaVMProjectSettings;
import org.teavm.eclipse.TeaVMRuntimeMode;
public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
private static final String TOOL_ID = "teavm-eclipse-m2e-plugin.tool";
@ -88,7 +87,7 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
private void configureProfile(MojoExecution execution, TeaVMProfile profile, IProgressMonitor monitor)
throws CoreException {
monitor.beginTask("Configuring profile " + profile.getName(), 110);
monitor.beginTask("Configuring profile " + profile.getName(), 100);
String buildDir = getProjectBuildDirectory();
String mainClass = maven.getMojoParameterValue(mavenSession, execution, "mainClass", String.class);
@ -104,10 +103,6 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
profile.setTargetFileName(targetFileName != null ? targetFileName : "classes.js");
monitor.worked(10);
String runtime = maven.getMojoParameterValue(mavenSession, execution, "runtime", String.class);
profile.setRuntimeMode(runtime != null ? getRuntimeMode(runtime) : TeaVMRuntimeMode.SEPARATE);
monitor.worked(10);
Properties properties = maven.getMojoParameterValue(mavenSession, execution, "properties", Properties.class);
profile.setProperties(properties != null ? properties : new Properties());
monitor.worked(10);
@ -184,19 +179,6 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
return varManager.generateVariableExpression("workspace_loc", path) + suffix;
}
private TeaVMRuntimeMode getRuntimeMode(String name) {
switch (name) {
case "SEPARATE":
return TeaVMRuntimeMode.SEPARATE;
case "MERGED":
return TeaVMRuntimeMode.MERGE;
case "NONE":
return TeaVMRuntimeMode.NONE;
default:
return TeaVMRuntimeMode.NONE;
}
}
private String getIdForProfile(MojoExecution pluginExecution) {
String executionId = pluginExecution.getExecutionId();
if (executionId != null && usedExecutionIds.add(executionId)) {

View File

@ -32,7 +32,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
public static final String MAIN_CLASS = "mainClass";
public static final String TARGET_DIRECTORY = "targetDirectory";
public static final String TARGET_FILE_NAME = "targetFileName";
public static final String RUNTIME = "runtime";
public static final String MINIFYING = "minifying";
public static final String INCREMENTAL = "incremental";
public static final String CACHE_DIRECTORY = "cacheDirectory";
@ -155,7 +154,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
private String mainClass;
private String targetDirectory;
private String targetFileName;
private TeaVMRuntimeMode runtimeMode = TeaVMRuntimeMode.SEPARATE;
private boolean incremental;
private String cacheDirectory;
private boolean sourceMapsGenerated;
@ -222,16 +220,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
this.targetFileName = targetFileName;
}
@Override
public TeaVMRuntimeMode getRuntimeMode() {
return runtimeMode;
}
@Override
public void setRuntimeMode(TeaVMRuntimeMode runtimeMode) {
this.runtimeMode = runtimeMode;
}
@Override
public boolean isIncremental() {
return incremental;
@ -332,7 +320,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
mainClass = preferences.get(MAIN_CLASS, "");
targetDirectory = preferences.get(TARGET_DIRECTORY, "");
targetFileName = preferences.get(TARGET_FILE_NAME, "");
runtimeMode = TeaVMRuntimeMode.valueOf(preferences.get(RUNTIME, TeaVMRuntimeMode.SEPARATE.name()));
incremental = preferences.getBoolean(INCREMENTAL, false);
cacheDirectory = preferences.get(CACHE_DIRECTORY, "");
sourceMapsGenerated = preferences.getBoolean(SOURCE_MAPS, true);
@ -357,7 +344,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
preferences.put(MAIN_CLASS, mainClass);
preferences.put(TARGET_DIRECTORY, targetDirectory);
preferences.put(TARGET_FILE_NAME, targetFileName);
preferences.put(RUNTIME, runtimeMode.name());
preferences.putBoolean(INCREMENTAL, incremental);
preferences.put(CACHE_DIRECTORY, cacheDirectory);
preferences.putBoolean(SOURCE_MAPS, sourceMapsGenerated);

View File

@ -39,10 +39,6 @@ public interface TeaVMProfile {
void setTargetFileName(String targetFileName);
TeaVMRuntimeMode getRuntimeMode();
void setRuntimeMode(TeaVMRuntimeMode runtimeMode);
boolean isIncremental();
void setIncremental(boolean incremental);

View File

@ -70,7 +70,6 @@ import org.teavm.model.FieldReference;
import org.teavm.model.MethodReference;
import org.teavm.model.TextLocation;
import org.teavm.model.ValueType;
import org.teavm.tooling.RuntimeCopyOperation;
import org.teavm.tooling.TeaVMTool;
import org.teavm.tooling.TeaVMToolException;
import org.teavm.tooling.sources.DirectorySourceFileProvider;
@ -152,7 +151,6 @@ public class TeaVMProjectBuilder extends IncrementalProjectBuilder {
tool.setTargetDirectory(new File(varManager.performStringSubstitution(targetDir, false)));
tool.setTargetFileName(profile.getTargetFileName());
tool.setMinifying(false);
tool.setRuntime(mapRuntime(profile.getRuntimeMode()));
tool.setMainClass(profile.getMainClass());
tool.getProperties().putAll(profile.getProperties());
tool.setIncremental(profile.isIncremental());
@ -209,17 +207,6 @@ public class TeaVMProjectBuilder extends IncrementalProjectBuilder {
}
}
private RuntimeCopyOperation mapRuntime(TeaVMRuntimeMode runtimeMode) {
switch (runtimeMode) {
case MERGE:
return RuntimeCopyOperation.MERGED;
case SEPARATE:
return RuntimeCopyOperation.SEPARATE;
default:
return RuntimeCopyOperation.NONE;
}
}
private void classesToResources(ProfileData profileData, TeaVMTool tool) {
Set<String> resourcePaths = new HashSet<>();
for (String className : tool.getClasses()) {

View File

@ -1,22 +0,0 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse;
public enum TeaVMRuntimeMode {
SEPARATE,
MERGE,
NONE
}

View File

@ -66,11 +66,8 @@ import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.ui.views.navigator.ResourceComparator;
import org.teavm.eclipse.TeaVMProfile;
import org.teavm.eclipse.TeaVMProjectSettings;
import org.teavm.eclipse.TeaVMRuntimeMode;
public class TeaVMProfileDialog extends Dialog {
private static List<TeaVMRuntimeMode> runtimeModes = Arrays.asList(TeaVMRuntimeMode.SEPARATE,
TeaVMRuntimeMode.MERGE, TeaVMRuntimeMode.NONE);
private TabFolder tabFolder;
private Text nameField;
private Text mainClassField;
@ -79,7 +76,6 @@ public class TeaVMProfileDialog extends Dialog {
private Button targetDirectoryWorkspaceButton;
private Button targetDirectoryFileSystemButton;
private Text targetFileNameField;
private Combo runtimeField;
private Button incrementalButton;
private Text cacheDirectoryField;
private Button cacheDirectoryWorkspaceButton;
@ -176,7 +172,6 @@ public class TeaVMProfileDialog extends Dialog {
Group group = createGroup(parent, "Output settings", 4, false);
createTargetDirectoryField(group);
createTargetFileNameField(group);
createRuntimeField(group);
}
private void createIncrementalGroup(Composite parent) {
@ -425,17 +420,6 @@ public class TeaVMProfileDialog extends Dialog {
targetFileNameField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
}
private void createRuntimeField(Composite container) {
Label label = new Label(container, SWT.NONE);
label.setText("Attach &runtime:");
runtimeField = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
runtimeField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
runtimeField.add("as a separate file (runtime.js)");
runtimeField.add("merge into output file");
runtimeField.add("don't attach");
}
private void createIncrementalField(Composite container) {
incrementalButton = new Button(container, SWT.CHECK);
incrementalButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
@ -626,7 +610,6 @@ public class TeaVMProfileDialog extends Dialog {
mainClassField.setText(profile.getMainClass() != null ? profile.getMainClass() : "");
targetDirectoryField.setText(profile.getTargetDirectory());
targetFileNameField.setText(profile.getTargetFileName());
runtimeField.select(runtimeModes.indexOf(profile.getRuntimeMode()));
incrementalButton.setSelection(profile.isIncremental());
cacheDirectoryField.setText(profile.getCacheDirectory());
debugInformationButton.setSelection(profile.isDebugInformationGenerated());
@ -663,7 +646,6 @@ public class TeaVMProfileDialog extends Dialog {
profile.setMainClass(!mainClass.isEmpty() ? mainClass : null);
profile.setTargetDirectory(targetDirectoryField.getText());
profile.setTargetFileName(targetFileNameField.getText().trim());
profile.setRuntimeMode(runtimeModes.get(runtimeField.getSelectionIndex()));
profile.setIncremental(incrementalButton.getSelection());
profile.setCacheDirectory(cacheDirectoryField.getText());
profile.setDebugInformationGenerated(debugInformationButton.getSelection());

View File

@ -58,7 +58,6 @@ class HtmlUnitRunStrategy implements TestRunStrategy {
} catch (IOException e) {
throw new RuntimeException(e);
}
page.get().executeJavaScript(readFile(new File(run.getBaseDirectory(), "runtime.js")));
page.get().executeJavaScript(readFile(new File(run.getBaseDirectory(), run.getFileName())));
AsyncResult asyncResult = new AsyncResult();

View File

@ -424,7 +424,6 @@ public class TeaVMTestRunner extends Runner implements Filterable {
}
private void copyJsFilesTo(File path) throws IOException {
resourceToFile("org/teavm/backend/javascript/runtime.js", new File(path, "runtime.js"));
resourceToFile("org/teavm/backend/wasm/wasm-runtime.js", new File(path, "test.wasm-runtime.js"));
resourceToFile("teavm-run-test.html", new File(path, "run-test.html"));
resourceToFile("teavm-run-test-wasm.html", new File(path, "run-test-wasm.html"));

View File

@ -5,7 +5,6 @@
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<script type="text/javascript" src="runtime.js"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript">
$rt_startThread(function() {

View File

@ -25,7 +25,6 @@ import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.teavm.backend.wasm.render.WasmBinaryVersion;
import org.teavm.tooling.RuntimeCopyOperation;
import org.teavm.tooling.TeaVMTargetType;
import org.teavm.tooling.TeaVMTool;
import org.teavm.tooling.TeaVMToolException;
@ -55,9 +54,6 @@ public class TeaVMCompileMojo extends AbstractTeaVMMojo {
@Parameter
private boolean stopOnErrors = true;
@Parameter
protected RuntimeCopyOperation runtime = RuntimeCopyOperation.SEPARATE;
@Parameter
private TeaVMOptimizationLevel optimizationLevel = TeaVMOptimizationLevel.SIMPLE;
@ -84,7 +80,6 @@ public class TeaVMCompileMojo extends AbstractTeaVMMojo {
tool.setLog(new MavenTeaVMToolLog(log));
try {
tool.setMainClass(mainClass);
tool.setRuntime(runtime);
if (!targetFileName.isEmpty()) {
tool.setTargetFileName(targetFileName);
}