Fix some bugs

This commit is contained in:
konsoletyper 2015-02-09 23:04:02 +04:00
parent dd25ae4759
commit 71195c04ce
9 changed files with 20 additions and 119 deletions

View File

@ -64,8 +64,9 @@ public class TObject {
.getPlatformClass().getMetadata().getArrayItem() == null) { .getPlatformClass().getMetadata().getArrayItem() == null) {
throw new TCloneNotSupportedException(); throw new TCloneNotSupportedException();
} }
Platform.getPlatformObject(this).setId(Platform.nextObjectId()); Object result = Platform.clone(this);
return Platform.clone(this); Platform.getPlatformObject(result).setId(Platform.nextObjectId());
return result;
} }
@Rename("notify") @Rename("notify")

View File

@ -47,6 +47,15 @@ public final class TSystem extends TObject {
} }
if (srcType != targetType) { if (srcType != targetType) {
if (!srcType.isPrimitive() && !targetType.isPrimitive()) { if (!srcType.isPrimitive() && !targetType.isPrimitive()) {
Object[] srcArray = (Object[])(Object)src;
int pos = srcPos;
for (int i = 0; i < length; ++i) {
Object elem = srcArray[pos++];
if (!targetType.isInstance(elem)) {
doArrayCopy(src, srcPos, dest, destPos, i);
throw new TArrayStoreException();
}
}
doArrayCopy(src, srcPos, dest, destPos, length); doArrayCopy(src, srcPos, dest, destPos, length);
return; return;
} else if (!srcType.isPrimitive() || !targetType.isPrimitive()) { } else if (!srcType.isPrimitive() || !targetType.isPrimitive()) {

View File

@ -35,13 +35,10 @@ package org.teavm.classlib.java.util;
import java.util.Arrays; import java.util.Arrays;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import org.teavm.classlib.java.io.TSerializable; import org.teavm.classlib.java.io.TSerializable;
import org.teavm.classlib.java.lang.TCloneNotSupportedException; import org.teavm.classlib.java.lang.*;
import org.teavm.classlib.java.lang.TIllegalArgumentException;
import org.teavm.classlib.java.lang.TIllegalStateException;
import org.teavm.classlib.java.lang.TObject;
import org.teavm.javascript.spi.Rename; import org.teavm.javascript.spi.Rename;
public class THashMap<K, V> extends TAbstractMap<K, V> implements TSerializable { public class THashMap<K, V> extends TAbstractMap<K, V> implements TCloneable, TSerializable {
transient int elementCount; transient int elementCount;
transient HashEntry<K, V>[] elementData; transient HashEntry<K, V>[] elementData;
transient int modCount = 0; transient int modCount = 0;

View File

@ -109,7 +109,7 @@ class TDecomposedCharSet extends TJointSet {
* Read testString until we met a decomposed char boundary and * Read testString until we met a decomposed char boundary and
* decompose obtained portion of testString * decompose obtained portion of testString
*/ */
while ((readCodePoints < TLexer.MAX_DECOMPOSITION_LENGTH) && !TLexer.isDecomposedCharBoundary(curChar)) { while ((readCodePoints < TLexer.MAX_DECOMPOSITION_LENGTH)) {
if (TLexer.hasDecompositionNonNullCanClass(curChar)) { if (TLexer.hasDecompositionNonNullCanClass(curChar)) {
@ -146,30 +146,6 @@ class TDecomposedCharSet extends TJointSet {
} }
} }
/*
* Some optimization since length of decomposed char is <= 3 usually
*/
switch (readCodePoints) {
case 0:
case 1:
case 2:
break;
case 3:
int i1 = TLexer.getCanonicalClass(decCodePoint[1]);
int i2 = TLexer.getCanonicalClass(decCodePoint[2]);
if ((i2 != 0) && (i1 > i2)) {
i1 = decCodePoint[1];
decCodePoint[1] = decCodePoint[2];
decCodePoint[2] = i1;
}
break;
default:
decCodePoint = TLexer.getCanonicalOrder(decCodePoint, readCodePoints);
}
/* /*
* Compare decomposedChar with decomposed char that was just read from * Compare decomposedChar with decomposed char that was just read from
* testString * testString

View File

@ -146,12 +146,6 @@ class TLexer {
// table that contains canonical decomposition mappings // table that contains canonical decomposition mappings
private static TIntArrHash decompTable = null; private static TIntArrHash decompTable = null;
// table that contains canonical combining classes
private static TIntHash canonClassesTable = null;
private static int canonClassesTableSize;
/* /*
* Table that contains information about Unicode codepoints with single * Table that contains information about Unicode codepoints with single
* codepoint decomposition * codepoint decomposition
@ -330,51 +324,6 @@ class TLexer {
return input; return input;
} }
/**
* Rearrange codepoints according to canonical order.
*
* @param inputInts
* - array that contains Unicode codepoints
* @param length
* - index of last Unicode codepoint plus 1
*
* @return array that contains rearranged codepoints.
*/
static int[] getCanonicalOrder(int[] inputInts, int length) {
int inputLength = (length < inputInts.length) ? length : inputInts.length;
/*
* Simple bubble-sort algorithm. Note that many codepoints have 0
* canonical class, so this algorithm works almost lineary in
* overwhelming majority of cases. This is due to specific of Unicode
* combining classes and codepoints.
*/
for (int i = 1; i < inputLength; i++) {
int j = i - 1;
int iCanonicalClass = getCanonicalClass(inputInts[i]);
int ch;
if (iCanonicalClass == 0) {
continue;
}
while (j > -1) {
if (getCanonicalClass(inputInts[j]) > iCanonicalClass) {
j = j - 1;
} else {
break;
}
}
ch = inputInts[i];
for (int k = i; k > j + 1; k--) {
inputInts[k] = inputInts[k - 1];
}
inputInts[j + 1] = ch;
}
return inputInts;
}
/** /**
* Reread current character, may be require if previous token changes mode * Reread current character, may be require if previous token changes mode
@ -1062,20 +1011,6 @@ class TLexer {
} }
} }
/**
* Gets canonical class for given codepoint from decomposition mappings
* table.
*
* @param - ch Unicode codepoint
* @return canonical class for given Unicode codepoint that is represented
* by ch.
*/
static int getCanonicalClass(int ch) {
int canClass = canonClassesTable.get(ch);
return (canClass == canonClassesTableSize) ? 0 : canClass;
}
/** /**
* Tests if given codepoint is a canonical decomposition of another * Tests if given codepoint is a canonical decomposition of another
* codepoint. * codepoint.
@ -1126,23 +1061,6 @@ class TLexer {
return high; return high;
} }
/**
* Tests Unicode codepoint if it is a boundary of decomposed Unicode
* codepoint.
*
* @param ch
* - Unicode codepoint to test
* @return true if given codepoint is a boundary.
*/
static boolean isDecomposedCharBoundary(int ch) {
int canClass = canonClassesTable.get(ch);
// Lexer.getCanonicalClass(ch) == 0
boolean isBoundary = (canClass == canonClassesTableSize);
return isBoundary;
}
/** /**
* Returns the curr. character index. * Returns the curr. character index.
*/ */

View File

@ -561,8 +561,7 @@ public final class TPattern implements Serializable {
} else { } else {
readCodePoints++; readCodePoints++;
while ((readCodePoints < TLexer.MAX_DECOMPOSITION_LENGTH) && !lexemes.isEmpty() && lexemes.isLetter() && while ((readCodePoints < TLexer.MAX_DECOMPOSITION_LENGTH) && !lexemes.isEmpty() && lexemes.isLetter()) {
!TLexer.isDecomposedCharBoundary(lexemes.peek())) {
codePoints[readCodePoints++] = lexemes.next(); codePoints[readCodePoints++] = lexemes.next();
} }

View File

@ -383,6 +383,7 @@ function $rt_declClass(cls, data) {
m.binaryName = "L" + data.name + ";"; m.binaryName = "L" + data.name + ";";
m.enum = data.enum; m.enum = data.enum;
m.item = null; m.item = null;
m.primitive = false;
cls.prototype.constructor = cls; cls.prototype.constructor = cls;
cls.classObject = null; cls.classObject = null;
cls.$clinit = data.clinit ? data.clinit : function() {}; cls.$clinit = data.clinit ? data.clinit : function() {};

View File

@ -23,9 +23,9 @@ import org.teavm.jso.JSObject;
* @author Alexey Andreev * @author Alexey Andreev
*/ */
public interface PlatformConsole extends JSObject { public interface PlatformConsole extends JSObject {
@JSMethod("rt_putStdout") @JSMethod("$rt_putStdout")
void output(int b); void output(int b);
@JSMethod("rt_putStderr") @JSMethod("$rt_putStderr")
void error(int b); void error(int b);
} }

View File

@ -38,7 +38,7 @@ public class PlatformGenerator implements Generator, Injector, DependencyPlugin
method.getResult().propagate(agent.getType("java.lang.Class")); method.getResult().propagate(agent.getType("java.lang.Class"));
return; return;
case "clone": case "clone":
method.getVariable(0).connect(method.getResult()); method.getVariable(1).connect(method.getResult());
break; break;
} }
} }