Skip to content

Commit

Permalink
#89 Super call with overriden method results in infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkosertic committed Jan 25, 2019
1 parent be27579 commit 98de2f4
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 269 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ public void optimize(final ControlFlowGraph aGraph, final BytecodeLinkerContext
theOptimizer.add(new RedundantVariablesOptimizer());
theOptimizer.add(new InlineFinalNodesOptimizer());
theOptimizer.add(new InvokeVirtualOptimizer());
// theOptimizer.add(new InlineGotoOptimizer());
run(aGraph, aLinkerContext, theOptimizer);
}
},

EXPERIMENTAL {
@Override
public void optimize(final ControlFlowGraph aGraph, final BytecodeLinkerContext aLinkerContext) {
ALL.optimize(aGraph, aLinkerContext);
final List<Optimizer> theOptimizer = new ArrayList<>();
theOptimizer.add(ALL);
run(aGraph, aLinkerContext, theOptimizer);
}
};
Expand Down
24 changes: 23 additions & 1 deletion core/src/test/java/de/mirkosertic/bytecoder/complex/LuaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public void testCallStringResult() throws IOException {
LuaC.install(theGlobals);
final Prototype thePrototype = theGlobals.compilePrototype(new StringReader("function add(a,b) return 'hello' end"), "script");
new LuaClosure(thePrototype, theGlobals).call();
final LuaValue theFunction = theGlobals.get("add");
final Varargs theArguments = LuaValue.varargsOf(new LuaValue[] {
LuaInteger.valueOf(100),
LuaInteger.valueOf(200)
});
final LuaValue theFunction = theGlobals.get("add");
final LuaValue theValue = (LuaValue) theFunction.invoke(theArguments);
Assert.assertTrue(theValue.isstring());
Assert.assertEquals("hello", theValue.tojstring());
Expand All @@ -131,4 +131,26 @@ public void testLuaTable() {
theTable.set("20", 200);
Assert.assertEquals(200, theTable.get("20").toint(), 0);
}

@Test
public void testLuaConversion() {
final Globals theGlobals = new Globals();
LuaC.install(theGlobals);
theGlobals.set("key", 10);
Assert.assertEquals(10, theGlobals.get("key").toint());
Assert.assertEquals(10, theGlobals.get(LuaString.valueOf("key")).toint());

final LuaValue chunk = theGlobals.load("return key").call();
Assert.assertEquals(10, chunk.toint());
}

@Test
public void testGlobalSize() {
final Globals theGlobals = new Globals();
for (int i =0;i<=100;i++) {
theGlobals.set("ABC", Integer.toString(i));
}
theGlobals.presize(1000);
Assert.assertEquals(100, theGlobals.get("ABC").toint(),0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2019 Mirko Sertic
*
* 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 de.mirkosertic.bytecoder.core;

import de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.HashMap;
import java.util.Map;

@RunWith(BytecoderUnitTestRunner.class)
public class MethodOverwriteCallTest {

public class Parent {

Map<String, Object> data = new HashMap<>();

public void add(final String key, final String aValue) {
data.remove(key);
}

public void add(final String aKey, final Object aValue) {
add(aKey, aValue.toString());
}
}

public class Child extends Parent {

public void add(final String aKey, final String aValue) {
data.put(aKey, aValue);
}

public Object get(final String aValue) {
return data.get(aValue);
}
}

@Test
public void testCall() {
final Child c = new Child();
c.add("key", Integer.valueOf(10));
Assert.assertEquals("10", c.get("key"));
}
}

This file was deleted.

0 comments on commit 98de2f4

Please sign in to comment.