mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Merged with latest async branch. Also added MonitorExitInstruction and MonitorEnterInstruction classes, and updated all associated visitors. These don't do anything yet though.
This commit is contained in:
parent
d84889798c
commit
cca4336a15
|
@ -127,13 +127,12 @@ public class ObjectNativeGenerator implements Generator, Injector, DependencyPlu
|
|||
writer.append("(function(){").indent().softNewLine();
|
||||
writer.append("var completed = false;").softNewLine();
|
||||
writer.append("var retCallback = ").append(context.getCompleteContinuation()).append(";").softNewLine();
|
||||
writer.append("console.log(retCallback);").softNewLine();
|
||||
writer.append("var callback = function(){").indent().softNewLine();
|
||||
writer.append("if (completed){return;} completed=true;").softNewLine();
|
||||
writer.append("retCallback();").softNewLine();
|
||||
writer.append("retCallback($rt_asyncResult(null));").softNewLine();
|
||||
writer.outdent().append("};").softNewLine();
|
||||
writer.append("if (").append(pname).append(">0){").indent().softNewLine();
|
||||
writer.append("setTimeout(callback, ").append(pname).append(");").softNewLine();
|
||||
writer.append("$rt_setTimeout(callback, ").append(pname).append(");").softNewLine();
|
||||
writer.outdent().append("}").softNewLine();
|
||||
addNotifyListener(context, writer, "callback");
|
||||
writer.outdent().append("})();").softNewLine();
|
||||
|
@ -162,18 +161,16 @@ public class ObjectNativeGenerator implements Generator, Injector, DependencyPlu
|
|||
|
||||
private void sendNotify(GeneratorContext context, SourceWriter writer) throws IOException {
|
||||
String lArr = getNotifyListeners(context);
|
||||
writer.append("setTimeout(function(){").indent().softNewLine();
|
||||
writer.append("$rt_setTimeout(function(){").indent().softNewLine();
|
||||
writer.append("if (!").append(lArr).append(" || ").append(lArr).append(".length===0){return;}").softNewLine();
|
||||
writer.append("var m = ").append(lArr).append(".shift();").softNewLine();
|
||||
writer.append("console.log('Notify callback : '+m);").softNewLine();
|
||||
writer.append("m.apply(null);").softNewLine();
|
||||
writer.append(lArr).append(".shift().apply(null);").softNewLine();
|
||||
writer.outdent().append("}, 0);").softNewLine();
|
||||
}
|
||||
|
||||
private void sendNotifyAll(GeneratorContext context, SourceWriter writer) throws IOException {
|
||||
String obj = context.getParameterName(0);
|
||||
String lArr = getNotifyListeners(context);
|
||||
writer.append("setTimeout(function(){").indent().softNewLine();
|
||||
writer.append("$rt_setTimeout(function(){").indent().softNewLine();
|
||||
writer.append("if (!").append(lArr).append("){return;}").softNewLine();
|
||||
writer.append("while (").append(lArr).append(".length>0){").indent().softNewLine();
|
||||
writer.append(lArr).append(".shift().call(null);").softNewLine();
|
||||
|
|
|
@ -58,20 +58,20 @@ public class ThreadNativeGenerator implements Generator, DependencyPlugin {
|
|||
}
|
||||
|
||||
private void generateSleep(GeneratorContext context, SourceWriter writer) throws IOException {
|
||||
writer.append("setTimeout(function() {").indent().softNewLine();
|
||||
writer.append("$rt_setTimeout(function() {").indent().softNewLine();
|
||||
writer.append(context.getCompleteContinuation()).append("($rt_asyncResult(null));").softNewLine();
|
||||
writer.outdent().append("},").ws().append(context.getParameterName(1)).append(");").softNewLine();
|
||||
}
|
||||
|
||||
private void generateYield(GeneratorContext context, SourceWriter writer) throws IOException {
|
||||
writer.append("setTimeout(function() {").indent().softNewLine();
|
||||
writer.append("$rt_setTimeout(function() {").indent().softNewLine();
|
||||
writer.append(context.getCompleteContinuation()).append("($rt_asyncResult(null));").softNewLine();
|
||||
writer.outdent().append("},").ws().append("0);").softNewLine();
|
||||
}
|
||||
|
||||
private void generateStart(GeneratorContext context, SourceWriter writer) throws IOException {
|
||||
String obj = context.getParameterName(0);
|
||||
writer.append("setTimeout(function() { $rt_rootInvocationAdapter(").appendMethodBody(launchRef).append(")(")
|
||||
writer.append("$rt_setTimeout(function() { $rt_rootInvocationAdapter(").appendMethodBody(launchRef).append(")(")
|
||||
.append(obj).append(");},0);").softNewLine();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,5 +153,15 @@ public class DiskProgramCache implements ProgramCache {
|
|||
@Override public void visit(IsInstanceInstruction insn) { }
|
||||
@Override public void visit(InitClassInstruction insn) { }
|
||||
@Override public void visit(NullCheckInstruction insn) { }
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -594,6 +594,16 @@ public class ProgramIO {
|
|||
throw new IOExceptionWrapper(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static class IOExceptionWrapper extends RuntimeException {
|
||||
|
|
|
@ -666,4 +666,14 @@ class StatementGenerator implements InstructionVisitor {
|
|||
public void visit(NullCheckInstruction insn) {
|
||||
assign(Expr.unary(UnaryOperation.NULL_CHECK, Expr.var(insn.getValue().getIndex())), insn.getReceiver());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,4 +201,14 @@ class InstructionReadVisitor implements InstructionVisitor {
|
|||
public void visit(NullCheckInstruction insn) {
|
||||
reader.nullCheck(insn.getReceiver(), insn.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,4 +87,8 @@ public interface InstructionVisitor {
|
|||
void visit(InitClassInstruction insn);
|
||||
|
||||
void visit(NullCheckInstruction insn);
|
||||
|
||||
void visit(MonitorEnterInstruction insn);
|
||||
|
||||
void visit(MonitorExitInstruction insn);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2013 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.model.instructions;
|
||||
|
||||
import org.teavm.model.Instruction;
|
||||
import org.teavm.model.Variable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author shannah
|
||||
*/
|
||||
public class MonitorEnterInstruction extends Instruction {
|
||||
|
||||
private Variable objectRef;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void acceptVisitor(InstructionVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the objectRef
|
||||
*/
|
||||
public Variable getObjectRef() {
|
||||
return objectRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param objectRef the objectRef to set
|
||||
*/
|
||||
public void setObjectRef(Variable objectRef) {
|
||||
this.objectRef = objectRef;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright 2013 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.model.instructions;
|
||||
|
||||
import org.teavm.model.Instruction;
|
||||
import org.teavm.model.Variable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author shannah
|
||||
*/
|
||||
public class MonitorExitInstruction extends Instruction {
|
||||
|
||||
private Variable objectRef;
|
||||
|
||||
@Override
|
||||
public void acceptVisitor(InstructionVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the objectRef
|
||||
*/
|
||||
public Variable getObjectRef() {
|
||||
return objectRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param objectRef the objectRef to set
|
||||
*/
|
||||
public void setObjectRef(Variable objectRef) {
|
||||
this.objectRef = objectRef;
|
||||
}
|
||||
|
||||
}
|
|
@ -184,4 +184,18 @@ public abstract class BasicBlockMapper implements InstructionVisitor {
|
|||
@Override
|
||||
public void visit(NullCheckInstruction insn) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -202,4 +202,14 @@ public class DefinitionExtractor implements InstructionVisitor {
|
|||
public void visit(NullCheckInstruction insn) {
|
||||
definedVariables = new Variable[] { insn.getReceiver() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,4 +204,14 @@ public class InstructionTransitionExtractor implements InstructionVisitor {
|
|||
public void visit(NullCheckInstruction insn) {
|
||||
targets = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
targets = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
targets = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,4 +228,18 @@ public abstract class InstructionVariableMapper implements InstructionVisitor {
|
|||
insn.setReceiver(map(insn.getReceiver()));
|
||||
insn.setValue(map(insn.getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -310,5 +310,15 @@ public class MissingItemsProcessor {
|
|||
@Override
|
||||
public void visit(EmptyInstruction insn) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -206,4 +206,14 @@ public class UsageExtractor implements InstructionVisitor {
|
|||
public void visit(NullCheckInstruction insn) {
|
||||
usedVariables = new Variable[] { insn.getValue() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
usedVariables = new Variable[] {insn.getObjectRef() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
usedVariables = new Variable[] {insn.getObjectRef()};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -418,5 +418,15 @@ public class GlobalValueNumbering implements MethodOptimization {
|
|||
insn.setValue(program.variableAt(val));
|
||||
bind(insn.getReceiver().getIndex(), "nullCheck @" + val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -379,6 +379,16 @@ public class LoopInvariantMotion implements MethodOptimization {
|
|||
public void visit(NullCheckInstruction insn) {
|
||||
canMove = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private class CopyConstantVisitor implements InstructionVisitor {
|
||||
|
@ -561,5 +571,15 @@ public class LoopInvariantMotion implements MethodOptimization {
|
|||
@Override
|
||||
public void visit(NullCheckInstruction insn) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,5 +248,15 @@ public class UnusedVariableElimination implements MethodOptimization {
|
|||
public void visit(NullCheckInstruction insn) {
|
||||
requestUsage(insn.getReceiver());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,5 +204,15 @@ public final class VariableEscapeAnalyzer {
|
|||
@Override
|
||||
public void visit(NullCheckInstruction insn) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -210,5 +210,15 @@ public final class VariableUsageGraphBuilder {
|
|||
public void visit(NullCheckInstruction insn) {
|
||||
use(insn.getReceiver(), insn.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,4 +284,14 @@ public class ClassRefsRenamer implements InstructionVisitor {
|
|||
@Override
|
||||
public void visit(NullCheckInstruction insn) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -447,5 +447,15 @@ public class SSATransformer {
|
|||
insn.setValue(use(insn.getValue()));
|
||||
insn.setReceiver(define(insn.getReceiver()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorEnterInstruction insn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MonitorExitInstruction insn) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -430,8 +430,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
|||
|
||||
|
||||
// Keep track of current running thread by overriding setTimeout
|
||||
sourceWriter.append("self.old_setTimeout=self.setTimeout;").softNewLine();
|
||||
sourceWriter.append("self.setTimeout=function(f,interval){").indent().softNewLine();
|
||||
sourceWriter.append("function $rt_setTimeout(f,interval){").indent().softNewLine();
|
||||
MethodReference currentThreadRef = new MethodReference(
|
||||
Thread.class, "currentThread", Thread.class);
|
||||
MethodReference setCurrentThreadRef = new MethodReference(
|
||||
|
@ -445,7 +444,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
|||
sourceWriter.appendMethodBody(setCurrentThreadRef).append("(").
|
||||
appendMethodBody(getMainThreadRef).append("());}").softNewLine();
|
||||
sourceWriter.outdent().append("};").softNewLine();
|
||||
sourceWriter.append("self.old_setTimeout(callback, interval);").softNewLine();
|
||||
sourceWriter.append("setTimeout(callback, interval);").softNewLine();
|
||||
sourceWriter.outdent().append("};").softNewLine();
|
||||
|
||||
// END Thread stuff
|
||||
|
|
|
@ -416,7 +416,7 @@ function $rt_asyncAdapter(f) {
|
|||
return $return($rt_asyncResult(result));
|
||||
}
|
||||
}
|
||||
function $rt_rootInvocationAdapter(f) {
|
||||
function $rt_rootInvocationAdapter(f, extraArgs) {
|
||||
return function() {
|
||||
var args = Array.prototype.slice.apply(arguments);
|
||||
if (extraArgs) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user