Remove $rt_global and indirect references to runtime function

This commit is contained in:
Alexey Andreev 2018-10-27 22:42:25 +03:00
parent 149775dd95
commit 63b2440e48
6 changed files with 14 additions and 72 deletions

View File

@ -19,15 +19,18 @@ import org.teavm.classlib.java.io.TIOException;
import org.teavm.classlib.java.io.TOutputStream;
import org.teavm.interop.DelegateTo;
import org.teavm.interop.Import;
import org.teavm.platform.Platform;
import org.teavm.jso.JSBody;
class TConsoleOutputStreamStderr extends TOutputStream {
@Override
@DelegateTo("writeLowLevel")
public void write(int b) throws TIOException {
Platform.getConsole().error(b);
writeJs(b);
}
@JSBody(params = "b", script = "$rt_putStderr(b);")
private static native void writeJs(int b);
private void writeLowLevel(int b) {
writeImpl(b);
}

View File

@ -18,15 +18,18 @@ package org.teavm.classlib.java.lang;
import org.teavm.classlib.java.io.TIOException;
import org.teavm.classlib.java.io.TOutputStream;
import org.teavm.interop.DelegateTo;
import org.teavm.platform.Platform;
import org.teavm.jso.JSBody;
class TConsoleOutputStreamStdout extends TOutputStream {
@Override
@DelegateTo("writeLowLevel")
public void write(int b) throws TIOException {
Platform.getConsole().output(b);
writeJs(b);
}
@JSBody(params = "b", script = "$rt_putStdout(b);")
private static native void writeJs(int b);
private void writeLowLevel(int b) {
TConsoleOutputStreamStderr.writeImpl(b);
}

View File

@ -14,7 +14,6 @@
* limitations under the License.
*/
"use strict";
var $rt_global = this;
var $rt_seed = 2463534242;
function $rt_nextId() {
var x = $rt_seed;

View File

@ -24,6 +24,8 @@ import org.teavm.interop.DelegateTo;
import org.teavm.interop.Unmanaged;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;
import org.teavm.jso.browser.Window;
import org.teavm.jso.core.JSString;
import org.teavm.platform.metadata.ClassResource;
import org.teavm.platform.metadata.StaticFieldResource;
import org.teavm.platform.plugin.PlatformGenerator;
@ -84,10 +86,6 @@ public final class Platform {
@Unmanaged
public static native Class<?> asJavaClass(PlatformObject obj);
public static PlatformConsole getConsole() {
return (PlatformConsole) getGlobal();
}
@JSBody(script = "return $rt_nextId();")
public static native int nextObjectId();
@ -191,14 +189,14 @@ public final class Platform {
public static native int schedule(PlatformRunnable runnable, int timeout);
public static void killSchedule(int id) {
((PlatformHelper) getGlobal()).killSchedule(id);
Window.clearTimeout(id);
}
@JSBody(script = "return [];")
public static native <T> PlatformQueue<T> createQueue();
public static PlatformString stringFromCharCode(int charCode) {
return ((PlatformHelper) getGlobal()).getStringClass().fromCharCode(charCode);
return JSString.fromCharCode(charCode).cast();
}
@DelegateTo("isPrimitiveLowLevel")
@ -231,7 +229,4 @@ public final class Platform {
public static String getName(PlatformClass cls) {
return cls.getMetadata().getName();
}
@JSBody(script = "return $rt_global;")
private static native JSObject getGlobal();
}

View File

@ -1,27 +0,0 @@
/*
* Copyright 2015 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.platform;
import org.teavm.jso.JSMethod;
import org.teavm.jso.JSObject;
public interface PlatformConsole extends JSObject {
@JSMethod("$rt_putStdout")
void output(int b);
@JSMethod("$rt_putStderr")
void error(int b);
}

View File

@ -1,31 +0,0 @@
/*
* Copyright 2015 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.platform;
import org.teavm.jso.JSMethod;
import org.teavm.jso.JSObject;
import org.teavm.jso.JSProperty;
interface PlatformHelper extends JSObject {
@JSMethod("$rt_nextId")
int nextId();
@JSProperty("String")
PlatformStringClass getStringClass();
@JSMethod("clearTimeout")
void killSchedule(int scheduleId);
}