mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fix bugs
This commit is contained in:
parent
04342d15e7
commit
7e23498c5b
|
@ -286,7 +286,7 @@ public class TObject {
|
|||
@Override
|
||||
public void onTimer() {
|
||||
if (!expired()) {
|
||||
Platform.postpone(this);
|
||||
run();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ public class TThread extends TObject implements TRunnable {
|
|||
private long id;
|
||||
private int priority = 0;
|
||||
private long timeSliceStart;
|
||||
private int yieldCount;
|
||||
|
||||
private TString name;
|
||||
TRunnable target;
|
||||
|
@ -101,6 +102,10 @@ public class TThread extends TObject implements TRunnable {
|
|||
}
|
||||
|
||||
public static void yield() {
|
||||
if (++currentThread.yieldCount < 30) {
|
||||
return;
|
||||
}
|
||||
currentThread.yieldCount = 0;
|
||||
if (currentThread.timeSliceStart + 100 < System.currentTimeMillis()) {
|
||||
switchContext(currentThread);
|
||||
}
|
||||
|
@ -146,12 +151,13 @@ public class TThread extends TObject implements TRunnable {
|
|||
|
||||
private static void sleep(long millis, final AsyncCallback<Void> callback) {
|
||||
final TThread current = currentThread();
|
||||
window.setTimeout(new TimerHandler() {
|
||||
@Override public void onTimer() {
|
||||
int intMillis = millis < Integer.MAX_VALUE ? (int)millis : Integer.MAX_VALUE;
|
||||
Platform.schedule(new PlatformRunnable() {
|
||||
@Override public void run() {
|
||||
setCurrentThread(current);
|
||||
callback.complete(null);
|
||||
}
|
||||
}, millis);
|
||||
}, intMillis);
|
||||
}
|
||||
|
||||
public final void setPriority(int newPriority){
|
||||
|
|
|
@ -264,6 +264,7 @@ public class Decompiler {
|
|||
generator.indexer = indexer;
|
||||
parentNode = codeTree.getRoot();
|
||||
currentNode = parentNode.getFirstChild();
|
||||
boolean saved = !async;
|
||||
for (int i = 0; i < this.graph.size(); ++i) {
|
||||
Block block = stack.peek();
|
||||
while (block.end == i) {
|
||||
|
@ -292,7 +293,6 @@ public class Decompiler {
|
|||
if (head != -1 && loopSuccessors[head] == next) {
|
||||
next = head;
|
||||
}
|
||||
boolean saved = !async;
|
||||
if (node >= 0) {
|
||||
generator.currentBlock = program.basicBlockAt(node);
|
||||
int tmp = indexer.nodeAt(next);
|
||||
|
|
|
@ -699,7 +699,11 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
|||
|
||||
writer.append("function $save()").ws().append("{").indent().softNewLine();
|
||||
writer.append("$rt_nativeThread()");
|
||||
for (int i = ref.parameterCount() + 1; i < variableCount; ++i) {
|
||||
int firstToSave = 0;
|
||||
if (methodNode.getModifiers().contains(NodeModifier.STATIC)) {
|
||||
firstToSave = 1;
|
||||
}
|
||||
for (int i = firstToSave; i < variableCount; ++i) {
|
||||
writer.append(".push(").append(variableName(i)).append(")");
|
||||
}
|
||||
writer.append(".push($ptr);");
|
||||
|
@ -710,7 +714,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
|||
writer.append("if").ws().append("($rt_resuming())").ws().append("{").indent().softNewLine();
|
||||
writer.append("var $T").ws().append('=').ws().append("$rt_nativeThread();").softNewLine();
|
||||
writer.append("$ptr").ws().append('=').ws().append("$T.pop();");
|
||||
for (int i = variableCount - 1; i > ref.parameterCount(); --i) {
|
||||
for (int i = variableCount - 1; i >= firstToSave; --i) {
|
||||
writer.append(variableName(i)).ws().append('=').ws().append("$T.pop();");
|
||||
}
|
||||
writer.softNewLine();
|
||||
|
@ -1990,9 +1994,6 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
|||
writer.appendMethodBody(monitorEnterRef).append("(");
|
||||
statement.getObjectRef().acceptVisitor(this);
|
||||
writer.append(");").softNewLine();
|
||||
writer.append("if").ws().append("($rt_suspending())").ws().append("{").indent().softNewLine();
|
||||
writer.append("return $save();").softNewLine();
|
||||
writer.outdent().append("}").softNewLine();
|
||||
} else {
|
||||
MethodReference monitorEnterRef = new MethodReference(
|
||||
Object.class, "monitorEnterSync", Object.class, void.class);
|
||||
|
|
|
@ -479,11 +479,16 @@ TeaVMThread.prototype.resume = function() {
|
|||
}
|
||||
TeaVMThread.prototype.run = function() {
|
||||
$rt_currentNativeThread = this;
|
||||
this.runner();
|
||||
$rt_currentNativeThread = null;
|
||||
try {
|
||||
this.runner();
|
||||
} finally {
|
||||
$rt_currentNativeThread = null;
|
||||
}
|
||||
if (this.suspendCallback !== null) {
|
||||
var self = this;
|
||||
this.suspendCallback(function() {
|
||||
var callback = this.suspendCallback;
|
||||
this.suspendCallback = null;
|
||||
callback(function() {
|
||||
self.resume();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user