# HG changeset patch # User Jaroslav Tulach # Date 1360959289 -3600 # Node ID ae352b76395918f66a1a838357b1c69c0570857f # Parent daca661c9bc404ed2ebd02df35c0734891e63e50# Parent cb5ac4ada10dfc305945f2d498cdf28b5fef689a Merge from default branch to resolve conflicts diff -r daca661c9bc4 -r ae352b763959 benchmarks/matrix-multiplication/pom.xml --- a/benchmarks/matrix-multiplication/pom.xml Fri Feb 15 21:02:01 2013 +0100 +++ b/benchmarks/matrix-multiplication/pom.xml Fri Feb 15 21:14:49 2013 +0100 @@ -7,6 +7,11 @@ matrix.multiplication 0.3-SNAPSHOT jar + + benchmarks + org.apidesign.bck2brwsr + 0.3-SNAPSHOT + Matrix multiplication @@ -25,6 +30,14 @@ 1.7 + + org.apache.maven.plugins + maven-deploy-plugin + 2.7 + + true + + diff -r daca661c9bc4 -r ae352b763959 emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/JFXIssuesTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/JFXIssuesTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,46 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.compact.tck; + +import org.apidesign.bck2brwsr.vmtest.Compare; +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.testng.annotations.Factory; + + +public class JFXIssuesTest { + private abstract class Application { + public abstract int getID(); + } + + private class MyApplication extends Application { + + @Override + public int getID() { + return 1; + } + + } + + @Compare public boolean isClassAssignable() { + return Application.class.isAssignableFrom(MyApplication.class); + } + + @Factory public static Object[] create() { + return VMTest.create(JFXIssuesTest.class); + } +} diff -r daca661c9bc4 -r ae352b763959 emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java Fri Feb 15 21:02:01 2013 +0100 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; import java.util.Arrays; import org.apidesign.bck2brwsr.vmtest.Compare; import org.apidesign.bck2brwsr.vmtest.VMTest; @@ -38,7 +39,7 @@ (byte)-120 }; ByteArrayInputStream is = new ByteArrayInputStream(arr); - InputStreamReader r = new InputStreamReader(is); + InputStreamReader r = new InputStreamReader(is, "UTF-8"); StringBuilder sb = new StringBuilder(); for (;;) { @@ -50,8 +51,8 @@ } return sb.toString().toString(); } - @Compare public String stringToBytes() { - return Arrays.toString("Žluťoučký kůň".getBytes()); + @Compare public String stringToBytes() throws UnsupportedEncodingException { + return Arrays.toString("\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("UTF-8")); } @Factory public static Object[] create() { diff -r daca661c9bc4 -r ae352b763959 emul/mini/src/main/java/java/lang/Class.java --- a/emul/mini/src/main/java/java/lang/Class.java Fri Feb 15 21:02:01 2013 +0100 +++ b/emul/mini/src/main/java/java/lang/Class.java Fri Feb 15 21:14:49 2013 +0100 @@ -403,10 +403,15 @@ return cmpType != null && getComponentType().isAssignableFrom(cmpType); } String prop = "$instOf_" + getName().replace('.', '_'); - return hasProperty(cls, prop); + return hasCnstrProperty(cls, prop); } - + @JavaScriptBody(args = { "who", "prop" }, body = + "if (who.cnstr.prototype[prop]) return true; else return false;" + ) + private static native boolean hasCnstrProperty(Object who, String prop); + + /** * Determines if the specified {@code Class} object represents an * interface type. diff -r daca661c9bc4 -r ae352b763959 emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java Fri Feb 15 21:02:01 2013 +0100 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java Fri Feb 15 21:14:49 2013 +0100 @@ -54,7 +54,7 @@ ) public static native byte[] expandArray(byte[] arr, int expectedSize); - @JavaScriptBody(args = {}, body = "return new Date().getMilliseconds();") + @JavaScriptBody(args = {}, body = "return new Date().getTime();") public static native long currentTimeMillis(); public static long nanoTime() { diff -r daca661c9bc4 -r ae352b763959 emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js --- a/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js Fri Feb 15 21:02:01 2013 +0100 +++ b/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js Fri Feb 15 21:14:49 2013 +0100 @@ -4,6 +4,7 @@ Number.prototype.mul32 = function(x) { return (((this * (x >> 16)) << 16) + this * (x & 0xFFFF)) | 0; }; +Number.prototype.neg32 = function() { return (-this) | 0; }; Number.prototype.toInt8 = function() { return (this << 24) >> 24; }; Number.prototype.toInt16 = function() { return (this << 16) >> 16; }; @@ -33,6 +34,10 @@ Number.prototype.toExactString = function() { if (this.hi) { + // check for Long.MIN_VALUE + if ((this.hi == (0x80000000 | 0)) && (this == 0)) { + return '-9223372036854775808'; + } var res = 0; var a = [ 6,9,2,7,6,9,4,9,2,4 ]; var s = ''; @@ -60,7 +65,8 @@ } s = String(digit).concat(s); } - return (neg ? '-' : '').concat(res).concat(s); + s = String(res).concat(s).replace(/^0+/, ''); + return (neg ? '-' : '').concat(s); } return String(this); }; diff -r daca661c9bc4 -r ae352b763959 ide/editor/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/pom.xml Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,198 @@ + + + 4.0.0 + + ide + org.apidesign.bck2brwsr + 0.3-SNAPSHOT + + + org.apidesign.bck2brwsr.ide.editor + editor + 0.3-SNAPSHOT + nbm + + Editor Support for Bck2Brwsr + + + UTF-8 + RELEASE72 + ${project.build.directory}/endorsed + + + + + + netbeans + NetBeans + http://bits.netbeans.org/maven2/ + + false + + + + + + + org.netbeans.api + org-netbeans-api-annotations-common + ${netbeans.version} + + + org.netbeans.api + org-netbeans-modules-java-source + ${netbeans.version} + + + org.netbeans.api + org-netbeans-libs-javacapi + ${netbeans.version} + + + org.netbeans.api + org-netbeans-spi-java-hints + ${netbeans.version} + + + org.netbeans.api + org-netbeans-modules-parsing-api + ${netbeans.version} + + + org.netbeans.api + org-netbeans-spi-editor-hints + ${netbeans.version} + + + org.netbeans.api + org-openide-util + ${netbeans.version} + + + org.netbeans.api + org-netbeans-modules-java-lexer + ${netbeans.version} + + + org.netbeans.api + org-netbeans-modules-lexer + ${netbeans.version} + + + org.apidesign.bck2brwsr + core + 0.3-SNAPSHOT + jar + test + + + org.netbeans.api + org-netbeans-modules-java-hints-test + ${netbeans.version} + test + + + org.netbeans.api + org-netbeans-libs-junit4 + ${netbeans.version} + test + + + org.netbeans.modules + org-netbeans-lib-nbjavac + ${netbeans.version} + test + + + org.testng + testng + test + + + + + + + org.codehaus.mojo + nbm-maven-plugin + 3.8 + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + 1.6 + 1.6 + + ${endorsed.dir} + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + true + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + endorsed + validate + + copy + + + + + ${endorsed.dir} + true + + + org.netbeans.api + org-netbeans-libs-javacapi + ${netbeans.version} + + + org.netbeans.external + nb-javac-api + ${netbeans.version} + + + org.netbeans.modules + org-netbeans-libs-javacimpl + ${netbeans.version} + + + org.netbeans.external + nb-javac-impl + ${netbeans.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + -Djava.endorsed.dirs=${endorsed.dir} + + + + + diff -r daca661c9bc4 -r ae352b763959 ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JNIHelper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JNIHelper.java Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,80 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.ide.editor; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +/** + * JNI Helper. + * To facilitate lookup of methods by name and signature, instead of manually parsing signatures, + * constructs the map of all methods and uses Class.getName() to generate almost-correct signatures. + */ +class JNIHelper { + + static Method method(String clazz, String method, String signature) { + final Map methods = methodMap(JNIHelper.clazz(clazz)); + return methods.get(methodKey(method, signature)); + } + + static Class clazz(String clazz) { + try { + return Class.forName(clazz); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(e); + } + } + + static Map methodMap(final Class clazz) { + final Map map = new HashMap(); + final Method[] methods = clazz.getDeclaredMethods(); + for (int i = 0; i < methods.length; i++) { + final Method method = methods[i]; + map.put(methodKey(method.getName(), signature(method)), method); + } + return map; + } + + static String methodKey(String method, String signature) { + return method + '@' + signature; + } + + static String signature(final Method method) { + final Class[] parameterTypes = method.getParameterTypes(); + final StringBuilder b = new StringBuilder(); + for (int j = 0; j < parameterTypes.length; j++) { + b.append(signature(parameterTypes[j])); + } + return b.toString(); + } + + static String signature(final Class clazz) { + if (clazz == boolean.class) return "Z"; + else if (clazz == byte.class) return "B"; + else if (clazz == char.class) return "C"; + else if (clazz == double.class) return "D"; + else if (clazz == float.class) return "F"; + else if (clazz == int.class) return "I"; + else if (clazz == long.class) return "J"; + else if (clazz == short.class) return "S"; + else if (clazz == void.class) return "V"; + else if (clazz.isArray()) return clazz.getName().replace('.','/'); + else return "L" + clazz.getName().replace('.','/') + ";"; + } +} diff -r daca661c9bc4 -r ae352b763959 ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JSEmbeddingProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JSEmbeddingProvider.java Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,188 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.ide.editor; + +import com.sun.source.tree.AnnotationTree; +import com.sun.source.tree.AssignmentTree; +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.LiteralTree; +import com.sun.source.tree.MethodTree; +import com.sun.source.util.SourcePositions; +import com.sun.source.util.TreePath; +import com.sun.source.util.TreePathScanner; +import com.sun.source.util.Trees; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.lang.model.element.TypeElement; +import javax.swing.text.Document; +import org.netbeans.api.editor.mimelookup.MimeRegistration; +import org.netbeans.api.java.source.CompilationInfo; +import org.netbeans.api.java.source.JavaParserResultTask; +import org.netbeans.api.java.source.JavaSource; +import org.netbeans.api.lexer.Language; +import org.netbeans.api.lexer.TokenHierarchy; +import org.netbeans.api.lexer.TokenSequence; +import org.netbeans.modules.parsing.api.Snapshot; +import org.netbeans.modules.parsing.spi.Parser; +import org.netbeans.modules.parsing.spi.Scheduler; +import org.netbeans.modules.parsing.spi.SchedulerEvent; +import org.netbeans.modules.parsing.spi.SchedulerTask; +import org.netbeans.modules.parsing.spi.TaskFactory; +import org.openide.util.Exceptions; + +/** + * + * @author Tomas Zezula + */ +public final class JSEmbeddingProvider extends JavaParserResultTask { + + private static final int PRIORITY = 1000; + private static final String JS_ANNOTATION = "org.apidesign.bck2brwsr.core.JavaScriptBody"; //NOI18N + private static final String BODY = "body"; //NOI18N + private static final String JAVA_MIME_TYPE = "text/x-java"; //NOI18N + private static final String JAVASCRIPT_MIME_TYPE = "text/javascript"; //NOI18N + private final AtomicBoolean canceled = new AtomicBoolean(); + + private JSEmbeddingProvider() { + super(JavaSource.Phase.ELEMENTS_RESOLVED); + } + + @Override + public int getPriority() { + return PRIORITY; + } + + @Override + public void cancel() { + canceled.set(true); + } + + @Override + public Class getSchedulerClass() { + return Scheduler.EDITOR_SENSITIVE_TASK_SCHEDULER; + } + + @Override + public void run(Parser.Result t, SchedulerEvent se) { + canceled.set(false); + final CompilationInfo ci = CompilationInfo.get(t); + final CompilationUnitTree cu = ci.getCompilationUnit(); + final Trees trees = ci.getTrees(); + final SourcePositions sp = trees.getSourcePositions(); + final Finder f = new Finder(trees); + final List result = new ArrayList(); + f.scan(cu, result); + if (!result.isEmpty()) { + try { + final TokenHierarchy tk = TokenHierarchy.get(ci.getDocument()); + final Language java = Language.find(JAVA_MIME_TYPE); + final Language javaScript = Language.find(JAVASCRIPT_MIME_TYPE); + if (java != null && javaScript != null) { + final TokenSequence seq = tk.tokenSequence(java); + if (seq != null) { + for (LiteralTree lt : result) { + final int start = (int) sp.getStartPosition(cu, lt); + final int end = (int) sp.getEndPosition(cu, lt); + seq.move(start); + while (seq.moveNext() && seq.offset() < end) { + seq.createEmbedding(javaScript, 1, 1, true); + } + } + } + } + } catch (IOException ioe) { + Exceptions.printStackTrace(ioe); + } + } + } + + + + + private static final class Finder extends TreePathScanner> { + + private final Trees trees; + private CompilationUnitTree cu; + private boolean inEmbedding; + + Finder(final Trees trees) { + this.trees = trees; + } + + @Override + public Void visitCompilationUnit( + final CompilationUnitTree unit, + final List p) { + this.cu = unit; + return super.visitCompilationUnit(unit, p); + } + + + + @Override + public Void visitMethod( + final MethodTree m, + final List p) { + for (AnnotationTree a : m.getModifiers().getAnnotations()) { + final TypeElement ae = (TypeElement) trees.getElement(TreePath.getPath(cu, a.getAnnotationType())); + if (ae != null && JS_ANNOTATION.contentEquals(ae.getQualifiedName())) { + final List args = a.getArguments(); + for (ExpressionTree kvp : args) { + if (kvp instanceof AssignmentTree) { + final AssignmentTree assignemt = (AssignmentTree) kvp; + if (BODY.equals(assignemt.getVariable().toString())) { + inEmbedding = true; + try { + scan(assignemt.getExpression(), p); + } finally { + inEmbedding = false; + } + } + } + } + } + } + return null; + } + + @Override + public Void visitLiteral(LiteralTree node, List p) { + if (inEmbedding) { + p.add(node); + } + return super.visitLiteral(node, p); + } + + } + + @MimeRegistration( + service = TaskFactory.class, + mimeType = JAVA_MIME_TYPE) + public static final class Factory extends TaskFactory { + @Override + public Collection create(Snapshot snpsht) { + return Collections.singleton(new JSEmbeddingProvider()); + } + } + +} diff -r daca661c9bc4 -r ae352b763959 ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBody.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBody.java Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,149 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.ide.editor; + +import com.sun.source.tree.AnnotationTree; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.LiteralTree; +import com.sun.source.tree.MethodTree; +import com.sun.source.tree.Tree.Kind; +import com.sun.source.tree.VariableTree; +import com.sun.source.util.TreePath; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.netbeans.api.java.lexer.JavaTokenId; +import static org.netbeans.api.java.lexer.JavaTokenId.BLOCK_COMMENT; +import static org.netbeans.api.java.lexer.JavaTokenId.JAVADOC_COMMENT; +import static org.netbeans.api.java.lexer.JavaTokenId.LINE_COMMENT; +import static org.netbeans.api.java.lexer.JavaTokenId.WHITESPACE; +import org.netbeans.api.java.source.CompilationInfo; +import org.netbeans.api.java.source.TreeMaker; +import org.netbeans.api.lexer.Token; +import org.netbeans.api.lexer.TokenSequence; +import org.netbeans.spi.editor.hints.ErrorDescription; +import org.netbeans.spi.editor.hints.Fix; +import org.netbeans.spi.java.hints.ErrorDescriptionFactory; +import org.netbeans.spi.java.hints.Hint; +import org.netbeans.spi.java.hints.HintContext; +import org.netbeans.spi.java.hints.JavaFix; +import org.netbeans.spi.java.hints.TriggerTreeKind; +import org.openide.util.NbBundle.Messages; + +@Hint(displayName = "#DN_JSNI2JavaScriptBody", description = "#DESC_JSNI2JavaScriptBody", category = "general") +@Messages({ + "DN_JSNI2JavaScriptBody=JSNI to @JavaScriptBody", + "DESC_JSNI2JavaScriptBody=JSNI to @JavaScriptBody" +}) +public class JSNI2JavaScriptBody { + + @TriggerTreeKind(Kind.METHOD) + @Messages("ERR_JSNI2JavaScriptBody=Can convert JSNI to @JavaScriptBody") + public static ErrorDescription computeWarning(final HintContext ctx) { + Token token = findBlockToken(ctx.getInfo(), ctx.getPath(), ctx); + + if (token == null) { + return null; + } + + Fix fix = new FixImpl(ctx.getInfo(), ctx.getPath()).toEditorFix(); + return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_JSNI2JavaScriptBody(), fix); + } + + private static Token findBlockToken(CompilationInfo info, TreePath path, HintContext ctx) { + int end = (int) info.getTrees().getSourcePositions().getEndPosition(path.getCompilationUnit(), path.getLeaf()); + TokenSequence ts = info.getTokenHierarchy().tokenSequence(JavaTokenId.language()); + + if (ts == null) return null; + + ts.move(end); + + if ((ctx != null && ctx.isCanceled()) || !ts.movePrevious() || ts.token().id() != JavaTokenId.SEMICOLON) return null; + + OUTER: while (ts.movePrevious()) { + if (ctx != null && ctx.isCanceled()) return null; + + switch (ts.token().id()) { + case WHITESPACE: break; + case LINE_COMMENT: break; + case JAVADOC_COMMENT: break; + case BLOCK_COMMENT: + final CharSequence tok = ts.token().text(); + final int l = tok.length(); + if (l > 4 + && tok.subSequence(0, 4).toString().equals("/*-{") // NOI18N + && tok.subSequence(l - 4, l).toString().equals("}-*/") // NOI18N + ) { + return ts.offsetToken(); + } + break; + default: + break OUTER; + } + } + + return null; + } + + private static final class FixImpl extends JavaFix { + + public FixImpl(CompilationInfo info, TreePath tp) { + super(info, tp); + } + + @Override + @Messages("FIX_JSNI2JavaScriptBody=Convert JSNI to @JavaScriptBody") + protected String getText() { + return Bundle.FIX_JSNI2JavaScriptBody(); + } + + @Override + protected void performRewrite(TransformationContext ctx) { + Token jsniComment = findBlockToken(ctx.getWorkingCopy(), ctx.getPath(), null); + + if (jsniComment == null) { + //XXX: warn? + return ; + } + + JsniCommentTokenizer tok = new JsniCommentTokenizer(); + ManglingSink ms = new ManglingSink(); + final CharSequence cmnt = jsniComment.text(); + tok.process(cmnt.subSequence(4, cmnt.length() - 4), ms); + + TreeMaker make = ctx.getWorkingCopy().getTreeMaker(); + MethodTree mt = (MethodTree) ctx.getPath().getLeaf(); + List params = new ArrayList(); + + for (VariableTree p : mt.getParameters()) { + params.add(make.Literal(p.getName().toString())); + } + + AnnotationTree jsBody = make.Annotation(make.QualIdent("org.apidesign.bck2brwsr.core.JavaScriptBody"), + Arrays.asList( + make.Assignment(make.Identifier("args"), make.NewArray(null, Collections.emptyList(), params)), + make.Assignment(make.Identifier("body"), make.Literal(ms.out.toString())) + ) + ); + + + ctx.getWorkingCopy().rewrite(mt.getModifiers(), make.addModifiersAnnotation(mt.getModifiers(), jsBody)); + } + } +} diff -r daca661c9bc4 -r ae352b763959 ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizer.java Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,70 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.ide.editor; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +final class JsniCommentTokenizer { + + /** + * Tokenize the contents of JSNI comment into the provided {@linkplain Sink}. + * @param in the contents of JSNI comment + * @param out the sink that consumes parsed tokens + */ + public void process(final CharSequence in, final Sink out) { + final Matcher member = Pattern.compile("@([^:]+)::([a-zA-Z_$][a-zA-Z\\d_$]*)").matcher(in); + final Matcher signature = Pattern.compile("\\(([^\\)]*)\\)").matcher(in); + + int i = 0; + while (true) { + if (member.find(i)) { + final int memberStart = member.start(); + final int memberEnd = member.end(); + if (memberStart > i) out.javascript(in.subSequence(i, memberStart).toString()); + + final String clazz = member.group(1); + final String name = member.group(2); + + if (in.charAt(memberEnd) == '(') { + if (!signature.find(memberEnd)) { + throw new IllegalStateException("Expected method signature"); + } + assert signature.start() == memberEnd; + out.method(clazz, name, signature.group(1)); + i = signature.end(); + } else { + out.field(clazz, name); + i = memberEnd; + } + } else { + out.javascript(in.subSequence(i, in.length()).toString()); + break; + } + } + } + + + static interface Sink { + void javascript(String s); + + void method(String clazz, String method, String signature); + + void field(String clazz, String field); + } +} diff -r daca661c9bc4 -r ae352b763959 ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/ManglingSink.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/ManglingSink.java Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,71 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.ide.editor; + +/** + * An implementation of {@linkplain JsniCommentTokenizer.Sink} that generates B2B + */ +class ManglingSink implements JsniCommentTokenizer.Sink { + + final StringBuilder out = new StringBuilder(); + + public void javascript(String s) { + out.append(s); + } + + public void method(String clazz, String method, String signature) { + out.append(mangle(clazz, method, signature)); + } + + public void field(String clazz, String field) { +// out.append(field); + out.append('_').append(field).append('(').append(')'); + } + + + @Override + public String toString() { + return out.toString(); + } + + + static String mangle(String clazz, String method, String signature) { + final StringBuilder builder = new StringBuilder(); + builder.append(method); + builder.append("__"); + builder.append(mangle(JNIHelper.signature(JNIHelper.method(clazz, method, signature).getReturnType()))); + builder.append(mangle(signature)); + return builder.toString(); + } + + + static String mangle(String txt) { + final StringBuilder sb = new StringBuilder(); + for (int i = 0; i < txt.length(); i++) { + final char ch = txt.charAt(i); + switch (ch) { + case '/': sb.append('_'); break; + case '_': sb.append("_1"); break; + case ';': sb.append("_2"); break; + case '[': sb.append("_3"); break; + default: sb.append(ch); break; + } + } + return sb.toString(); + } +} diff -r daca661c9bc4 -r ae352b763959 ide/editor/src/main/nbm/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/src/main/nbm/manifest.mf Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/test/hints/Bundle.properties diff -r daca661c9bc4 -r ae352b763959 ide/editor/src/main/resources/org/netbeans/modules/jackpot30/test/hints/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/src/main/resources/org/netbeans/modules/jackpot30/test/hints/Bundle.properties Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,21 @@ +# +# Back 2 Browser Bytecode Translator +# Copyright (C) 2012 Jaroslav Tulach +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. Look for COPYING file in the top folder. +# If not, see http://opensource.org/licenses/GPL-2.0. +# + +OpenIDE-Module-Name=Bck2Brwsr Editor Support +OpenIDE-Module-Short-Description=Provides hints, coloring, etc. for the bck2brwsr.apidesign.org project +OpenIDE-Module-Display-Category=Java diff -r daca661c9bc4 -r ae352b763959 ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/DejsniReaderTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/DejsniReaderTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,84 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.ide.editor; + +import org.apidesign.bck2brwsr.core.JavaScriptBody; +import org.netbeans.modules.java.hints.test.api.HintTest; +import org.openide.filesystems.FileUtil; +import org.testng.annotations.Test; + +public class DejsniReaderTest { + + @Test + public void test1() throws Exception { + String s = "class Test {\n" + + " /** javadoc */\n" + + " public native void test() /*-{\n" + + " // body\n" + + " }-*/;\n" + + "}\n"; + + String expected = " import org.apidesign.bck2brwsr.core.JavaScriptBody;\n" + + "class Test {\n" + + "\n" + + " /** javadoc */\n" + + " @JavaScriptBody(args = {}, body = \"\\n // body\\n \")\n" + + " public native void test();\n" + + "}\n"; + + HintTest.create() + .input(s) + .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation())) + .run(JSNI2JavaScriptBody.class) + .findWarning("2:23-2:27:verifier:" + Bundle.ERR_JSNI2JavaScriptBody()) + .applyFix() + .assertCompilable() + .assertOutput(expected); + } + + + @Test + public void test2() throws Exception { + String s = "class Test {\n" + + " /** javadoc */\n" + + " @SuppressWarnings(\"unused\")\n" + + " // comment\n" + + " public native void test() /*-{\n" + + " // body\n" + + " }-*/;\n" + + "}\n"; + + String expected = " import org.apidesign.bck2brwsr.core.JavaScriptBody;\n" + + "class Test {\n" + + "\n" + + " /** javadoc */\n" + + " @SuppressWarnings(\"unused\")\n" + + " // comment\n" + + " @JavaScriptBody(args = {}, body = \"\\n // body\\n \")\n" + + " public native void test();\n" + + "}\n"; + HintTest.create() + .input(s) + .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation())) + .run(JSNI2JavaScriptBody.class) + .findWarning("4:23-4:27:verifier:" + Bundle.ERR_JSNI2JavaScriptBody()) + .applyFix() + .assertCompilable() + .assertOutput(expected); + } +} \ No newline at end of file diff -r daca661c9bc4 -r ae352b763959 ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBodyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBodyTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,46 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.ide.editor; + +import org.apidesign.bck2brwsr.core.JavaScriptBody; +import org.netbeans.modules.java.hints.test.api.HintTest; +import org.openide.filesystems.FileUtil; +import org.testng.annotations.Test; + +public class JSNI2JavaScriptBodyTest { + + @Test + public void testFixWorking() throws Exception { + HintTest.create() + .input("package test;\n" + + "public class Test {\n" + + " public native void run(int a) /*-{ this.a = a; }-*/;\n" + + "}\n") + .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation())) + .run(JSNI2JavaScriptBody.class) + .findWarning("2:23-2:26:verifier:" + Bundle.ERR_JSNI2JavaScriptBody()) + .applyFix() + .assertCompilable() + .assertOutput("package test;\n" + + "import org.apidesign.bck2brwsr.core.JavaScriptBody;\n" + + "public class Test {\n" + + " @JavaScriptBody(args = {\"a\"}, body = \" this.a = a; \")\n" + + " public native void run(int a);\n" + + "}\n"); + } +} diff -r daca661c9bc4 -r ae352b763959 ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizerTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizerTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,154 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.ide.editor; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class JsniCommentTokenizerTest { + + private static class MockSink implements JsniCommentTokenizer.Sink { + final List out = new ArrayList(); + + public void javascript(String s) { + out.add("J " + s); + } + + public void method(String clazz, String method, String signature) { + out.add("M " + clazz + "|" + method + "|" + signature); + } + + public void field(String clazz, String field) { + out.add("F " + clazz + "|" + field); + } + } + + + @Test + public void testProcess_nop() throws IOException { + final String in = "foo bar"; + final List expected = new ArrayList(); + expected.add("J foo bar"); + + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer(); + final MockSink out = new MockSink(); + jsniCommentTokenizer.process(in, out); + + Assert.assertEquals(expected, out.out); + } + + @Test + public void testProcess_read_static_field() throws IOException { + final String in = " @com.google.gwt.examples.JSNIExample::myStaticField = val + \" and stuff\";"; + final List expected = new ArrayList(); + expected.add("J "); + expected.add("F com.google.gwt.examples.JSNIExample|myStaticField"); + expected.add("J = val + \" and stuff\";"); + + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer(); + final MockSink out = new MockSink(); + jsniCommentTokenizer.process(in, out); + + Assert.assertEquals(expected, out.out); + } + + @Test + public void testProcess_write_instance_field() throws IOException { + final String in = " x.@com.google.gwt.examples.JSNIExample::myInstanceField = val + \" and stuff\";"; + final List expected = new ArrayList(); + expected.add("J x."); + expected.add("F com.google.gwt.examples.JSNIExample|myInstanceField"); + expected.add("J = val + \" and stuff\";"); + + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer(); + final MockSink out = new MockSink(); + jsniCommentTokenizer.process(in, out); + + Assert.assertEquals(expected, out.out); + } + + @Test + public void testProcess_read_instance_field() throws IOException { + final String in = " var val = this.@com.google.gwt.examples.JSNIExample::myInstanceField;"; + final List expected = new ArrayList(); + expected.add("J var val = this."); + expected.add("F com.google.gwt.examples.JSNIExample|myInstanceField"); + expected.add("J ;"); + + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer(); + final MockSink out = new MockSink(); + jsniCommentTokenizer.process(in, out); + + Assert.assertEquals(expected, out.out); + } + + + @Test + public void testProcess_static_method() throws IOException { + final String in = " @com.google.gwt.examples.JSNIExample::staticFoo(Ljava/lang/String;)(s);"; + final List expected = new ArrayList(); + expected.add("J "); + expected.add("M com.google.gwt.examples.JSNIExample|staticFoo|Ljava/lang/String;"); + expected.add("J (s);"); + + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer(); + final MockSink out = new MockSink(); + jsniCommentTokenizer.process(in, out); + + Assert.assertEquals(expected, out.out); + } + + + @Test + public void testProcess_instance_method() throws IOException { + final String in = " x.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);"; + final List expected = new ArrayList(); + expected.add("J x."); + expected.add("M com.google.gwt.examples.JSNIExample|instanceFoo|Ljava/lang/String;"); + expected.add("J (s);"); + + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer(); + final MockSink out = new MockSink(); + jsniCommentTokenizer.process(in, out); + + Assert.assertEquals(expected, out.out); + } + + + @Test + public void testProcess_multiline() throws IOException { + final String in = + " x.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);" + + " @com.google.gwt.examples.JSNIExample::myStaticField = val + \" and stuff\";"; + final List expected = new ArrayList(); + expected.add("J x."); + expected.add("M com.google.gwt.examples.JSNIExample|instanceFoo|Ljava/lang/String;"); + expected.add("J (s); "); + expected.add("F com.google.gwt.examples.JSNIExample|myStaticField"); + expected.add("J = val + \" and stuff\";"); + + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer(); + final MockSink out = new MockSink(); + jsniCommentTokenizer.process(in, out); + + Assert.assertEquals(expected, out.out); + } +} diff -r daca661c9bc4 -r ae352b763959 ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/ManglingSinkTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/ManglingSinkTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,58 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.ide.editor; + +import org.testng.Assert; +import org.testng.annotations.Test; + + +public class ManglingSinkTest { + + @Test + public void testMangle_1() { + Assert.assertEquals( + "binarySearch__I_3BIIB", + ManglingSink.mangle("java.util.Arrays", "binarySearch", "[BIIB") + ); + } + + @Test + public void testMangle_2() { + Assert.assertEquals( + "sort__V_3I", + ManglingSink.mangle("java.util.Arrays", "sort", "[I") + ); + } + + @Test + public void testMangle_3() { + Assert.assertEquals( + "binarySearch__I_3Ljava_lang_Object_2IILjava_lang_Object_2", + ManglingSink.mangle("java.util.Arrays", "binarySearch", "[Ljava/lang/Object;IILjava/lang/Object;") + ); + } + + + @Test + public void testField() { + final ManglingSink manglingSink = new ManglingSink(); + manglingSink.field(null, "value"); + + Assert.assertEquals("_value()", manglingSink.toString()); + } +} diff -r daca661c9bc4 -r ae352b763959 ide/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/pom.xml Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,17 @@ + + + 4.0.0 + + bck2brwsr + org.apidesign + 0.3-SNAPSHOT + + org.apidesign.bck2brwsr + ide + 0.3-SNAPSHOT + pom + IDE Support + + editor + + diff -r daca661c9bc4 -r ae352b763959 javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java Fri Feb 15 21:02:01 2013 +0100 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java Fri Feb 15 21:14:49 2013 +0100 @@ -307,10 +307,10 @@ public native double getGlobalAlpha(); @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation;") - public native void setGlobalCompositeOperation(double alpha); + public native void setGlobalCompositeOperation(String operation); @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;") - public native double getGlobalCompositeOperation(); + public native String getGlobalCompositeOperation(); public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) { return new LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1)); diff -r daca661c9bc4 -r ae352b763959 javaquery/demo-calculator-dynamic/pom.xml --- a/javaquery/demo-calculator-dynamic/pom.xml Fri Feb 15 21:02:01 2013 +0100 +++ b/javaquery/demo-calculator-dynamic/pom.xml Fri Feb 15 21:14:49 2013 +0100 @@ -54,6 +54,14 @@ + org.apache.maven.plugins + maven-deploy-plugin + 2.7 + + true + + + maven-assembly-plugin 2.4 diff -r daca661c9bc4 -r ae352b763959 javaquery/demo-calculator/pom.xml --- a/javaquery/demo-calculator/pom.xml Fri Feb 15 21:02:01 2013 +0100 +++ b/javaquery/demo-calculator/pom.xml Fri Feb 15 21:14:49 2013 +0100 @@ -72,6 +72,14 @@ + + org.apache.maven.plugins + maven-deploy-plugin + 2.7 + + true + + diff -r daca661c9bc4 -r ae352b763959 launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Fri Feb 15 21:02:01 2013 +0100 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Fri Feb 15 21:14:49 2013 +0100 @@ -312,10 +312,10 @@ if (ch == '$' && params.length > 0) { int cnt = is.read() - '0'; if (cnt == 'U' - '0') { - os.write(baseURL.getBytes()); + os.write(baseURL.getBytes("UTF-8")); } if (cnt >= 0 && cnt < params.length) { - os.write(params[cnt].getBytes()); + os.write(params[cnt].getBytes("UTF-8")); } } else { os.write(ch); diff -r daca661c9bc4 -r ae352b763959 mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java --- a/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java Fri Feb 15 21:02:01 2013 +0100 +++ b/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java Fri Feb 15 21:14:49 2013 +0100 @@ -37,7 +37,7 @@ import org.apidesign.bck2brwsr.launcher.Launcher; /** Executes given HTML page in a browser. */ -@Mojo(name="brwsr", defaultPhase=LifecyclePhase.DEPLOY) +@Mojo(name="brwsr", defaultPhase=LifecyclePhase.NONE) public class BrswrMojo extends AbstractMojo { public BrswrMojo() { } diff -r daca661c9bc4 -r ae352b763959 mojo/src/main/resources/archetype-resources/pom.xml --- a/mojo/src/main/resources/archetype-resources/pom.xml Fri Feb 15 21:02:01 2013 +0100 +++ b/mojo/src/main/resources/archetype-resources/pom.xml Fri Feb 15 21:14:49 2013 +0100 @@ -10,6 +10,32 @@ ${artifactId} + + + java.net + Java.net + https://maven.java.net/content/repositories/snapshots/ + + true + + + + netbeans + NetBeans + http://bits.netbeans.org/maven2/ + + + + + java.net + Local Maven repository of releases + https://maven.java.net/content/repositories/snapshots/ + + true + + + + UTF-8 diff -r daca661c9bc4 -r ae352b763959 pom.xml --- a/pom.xml Fri Feb 15 21:02:01 2013 +0100 +++ b/pom.xml Fri Feb 15 21:14:49 2013 +0100 @@ -6,6 +6,11 @@ 0.3-SNAPSHOT pom Back 2 Browser + + net.java + jvnet-parent + 3 + vm emul @@ -17,6 +22,7 @@ benchmarks launcher vmtest + ide @@ -29,6 +35,11 @@ API Design http://apidesign.org + + scm:hg:http://source.apidesign.org/hg/bck2brwsr + scm:hg:https://source.apidesign.org/hg/bck2brwsr + http://source.apidesign.org/hg/bck2brwsr + netbeans diff -r daca661c9bc4 -r ae352b763959 vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Feb 15 21:02:01 2013 +0100 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Feb 15 21:14:49 2013 +0100 @@ -600,7 +600,7 @@ emit(out, "@1 = @1.xor64(@2);", smapper.getL(1), smapper.popL()); break; case opc_ineg: - emit(out, "@1 = -@1;", smapper.getI(0)); + emit(out, "@1 = @1.neg32();", smapper.getI(0)); break; case opc_lneg: emit(out, "@1 = @1.neg64();", smapper.getL(0)); @@ -634,7 +634,7 @@ final int varIndx = wide ? readUShort(byteCodes, i++) : readUByte(byteCodes, i); ++i; - final int incrBy = wide ? readIntArg(byteCodes, i++) + final int incrBy = wide ? readShort(byteCodes, i++) : byteCodes[i]; wide = false; if (incrBy == 1) { @@ -1355,20 +1355,25 @@ final int indxLo = byteCodes[offsetInstruction + 2]; return (indxHi & 0xffffff00) | (indxLo & 0xff); } - private int readInt4(byte[] byteCodes, int offsetInstruction) { - final int d = byteCodes[offsetInstruction + 0] << 24; - final int c = byteCodes[offsetInstruction + 1] << 16; - final int b = byteCodes[offsetInstruction + 2] << 8; - final int a = byteCodes[offsetInstruction + 3]; + private int readInt4(byte[] byteCodes, int offset) { + final int d = byteCodes[offset + 0] << 24; + final int c = byteCodes[offset + 1] << 16; + final int b = byteCodes[offset + 2] << 8; + final int a = byteCodes[offset + 3]; return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff); } - private int readUByte(byte[] byteCodes, int offsetInstruction) { - return byteCodes[offsetInstruction] & 0xff; + private int readUByte(byte[] byteCodes, int offset) { + return byteCodes[offset] & 0xff; } - private int readUShort(byte[] byteCodes, int offsetInstruction) { - return ((byteCodes[offsetInstruction] & 0xff) << 8) - | (byteCodes[offsetInstruction + 1] & 0xff); + private int readUShort(byte[] byteCodes, int offset) { + return ((byteCodes[offset] & 0xff) << 8) + | (byteCodes[offset + 1] & 0xff); + } + + private int readShort(byte[] byteCodes, int offset) { + return (byteCodes[offset] << 8) + | (byteCodes[offset + 1] & 0xff); } private static void countArgs(String descriptor, char[] returnType, StringBuilder sig, StringBuilder cnt) { diff -r daca661c9bc4 -r ae352b763959 vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java Fri Feb 15 21:02:01 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -196,5 +196,11 @@ ) throws Exception { code.assertExec(msg, clazz, method, expRes, args); } + @Test public void isClassAssignable() throws Exception { + assertExec("isAssignable works on subclasses", Classes.class, + "isClassAssignable__Z", + true + ); + } } diff -r daca661c9bc4 -r ae352b763959 vm/src/test/java/org/apidesign/vm4brwsr/Classes.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java Fri Feb 15 21:02:01 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java Fri Feb 15 21:14:49 2013 +0100 @@ -214,4 +214,20 @@ Method m = StaticMethod.class.getMethod("sum", int.class, int.class); return (int) m.invoke(null, a, b); } + + private abstract class Application { + public abstract int getID(); + } + + private class MyApplication extends Application { + @Override + public int getID() { + return 1; + } + } + + public static boolean isClassAssignable() { + return Application.class.isAssignableFrom(MyApplication.class); + } + } diff -r daca661c9bc4 -r ae352b763959 vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Fri Feb 15 21:02:01 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -141,552 +141,6 @@ s ); } - - @Test public void longConversion() throws Exception { - assertExec("Long from cPool", - Numbers.class, "conversionL__J", - Double.valueOf(Long.MAX_VALUE) - ); - } - - @Test public void longNegate1() throws Exception { - final long res = -0x00fa37d7763e0ca1l; - assertExec("Long negate", - Numbers.class, "negL__J_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 } - ); - } - - @Test public void longNegate2() throws Exception { - final long res = -0x80fa37d7763e0ca1l; - assertExec("Long negate", - Numbers.class, "negL__J_3B", - Double.valueOf(res), - new byte[] { (byte)0x80, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 } - ); - } - - @Test public void longNegate3() throws Exception { - final long res = -0xfffffffffffffeddl; - assertExec("Long negate", - Numbers.class, "negL__J_3B", - Double.valueOf(res), - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd } - ); - } - - @Test public void longAddOverflow() throws Exception { - final long res = Long.MAX_VALUE + 1l; - assertExec("Addition 1+MAX", - Numbers.class, "addL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, - new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1 } - ); - } - - @Test public void longAddMaxAndMax() throws Exception { - final long res = Long.MAX_VALUE + Long.MAX_VALUE; - assertExec("Addition MAX+MAX", - Numbers.class, "addL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff } - ); - } - - @Test public void longSubUnderflow() throws Exception { - final long res = Long.MIN_VALUE - 1l; - assertExec("Subtraction MIN-1", - Numbers.class, "subL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1 } - ); - } - - @Test public void longSubMinAndMin() throws Exception { - final long res = Long.MIN_VALUE - Long.MIN_VALUE; - assertExec("Subtraction MIN-MIN", - Numbers.class, "subL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 } - ); - } - - @Test public void longSubMinAndMax() throws Exception { - final long res = Long.MIN_VALUE - Long.MAX_VALUE; - assertExec("Subtraction MIN-MAX", - Numbers.class, "subL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff } - ); - } - - @Test public void longMultiplyMax() throws Exception { - final long res = Long.MAX_VALUE * 2l; - assertExec("Multiplication MAX*2", - Numbers.class, "mulL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02 } - ); - } - - @Test public void longMultiplyMaxAndMax() throws Exception { - final long res = Long.MAX_VALUE * Long.MAX_VALUE; - assertExec("Multiplication MAX*MAX", - Numbers.class, "mulL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff } - ); - } - - @Test public void longMultiplyMin() throws Exception { - final long res = Long.MIN_VALUE * 2l; - assertExec("Multiplication MIN*2", - Numbers.class, "mulL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02 } - ); - } - - @Test public void longMultiplyMinAndMin() throws Exception { - final long res = Long.MIN_VALUE * Long.MIN_VALUE; - assertExec("Multiplication MIN*2", - Numbers.class, "mulL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 } - ); - } - - @Test public void longMultiplyPrecision() throws Exception { - final long res = 0x00fa37d7763e0ca1l * 0xa7b3432fff00123el; - assertExec("Multiplication", - Numbers.class, "mulL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } - ); - } - - @Test public void longDivideSmallPositiveNumbers() throws Exception { - final long res = 0xabcdef / 0x123; - assertExec("Division Small Positive Numbers", - Numbers.class, "divL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x23 } - ); - } - - @Test public void longDivideSmallNegativeNumbers() throws Exception { - final long res = -0xabcdef / -0x123; - assertExec("Division Small Negative Numbers", - Numbers.class, "divL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x11 }, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd } - ); - } - - @Test public void longDivideSmallMixedNumbers() throws Exception { - final long res = 0xabcdef / -0x123; - assertExec("Division Small Mixed Numbers", - Numbers.class, "divL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef }, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd } - ); - } - - @Test public void longDividePositiveNumbersOneDigitDenom() - throws Exception { - final long res = 0xabcdef0102ffffL / 0x654; - assertExec("Division Positive Numbers One Digit Denom", - Numbers.class, "divL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef, (byte)0x01, (byte)0x02, (byte)0xff, (byte)0xff }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 } - ); - } - - @Test public void longDivideNegativeNumbersOneDigitDenom() - throws Exception { - final long res = -0xabcdef0102ffffL / -0x654; - assertExec("Division Negative Numbers One Digit Denom", - Numbers.class, "divL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 }, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xf9, (byte)0xac } - ); - } - - @Test public void longDivideMixedNumbersOneDigitDenom() - throws Exception { - final long res = -0xabcdef0102ffffL / 0x654; - assertExec("Division Mixed Numbers One Digit Denom", - Numbers.class, "divL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 } - ); - } - - @Test public void longDividePositiveNumbersMultiDigitDenom() - throws Exception { - final long res = 0x7ffefc003322aabbL / 0x89ab1000L; - assertExec("Division Positive Numbers Multi Digit Denom", - Numbers.class, "divL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x89, (byte)0xab, (byte)0x10, (byte)0x00 } - ); - } - - @Test public void longDivideNegativeNumbersMultiDigitDenom() - throws Exception { - final long res = -0x7ffefc003322aabbL / -0x123489ab1001L; - assertExec("Division Negative Numbers Multi Digit Denom", - Numbers.class, "divL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x80, (byte)0x01, (byte)0x03, (byte)0xff, (byte)0xcc, (byte)0xdd, (byte)0x55, (byte)0x45 }, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xed, (byte)0xcb, (byte)0x76, (byte)0x54, (byte)0xef, (byte)0xff } - ); - } - - @Test public void longDivideMixedNumbersMultiDigitDenom() - throws Exception { - final long res = 0x7ffefc003322aabbL / -0x38f49b0b7574e36L; - assertExec("Division Mixed Numbers Multi Digit Denom", - Numbers.class, "divL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb }, - new byte[] { (byte)0xfc, (byte)0x70, (byte)0xb6, (byte)0x4f, (byte)0x48, (byte)0xa8, (byte)0xb1, (byte)0xca } - ); - } - - @Test public void longDivideWithOverflow() throws Exception { - final long res = 0x8000fffe0000L / 0x8000ffffL; - assertExec("Division With Overflow", - Numbers.class, "divL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xfe, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xff } - ); - } - - @Test public void longDivideWithCorrection() throws Exception { - final long res = 0x7fff800000000000L / 0x800000000001L; - assertExec("Division With Correction", - Numbers.class, "divL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x7f, (byte)0xff, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01 } - ); - } - - @Test public void longModuloSmallPositiveNumbers() throws Exception { - final long res = 0xabcdef % 0x123; - assertExec("Modulo Small Positive Numbers", - Numbers.class, "modL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x23 } - ); - } - - @Test public void longModuloSmallNegativeNumbers() throws Exception { - final long res = -0xabcdef % -0x123; - assertExec("Modulo Small Negative Numbers", - Numbers.class, "modL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x11 }, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd } - ); - } - - @Test public void longModuloSmallMixedNumbers() throws Exception { - final long res = 0xabcdef % -0x123; - assertExec("Modulo Small Mixed Numbers", - Numbers.class, "modL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef }, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd } - ); - } - - @Test public void longModuloPositiveNumbersOneDigitDenom() - throws Exception { - final long res = 0xabcdef0102ffffL % 0x654; - assertExec("Modulo Positive Numbers One Digit Denom", - Numbers.class, "modL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef, (byte)0x01, (byte)0x02, (byte)0xff, (byte)0xff }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 } - ); - } - - @Test public void longModuloNegativeNumbersOneDigitDenom() - throws Exception { - final long res = -0xabcdef0102ffffL % -0x654; - assertExec("Modulo Negative Numbers One Digit Denom", - Numbers.class, "modL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 }, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xf9, (byte)0xac } - ); - } - - @Test public void longModuloMixedNumbersOneDigitDenom() - throws Exception { - final long res = -0xabcdef0102ffffL % 0x654; - assertExec("Modulo Mixed Numbers One Digit Denom", - Numbers.class, "modL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 } - ); - } - - @Test public void longModuloPositiveNumbersMultiDigitDenom() - throws Exception { - final long res = 0x7ffefc003322aabbL % 0x89ab1000L; - assertExec("Modulo Positive Numbers Multi Digit Denom", - Numbers.class, "modL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x89, (byte)0xab, (byte)0x10, (byte)0x00 } - ); - } - - @Test public void longModuloNegativeNumbersMultiDigitDenom() - throws Exception { - final long res = -0x7ffefc003322aabbL % -0x123489ab1001L; - assertExec("Modulo Negative Numbers Multi Digit Denom", - Numbers.class, "modL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x80, (byte)0x01, (byte)0x03, (byte)0xff, (byte)0xcc, (byte)0xdd, (byte)0x55, (byte)0x45 }, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xed, (byte)0xcb, (byte)0x76, (byte)0x54, (byte)0xef, (byte)0xff } - ); - } - - @Test public void longModuloMixedNumbersMultiDigitDenom() - throws Exception { - final long res = 0x7ffefc003322aabbL % -0x38f49b0b7574e36L; - assertExec("Modulo Mixed Numbers Multi Digit Denom", - Numbers.class, "modL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb }, - new byte[] { (byte)0xfc, (byte)0x70, (byte)0xb6, (byte)0x4f, (byte)0x48, (byte)0xa8, (byte)0xb1, (byte)0xca } - ); - } - - @Test public void longModuloWithOverflow() throws Exception { - final long res = 0x8000fffe0000L % 0x8000ffffL; - assertExec("Modulo With Overflow", - Numbers.class, "modL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xfe, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xff } - ); - } - - @Test public void longModuloWithCorrection() throws Exception { - final long res = 0x7fff800000000000L % 0x800000000001L; - assertExec("Modulo With Correction", - Numbers.class, "modL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x7f, (byte)0xff, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01 } - ); - } - - @Test public void longShiftL1() throws Exception { - final long res = 0x00fa37d7763e0ca1l << 5; - assertExec("Long << 5", - Numbers.class, "shlL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 5); - } - - @Test public void longShiftL2() throws Exception { - final long res = 0x00fa37d7763e0ca1l << 32; - assertExec("Long << 32", - Numbers.class, "shlL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 32); - } - - @Test public void longShiftL3() throws Exception { - final long res = 0x00fa37d7763e0ca1l << 45; - assertExec("Long << 45", - Numbers.class, "shlL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 45); - } - - @Test public void longShiftR1() throws Exception { - final long res = 0x00fa37d7763e0ca1l >> 5; - assertExec("Long >> 5", - Numbers.class, "shrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 5); - } - - @Test public void longShiftR2() throws Exception { - final long res = 0x00fa37d7763e0ca1l >> 32; - assertExec("Long >> 32", - Numbers.class, "shrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 32); - } - - @Test public void longShiftR3() throws Exception { - final long res = 0x00fa37d7763e0ca1l >> 45; - assertExec("Long >> 45", - Numbers.class, "shrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 45); - } - - @Test public void longUShiftR1() throws Exception { - final long res = 0x00fa37d7763e0ca1l >>> 5; - assertExec("Long >>> 5", - Numbers.class, "ushrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 5); - } - - @Test public void longUShiftR2() throws Exception { - final long res = 0x00fa37d7763e0ca1l >>> 45; - assertExec("Long >>> 45", - Numbers.class, "ushrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 45); - } - - @Test public void longUShiftR3() throws Exception { - final long res = 0xf0fa37d7763e0ca1l >>> 5; - assertExec("Long >>> 5", - Numbers.class, "ushrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 5); - } - - @Test public void longUShiftR4() throws Exception { - final long res = 0xf0fa37d7763e0ca1l >>> 45; - assertExec("Long >>> 45", - Numbers.class, "ushrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 45); - } - - @Test public void longAnd() throws Exception { - final long res = 0x00fa37d7763e0ca1l & 0xa7b3432fff00123el; - assertExec("LOng binary AND", - Numbers.class, "andL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } - ); - } - - @Test public void longOr() throws Exception { - final long res = 0x00fa37d7763e0ca1l | 0xa7b3432fff00123el; - assertExec("Long binary OR", - Numbers.class, "orL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } - ); - } - - @Test public void longXor1() throws Exception { - final long res = 0x00fa37d7763e0ca1l ^ 0xa7b3432fff00123el; - assertExec("Long binary XOR", - Numbers.class, "xorL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } - ); - } - - @Test public void longXor2() throws Exception { - final long res = 0x00fa37d7763e0ca1l ^ 0x00000000ff00123el; - assertExec("Long binary XOR", - Numbers.class, "xorL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } - ); - } - - @Test public void longXor3() throws Exception { - final long res = 0x00000000763e0ca1l ^ 0x00000000ff00123el; - assertExec("Long binary XOR", - Numbers.class, "xorL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } - ); - } - - @Test public void longCompareSameNumbers() throws Exception { - assertExec("Long compare same numbers", - Numbers.class, "compareL__I_3B_3BI", - 0.0, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - 0 - ); - } - - @Test public void longComparePositiveNumbers() throws Exception { - assertExec("Long compare positive numbers", - Numbers.class, "compareL__I_3B_3BI", - -1.0, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00 }, - 0 - ); - } - - @Test public void longCompareNegativeNumbers() throws Exception { - assertExec("Long compare negative numbers", - Numbers.class, "compareL__I_3B_3BI", - 1.0, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - 0 - ); - } - - @Test public void longCompareMixedNumbers() throws Exception { - assertExec("Long compare mixed numbers", - Numbers.class, "compareL__I_3B_3BI", - -1.0, - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, - 0 - ); - } private static TestVM code; diff -r daca661c9bc4 -r ae352b763959 vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Fri Feb 15 21:02:01 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Fri Feb 15 21:14:49 2013 +0100 @@ -67,136 +67,4 @@ static String floatToString() { return new Float(7.0).toString().toString(); } - - public static long conversionL() { - return Long.MAX_VALUE; - } - - public static long negL(byte[] arrValue) throws IOException { - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue); - DataInputStream disValue = new DataInputStream(isValue); - return (-disValue.readLong()); - } - - public static long addL(byte[] arrX, byte[] arrY) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - return (disX.readLong() + disY.readLong()); - } - - public static long subL(byte[] arrX, byte[] arrY) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - return (disX.readLong() - disY.readLong()); - } - - public static long mulL(byte[] arrX, byte[] arrY) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - return (disX.readLong() * disY.readLong()); - } - - public static long divL(byte[] arrX, byte[] arrY) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - return (disX.readLong() / disY.readLong()); - } - - public static long modL(byte[] arrX, byte[] arrY) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - return (disX.readLong() % disY.readLong()); - } - - public static long shlL(byte[] arrValue, int nBits) throws IOException { - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue); - DataInputStream disValue = new DataInputStream(isValue); - return (disValue.readLong() << nBits); - } - - public static long shrL(byte[] arrValue, int nBits) throws IOException { - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue); - DataInputStream disValue = new DataInputStream(isValue); - return (disValue.readLong() >> nBits); - } - - public static long ushrL(byte[] arrValue, int nBits) throws IOException { - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue); - DataInputStream disValue = new DataInputStream(isValue); - return (disValue.readLong() >>> nBits); - } - - public static long andL(byte[] arrX, byte[] arrY) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - return (disX.readLong() & disY.readLong()); - } - - public static long orL(byte[] arrX, byte[] arrY) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - return (disX.readLong() | disY.readLong()); - } - - public static long xorL(byte[] arrX, byte[] arrY) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - return (disX.readLong() ^ disY.readLong()); - } - - public static int compareL(byte[] arrX, byte[] arrY, - int zero) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - final long x = disX.readLong(); - final long y = disY.readLong(); - - final int xyResult = compareL(x, y, zero); - final int yxResult = compareL(y, x, zero); - - return ((xyResult + yxResult) == 0) ? xyResult : -2; - } - - private static int compareL(long x, long y, int zero) { - int result = -2; - int trueCount = 0; - - x += zero; - if (x == y) { - result = 0; - ++trueCount; - } - - x += zero; - if (x < y) { - result = -1; - ++trueCount; - } - - x += zero; - if (x > y) { - result = 1; - ++trueCount; - } - - return (trueCount == 1) ? result : -2; - } } diff -r daca661c9bc4 -r ae352b763959 vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java Fri Feb 15 21:02:01 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java Fri Feb 15 21:14:49 2013 +0100 @@ -17,6 +17,8 @@ */ package org.apidesign.vm4brwsr; +import java.io.UnsupportedEncodingException; + /** * * @author Jaroslav Tulach @@ -68,8 +70,8 @@ return chars('a', (char)30, 'b') instanceof String; } - public static String getBytes(String s) { - byte[] arr = s.getBytes(); + public static String getBytes(String s) throws UnsupportedEncodingException { + byte[] arr = s.getBytes("UTF-8"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.length; i++) { sb.append(arr[i]).append(" "); diff -r daca661c9bc4 -r ae352b763959 vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Fri Feb 15 21:02:01 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -75,7 +75,7 @@ } @Test public void getBytes() throws Exception { - final String horse = "Žluťoučký kůň"; + final String horse = "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148"; final String expected = StringSample.getBytes(horse); assertExec( "Bytes look simplar", diff -r daca661c9bc4 -r ae352b763959 vm/src/test/java/org/apidesign/vm4brwsr/SystemTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/SystemTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -0,0 +1,56 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.vm4brwsr; + +import org.testng.annotations.BeforeClass; +import static org.testng.Assert.*; +import org.testng.annotations.Test; + +/** + * + * @author Jaroslav Tulach + */ +public class SystemTest { + private static TestVM code; + + @Test public void verifyJSTime() throws Exception { + long now = System.currentTimeMillis(); + + Object js = code.execCode("Get js time", + org.apidesign.bck2brwsr.emul.lang.System.class, "currentTimeMillis__J", + null + ); + + assertTrue(js instanceof Double, "Double " + js); + long time = ((Double)js).longValue(); + + long later = System.currentTimeMillis(); + + assertTrue(now <= time, "Lower bound is OK: " + now + " <= " + time); + assertTrue(time <= later, "Upper bound is OK: " + time + " <= " + later); + } + + + @BeforeClass + public static void compileTheCode() throws Exception { + code = TestVM.compileClass( + "org/apidesign/bck2brwsr/emul/lang/System"); + } + +} + diff -r daca661c9bc4 -r ae352b763959 vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java Fri Feb 15 21:02:01 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java Fri Feb 15 21:14:49 2013 +0100 @@ -58,7 +58,7 @@ if (ret == null && expRes == null) { return null; } - if (expRes.equals(ret)) { + if (expRes != null && expRes.equals(ret)) { return null; } if (expRes instanceof Number) { diff -r daca661c9bc4 -r ae352b763959 vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java Fri Feb 15 21:02:01 2013 +0100 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -147,7 +147,7 @@ @Compare public int stringToBytesLenght() throws UnsupportedEncodingException { - return "Žluťoučký kůň".getBytes("utf8").length; + return "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("utf8").length; } @Factory diff -r daca661c9bc4 -r ae352b763959 vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java Fri Feb 15 21:02:01 2013 +0100 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -47,6 +47,10 @@ return x % y; } + private static int neg(int x) { + return (-x); + } + @Compare public int addOverflow() { return add(Integer.MAX_VALUE, 1); } @@ -91,6 +95,18 @@ return mod(1, 2); } + @Compare public int negate() { + return neg(123456); + } + + @Compare public int negateMaxInt() { + return neg(Integer.MAX_VALUE); + } + + @Compare public int negateMinInt() { + return neg(Integer.MIN_VALUE); + } + @Compare public int sumTwoDimensions() { int[][] matrix = createMatrix(4, 3); matrix[0][0] += 10; diff -r daca661c9bc4 -r ae352b763959 vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Fri Feb 15 21:02:01 2013 +0100 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Fri Feb 15 21:14:49 2013 +0100 @@ -47,19 +47,90 @@ return (x % y); } + private static long neg(long x) { + return (-x); + } + + private static long shl(long x, int b) { + return (x << b); + } + + private static long shr(long x, int b) { + return (x >> b); + } + + private static long ushr(long x, int b) { + return (x >>> b); + } + + private static long and(long x, long y) { + return (x & y); + } + + private static long or(long x, long y) { + return (x | y); + } + + private static long xor(long x, long y) { + return (x ^ y); + } + + public static int compare(long x, long y, int zero) { + final int xyResult = compareL(x, y, zero); + final int yxResult = compareL(y, x, zero); + + return ((xyResult + yxResult) == 0) ? xyResult : -2; + } + + private static int compareL(long x, long y, int zero) { + int result = -2; + int trueCount = 0; + + x += zero; + if (x == y) { + result = 0; + ++trueCount; + } + + x += zero; + if (x < y) { + result = -1; + ++trueCount; + } + + x += zero; + if (x > y) { + result = 1; + ++trueCount; + } + + return (trueCount == 1) ? result : -2; + } + @Compare public long conversion() { return Long.MAX_VALUE; } - /* + @Compare public long negate1() { + return neg(0x00fa37d7763e0ca1l); + } + + @Compare public long negate2() { + return neg(0x80fa37d7763e0ca1l); + } + + @Compare public long negate3() { + return neg(0xfffffffffffffeddl); + } + @Compare public long addOverflow() { return add(Long.MAX_VALUE, 1l); } - + @Compare public long subUnderflow() { return sub(Long.MIN_VALUE, 1l); } - + @Compare public long addMaxLongAndMaxLong() { return add(Long.MAX_VALUE, Long.MAX_VALUE); } @@ -68,6 +139,10 @@ return sub(Long.MIN_VALUE, Long.MIN_VALUE); } + @Compare public long subMinLongAndMaxLong() { + return sub(Long.MIN_VALUE, Long.MAX_VALUE); + } + @Compare public long multiplyMaxLong() { return mul(Long.MAX_VALUE, 2l); } @@ -85,17 +160,172 @@ } @Compare public long multiplyPrecision() { - return mul(17638l, 1103l); + return mul(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el); } - @Compare public long division() { - return div(1l, 2l); + @Compare public long divideSmallPositiveNumbers() { + return div(0xabcdef, 0x123); + } + + @Compare public long divideSmallNegativeNumbers() { + return div(-0xabcdef, -0x123); + } + + @Compare public long divideSmallMixedNumbers() { + return div(0xabcdef, -0x123); + } + + @Compare public long dividePositiveNumbersOneDigitDenom() { + return div(0xabcdef0102ffffl, 0x654); + } + + @Compare public long divideNegativeNumbersOneDigitDenom() { + return div(-0xabcdef0102ffffl, -0x654); + } + + @Compare public long divideMixedNumbersOneDigitDenom() { + return div(-0xabcdef0102ffffl, 0x654); + } + + @Compare public long dividePositiveNumbersMultiDigitDenom() { + return div(0x7ffefc003322aabbl, 0x89ab1000l); + } + + @Compare public long divideNegativeNumbersMultiDigitDenom() { + return div(-0x7ffefc003322aabbl, -0x123489ab1001l); + } + + @Compare public long divideMixedNumbersMultiDigitDenom() { + return div(0x7ffefc003322aabbl, -0x38f49b0b7574e36l); + } + + @Compare public long divideWithOverflow() { + return div(0x8000fffe0000l, 0x8000ffffl); + } + + @Compare public long divideWithCorrection() { + return div(0x7fff800000000000l, 0x800000000001l); + } + + @Compare public long moduloSmallPositiveNumbers() { + return mod(0xabcdef, 0x123); + } + + @Compare public long moduloSmallNegativeNumbers() { + return mod(-0xabcdef, -0x123); + } + + @Compare public long moduloSmallMixedNumbers() { + return mod(0xabcdef, -0x123); + } + + @Compare public long moduloPositiveNumbersOneDigitDenom() { + return mod(0xabcdef0102ffffl, 0x654); + } + + @Compare public long moduloNegativeNumbersOneDigitDenom() { + return mod(-0xabcdef0102ffffl, -0x654); + } + + @Compare public long moduloMixedNumbersOneDigitDenom() { + return mod(-0xabcdef0102ffffl, 0x654); + } + + @Compare public long moduloPositiveNumbersMultiDigitDenom() { + return mod(0x7ffefc003322aabbl, 0x89ab1000l); + } + + @Compare public long moduloNegativeNumbersMultiDigitDenom() { + return mod(-0x7ffefc003322aabbl, -0x123489ab1001l); + } + + @Compare public long moduloMixedNumbersMultiDigitDenom() { + return mod(0x7ffefc003322aabbl, -0x38f49b0b7574e36l); + } + + @Compare public long moduloWithOverflow() { + return mod(0x8000fffe0000l, 0x8000ffffl); + } + + @Compare public long moduloWithCorrection() { + return mod(0x7fff800000000000l, 0x800000000001l); } - @Compare public long divisionReminder() { - return mod(1l, 2l); + @Compare public long shiftL1() { + return shl(0x00fa37d7763e0ca1l, 5); } - */ + + @Compare public long shiftL2() { + return shl(0x00fa37d7763e0ca1l, 32); + } + + @Compare public long shiftL3() { + return shl(0x00fa37d7763e0ca1l, 45); + } + + @Compare public long shiftR1() { + return shr(0x00fa37d7763e0ca1l, 5); + } + + @Compare public long shiftR2() { + return shr(0x00fa37d7763e0ca1l, 32); + } + + @Compare public long shiftR3() { + return shr(0x00fa37d7763e0ca1l, 45); + } + + @Compare public long uShiftR1() { + return ushr(0x00fa37d7763e0ca1l, 5); + } + + @Compare public long uShiftR2() { + return ushr(0x00fa37d7763e0ca1l, 45); + } + + @Compare public long uShiftR3() { + return ushr(0xf0fa37d7763e0ca1l, 5); + } + + @Compare public long uShiftR4() { + return ushr(0xf0fa37d7763e0ca1l, 45); + } + + @Compare public long and1() { + return and(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el); + } + + @Compare public long or1() { + return or(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el); + } + + @Compare public long xor1() { + return xor(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el); + } + + @Compare public long xor2() { + return xor(0x00fa37d7763e0ca1l, 0x00000000ff00123el); + } + + @Compare public long xor3() { + return xor(0x00000000763e0ca1l, 0x00000000ff00123el); + } + + @Compare public int compareSameNumbers() { + return compare(0x0000000000000000l, 0x0000000000000000l, 0); + } + + @Compare public int comparePositiveNumbers() { + return compare(0x0000000000200000l, 0x0000000010000000l, 0); + } + + @Compare public int compareNegativeNumbers() { + return compare(0xffffffffffffffffl, 0xffffffff00000000l, 0); + } + + @Compare public int compareMixedNumbers() { + return compare(0x8000000000000000l, 0x7fffffffffffffffl, 0); + } @Factory public static Object[] create() {