1.1 --- a/benchmarks/matrix-multiplication/pom.xml Fri Feb 15 21:02:01 2013 +0100
1.2 +++ b/benchmarks/matrix-multiplication/pom.xml Fri Feb 15 21:14:49 2013 +0100
1.3 @@ -7,6 +7,11 @@
1.4 <artifactId>matrix.multiplication</artifactId>
1.5 <version>0.3-SNAPSHOT</version>
1.6 <packaging>jar</packaging>
1.7 + <parent>
1.8 + <artifactId>benchmarks</artifactId>
1.9 + <groupId>org.apidesign.bck2brwsr</groupId>
1.10 + <version>0.3-SNAPSHOT</version>
1.11 + </parent>
1.12
1.13 <name>Matrix multiplication</name>
1.14
1.15 @@ -25,6 +30,14 @@
1.16 <target>1.7</target>
1.17 </configuration>
1.18 </plugin>
1.19 + <plugin>
1.20 + <groupId>org.apache.maven.plugins</groupId>
1.21 + <artifactId>maven-deploy-plugin</artifactId>
1.22 + <version>2.7</version>
1.23 + <configuration>
1.24 + <skip>true</skip>
1.25 + </configuration>
1.26 + </plugin>
1.27 </plugins>
1.28 </build>
1.29
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/JFXIssuesTest.java Fri Feb 15 21:14:49 2013 +0100
2.3 @@ -0,0 +1,46 @@
2.4 +/**
2.5 + * Back 2 Browser Bytecode Translator
2.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
2.7 + *
2.8 + * This program is free software: you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation, version 2 of the License.
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details.
2.16 + *
2.17 + * You should have received a copy of the GNU General Public License
2.18 + * along with this program. Look for COPYING file in the top folder.
2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
2.20 + */
2.21 +package org.apidesign.bck2brwsr.compact.tck;
2.22 +
2.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
2.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
2.25 +import org.testng.annotations.Factory;
2.26 +
2.27 +
2.28 +public class JFXIssuesTest {
2.29 + private abstract class Application {
2.30 + public abstract int getID();
2.31 + }
2.32 +
2.33 + private class MyApplication extends Application {
2.34 +
2.35 + @Override
2.36 + public int getID() {
2.37 + return 1;
2.38 + }
2.39 +
2.40 + }
2.41 +
2.42 + @Compare public boolean isClassAssignable() {
2.43 + return Application.class.isAssignableFrom(MyApplication.class);
2.44 + }
2.45 +
2.46 + @Factory public static Object[] create() {
2.47 + return VMTest.create(JFXIssuesTest.class);
2.48 + }
2.49 +}
3.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java Fri Feb 15 21:02:01 2013 +0100
3.2 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java Fri Feb 15 21:14:49 2013 +0100
3.3 @@ -20,6 +20,7 @@
3.4 import java.io.ByteArrayInputStream;
3.5 import java.io.IOException;
3.6 import java.io.InputStreamReader;
3.7 +import java.io.UnsupportedEncodingException;
3.8 import java.util.Arrays;
3.9 import org.apidesign.bck2brwsr.vmtest.Compare;
3.10 import org.apidesign.bck2brwsr.vmtest.VMTest;
3.11 @@ -38,7 +39,7 @@
3.12 (byte)-120
3.13 };
3.14 ByteArrayInputStream is = new ByteArrayInputStream(arr);
3.15 - InputStreamReader r = new InputStreamReader(is);
3.16 + InputStreamReader r = new InputStreamReader(is, "UTF-8");
3.17
3.18 StringBuilder sb = new StringBuilder();
3.19 for (;;) {
3.20 @@ -50,8 +51,8 @@
3.21 }
3.22 return sb.toString().toString();
3.23 }
3.24 - @Compare public String stringToBytes() {
3.25 - return Arrays.toString("Žluťoučký kůň".getBytes());
3.26 + @Compare public String stringToBytes() throws UnsupportedEncodingException {
3.27 + return Arrays.toString("\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("UTF-8"));
3.28 }
3.29
3.30 @Factory public static Object[] create() {
4.1 --- a/emul/mini/src/main/java/java/lang/Class.java Fri Feb 15 21:02:01 2013 +0100
4.2 +++ b/emul/mini/src/main/java/java/lang/Class.java Fri Feb 15 21:14:49 2013 +0100
4.3 @@ -403,10 +403,15 @@
4.4 return cmpType != null && getComponentType().isAssignableFrom(cmpType);
4.5 }
4.6 String prop = "$instOf_" + getName().replace('.', '_');
4.7 - return hasProperty(cls, prop);
4.8 + return hasCnstrProperty(cls, prop);
4.9 }
4.10
4.11 -
4.12 + @JavaScriptBody(args = { "who", "prop" }, body =
4.13 + "if (who.cnstr.prototype[prop]) return true; else return false;"
4.14 + )
4.15 + private static native boolean hasCnstrProperty(Object who, String prop);
4.16 +
4.17 +
4.18 /**
4.19 * Determines if the specified {@code Class} object represents an
4.20 * interface type.
5.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java Fri Feb 15 21:02:01 2013 +0100
5.2 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java Fri Feb 15 21:14:49 2013 +0100
5.3 @@ -54,7 +54,7 @@
5.4 )
5.5 public static native byte[] expandArray(byte[] arr, int expectedSize);
5.6
5.7 - @JavaScriptBody(args = {}, body = "return new Date().getMilliseconds();")
5.8 + @JavaScriptBody(args = {}, body = "return new Date().getTime();")
5.9 public static native long currentTimeMillis();
5.10
5.11 public static long nanoTime() {
6.1 --- a/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js Fri Feb 15 21:02:01 2013 +0100
6.2 +++ b/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js Fri Feb 15 21:14:49 2013 +0100
6.3 @@ -4,6 +4,7 @@
6.4 Number.prototype.mul32 = function(x) {
6.5 return (((this * (x >> 16)) << 16) + this * (x & 0xFFFF)) | 0;
6.6 };
6.7 +Number.prototype.neg32 = function() { return (-this) | 0; };
6.8
6.9 Number.prototype.toInt8 = function() { return (this << 24) >> 24; };
6.10 Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
6.11 @@ -33,6 +34,10 @@
6.12
6.13 Number.prototype.toExactString = function() {
6.14 if (this.hi) {
6.15 + // check for Long.MIN_VALUE
6.16 + if ((this.hi == (0x80000000 | 0)) && (this == 0)) {
6.17 + return '-9223372036854775808';
6.18 + }
6.19 var res = 0;
6.20 var a = [ 6,9,2,7,6,9,4,9,2,4 ];
6.21 var s = '';
6.22 @@ -60,7 +65,8 @@
6.23 }
6.24 s = String(digit).concat(s);
6.25 }
6.26 - return (neg ? '-' : '').concat(res).concat(s);
6.27 + s = String(res).concat(s).replace(/^0+/, '');
6.28 + return (neg ? '-' : '').concat(s);
6.29 }
6.30 return String(this);
6.31 };
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/ide/editor/pom.xml Fri Feb 15 21:14:49 2013 +0100
7.3 @@ -0,0 +1,198 @@
7.4 +<?xml version="1.0" encoding="UTF-8"?>
7.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
7.6 + <modelVersion>4.0.0</modelVersion>
7.7 + <parent>
7.8 + <artifactId>ide</artifactId>
7.9 + <groupId>org.apidesign.bck2brwsr</groupId>
7.10 + <version>0.3-SNAPSHOT</version>
7.11 + </parent>
7.12 +
7.13 + <groupId>org.apidesign.bck2brwsr.ide.editor</groupId>
7.14 + <artifactId>editor</artifactId>
7.15 + <version>0.3-SNAPSHOT</version>
7.16 + <packaging>nbm</packaging>
7.17 +
7.18 + <name>Editor Support for Bck2Brwsr</name>
7.19 +
7.20 + <properties>
7.21 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
7.22 + <netbeans.version>RELEASE72</netbeans.version>
7.23 + <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
7.24 + </properties>
7.25 +
7.26 + <repositories>
7.27 + <!--
7.28 + Repository hosting NetBeans modules, especially APIs.
7.29 + Versions are based on IDE releases, e.g.: RELEASE691
7.30 + To create your own repository, use: nbm:populate-repository
7.31 + -->
7.32 + <repository>
7.33 + <id>netbeans</id>
7.34 + <name>NetBeans</name>
7.35 + <url>http://bits.netbeans.org/maven2/</url>
7.36 + <snapshots>
7.37 + <enabled>false</enabled>
7.38 + </snapshots>
7.39 + </repository>
7.40 + </repositories>
7.41 +
7.42 + <dependencies>
7.43 + <dependency>
7.44 + <groupId>org.netbeans.api</groupId>
7.45 + <artifactId>org-netbeans-api-annotations-common</artifactId>
7.46 + <version>${netbeans.version}</version>
7.47 + </dependency>
7.48 + <dependency>
7.49 + <groupId>org.netbeans.api</groupId>
7.50 + <artifactId>org-netbeans-modules-java-source</artifactId>
7.51 + <version>${netbeans.version}</version>
7.52 + </dependency>
7.53 + <dependency>
7.54 + <groupId>org.netbeans.api</groupId>
7.55 + <artifactId>org-netbeans-libs-javacapi</artifactId>
7.56 + <version>${netbeans.version}</version>
7.57 + </dependency>
7.58 + <dependency>
7.59 + <groupId>org.netbeans.api</groupId>
7.60 + <artifactId>org-netbeans-spi-java-hints</artifactId>
7.61 + <version>${netbeans.version}</version>
7.62 + </dependency>
7.63 + <dependency>
7.64 + <groupId>org.netbeans.api</groupId>
7.65 + <artifactId>org-netbeans-modules-parsing-api</artifactId>
7.66 + <version>${netbeans.version}</version>
7.67 + </dependency>
7.68 + <dependency>
7.69 + <groupId>org.netbeans.api</groupId>
7.70 + <artifactId>org-netbeans-spi-editor-hints</artifactId>
7.71 + <version>${netbeans.version}</version>
7.72 + </dependency>
7.73 + <dependency>
7.74 + <groupId>org.netbeans.api</groupId>
7.75 + <artifactId>org-openide-util</artifactId>
7.76 + <version>${netbeans.version}</version>
7.77 + </dependency>
7.78 + <dependency>
7.79 + <groupId>org.netbeans.api</groupId>
7.80 + <artifactId>org-netbeans-modules-java-lexer</artifactId>
7.81 + <version>${netbeans.version}</version>
7.82 + </dependency>
7.83 + <dependency>
7.84 + <groupId>org.netbeans.api</groupId>
7.85 + <artifactId>org-netbeans-modules-lexer</artifactId>
7.86 + <version>${netbeans.version}</version>
7.87 + </dependency>
7.88 + <dependency>
7.89 + <groupId>org.apidesign.bck2brwsr</groupId>
7.90 + <artifactId>core</artifactId>
7.91 + <version>0.3-SNAPSHOT</version>
7.92 + <type>jar</type>
7.93 + <scope>test</scope>
7.94 + </dependency>
7.95 + <dependency>
7.96 + <groupId>org.netbeans.api</groupId>
7.97 + <artifactId>org-netbeans-modules-java-hints-test</artifactId>
7.98 + <version>${netbeans.version}</version>
7.99 + <scope>test</scope>
7.100 + </dependency>
7.101 + <dependency>
7.102 + <groupId>org.netbeans.api</groupId>
7.103 + <artifactId>org-netbeans-libs-junit4</artifactId>
7.104 + <version>${netbeans.version}</version>
7.105 + <scope>test</scope>
7.106 + </dependency>
7.107 + <dependency>
7.108 + <groupId>org.netbeans.modules</groupId>
7.109 + <artifactId>org-netbeans-lib-nbjavac</artifactId>
7.110 + <version>${netbeans.version}</version>
7.111 + <scope>test</scope>
7.112 + </dependency>
7.113 + <dependency>
7.114 + <groupId>org.testng</groupId>
7.115 + <artifactId>testng</artifactId>
7.116 + <scope>test</scope>
7.117 + </dependency>
7.118 + </dependencies>
7.119 +
7.120 + <build>
7.121 + <plugins>
7.122 + <plugin>
7.123 + <groupId>org.codehaus.mojo</groupId>
7.124 + <artifactId>nbm-maven-plugin</artifactId>
7.125 + <version>3.8</version>
7.126 + <extensions>true</extensions>
7.127 + </plugin>
7.128 +
7.129 + <plugin>
7.130 + <!-- NetBeans 6.9+ requires JDK 6 -->
7.131 + <groupId>org.apache.maven.plugins</groupId>
7.132 + <artifactId>maven-compiler-plugin</artifactId>
7.133 + <version>2.5.1</version>
7.134 + <configuration>
7.135 + <source>1.6</source>
7.136 + <target>1.6</target>
7.137 + <compilerArguments>
7.138 + <endorseddirs>${endorsed.dir}</endorseddirs>
7.139 + </compilerArguments>
7.140 + </configuration>
7.141 + </plugin>
7.142 +
7.143 + <plugin>
7.144 + <groupId>org.apache.maven.plugins</groupId>
7.145 + <artifactId>maven-jar-plugin</artifactId>
7.146 + <version>2.4</version>
7.147 + <configuration>
7.148 + <!-- to have the jar plugin pickup the nbm generated manifest -->
7.149 + <useDefaultManifestFile>true</useDefaultManifestFile>
7.150 + </configuration>
7.151 + </plugin>
7.152 +
7.153 + <plugin>
7.154 + <groupId>org.apache.maven.plugins</groupId>
7.155 + <artifactId>maven-dependency-plugin</artifactId>
7.156 + <executions>
7.157 + <execution>
7.158 + <id>endorsed</id>
7.159 + <phase>validate</phase>
7.160 + <goals>
7.161 + <goal>copy</goal>
7.162 + </goals>
7.163 + </execution>
7.164 + </executions>
7.165 + <configuration>
7.166 + <outputDirectory>${endorsed.dir}</outputDirectory>
7.167 + <silent>true</silent>
7.168 + <artifactItems>
7.169 + <artifactItem>
7.170 + <groupId>org.netbeans.api</groupId>
7.171 + <artifactId>org-netbeans-libs-javacapi</artifactId>
7.172 + <version>${netbeans.version}</version>
7.173 + </artifactItem>
7.174 + <artifactItem>
7.175 + <groupId>org.netbeans.external</groupId>
7.176 + <artifactId>nb-javac-api</artifactId>
7.177 + <version>${netbeans.version}</version>
7.178 + </artifactItem>
7.179 + <artifactItem>
7.180 + <groupId>org.netbeans.modules</groupId>
7.181 + <artifactId>org-netbeans-libs-javacimpl</artifactId>
7.182 + <version>${netbeans.version}</version>
7.183 + </artifactItem>
7.184 + <artifactItem>
7.185 + <groupId>org.netbeans.external</groupId>
7.186 + <artifactId>nb-javac-impl</artifactId>
7.187 + <version>${netbeans.version}</version>
7.188 + </artifactItem>
7.189 + </artifactItems>
7.190 + </configuration>
7.191 + </plugin>
7.192 + <plugin>
7.193 + <groupId>org.apache.maven.plugins</groupId>
7.194 + <artifactId>maven-surefire-plugin</artifactId>
7.195 + <configuration>
7.196 + <argLine>-Djava.endorsed.dirs=${endorsed.dir}</argLine>
7.197 + </configuration>
7.198 + </plugin>
7.199 + </plugins>
7.200 + </build>
7.201 +</project>
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JNIHelper.java Fri Feb 15 21:14:49 2013 +0100
8.3 @@ -0,0 +1,80 @@
8.4 +/**
8.5 + * Back 2 Browser Bytecode Translator
8.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
8.7 + *
8.8 + * This program is free software: you can redistribute it and/or modify
8.9 + * it under the terms of the GNU General Public License as published by
8.10 + * the Free Software Foundation, version 2 of the License.
8.11 + *
8.12 + * This program is distributed in the hope that it will be useful,
8.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.15 + * GNU General Public License for more details.
8.16 + *
8.17 + * You should have received a copy of the GNU General Public License
8.18 + * along with this program. Look for COPYING file in the top folder.
8.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
8.20 + */
8.21 +package org.apidesign.bck2brwsr.ide.editor;
8.22 +
8.23 +import java.lang.reflect.Method;
8.24 +import java.util.HashMap;
8.25 +import java.util.Map;
8.26 +
8.27 +/**
8.28 + * JNI Helper.
8.29 + * To facilitate lookup of methods by name and signature, instead of manually parsing signatures,
8.30 + * constructs the map of all methods and uses Class.getName() to generate almost-correct signatures.
8.31 + */
8.32 +class JNIHelper {
8.33 +
8.34 + static Method method(String clazz, String method, String signature) {
8.35 + final Map<String, Method> methods = methodMap(JNIHelper.clazz(clazz));
8.36 + return methods.get(methodKey(method, signature));
8.37 + }
8.38 +
8.39 + static Class<?> clazz(String clazz) {
8.40 + try {
8.41 + return Class.forName(clazz);
8.42 + } catch (ClassNotFoundException e) {
8.43 + throw new IllegalArgumentException(e);
8.44 + }
8.45 + }
8.46 +
8.47 + static Map<String, Method> methodMap(final Class<?> clazz) {
8.48 + final Map<String, Method> map = new HashMap<String, Method>();
8.49 + final Method[] methods = clazz.getDeclaredMethods();
8.50 + for (int i = 0; i < methods.length; i++) {
8.51 + final Method method = methods[i];
8.52 + map.put(methodKey(method.getName(), signature(method)), method);
8.53 + }
8.54 + return map;
8.55 + }
8.56 +
8.57 + static String methodKey(String method, String signature) {
8.58 + return method + '@' + signature;
8.59 + }
8.60 +
8.61 + static String signature(final Method method) {
8.62 + final Class<?>[] parameterTypes = method.getParameterTypes();
8.63 + final StringBuilder b = new StringBuilder();
8.64 + for (int j = 0; j < parameterTypes.length; j++) {
8.65 + b.append(signature(parameterTypes[j]));
8.66 + }
8.67 + return b.toString();
8.68 + }
8.69 +
8.70 + static String signature(final Class<?> clazz) {
8.71 + if (clazz == boolean.class) return "Z";
8.72 + else if (clazz == byte.class) return "B";
8.73 + else if (clazz == char.class) return "C";
8.74 + else if (clazz == double.class) return "D";
8.75 + else if (clazz == float.class) return "F";
8.76 + else if (clazz == int.class) return "I";
8.77 + else if (clazz == long.class) return "J";
8.78 + else if (clazz == short.class) return "S";
8.79 + else if (clazz == void.class) return "V";
8.80 + else if (clazz.isArray()) return clazz.getName().replace('.','/');
8.81 + else return "L" + clazz.getName().replace('.','/') + ";";
8.82 + }
8.83 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JSEmbeddingProvider.java Fri Feb 15 21:14:49 2013 +0100
9.3 @@ -0,0 +1,188 @@
9.4 +/**
9.5 + * Back 2 Browser Bytecode Translator
9.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
9.7 + *
9.8 + * This program is free software: you can redistribute it and/or modify
9.9 + * it under the terms of the GNU General Public License as published by
9.10 + * the Free Software Foundation, version 2 of the License.
9.11 + *
9.12 + * This program is distributed in the hope that it will be useful,
9.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9.15 + * GNU General Public License for more details.
9.16 + *
9.17 + * You should have received a copy of the GNU General Public License
9.18 + * along with this program. Look for COPYING file in the top folder.
9.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
9.20 + */
9.21 +package org.apidesign.bck2brwsr.ide.editor;
9.22 +
9.23 +import com.sun.source.tree.AnnotationTree;
9.24 +import com.sun.source.tree.AssignmentTree;
9.25 +import com.sun.source.tree.CompilationUnitTree;
9.26 +import com.sun.source.tree.ExpressionTree;
9.27 +import com.sun.source.tree.LiteralTree;
9.28 +import com.sun.source.tree.MethodTree;
9.29 +import com.sun.source.util.SourcePositions;
9.30 +import com.sun.source.util.TreePath;
9.31 +import com.sun.source.util.TreePathScanner;
9.32 +import com.sun.source.util.Trees;
9.33 +import java.io.IOException;
9.34 +import java.util.ArrayList;
9.35 +import java.util.Collection;
9.36 +import java.util.Collections;
9.37 +import java.util.List;
9.38 +import java.util.concurrent.atomic.AtomicBoolean;
9.39 +import javax.lang.model.element.TypeElement;
9.40 +import javax.swing.text.Document;
9.41 +import org.netbeans.api.editor.mimelookup.MimeRegistration;
9.42 +import org.netbeans.api.java.source.CompilationInfo;
9.43 +import org.netbeans.api.java.source.JavaParserResultTask;
9.44 +import org.netbeans.api.java.source.JavaSource;
9.45 +import org.netbeans.api.lexer.Language;
9.46 +import org.netbeans.api.lexer.TokenHierarchy;
9.47 +import org.netbeans.api.lexer.TokenSequence;
9.48 +import org.netbeans.modules.parsing.api.Snapshot;
9.49 +import org.netbeans.modules.parsing.spi.Parser;
9.50 +import org.netbeans.modules.parsing.spi.Scheduler;
9.51 +import org.netbeans.modules.parsing.spi.SchedulerEvent;
9.52 +import org.netbeans.modules.parsing.spi.SchedulerTask;
9.53 +import org.netbeans.modules.parsing.spi.TaskFactory;
9.54 +import org.openide.util.Exceptions;
9.55 +
9.56 +/**
9.57 + *
9.58 + * @author Tomas Zezula
9.59 + */
9.60 +public final class JSEmbeddingProvider extends JavaParserResultTask<Parser.Result> {
9.61 +
9.62 + private static final int PRIORITY = 1000;
9.63 + private static final String JS_ANNOTATION = "org.apidesign.bck2brwsr.core.JavaScriptBody"; //NOI18N
9.64 + private static final String BODY = "body"; //NOI18N
9.65 + private static final String JAVA_MIME_TYPE = "text/x-java"; //NOI18N
9.66 + private static final String JAVASCRIPT_MIME_TYPE = "text/javascript"; //NOI18N
9.67 + private final AtomicBoolean canceled = new AtomicBoolean();
9.68 +
9.69 + private JSEmbeddingProvider() {
9.70 + super(JavaSource.Phase.ELEMENTS_RESOLVED);
9.71 + }
9.72 +
9.73 + @Override
9.74 + public int getPriority() {
9.75 + return PRIORITY;
9.76 + }
9.77 +
9.78 + @Override
9.79 + public void cancel() {
9.80 + canceled.set(true);
9.81 + }
9.82 +
9.83 + @Override
9.84 + public Class<? extends Scheduler> getSchedulerClass() {
9.85 + return Scheduler.EDITOR_SENSITIVE_TASK_SCHEDULER;
9.86 + }
9.87 +
9.88 + @Override
9.89 + public void run(Parser.Result t, SchedulerEvent se) {
9.90 + canceled.set(false);
9.91 + final CompilationInfo ci = CompilationInfo.get(t);
9.92 + final CompilationUnitTree cu = ci.getCompilationUnit();
9.93 + final Trees trees = ci.getTrees();
9.94 + final SourcePositions sp = trees.getSourcePositions();
9.95 + final Finder f = new Finder(trees);
9.96 + final List<LiteralTree> result = new ArrayList<LiteralTree>();
9.97 + f.scan(cu, result);
9.98 + if (!result.isEmpty()) {
9.99 + try {
9.100 + final TokenHierarchy<Document> tk = TokenHierarchy.get(ci.getDocument());
9.101 + final Language<?> java = Language.find(JAVA_MIME_TYPE);
9.102 + final Language<?> javaScript = Language.find(JAVASCRIPT_MIME_TYPE);
9.103 + if (java != null && javaScript != null) {
9.104 + final TokenSequence<?> seq = tk.tokenSequence(java);
9.105 + if (seq != null) {
9.106 + for (LiteralTree lt : result) {
9.107 + final int start = (int) sp.getStartPosition(cu, lt);
9.108 + final int end = (int) sp.getEndPosition(cu, lt);
9.109 + seq.move(start);
9.110 + while (seq.moveNext() && seq.offset() < end) {
9.111 + seq.createEmbedding(javaScript, 1, 1, true);
9.112 + }
9.113 + }
9.114 + }
9.115 + }
9.116 + } catch (IOException ioe) {
9.117 + Exceptions.printStackTrace(ioe);
9.118 + }
9.119 + }
9.120 + }
9.121 +
9.122 +
9.123 +
9.124 +
9.125 + private static final class Finder extends TreePathScanner<Void, List<? super LiteralTree>> {
9.126 +
9.127 + private final Trees trees;
9.128 + private CompilationUnitTree cu;
9.129 + private boolean inEmbedding;
9.130 +
9.131 + Finder(final Trees trees) {
9.132 + this.trees = trees;
9.133 + }
9.134 +
9.135 + @Override
9.136 + public Void visitCompilationUnit(
9.137 + final CompilationUnitTree unit,
9.138 + final List p) {
9.139 + this.cu = unit;
9.140 + return super.visitCompilationUnit(unit, p);
9.141 + }
9.142 +
9.143 +
9.144 +
9.145 + @Override
9.146 + public Void visitMethod(
9.147 + final MethodTree m,
9.148 + final List<? super LiteralTree> p) {
9.149 + for (AnnotationTree a : m.getModifiers().getAnnotations()) {
9.150 + final TypeElement ae = (TypeElement) trees.getElement(TreePath.getPath(cu, a.getAnnotationType()));
9.151 + if (ae != null && JS_ANNOTATION.contentEquals(ae.getQualifiedName())) {
9.152 + final List<? extends ExpressionTree> args = a.getArguments();
9.153 + for (ExpressionTree kvp : args) {
9.154 + if (kvp instanceof AssignmentTree) {
9.155 + final AssignmentTree assignemt = (AssignmentTree) kvp;
9.156 + if (BODY.equals(assignemt.getVariable().toString())) {
9.157 + inEmbedding = true;
9.158 + try {
9.159 + scan(assignemt.getExpression(), p);
9.160 + } finally {
9.161 + inEmbedding = false;
9.162 + }
9.163 + }
9.164 + }
9.165 + }
9.166 + }
9.167 + }
9.168 + return null;
9.169 + }
9.170 +
9.171 + @Override
9.172 + public Void visitLiteral(LiteralTree node, List<? super LiteralTree> p) {
9.173 + if (inEmbedding) {
9.174 + p.add(node);
9.175 + }
9.176 + return super.visitLiteral(node, p);
9.177 + }
9.178 +
9.179 + }
9.180 +
9.181 + @MimeRegistration(
9.182 + service = TaskFactory.class,
9.183 + mimeType = JAVA_MIME_TYPE)
9.184 + public static final class Factory extends TaskFactory {
9.185 + @Override
9.186 + public Collection<? extends SchedulerTask> create(Snapshot snpsht) {
9.187 + return Collections.singleton(new JSEmbeddingProvider());
9.188 + }
9.189 + }
9.190 +
9.191 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBody.java Fri Feb 15 21:14:49 2013 +0100
10.3 @@ -0,0 +1,149 @@
10.4 +/**
10.5 + * Back 2 Browser Bytecode Translator
10.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
10.7 + *
10.8 + * This program is free software: you can redistribute it and/or modify
10.9 + * it under the terms of the GNU General Public License as published by
10.10 + * the Free Software Foundation, version 2 of the License.
10.11 + *
10.12 + * This program is distributed in the hope that it will be useful,
10.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10.15 + * GNU General Public License for more details.
10.16 + *
10.17 + * You should have received a copy of the GNU General Public License
10.18 + * along with this program. Look for COPYING file in the top folder.
10.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
10.20 + */
10.21 +package org.apidesign.bck2brwsr.ide.editor;
10.22 +
10.23 +import com.sun.source.tree.AnnotationTree;
10.24 +import com.sun.source.tree.ExpressionTree;
10.25 +import com.sun.source.tree.LiteralTree;
10.26 +import com.sun.source.tree.MethodTree;
10.27 +import com.sun.source.tree.Tree.Kind;
10.28 +import com.sun.source.tree.VariableTree;
10.29 +import com.sun.source.util.TreePath;
10.30 +import java.util.ArrayList;
10.31 +import java.util.Arrays;
10.32 +import java.util.Collections;
10.33 +import java.util.List;
10.34 +import org.netbeans.api.java.lexer.JavaTokenId;
10.35 +import static org.netbeans.api.java.lexer.JavaTokenId.BLOCK_COMMENT;
10.36 +import static org.netbeans.api.java.lexer.JavaTokenId.JAVADOC_COMMENT;
10.37 +import static org.netbeans.api.java.lexer.JavaTokenId.LINE_COMMENT;
10.38 +import static org.netbeans.api.java.lexer.JavaTokenId.WHITESPACE;
10.39 +import org.netbeans.api.java.source.CompilationInfo;
10.40 +import org.netbeans.api.java.source.TreeMaker;
10.41 +import org.netbeans.api.lexer.Token;
10.42 +import org.netbeans.api.lexer.TokenSequence;
10.43 +import org.netbeans.spi.editor.hints.ErrorDescription;
10.44 +import org.netbeans.spi.editor.hints.Fix;
10.45 +import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
10.46 +import org.netbeans.spi.java.hints.Hint;
10.47 +import org.netbeans.spi.java.hints.HintContext;
10.48 +import org.netbeans.spi.java.hints.JavaFix;
10.49 +import org.netbeans.spi.java.hints.TriggerTreeKind;
10.50 +import org.openide.util.NbBundle.Messages;
10.51 +
10.52 +@Hint(displayName = "#DN_JSNI2JavaScriptBody", description = "#DESC_JSNI2JavaScriptBody", category = "general")
10.53 +@Messages({
10.54 + "DN_JSNI2JavaScriptBody=JSNI to @JavaScriptBody",
10.55 + "DESC_JSNI2JavaScriptBody=JSNI to @JavaScriptBody"
10.56 +})
10.57 +public class JSNI2JavaScriptBody {
10.58 +
10.59 + @TriggerTreeKind(Kind.METHOD)
10.60 + @Messages("ERR_JSNI2JavaScriptBody=Can convert JSNI to @JavaScriptBody")
10.61 + public static ErrorDescription computeWarning(final HintContext ctx) {
10.62 + Token<JavaTokenId> token = findBlockToken(ctx.getInfo(), ctx.getPath(), ctx);
10.63 +
10.64 + if (token == null) {
10.65 + return null;
10.66 + }
10.67 +
10.68 + Fix fix = new FixImpl(ctx.getInfo(), ctx.getPath()).toEditorFix();
10.69 + return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_JSNI2JavaScriptBody(), fix);
10.70 + }
10.71 +
10.72 + private static Token<JavaTokenId> findBlockToken(CompilationInfo info, TreePath path, HintContext ctx) {
10.73 + int end = (int) info.getTrees().getSourcePositions().getEndPosition(path.getCompilationUnit(), path.getLeaf());
10.74 + TokenSequence<JavaTokenId> ts = info.getTokenHierarchy().tokenSequence(JavaTokenId.language());
10.75 +
10.76 + if (ts == null) return null;
10.77 +
10.78 + ts.move(end);
10.79 +
10.80 + if ((ctx != null && ctx.isCanceled()) || !ts.movePrevious() || ts.token().id() != JavaTokenId.SEMICOLON) return null;
10.81 +
10.82 + OUTER: while (ts.movePrevious()) {
10.83 + if (ctx != null && ctx.isCanceled()) return null;
10.84 +
10.85 + switch (ts.token().id()) {
10.86 + case WHITESPACE: break;
10.87 + case LINE_COMMENT: break;
10.88 + case JAVADOC_COMMENT: break;
10.89 + case BLOCK_COMMENT:
10.90 + final CharSequence tok = ts.token().text();
10.91 + final int l = tok.length();
10.92 + if (l > 4
10.93 + && tok.subSequence(0, 4).toString().equals("/*-{") // NOI18N
10.94 + && tok.subSequence(l - 4, l).toString().equals("}-*/") // NOI18N
10.95 + ) {
10.96 + return ts.offsetToken();
10.97 + }
10.98 + break;
10.99 + default:
10.100 + break OUTER;
10.101 + }
10.102 + }
10.103 +
10.104 + return null;
10.105 + }
10.106 +
10.107 + private static final class FixImpl extends JavaFix {
10.108 +
10.109 + public FixImpl(CompilationInfo info, TreePath tp) {
10.110 + super(info, tp);
10.111 + }
10.112 +
10.113 + @Override
10.114 + @Messages("FIX_JSNI2JavaScriptBody=Convert JSNI to @JavaScriptBody")
10.115 + protected String getText() {
10.116 + return Bundle.FIX_JSNI2JavaScriptBody();
10.117 + }
10.118 +
10.119 + @Override
10.120 + protected void performRewrite(TransformationContext ctx) {
10.121 + Token<JavaTokenId> jsniComment = findBlockToken(ctx.getWorkingCopy(), ctx.getPath(), null);
10.122 +
10.123 + if (jsniComment == null) {
10.124 + //XXX: warn?
10.125 + return ;
10.126 + }
10.127 +
10.128 + JsniCommentTokenizer tok = new JsniCommentTokenizer();
10.129 + ManglingSink ms = new ManglingSink();
10.130 + final CharSequence cmnt = jsniComment.text();
10.131 + tok.process(cmnt.subSequence(4, cmnt.length() - 4), ms);
10.132 +
10.133 + TreeMaker make = ctx.getWorkingCopy().getTreeMaker();
10.134 + MethodTree mt = (MethodTree) ctx.getPath().getLeaf();
10.135 + List<LiteralTree> params = new ArrayList<LiteralTree>();
10.136 +
10.137 + for (VariableTree p : mt.getParameters()) {
10.138 + params.add(make.Literal(p.getName().toString()));
10.139 + }
10.140 +
10.141 + AnnotationTree jsBody = make.Annotation(make.QualIdent("org.apidesign.bck2brwsr.core.JavaScriptBody"),
10.142 + Arrays.<ExpressionTree>asList(
10.143 + make.Assignment(make.Identifier("args"), make.NewArray(null, Collections.<ExpressionTree>emptyList(), params)),
10.144 + make.Assignment(make.Identifier("body"), make.Literal(ms.out.toString()))
10.145 + )
10.146 + );
10.147 +
10.148 +
10.149 + ctx.getWorkingCopy().rewrite(mt.getModifiers(), make.addModifiersAnnotation(mt.getModifiers(), jsBody));
10.150 + }
10.151 + }
10.152 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizer.java Fri Feb 15 21:14:49 2013 +0100
11.3 @@ -0,0 +1,70 @@
11.4 +/**
11.5 + * Back 2 Browser Bytecode Translator
11.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
11.7 + *
11.8 + * This program is free software: you can redistribute it and/or modify
11.9 + * it under the terms of the GNU General Public License as published by
11.10 + * the Free Software Foundation, version 2 of the License.
11.11 + *
11.12 + * This program is distributed in the hope that it will be useful,
11.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11.15 + * GNU General Public License for more details.
11.16 + *
11.17 + * You should have received a copy of the GNU General Public License
11.18 + * along with this program. Look for COPYING file in the top folder.
11.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
11.20 + */
11.21 +package org.apidesign.bck2brwsr.ide.editor;
11.22 +
11.23 +import java.util.regex.Matcher;
11.24 +import java.util.regex.Pattern;
11.25 +
11.26 +final class JsniCommentTokenizer {
11.27 +
11.28 + /**
11.29 + * Tokenize the contents of JSNI comment into the provided {@linkplain Sink}.
11.30 + * @param in the contents of JSNI comment
11.31 + * @param out the sink that consumes parsed tokens
11.32 + */
11.33 + public void process(final CharSequence in, final Sink out) {
11.34 + final Matcher member = Pattern.compile("@([^:]+)::([a-zA-Z_$][a-zA-Z\\d_$]*)").matcher(in);
11.35 + final Matcher signature = Pattern.compile("\\(([^\\)]*)\\)").matcher(in);
11.36 +
11.37 + int i = 0;
11.38 + while (true) {
11.39 + if (member.find(i)) {
11.40 + final int memberStart = member.start();
11.41 + final int memberEnd = member.end();
11.42 + if (memberStart > i) out.javascript(in.subSequence(i, memberStart).toString());
11.43 +
11.44 + final String clazz = member.group(1);
11.45 + final String name = member.group(2);
11.46 +
11.47 + if (in.charAt(memberEnd) == '(') {
11.48 + if (!signature.find(memberEnd)) {
11.49 + throw new IllegalStateException("Expected method signature");
11.50 + }
11.51 + assert signature.start() == memberEnd;
11.52 + out.method(clazz, name, signature.group(1));
11.53 + i = signature.end();
11.54 + } else {
11.55 + out.field(clazz, name);
11.56 + i = memberEnd;
11.57 + }
11.58 + } else {
11.59 + out.javascript(in.subSequence(i, in.length()).toString());
11.60 + break;
11.61 + }
11.62 + }
11.63 + }
11.64 +
11.65 +
11.66 + static interface Sink {
11.67 + void javascript(String s);
11.68 +
11.69 + void method(String clazz, String method, String signature);
11.70 +
11.71 + void field(String clazz, String field);
11.72 + }
11.73 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/ManglingSink.java Fri Feb 15 21:14:49 2013 +0100
12.3 @@ -0,0 +1,71 @@
12.4 +/**
12.5 + * Back 2 Browser Bytecode Translator
12.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
12.7 + *
12.8 + * This program is free software: you can redistribute it and/or modify
12.9 + * it under the terms of the GNU General Public License as published by
12.10 + * the Free Software Foundation, version 2 of the License.
12.11 + *
12.12 + * This program is distributed in the hope that it will be useful,
12.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12.15 + * GNU General Public License for more details.
12.16 + *
12.17 + * You should have received a copy of the GNU General Public License
12.18 + * along with this program. Look for COPYING file in the top folder.
12.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
12.20 + */
12.21 +package org.apidesign.bck2brwsr.ide.editor;
12.22 +
12.23 +/**
12.24 + * An implementation of {@linkplain JsniCommentTokenizer.Sink} that generates B2B
12.25 + */
12.26 +class ManglingSink implements JsniCommentTokenizer.Sink {
12.27 +
12.28 + final StringBuilder out = new StringBuilder();
12.29 +
12.30 + public void javascript(String s) {
12.31 + out.append(s);
12.32 + }
12.33 +
12.34 + public void method(String clazz, String method, String signature) {
12.35 + out.append(mangle(clazz, method, signature));
12.36 + }
12.37 +
12.38 + public void field(String clazz, String field) {
12.39 +// out.append(field);
12.40 + out.append('_').append(field).append('(').append(')');
12.41 + }
12.42 +
12.43 +
12.44 + @Override
12.45 + public String toString() {
12.46 + return out.toString();
12.47 + }
12.48 +
12.49 +
12.50 + static String mangle(String clazz, String method, String signature) {
12.51 + final StringBuilder builder = new StringBuilder();
12.52 + builder.append(method);
12.53 + builder.append("__");
12.54 + builder.append(mangle(JNIHelper.signature(JNIHelper.method(clazz, method, signature).getReturnType())));
12.55 + builder.append(mangle(signature));
12.56 + return builder.toString();
12.57 + }
12.58 +
12.59 +
12.60 + static String mangle(String txt) {
12.61 + final StringBuilder sb = new StringBuilder();
12.62 + for (int i = 0; i < txt.length(); i++) {
12.63 + final char ch = txt.charAt(i);
12.64 + switch (ch) {
12.65 + case '/': sb.append('_'); break;
12.66 + case '_': sb.append("_1"); break;
12.67 + case ';': sb.append("_2"); break;
12.68 + case '[': sb.append("_3"); break;
12.69 + default: sb.append(ch); break;
12.70 + }
12.71 + }
12.72 + return sb.toString();
12.73 + }
12.74 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/ide/editor/src/main/nbm/manifest.mf Fri Feb 15 21:14:49 2013 +0100
13.3 @@ -0,0 +1,2 @@
13.4 +Manifest-Version: 1.0
13.5 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/test/hints/Bundle.properties
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/ide/editor/src/main/resources/org/netbeans/modules/jackpot30/test/hints/Bundle.properties Fri Feb 15 21:14:49 2013 +0100
14.3 @@ -0,0 +1,21 @@
14.4 +#
14.5 +# Back 2 Browser Bytecode Translator
14.6 +# Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
14.7 +#
14.8 +# This program is free software: you can redistribute it and/or modify
14.9 +# it under the terms of the GNU General Public License as published by
14.10 +# the Free Software Foundation, version 2 of the License.
14.11 +#
14.12 +# This program is distributed in the hope that it will be useful,
14.13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14.14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14.15 +# GNU General Public License for more details.
14.16 +#
14.17 +# You should have received a copy of the GNU General Public License
14.18 +# along with this program. Look for COPYING file in the top folder.
14.19 +# If not, see http://opensource.org/licenses/GPL-2.0.
14.20 +#
14.21 +
14.22 +OpenIDE-Module-Name=Bck2Brwsr Editor Support
14.23 +OpenIDE-Module-Short-Description=Provides hints, coloring, etc. for the bck2brwsr.apidesign.org project
14.24 +OpenIDE-Module-Display-Category=Java
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/DejsniReaderTest.java Fri Feb 15 21:14:49 2013 +0100
15.3 @@ -0,0 +1,84 @@
15.4 +/**
15.5 + * Back 2 Browser Bytecode Translator
15.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
15.7 + *
15.8 + * This program is free software: you can redistribute it and/or modify
15.9 + * it under the terms of the GNU General Public License as published by
15.10 + * the Free Software Foundation, version 2 of the License.
15.11 + *
15.12 + * This program is distributed in the hope that it will be useful,
15.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15.15 + * GNU General Public License for more details.
15.16 + *
15.17 + * You should have received a copy of the GNU General Public License
15.18 + * along with this program. Look for COPYING file in the top folder.
15.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
15.20 + */
15.21 +package org.apidesign.bck2brwsr.ide.editor;
15.22 +
15.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
15.24 +import org.netbeans.modules.java.hints.test.api.HintTest;
15.25 +import org.openide.filesystems.FileUtil;
15.26 +import org.testng.annotations.Test;
15.27 +
15.28 +public class DejsniReaderTest {
15.29 +
15.30 + @Test
15.31 + public void test1() throws Exception {
15.32 + String s = "class Test {\n" +
15.33 + " /** javadoc */\n" +
15.34 + " public native void test() /*-{\n" +
15.35 + " // body\n" +
15.36 + " }-*/;\n" +
15.37 + "}\n";
15.38 +
15.39 + String expected = " import org.apidesign.bck2brwsr.core.JavaScriptBody;\n"
15.40 + + "class Test {\n" +
15.41 + "\n" +
15.42 + " /** javadoc */\n" +
15.43 + " @JavaScriptBody(args = {}, body = \"\\n // body\\n \")\n" +
15.44 + " public native void test();\n" +
15.45 + "}\n";
15.46 +
15.47 + HintTest.create()
15.48 + .input(s)
15.49 + .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation()))
15.50 + .run(JSNI2JavaScriptBody.class)
15.51 + .findWarning("2:23-2:27:verifier:" + Bundle.ERR_JSNI2JavaScriptBody())
15.52 + .applyFix()
15.53 + .assertCompilable()
15.54 + .assertOutput(expected);
15.55 + }
15.56 +
15.57 +
15.58 + @Test
15.59 + public void test2() throws Exception {
15.60 + String s = "class Test {\n" +
15.61 + " /** javadoc */\n" +
15.62 + " @SuppressWarnings(\"unused\")\n" +
15.63 + " // comment\n" +
15.64 + " public native void test() /*-{\n" +
15.65 + " // body\n" +
15.66 + " }-*/;\n" +
15.67 + "}\n";
15.68 +
15.69 + String expected = " import org.apidesign.bck2brwsr.core.JavaScriptBody;\n"
15.70 + + "class Test {\n" +
15.71 + "\n" +
15.72 + " /** javadoc */\n" +
15.73 + " @SuppressWarnings(\"unused\")\n" +
15.74 + " // comment\n" +
15.75 + " @JavaScriptBody(args = {}, body = \"\\n // body\\n \")\n" +
15.76 + " public native void test();\n" +
15.77 + "}\n";
15.78 + HintTest.create()
15.79 + .input(s)
15.80 + .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation()))
15.81 + .run(JSNI2JavaScriptBody.class)
15.82 + .findWarning("4:23-4:27:verifier:" + Bundle.ERR_JSNI2JavaScriptBody())
15.83 + .applyFix()
15.84 + .assertCompilable()
15.85 + .assertOutput(expected);
15.86 + }
15.87 +}
15.88 \ No newline at end of file
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBodyTest.java Fri Feb 15 21:14:49 2013 +0100
16.3 @@ -0,0 +1,46 @@
16.4 +/**
16.5 + * Back 2 Browser Bytecode Translator
16.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
16.7 + *
16.8 + * This program is free software: you can redistribute it and/or modify
16.9 + * it under the terms of the GNU General Public License as published by
16.10 + * the Free Software Foundation, version 2 of the License.
16.11 + *
16.12 + * This program is distributed in the hope that it will be useful,
16.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16.15 + * GNU General Public License for more details.
16.16 + *
16.17 + * You should have received a copy of the GNU General Public License
16.18 + * along with this program. Look for COPYING file in the top folder.
16.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
16.20 + */
16.21 +package org.apidesign.bck2brwsr.ide.editor;
16.22 +
16.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
16.24 +import org.netbeans.modules.java.hints.test.api.HintTest;
16.25 +import org.openide.filesystems.FileUtil;
16.26 +import org.testng.annotations.Test;
16.27 +
16.28 +public class JSNI2JavaScriptBodyTest {
16.29 +
16.30 + @Test
16.31 + public void testFixWorking() throws Exception {
16.32 + HintTest.create()
16.33 + .input("package test;\n" +
16.34 + "public class Test {\n" +
16.35 + " public native void run(int a) /*-{ this.a = a; }-*/;\n" +
16.36 + "}\n")
16.37 + .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation()))
16.38 + .run(JSNI2JavaScriptBody.class)
16.39 + .findWarning("2:23-2:26:verifier:" + Bundle.ERR_JSNI2JavaScriptBody())
16.40 + .applyFix()
16.41 + .assertCompilable()
16.42 + .assertOutput("package test;\n" +
16.43 + "import org.apidesign.bck2brwsr.core.JavaScriptBody;\n" +
16.44 + "public class Test {\n" +
16.45 + " @JavaScriptBody(args = {\"a\"}, body = \" this.a = a; \")\n" +
16.46 + " public native void run(int a);\n" +
16.47 + "}\n");
16.48 + }
16.49 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizerTest.java Fri Feb 15 21:14:49 2013 +0100
17.3 @@ -0,0 +1,154 @@
17.4 +/**
17.5 + * Back 2 Browser Bytecode Translator
17.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
17.7 + *
17.8 + * This program is free software: you can redistribute it and/or modify
17.9 + * it under the terms of the GNU General Public License as published by
17.10 + * the Free Software Foundation, version 2 of the License.
17.11 + *
17.12 + * This program is distributed in the hope that it will be useful,
17.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17.15 + * GNU General Public License for more details.
17.16 + *
17.17 + * You should have received a copy of the GNU General Public License
17.18 + * along with this program. Look for COPYING file in the top folder.
17.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
17.20 + */
17.21 +package org.apidesign.bck2brwsr.ide.editor;
17.22 +
17.23 +import java.io.IOException;
17.24 +import java.util.ArrayList;
17.25 +import java.util.List;
17.26 +import org.testng.Assert;
17.27 +import org.testng.annotations.Test;
17.28 +
17.29 +public class JsniCommentTokenizerTest {
17.30 +
17.31 + private static class MockSink implements JsniCommentTokenizer.Sink {
17.32 + final List<String> out = new ArrayList<String>();
17.33 +
17.34 + public void javascript(String s) {
17.35 + out.add("J " + s);
17.36 + }
17.37 +
17.38 + public void method(String clazz, String method, String signature) {
17.39 + out.add("M " + clazz + "|" + method + "|" + signature);
17.40 + }
17.41 +
17.42 + public void field(String clazz, String field) {
17.43 + out.add("F " + clazz + "|" + field);
17.44 + }
17.45 + }
17.46 +
17.47 +
17.48 + @Test
17.49 + public void testProcess_nop() throws IOException {
17.50 + final String in = "foo bar";
17.51 + final List<String> expected = new ArrayList<String>();
17.52 + expected.add("J foo bar");
17.53 +
17.54 + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
17.55 + final MockSink out = new MockSink();
17.56 + jsniCommentTokenizer.process(in, out);
17.57 +
17.58 + Assert.assertEquals(expected, out.out);
17.59 + }
17.60 +
17.61 + @Test
17.62 + public void testProcess_read_static_field() throws IOException {
17.63 + final String in = " @com.google.gwt.examples.JSNIExample::myStaticField = val + \" and stuff\";";
17.64 + final List<String> expected = new ArrayList<String>();
17.65 + expected.add("J ");
17.66 + expected.add("F com.google.gwt.examples.JSNIExample|myStaticField");
17.67 + expected.add("J = val + \" and stuff\";");
17.68 +
17.69 + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
17.70 + final MockSink out = new MockSink();
17.71 + jsniCommentTokenizer.process(in, out);
17.72 +
17.73 + Assert.assertEquals(expected, out.out);
17.74 + }
17.75 +
17.76 + @Test
17.77 + public void testProcess_write_instance_field() throws IOException {
17.78 + final String in = " x.@com.google.gwt.examples.JSNIExample::myInstanceField = val + \" and stuff\";";
17.79 + final List<String> expected = new ArrayList<String>();
17.80 + expected.add("J x.");
17.81 + expected.add("F com.google.gwt.examples.JSNIExample|myInstanceField");
17.82 + expected.add("J = val + \" and stuff\";");
17.83 +
17.84 + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
17.85 + final MockSink out = new MockSink();
17.86 + jsniCommentTokenizer.process(in, out);
17.87 +
17.88 + Assert.assertEquals(expected, out.out);
17.89 + }
17.90 +
17.91 + @Test
17.92 + public void testProcess_read_instance_field() throws IOException {
17.93 + final String in = " var val = this.@com.google.gwt.examples.JSNIExample::myInstanceField;";
17.94 + final List<String> expected = new ArrayList<String>();
17.95 + expected.add("J var val = this.");
17.96 + expected.add("F com.google.gwt.examples.JSNIExample|myInstanceField");
17.97 + expected.add("J ;");
17.98 +
17.99 + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
17.100 + final MockSink out = new MockSink();
17.101 + jsniCommentTokenizer.process(in, out);
17.102 +
17.103 + Assert.assertEquals(expected, out.out);
17.104 + }
17.105 +
17.106 +
17.107 + @Test
17.108 + public void testProcess_static_method() throws IOException {
17.109 + final String in = " @com.google.gwt.examples.JSNIExample::staticFoo(Ljava/lang/String;)(s);";
17.110 + final List<String> expected = new ArrayList<String>();
17.111 + expected.add("J ");
17.112 + expected.add("M com.google.gwt.examples.JSNIExample|staticFoo|Ljava/lang/String;");
17.113 + expected.add("J (s);");
17.114 +
17.115 + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
17.116 + final MockSink out = new MockSink();
17.117 + jsniCommentTokenizer.process(in, out);
17.118 +
17.119 + Assert.assertEquals(expected, out.out);
17.120 + }
17.121 +
17.122 +
17.123 + @Test
17.124 + public void testProcess_instance_method() throws IOException {
17.125 + final String in = " x.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);";
17.126 + final List<String> expected = new ArrayList<String>();
17.127 + expected.add("J x.");
17.128 + expected.add("M com.google.gwt.examples.JSNIExample|instanceFoo|Ljava/lang/String;");
17.129 + expected.add("J (s);");
17.130 +
17.131 + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
17.132 + final MockSink out = new MockSink();
17.133 + jsniCommentTokenizer.process(in, out);
17.134 +
17.135 + Assert.assertEquals(expected, out.out);
17.136 + }
17.137 +
17.138 +
17.139 + @Test
17.140 + public void testProcess_multiline() throws IOException {
17.141 + final String in =
17.142 + " x.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);" +
17.143 + " @com.google.gwt.examples.JSNIExample::myStaticField = val + \" and stuff\";";
17.144 + final List<String> expected = new ArrayList<String>();
17.145 + expected.add("J x.");
17.146 + expected.add("M com.google.gwt.examples.JSNIExample|instanceFoo|Ljava/lang/String;");
17.147 + expected.add("J (s); ");
17.148 + expected.add("F com.google.gwt.examples.JSNIExample|myStaticField");
17.149 + expected.add("J = val + \" and stuff\";");
17.150 +
17.151 + final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
17.152 + final MockSink out = new MockSink();
17.153 + jsniCommentTokenizer.process(in, out);
17.154 +
17.155 + Assert.assertEquals(expected, out.out);
17.156 + }
17.157 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/ManglingSinkTest.java Fri Feb 15 21:14:49 2013 +0100
18.3 @@ -0,0 +1,58 @@
18.4 +/**
18.5 + * Back 2 Browser Bytecode Translator
18.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
18.7 + *
18.8 + * This program is free software: you can redistribute it and/or modify
18.9 + * it under the terms of the GNU General Public License as published by
18.10 + * the Free Software Foundation, version 2 of the License.
18.11 + *
18.12 + * This program is distributed in the hope that it will be useful,
18.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18.15 + * GNU General Public License for more details.
18.16 + *
18.17 + * You should have received a copy of the GNU General Public License
18.18 + * along with this program. Look for COPYING file in the top folder.
18.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
18.20 + */
18.21 +package org.apidesign.bck2brwsr.ide.editor;
18.22 +
18.23 +import org.testng.Assert;
18.24 +import org.testng.annotations.Test;
18.25 +
18.26 +
18.27 +public class ManglingSinkTest {
18.28 +
18.29 + @Test
18.30 + public void testMangle_1() {
18.31 + Assert.assertEquals(
18.32 + "binarySearch__I_3BIIB",
18.33 + ManglingSink.mangle("java.util.Arrays", "binarySearch", "[BIIB")
18.34 + );
18.35 + }
18.36 +
18.37 + @Test
18.38 + public void testMangle_2() {
18.39 + Assert.assertEquals(
18.40 + "sort__V_3I",
18.41 + ManglingSink.mangle("java.util.Arrays", "sort", "[I")
18.42 + );
18.43 + }
18.44 +
18.45 + @Test
18.46 + public void testMangle_3() {
18.47 + Assert.assertEquals(
18.48 + "binarySearch__I_3Ljava_lang_Object_2IILjava_lang_Object_2",
18.49 + ManglingSink.mangle("java.util.Arrays", "binarySearch", "[Ljava/lang/Object;IILjava/lang/Object;")
18.50 + );
18.51 + }
18.52 +
18.53 +
18.54 + @Test
18.55 + public void testField() {
18.56 + final ManglingSink manglingSink = new ManglingSink();
18.57 + manglingSink.field(null, "value");
18.58 +
18.59 + Assert.assertEquals("_value()", manglingSink.toString());
18.60 + }
18.61 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/ide/pom.xml Fri Feb 15 21:14:49 2013 +0100
19.3 @@ -0,0 +1,17 @@
19.4 +<?xml version="1.0" encoding="UTF-8"?>
19.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
19.6 + <modelVersion>4.0.0</modelVersion>
19.7 + <parent>
19.8 + <artifactId>bck2brwsr</artifactId>
19.9 + <groupId>org.apidesign</groupId>
19.10 + <version>0.3-SNAPSHOT</version>
19.11 + </parent>
19.12 + <groupId>org.apidesign.bck2brwsr</groupId>
19.13 + <artifactId>ide</artifactId>
19.14 + <version>0.3-SNAPSHOT</version>
19.15 + <packaging>pom</packaging>
19.16 + <name>IDE Support</name>
19.17 + <modules>
19.18 + <module>editor</module>
19.19 + </modules>
19.20 +</project>
20.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java Fri Feb 15 21:02:01 2013 +0100
20.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java Fri Feb 15 21:14:49 2013 +0100
20.3 @@ -307,10 +307,10 @@
20.4 public native double getGlobalAlpha();
20.5
20.6 @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation;")
20.7 - public native void setGlobalCompositeOperation(double alpha);
20.8 + public native void setGlobalCompositeOperation(String operation);
20.9
20.10 @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
20.11 - public native double getGlobalCompositeOperation();
20.12 + public native String getGlobalCompositeOperation();
20.13
20.14 public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
20.15 return new LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1));
21.1 --- a/javaquery/demo-calculator-dynamic/pom.xml Fri Feb 15 21:02:01 2013 +0100
21.2 +++ b/javaquery/demo-calculator-dynamic/pom.xml Fri Feb 15 21:14:49 2013 +0100
21.3 @@ -54,6 +54,14 @@
21.4 </configuration>
21.5 </plugin>
21.6 <plugin>
21.7 + <groupId>org.apache.maven.plugins</groupId>
21.8 + <artifactId>maven-deploy-plugin</artifactId>
21.9 + <version>2.7</version>
21.10 + <configuration>
21.11 + <skip>true</skip>
21.12 + </configuration>
21.13 + </plugin>
21.14 + <plugin>
21.15 <artifactId>maven-assembly-plugin</artifactId>
21.16 <version>2.4</version>
21.17 <executions>
22.1 --- a/javaquery/demo-calculator/pom.xml Fri Feb 15 21:02:01 2013 +0100
22.2 +++ b/javaquery/demo-calculator/pom.xml Fri Feb 15 21:14:49 2013 +0100
22.3 @@ -72,6 +72,14 @@
22.4 </execution>
22.5 </executions>
22.6 </plugin>
22.7 + <plugin>
22.8 + <groupId>org.apache.maven.plugins</groupId>
22.9 + <artifactId>maven-deploy-plugin</artifactId>
22.10 + <version>2.7</version>
22.11 + <configuration>
22.12 + <skip>true</skip>
22.13 + </configuration>
22.14 + </plugin>
22.15 </plugins>
22.16 </build>
22.17
23.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Fri Feb 15 21:02:01 2013 +0100
23.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Fri Feb 15 21:14:49 2013 +0100
23.3 @@ -312,10 +312,10 @@
23.4 if (ch == '$' && params.length > 0) {
23.5 int cnt = is.read() - '0';
23.6 if (cnt == 'U' - '0') {
23.7 - os.write(baseURL.getBytes());
23.8 + os.write(baseURL.getBytes("UTF-8"));
23.9 }
23.10 if (cnt >= 0 && cnt < params.length) {
23.11 - os.write(params[cnt].getBytes());
23.12 + os.write(params[cnt].getBytes("UTF-8"));
23.13 }
23.14 } else {
23.15 os.write(ch);
24.1 --- a/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java Fri Feb 15 21:02:01 2013 +0100
24.2 +++ b/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java Fri Feb 15 21:14:49 2013 +0100
24.3 @@ -37,7 +37,7 @@
24.4 import org.apidesign.bck2brwsr.launcher.Launcher;
24.5
24.6 /** Executes given HTML page in a browser. */
24.7 -@Mojo(name="brwsr", defaultPhase=LifecyclePhase.DEPLOY)
24.8 +@Mojo(name="brwsr", defaultPhase=LifecyclePhase.NONE)
24.9 public class BrswrMojo extends AbstractMojo {
24.10 public BrswrMojo() {
24.11 }
25.1 --- a/mojo/src/main/resources/archetype-resources/pom.xml Fri Feb 15 21:02:01 2013 +0100
25.2 +++ b/mojo/src/main/resources/archetype-resources/pom.xml Fri Feb 15 21:14:49 2013 +0100
25.3 @@ -10,6 +10,32 @@
25.4
25.5 <name>${artifactId}</name>
25.6
25.7 + <repositories>
25.8 + <repository>
25.9 + <id>java.net</id>
25.10 + <name>Java.net</name>
25.11 + <url>https://maven.java.net/content/repositories/snapshots/</url>
25.12 + <snapshots>
25.13 + <enabled>true</enabled>
25.14 + </snapshots>
25.15 + </repository>
25.16 + <repository>
25.17 + <id>netbeans</id>
25.18 + <name>NetBeans</name>
25.19 + <url>http://bits.netbeans.org/maven2/</url>
25.20 + </repository>
25.21 + </repositories>
25.22 + <pluginRepositories>
25.23 + <pluginRepository>
25.24 + <id>java.net</id>
25.25 + <name>Local Maven repository of releases</name>
25.26 + <url>https://maven.java.net/content/repositories/snapshots/</url>
25.27 + <snapshots>
25.28 + <enabled>true</enabled>
25.29 + </snapshots>
25.30 + </pluginRepository>
25.31 + </pluginRepositories>
25.32 +
25.33 <properties>
25.34 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
25.35 </properties>
26.1 --- a/pom.xml Fri Feb 15 21:02:01 2013 +0100
26.2 +++ b/pom.xml Fri Feb 15 21:14:49 2013 +0100
26.3 @@ -6,6 +6,11 @@
26.4 <version>0.3-SNAPSHOT</version>
26.5 <packaging>pom</packaging>
26.6 <name>Back 2 Browser</name>
26.7 + <parent>
26.8 + <groupId>net.java</groupId>
26.9 + <artifactId>jvnet-parent</artifactId>
26.10 + <version>3</version>
26.11 + </parent>
26.12 <modules>
26.13 <module>vm</module>
26.14 <module>emul</module>
26.15 @@ -17,6 +22,7 @@
26.16 <module>benchmarks</module>
26.17 <module>launcher</module>
26.18 <module>vmtest</module>
26.19 + <module>ide</module>
26.20 </modules>
26.21 <licenses>
26.22 <license>
26.23 @@ -29,6 +35,11 @@
26.24 <name>API Design</name>
26.25 <url>http://apidesign.org</url>
26.26 </organization>
26.27 + <scm>
26.28 + <connection>scm:hg:http://source.apidesign.org/hg/bck2brwsr</connection>
26.29 + <developerConnection>scm:hg:https://source.apidesign.org/hg/bck2brwsr</developerConnection>
26.30 + <url>http://source.apidesign.org/hg/bck2brwsr</url>
26.31 + </scm>
26.32 <repositories>
26.33 <repository>
26.34 <id>netbeans</id>
27.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Feb 15 21:02:01 2013 +0100
27.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Feb 15 21:14:49 2013 +0100
27.3 @@ -600,7 +600,7 @@
27.4 emit(out, "@1 = @1.xor64(@2);", smapper.getL(1), smapper.popL());
27.5 break;
27.6 case opc_ineg:
27.7 - emit(out, "@1 = -@1;", smapper.getI(0));
27.8 + emit(out, "@1 = @1.neg32();", smapper.getI(0));
27.9 break;
27.10 case opc_lneg:
27.11 emit(out, "@1 = @1.neg64();", smapper.getL(0));
27.12 @@ -634,7 +634,7 @@
27.13 final int varIndx = wide ? readUShort(byteCodes, i++)
27.14 : readUByte(byteCodes, i);
27.15 ++i;
27.16 - final int incrBy = wide ? readIntArg(byteCodes, i++)
27.17 + final int incrBy = wide ? readShort(byteCodes, i++)
27.18 : byteCodes[i];
27.19 wide = false;
27.20 if (incrBy == 1) {
27.21 @@ -1355,20 +1355,25 @@
27.22 final int indxLo = byteCodes[offsetInstruction + 2];
27.23 return (indxHi & 0xffffff00) | (indxLo & 0xff);
27.24 }
27.25 - private int readInt4(byte[] byteCodes, int offsetInstruction) {
27.26 - final int d = byteCodes[offsetInstruction + 0] << 24;
27.27 - final int c = byteCodes[offsetInstruction + 1] << 16;
27.28 - final int b = byteCodes[offsetInstruction + 2] << 8;
27.29 - final int a = byteCodes[offsetInstruction + 3];
27.30 + private int readInt4(byte[] byteCodes, int offset) {
27.31 + final int d = byteCodes[offset + 0] << 24;
27.32 + final int c = byteCodes[offset + 1] << 16;
27.33 + final int b = byteCodes[offset + 2] << 8;
27.34 + final int a = byteCodes[offset + 3];
27.35 return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff);
27.36 }
27.37 - private int readUByte(byte[] byteCodes, int offsetInstruction) {
27.38 - return byteCodes[offsetInstruction] & 0xff;
27.39 + private int readUByte(byte[] byteCodes, int offset) {
27.40 + return byteCodes[offset] & 0xff;
27.41 }
27.42
27.43 - private int readUShort(byte[] byteCodes, int offsetInstruction) {
27.44 - return ((byteCodes[offsetInstruction] & 0xff) << 8)
27.45 - | (byteCodes[offsetInstruction + 1] & 0xff);
27.46 + private int readUShort(byte[] byteCodes, int offset) {
27.47 + return ((byteCodes[offset] & 0xff) << 8)
27.48 + | (byteCodes[offset + 1] & 0xff);
27.49 + }
27.50 +
27.51 + private int readShort(byte[] byteCodes, int offset) {
27.52 + return (byteCodes[offset] << 8)
27.53 + | (byteCodes[offset + 1] & 0xff);
27.54 }
27.55
27.56 private static void countArgs(String descriptor, char[] returnType, StringBuilder sig, StringBuilder cnt) {
28.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java Fri Feb 15 21:02:01 2013 +0100
28.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java Fri Feb 15 21:14:49 2013 +0100
28.3 @@ -196,5 +196,11 @@
28.4 ) throws Exception {
28.5 code.assertExec(msg, clazz, method, expRes, args);
28.6 }
28.7 + @Test public void isClassAssignable() throws Exception {
28.8 + assertExec("isAssignable works on subclasses", Classes.class,
28.9 + "isClassAssignable__Z",
28.10 + true
28.11 + );
28.12 + }
28.13
28.14 }
29.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java Fri Feb 15 21:02:01 2013 +0100
29.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java Fri Feb 15 21:14:49 2013 +0100
29.3 @@ -214,4 +214,20 @@
29.4 Method m = StaticMethod.class.getMethod("sum", int.class, int.class);
29.5 return (int) m.invoke(null, a, b);
29.6 }
29.7 +
29.8 + private abstract class Application {
29.9 + public abstract int getID();
29.10 + }
29.11 +
29.12 + private class MyApplication extends Application {
29.13 + @Override
29.14 + public int getID() {
29.15 + return 1;
29.16 + }
29.17 + }
29.18 +
29.19 + public static boolean isClassAssignable() {
29.20 + return Application.class.isAssignableFrom(MyApplication.class);
29.21 + }
29.22 +
29.23 }
30.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Fri Feb 15 21:02:01 2013 +0100
30.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Fri Feb 15 21:14:49 2013 +0100
30.3 @@ -141,552 +141,6 @@
30.4 s
30.5 );
30.6 }
30.7 -
30.8 - @Test public void longConversion() throws Exception {
30.9 - assertExec("Long from cPool",
30.10 - Numbers.class, "conversionL__J",
30.11 - Double.valueOf(Long.MAX_VALUE)
30.12 - );
30.13 - }
30.14 -
30.15 - @Test public void longNegate1() throws Exception {
30.16 - final long res = -0x00fa37d7763e0ca1l;
30.17 - assertExec("Long negate",
30.18 - Numbers.class, "negL__J_3B",
30.19 - Double.valueOf(res),
30.20 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }
30.21 - );
30.22 - }
30.23 -
30.24 - @Test public void longNegate2() throws Exception {
30.25 - final long res = -0x80fa37d7763e0ca1l;
30.26 - assertExec("Long negate",
30.27 - Numbers.class, "negL__J_3B",
30.28 - Double.valueOf(res),
30.29 - new byte[] { (byte)0x80, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }
30.30 - );
30.31 - }
30.32 -
30.33 - @Test public void longNegate3() throws Exception {
30.34 - final long res = -0xfffffffffffffeddl;
30.35 - assertExec("Long negate",
30.36 - Numbers.class, "negL__J_3B",
30.37 - Double.valueOf(res),
30.38 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
30.39 - );
30.40 - }
30.41 -
30.42 - @Test public void longAddOverflow() throws Exception {
30.43 - final long res = Long.MAX_VALUE + 1l;
30.44 - assertExec("Addition 1+MAX",
30.45 - Numbers.class, "addL__J_3B_3B",
30.46 - Double.valueOf(res),
30.47 - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
30.48 - new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1 }
30.49 - );
30.50 - }
30.51 -
30.52 - @Test public void longAddMaxAndMax() throws Exception {
30.53 - final long res = Long.MAX_VALUE + Long.MAX_VALUE;
30.54 - assertExec("Addition MAX+MAX",
30.55 - Numbers.class, "addL__J_3B_3B",
30.56 - Double.valueOf(res),
30.57 - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
30.58 - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }
30.59 - );
30.60 - }
30.61 -
30.62 - @Test public void longSubUnderflow() throws Exception {
30.63 - final long res = Long.MIN_VALUE - 1l;
30.64 - assertExec("Subtraction MIN-1",
30.65 - Numbers.class, "subL__J_3B_3B",
30.66 - Double.valueOf(res),
30.67 - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
30.68 - new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1 }
30.69 - );
30.70 - }
30.71 -
30.72 - @Test public void longSubMinAndMin() throws Exception {
30.73 - final long res = Long.MIN_VALUE - Long.MIN_VALUE;
30.74 - assertExec("Subtraction MIN-MIN",
30.75 - Numbers.class, "subL__J_3B_3B",
30.76 - Double.valueOf(res),
30.77 - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
30.78 - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }
30.79 - );
30.80 - }
30.81 -
30.82 - @Test public void longSubMinAndMax() throws Exception {
30.83 - final long res = Long.MIN_VALUE - Long.MAX_VALUE;
30.84 - assertExec("Subtraction MIN-MAX",
30.85 - Numbers.class, "subL__J_3B_3B",
30.86 - Double.valueOf(res),
30.87 - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
30.88 - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }
30.89 - );
30.90 - }
30.91 -
30.92 - @Test public void longMultiplyMax() throws Exception {
30.93 - final long res = Long.MAX_VALUE * 2l;
30.94 - assertExec("Multiplication MAX*2",
30.95 - Numbers.class, "mulL__J_3B_3B",
30.96 - Double.valueOf(res),
30.97 - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
30.98 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02 }
30.99 - );
30.100 - }
30.101 -
30.102 - @Test public void longMultiplyMaxAndMax() throws Exception {
30.103 - final long res = Long.MAX_VALUE * Long.MAX_VALUE;
30.104 - assertExec("Multiplication MAX*MAX",
30.105 - Numbers.class, "mulL__J_3B_3B",
30.106 - Double.valueOf(res),
30.107 - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
30.108 - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }
30.109 - );
30.110 - }
30.111 -
30.112 - @Test public void longMultiplyMin() throws Exception {
30.113 - final long res = Long.MIN_VALUE * 2l;
30.114 - assertExec("Multiplication MIN*2",
30.115 - Numbers.class, "mulL__J_3B_3B",
30.116 - Double.valueOf(res),
30.117 - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
30.118 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02 }
30.119 - );
30.120 - }
30.121 -
30.122 - @Test public void longMultiplyMinAndMin() throws Exception {
30.123 - final long res = Long.MIN_VALUE * Long.MIN_VALUE;
30.124 - assertExec("Multiplication MIN*2",
30.125 - Numbers.class, "mulL__J_3B_3B",
30.126 - Double.valueOf(res),
30.127 - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
30.128 - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }
30.129 - );
30.130 - }
30.131 -
30.132 - @Test public void longMultiplyPrecision() throws Exception {
30.133 - final long res = 0x00fa37d7763e0ca1l * 0xa7b3432fff00123el;
30.134 - assertExec("Multiplication",
30.135 - Numbers.class, "mulL__J_3B_3B",
30.136 - Double.valueOf(res),
30.137 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.138 - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
30.139 - );
30.140 - }
30.141 -
30.142 - @Test public void longDivideSmallPositiveNumbers() throws Exception {
30.143 - final long res = 0xabcdef / 0x123;
30.144 - assertExec("Division Small Positive Numbers",
30.145 - Numbers.class, "divL__J_3B_3B",
30.146 - Double.valueOf(res),
30.147 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
30.148 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x23 }
30.149 - );
30.150 - }
30.151 -
30.152 - @Test public void longDivideSmallNegativeNumbers() throws Exception {
30.153 - final long res = -0xabcdef / -0x123;
30.154 - assertExec("Division Small Negative Numbers",
30.155 - Numbers.class, "divL__J_3B_3B",
30.156 - Double.valueOf(res),
30.157 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x11 },
30.158 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
30.159 - );
30.160 - }
30.161 -
30.162 - @Test public void longDivideSmallMixedNumbers() throws Exception {
30.163 - final long res = 0xabcdef / -0x123;
30.164 - assertExec("Division Small Mixed Numbers",
30.165 - Numbers.class, "divL__J_3B_3B",
30.166 - Double.valueOf(res),
30.167 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
30.168 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
30.169 - );
30.170 - }
30.171 -
30.172 - @Test public void longDividePositiveNumbersOneDigitDenom()
30.173 - throws Exception {
30.174 - final long res = 0xabcdef0102ffffL / 0x654;
30.175 - assertExec("Division Positive Numbers One Digit Denom",
30.176 - Numbers.class, "divL__J_3B_3B",
30.177 - Double.valueOf(res),
30.178 - new byte[] { (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef, (byte)0x01, (byte)0x02, (byte)0xff, (byte)0xff },
30.179 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
30.180 - );
30.181 - }
30.182 -
30.183 - @Test public void longDivideNegativeNumbersOneDigitDenom()
30.184 - throws Exception {
30.185 - final long res = -0xabcdef0102ffffL / -0x654;
30.186 - assertExec("Division Negative Numbers One Digit Denom",
30.187 - Numbers.class, "divL__J_3B_3B",
30.188 - Double.valueOf(res),
30.189 - new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
30.190 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xf9, (byte)0xac }
30.191 - );
30.192 - }
30.193 -
30.194 - @Test public void longDivideMixedNumbersOneDigitDenom()
30.195 - throws Exception {
30.196 - final long res = -0xabcdef0102ffffL / 0x654;
30.197 - assertExec("Division Mixed Numbers One Digit Denom",
30.198 - Numbers.class, "divL__J_3B_3B",
30.199 - Double.valueOf(res),
30.200 - new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
30.201 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
30.202 - );
30.203 - }
30.204 -
30.205 - @Test public void longDividePositiveNumbersMultiDigitDenom()
30.206 - throws Exception {
30.207 - final long res = 0x7ffefc003322aabbL / 0x89ab1000L;
30.208 - assertExec("Division Positive Numbers Multi Digit Denom",
30.209 - Numbers.class, "divL__J_3B_3B",
30.210 - Double.valueOf(res),
30.211 - new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
30.212 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x89, (byte)0xab, (byte)0x10, (byte)0x00 }
30.213 - );
30.214 - }
30.215 -
30.216 - @Test public void longDivideNegativeNumbersMultiDigitDenom()
30.217 - throws Exception {
30.218 - final long res = -0x7ffefc003322aabbL / -0x123489ab1001L;
30.219 - assertExec("Division Negative Numbers Multi Digit Denom",
30.220 - Numbers.class, "divL__J_3B_3B",
30.221 - Double.valueOf(res),
30.222 - new byte[] { (byte)0x80, (byte)0x01, (byte)0x03, (byte)0xff, (byte)0xcc, (byte)0xdd, (byte)0x55, (byte)0x45 },
30.223 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xed, (byte)0xcb, (byte)0x76, (byte)0x54, (byte)0xef, (byte)0xff }
30.224 - );
30.225 - }
30.226 -
30.227 - @Test public void longDivideMixedNumbersMultiDigitDenom()
30.228 - throws Exception {
30.229 - final long res = 0x7ffefc003322aabbL / -0x38f49b0b7574e36L;
30.230 - assertExec("Division Mixed Numbers Multi Digit Denom",
30.231 - Numbers.class, "divL__J_3B_3B",
30.232 - Double.valueOf(res),
30.233 - new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
30.234 - new byte[] { (byte)0xfc, (byte)0x70, (byte)0xb6, (byte)0x4f, (byte)0x48, (byte)0xa8, (byte)0xb1, (byte)0xca }
30.235 - );
30.236 - }
30.237 -
30.238 - @Test public void longDivideWithOverflow() throws Exception {
30.239 - final long res = 0x8000fffe0000L / 0x8000ffffL;
30.240 - assertExec("Division With Overflow",
30.241 - Numbers.class, "divL__J_3B_3B",
30.242 - Double.valueOf(res),
30.243 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xfe, (byte)0x00, (byte)0x00 },
30.244 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xff }
30.245 - );
30.246 - }
30.247 -
30.248 - @Test public void longDivideWithCorrection() throws Exception {
30.249 - final long res = 0x7fff800000000000L / 0x800000000001L;
30.250 - assertExec("Division With Correction",
30.251 - Numbers.class, "divL__J_3B_3B",
30.252 - Double.valueOf(res),
30.253 - new byte[] { (byte)0x7f, (byte)0xff, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
30.254 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01 }
30.255 - );
30.256 - }
30.257 -
30.258 - @Test public void longModuloSmallPositiveNumbers() throws Exception {
30.259 - final long res = 0xabcdef % 0x123;
30.260 - assertExec("Modulo Small Positive Numbers",
30.261 - Numbers.class, "modL__J_3B_3B",
30.262 - Double.valueOf(res),
30.263 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
30.264 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x23 }
30.265 - );
30.266 - }
30.267 -
30.268 - @Test public void longModuloSmallNegativeNumbers() throws Exception {
30.269 - final long res = -0xabcdef % -0x123;
30.270 - assertExec("Modulo Small Negative Numbers",
30.271 - Numbers.class, "modL__J_3B_3B",
30.272 - Double.valueOf(res),
30.273 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x11 },
30.274 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
30.275 - );
30.276 - }
30.277 -
30.278 - @Test public void longModuloSmallMixedNumbers() throws Exception {
30.279 - final long res = 0xabcdef % -0x123;
30.280 - assertExec("Modulo Small Mixed Numbers",
30.281 - Numbers.class, "modL__J_3B_3B",
30.282 - Double.valueOf(res),
30.283 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
30.284 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
30.285 - );
30.286 - }
30.287 -
30.288 - @Test public void longModuloPositiveNumbersOneDigitDenom()
30.289 - throws Exception {
30.290 - final long res = 0xabcdef0102ffffL % 0x654;
30.291 - assertExec("Modulo Positive Numbers One Digit Denom",
30.292 - Numbers.class, "modL__J_3B_3B",
30.293 - Double.valueOf(res),
30.294 - new byte[] { (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef, (byte)0x01, (byte)0x02, (byte)0xff, (byte)0xff },
30.295 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
30.296 - );
30.297 - }
30.298 -
30.299 - @Test public void longModuloNegativeNumbersOneDigitDenom()
30.300 - throws Exception {
30.301 - final long res = -0xabcdef0102ffffL % -0x654;
30.302 - assertExec("Modulo Negative Numbers One Digit Denom",
30.303 - Numbers.class, "modL__J_3B_3B",
30.304 - Double.valueOf(res),
30.305 - new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
30.306 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xf9, (byte)0xac }
30.307 - );
30.308 - }
30.309 -
30.310 - @Test public void longModuloMixedNumbersOneDigitDenom()
30.311 - throws Exception {
30.312 - final long res = -0xabcdef0102ffffL % 0x654;
30.313 - assertExec("Modulo Mixed Numbers One Digit Denom",
30.314 - Numbers.class, "modL__J_3B_3B",
30.315 - Double.valueOf(res),
30.316 - new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
30.317 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
30.318 - );
30.319 - }
30.320 -
30.321 - @Test public void longModuloPositiveNumbersMultiDigitDenom()
30.322 - throws Exception {
30.323 - final long res = 0x7ffefc003322aabbL % 0x89ab1000L;
30.324 - assertExec("Modulo Positive Numbers Multi Digit Denom",
30.325 - Numbers.class, "modL__J_3B_3B",
30.326 - Double.valueOf(res),
30.327 - new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
30.328 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x89, (byte)0xab, (byte)0x10, (byte)0x00 }
30.329 - );
30.330 - }
30.331 -
30.332 - @Test public void longModuloNegativeNumbersMultiDigitDenom()
30.333 - throws Exception {
30.334 - final long res = -0x7ffefc003322aabbL % -0x123489ab1001L;
30.335 - assertExec("Modulo Negative Numbers Multi Digit Denom",
30.336 - Numbers.class, "modL__J_3B_3B",
30.337 - Double.valueOf(res),
30.338 - new byte[] { (byte)0x80, (byte)0x01, (byte)0x03, (byte)0xff, (byte)0xcc, (byte)0xdd, (byte)0x55, (byte)0x45 },
30.339 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xed, (byte)0xcb, (byte)0x76, (byte)0x54, (byte)0xef, (byte)0xff }
30.340 - );
30.341 - }
30.342 -
30.343 - @Test public void longModuloMixedNumbersMultiDigitDenom()
30.344 - throws Exception {
30.345 - final long res = 0x7ffefc003322aabbL % -0x38f49b0b7574e36L;
30.346 - assertExec("Modulo Mixed Numbers Multi Digit Denom",
30.347 - Numbers.class, "modL__J_3B_3B",
30.348 - Double.valueOf(res),
30.349 - new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
30.350 - new byte[] { (byte)0xfc, (byte)0x70, (byte)0xb6, (byte)0x4f, (byte)0x48, (byte)0xa8, (byte)0xb1, (byte)0xca }
30.351 - );
30.352 - }
30.353 -
30.354 - @Test public void longModuloWithOverflow() throws Exception {
30.355 - final long res = 0x8000fffe0000L % 0x8000ffffL;
30.356 - assertExec("Modulo With Overflow",
30.357 - Numbers.class, "modL__J_3B_3B",
30.358 - Double.valueOf(res),
30.359 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xfe, (byte)0x00, (byte)0x00 },
30.360 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xff }
30.361 - );
30.362 - }
30.363 -
30.364 - @Test public void longModuloWithCorrection() throws Exception {
30.365 - final long res = 0x7fff800000000000L % 0x800000000001L;
30.366 - assertExec("Modulo With Correction",
30.367 - Numbers.class, "modL__J_3B_3B",
30.368 - Double.valueOf(res),
30.369 - new byte[] { (byte)0x7f, (byte)0xff, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
30.370 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01 }
30.371 - );
30.372 - }
30.373 -
30.374 - @Test public void longShiftL1() throws Exception {
30.375 - final long res = 0x00fa37d7763e0ca1l << 5;
30.376 - assertExec("Long << 5",
30.377 - Numbers.class, "shlL__J_3BI",
30.378 - Double.valueOf(res),
30.379 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.380 - 5);
30.381 - }
30.382 -
30.383 - @Test public void longShiftL2() throws Exception {
30.384 - final long res = 0x00fa37d7763e0ca1l << 32;
30.385 - assertExec("Long << 32",
30.386 - Numbers.class, "shlL__J_3BI",
30.387 - Double.valueOf(res),
30.388 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.389 - 32);
30.390 - }
30.391 -
30.392 - @Test public void longShiftL3() throws Exception {
30.393 - final long res = 0x00fa37d7763e0ca1l << 45;
30.394 - assertExec("Long << 45",
30.395 - Numbers.class, "shlL__J_3BI",
30.396 - Double.valueOf(res),
30.397 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.398 - 45);
30.399 - }
30.400 -
30.401 - @Test public void longShiftR1() throws Exception {
30.402 - final long res = 0x00fa37d7763e0ca1l >> 5;
30.403 - assertExec("Long >> 5",
30.404 - Numbers.class, "shrL__J_3BI",
30.405 - Double.valueOf(res),
30.406 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.407 - 5);
30.408 - }
30.409 -
30.410 - @Test public void longShiftR2() throws Exception {
30.411 - final long res = 0x00fa37d7763e0ca1l >> 32;
30.412 - assertExec("Long >> 32",
30.413 - Numbers.class, "shrL__J_3BI",
30.414 - Double.valueOf(res),
30.415 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.416 - 32);
30.417 - }
30.418 -
30.419 - @Test public void longShiftR3() throws Exception {
30.420 - final long res = 0x00fa37d7763e0ca1l >> 45;
30.421 - assertExec("Long >> 45",
30.422 - Numbers.class, "shrL__J_3BI",
30.423 - Double.valueOf(res),
30.424 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.425 - 45);
30.426 - }
30.427 -
30.428 - @Test public void longUShiftR1() throws Exception {
30.429 - final long res = 0x00fa37d7763e0ca1l >>> 5;
30.430 - assertExec("Long >>> 5",
30.431 - Numbers.class, "ushrL__J_3BI",
30.432 - Double.valueOf(res),
30.433 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.434 - 5);
30.435 - }
30.436 -
30.437 - @Test public void longUShiftR2() throws Exception {
30.438 - final long res = 0x00fa37d7763e0ca1l >>> 45;
30.439 - assertExec("Long >>> 45",
30.440 - Numbers.class, "ushrL__J_3BI",
30.441 - Double.valueOf(res),
30.442 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.443 - 45);
30.444 - }
30.445 -
30.446 - @Test public void longUShiftR3() throws Exception {
30.447 - final long res = 0xf0fa37d7763e0ca1l >>> 5;
30.448 - assertExec("Long >>> 5",
30.449 - Numbers.class, "ushrL__J_3BI",
30.450 - Double.valueOf(res),
30.451 - new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.452 - 5);
30.453 - }
30.454 -
30.455 - @Test public void longUShiftR4() throws Exception {
30.456 - final long res = 0xf0fa37d7763e0ca1l >>> 45;
30.457 - assertExec("Long >>> 45",
30.458 - Numbers.class, "ushrL__J_3BI",
30.459 - Double.valueOf(res),
30.460 - new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.461 - 45);
30.462 - }
30.463 -
30.464 - @Test public void longAnd() throws Exception {
30.465 - final long res = 0x00fa37d7763e0ca1l & 0xa7b3432fff00123el;
30.466 - assertExec("LOng binary AND",
30.467 - Numbers.class, "andL__J_3B_3B",
30.468 - Double.valueOf(res),
30.469 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.470 - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
30.471 - );
30.472 - }
30.473 -
30.474 - @Test public void longOr() throws Exception {
30.475 - final long res = 0x00fa37d7763e0ca1l | 0xa7b3432fff00123el;
30.476 - assertExec("Long binary OR",
30.477 - Numbers.class, "orL__J_3B_3B",
30.478 - Double.valueOf(res),
30.479 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.480 - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
30.481 - );
30.482 - }
30.483 -
30.484 - @Test public void longXor1() throws Exception {
30.485 - final long res = 0x00fa37d7763e0ca1l ^ 0xa7b3432fff00123el;
30.486 - assertExec("Long binary XOR",
30.487 - Numbers.class, "xorL__J_3B_3B",
30.488 - Double.valueOf(res),
30.489 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.490 - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
30.491 - );
30.492 - }
30.493 -
30.494 - @Test public void longXor2() throws Exception {
30.495 - final long res = 0x00fa37d7763e0ca1l ^ 0x00000000ff00123el;
30.496 - assertExec("Long binary XOR",
30.497 - Numbers.class, "xorL__J_3B_3B",
30.498 - Double.valueOf(res),
30.499 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.500 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
30.501 - );
30.502 - }
30.503 -
30.504 - @Test public void longXor3() throws Exception {
30.505 - final long res = 0x00000000763e0ca1l ^ 0x00000000ff00123el;
30.506 - assertExec("Long binary XOR",
30.507 - Numbers.class, "xorL__J_3B_3B",
30.508 - Double.valueOf(res),
30.509 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
30.510 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
30.511 - );
30.512 - }
30.513 -
30.514 - @Test public void longCompareSameNumbers() throws Exception {
30.515 - assertExec("Long compare same numbers",
30.516 - Numbers.class, "compareL__I_3B_3BI",
30.517 - 0.0,
30.518 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
30.519 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
30.520 - 0
30.521 - );
30.522 - }
30.523 -
30.524 - @Test public void longComparePositiveNumbers() throws Exception {
30.525 - assertExec("Long compare positive numbers",
30.526 - Numbers.class, "compareL__I_3B_3BI",
30.527 - -1.0,
30.528 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x00 },
30.529 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00 },
30.530 - 0
30.531 - );
30.532 - }
30.533 -
30.534 - @Test public void longCompareNegativeNumbers() throws Exception {
30.535 - assertExec("Long compare negative numbers",
30.536 - Numbers.class, "compareL__I_3B_3BI",
30.537 - 1.0,
30.538 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
30.539 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
30.540 - 0
30.541 - );
30.542 - }
30.543 -
30.544 - @Test public void longCompareMixedNumbers() throws Exception {
30.545 - assertExec("Long compare mixed numbers",
30.546 - Numbers.class, "compareL__I_3B_3BI",
30.547 - -1.0,
30.548 - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
30.549 - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
30.550 - 0
30.551 - );
30.552 - }
30.553
30.554 private static TestVM code;
30.555
31.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Fri Feb 15 21:02:01 2013 +0100
31.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Fri Feb 15 21:14:49 2013 +0100
31.3 @@ -67,136 +67,4 @@
31.4 static String floatToString() {
31.5 return new Float(7.0).toString().toString();
31.6 }
31.7 -
31.8 - public static long conversionL() {
31.9 - return Long.MAX_VALUE;
31.10 - }
31.11 -
31.12 - public static long negL(byte[] arrValue) throws IOException {
31.13 - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue);
31.14 - DataInputStream disValue = new DataInputStream(isValue);
31.15 - return (-disValue.readLong());
31.16 - }
31.17 -
31.18 - public static long addL(byte[] arrX, byte[] arrY) throws IOException {
31.19 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
31.20 - DataInputStream disX = new DataInputStream(isX);
31.21 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
31.22 - DataInputStream disY = new DataInputStream(isY);
31.23 - return (disX.readLong() + disY.readLong());
31.24 - }
31.25 -
31.26 - public static long subL(byte[] arrX, byte[] arrY) throws IOException {
31.27 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
31.28 - DataInputStream disX = new DataInputStream(isX);
31.29 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
31.30 - DataInputStream disY = new DataInputStream(isY);
31.31 - return (disX.readLong() - disY.readLong());
31.32 - }
31.33 -
31.34 - public static long mulL(byte[] arrX, byte[] arrY) throws IOException {
31.35 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
31.36 - DataInputStream disX = new DataInputStream(isX);
31.37 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
31.38 - DataInputStream disY = new DataInputStream(isY);
31.39 - return (disX.readLong() * disY.readLong());
31.40 - }
31.41 -
31.42 - public static long divL(byte[] arrX, byte[] arrY) throws IOException {
31.43 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
31.44 - DataInputStream disX = new DataInputStream(isX);
31.45 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
31.46 - DataInputStream disY = new DataInputStream(isY);
31.47 - return (disX.readLong() / disY.readLong());
31.48 - }
31.49 -
31.50 - public static long modL(byte[] arrX, byte[] arrY) throws IOException {
31.51 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
31.52 - DataInputStream disX = new DataInputStream(isX);
31.53 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
31.54 - DataInputStream disY = new DataInputStream(isY);
31.55 - return (disX.readLong() % disY.readLong());
31.56 - }
31.57 -
31.58 - public static long shlL(byte[] arrValue, int nBits) throws IOException {
31.59 - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue);
31.60 - DataInputStream disValue = new DataInputStream(isValue);
31.61 - return (disValue.readLong() << nBits);
31.62 - }
31.63 -
31.64 - public static long shrL(byte[] arrValue, int nBits) throws IOException {
31.65 - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue);
31.66 - DataInputStream disValue = new DataInputStream(isValue);
31.67 - return (disValue.readLong() >> nBits);
31.68 - }
31.69 -
31.70 - public static long ushrL(byte[] arrValue, int nBits) throws IOException {
31.71 - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue);
31.72 - DataInputStream disValue = new DataInputStream(isValue);
31.73 - return (disValue.readLong() >>> nBits);
31.74 - }
31.75 -
31.76 - public static long andL(byte[] arrX, byte[] arrY) throws IOException {
31.77 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
31.78 - DataInputStream disX = new DataInputStream(isX);
31.79 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
31.80 - DataInputStream disY = new DataInputStream(isY);
31.81 - return (disX.readLong() & disY.readLong());
31.82 - }
31.83 -
31.84 - public static long orL(byte[] arrX, byte[] arrY) throws IOException {
31.85 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
31.86 - DataInputStream disX = new DataInputStream(isX);
31.87 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
31.88 - DataInputStream disY = new DataInputStream(isY);
31.89 - return (disX.readLong() | disY.readLong());
31.90 - }
31.91 -
31.92 - public static long xorL(byte[] arrX, byte[] arrY) throws IOException {
31.93 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
31.94 - DataInputStream disX = new DataInputStream(isX);
31.95 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
31.96 - DataInputStream disY = new DataInputStream(isY);
31.97 - return (disX.readLong() ^ disY.readLong());
31.98 - }
31.99 -
31.100 - public static int compareL(byte[] arrX, byte[] arrY,
31.101 - int zero) throws IOException {
31.102 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
31.103 - DataInputStream disX = new DataInputStream(isX);
31.104 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
31.105 - DataInputStream disY = new DataInputStream(isY);
31.106 - final long x = disX.readLong();
31.107 - final long y = disY.readLong();
31.108 -
31.109 - final int xyResult = compareL(x, y, zero);
31.110 - final int yxResult = compareL(y, x, zero);
31.111 -
31.112 - return ((xyResult + yxResult) == 0) ? xyResult : -2;
31.113 - }
31.114 -
31.115 - private static int compareL(long x, long y, int zero) {
31.116 - int result = -2;
31.117 - int trueCount = 0;
31.118 -
31.119 - x += zero;
31.120 - if (x == y) {
31.121 - result = 0;
31.122 - ++trueCount;
31.123 - }
31.124 -
31.125 - x += zero;
31.126 - if (x < y) {
31.127 - result = -1;
31.128 - ++trueCount;
31.129 - }
31.130 -
31.131 - x += zero;
31.132 - if (x > y) {
31.133 - result = 1;
31.134 - ++trueCount;
31.135 - }
31.136 -
31.137 - return (trueCount == 1) ? result : -2;
31.138 - }
31.139 }
32.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java Fri Feb 15 21:02:01 2013 +0100
32.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java Fri Feb 15 21:14:49 2013 +0100
32.3 @@ -17,6 +17,8 @@
32.4 */
32.5 package org.apidesign.vm4brwsr;
32.6
32.7 +import java.io.UnsupportedEncodingException;
32.8 +
32.9 /**
32.10 *
32.11 * @author Jaroslav Tulach <jtulach@netbeans.org>
32.12 @@ -68,8 +70,8 @@
32.13 return chars('a', (char)30, 'b') instanceof String;
32.14 }
32.15
32.16 - public static String getBytes(String s) {
32.17 - byte[] arr = s.getBytes();
32.18 + public static String getBytes(String s) throws UnsupportedEncodingException {
32.19 + byte[] arr = s.getBytes("UTF-8");
32.20 StringBuilder sb = new StringBuilder();
32.21 for (int i = 0; i < arr.length; i++) {
32.22 sb.append(arr[i]).append(" ");
33.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Fri Feb 15 21:02:01 2013 +0100
33.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Fri Feb 15 21:14:49 2013 +0100
33.3 @@ -75,7 +75,7 @@
33.4 }
33.5
33.6 @Test public void getBytes() throws Exception {
33.7 - final String horse = "Žluťoučký kůň";
33.8 + final String horse = "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148";
33.9 final String expected = StringSample.getBytes(horse);
33.10 assertExec(
33.11 "Bytes look simplar",
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
34.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/SystemTest.java Fri Feb 15 21:14:49 2013 +0100
34.3 @@ -0,0 +1,56 @@
34.4 +/**
34.5 + * Back 2 Browser Bytecode Translator
34.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
34.7 + *
34.8 + * This program is free software: you can redistribute it and/or modify
34.9 + * it under the terms of the GNU General Public License as published by
34.10 + * the Free Software Foundation, version 2 of the License.
34.11 + *
34.12 + * This program is distributed in the hope that it will be useful,
34.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34.15 + * GNU General Public License for more details.
34.16 + *
34.17 + * You should have received a copy of the GNU General Public License
34.18 + * along with this program. Look for COPYING file in the top folder.
34.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
34.20 + */
34.21 +package org.apidesign.vm4brwsr;
34.22 +
34.23 +import org.testng.annotations.BeforeClass;
34.24 +import static org.testng.Assert.*;
34.25 +import org.testng.annotations.Test;
34.26 +
34.27 +/**
34.28 + *
34.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
34.30 + */
34.31 +public class SystemTest {
34.32 + private static TestVM code;
34.33 +
34.34 + @Test public void verifyJSTime() throws Exception {
34.35 + long now = System.currentTimeMillis();
34.36 +
34.37 + Object js = code.execCode("Get js time",
34.38 + org.apidesign.bck2brwsr.emul.lang.System.class, "currentTimeMillis__J",
34.39 + null
34.40 + );
34.41 +
34.42 + assertTrue(js instanceof Double, "Double " + js);
34.43 + long time = ((Double)js).longValue();
34.44 +
34.45 + long later = System.currentTimeMillis();
34.46 +
34.47 + assertTrue(now <= time, "Lower bound is OK: " + now + " <= " + time);
34.48 + assertTrue(time <= later, "Upper bound is OK: " + time + " <= " + later);
34.49 + }
34.50 +
34.51 +
34.52 + @BeforeClass
34.53 + public static void compileTheCode() throws Exception {
34.54 + code = TestVM.compileClass(
34.55 + "org/apidesign/bck2brwsr/emul/lang/System");
34.56 + }
34.57 +
34.58 +}
34.59 +
35.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java Fri Feb 15 21:02:01 2013 +0100
35.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java Fri Feb 15 21:14:49 2013 +0100
35.3 @@ -58,7 +58,7 @@
35.4 if (ret == null && expRes == null) {
35.5 return null;
35.6 }
35.7 - if (expRes.equals(ret)) {
35.8 + if (expRes != null && expRes.equals(ret)) {
35.9 return null;
35.10 }
35.11 if (expRes instanceof Number) {
36.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java Fri Feb 15 21:02:01 2013 +0100
36.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java Fri Feb 15 21:14:49 2013 +0100
36.3 @@ -147,7 +147,7 @@
36.4
36.5 @Compare
36.6 public int stringToBytesLenght() throws UnsupportedEncodingException {
36.7 - return "Žluťoučký kůň".getBytes("utf8").length;
36.8 + return "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("utf8").length;
36.9 }
36.10
36.11 @Factory
37.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java Fri Feb 15 21:02:01 2013 +0100
37.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java Fri Feb 15 21:14:49 2013 +0100
37.3 @@ -47,6 +47,10 @@
37.4 return x % y;
37.5 }
37.6
37.7 + private static int neg(int x) {
37.8 + return (-x);
37.9 + }
37.10 +
37.11 @Compare public int addOverflow() {
37.12 return add(Integer.MAX_VALUE, 1);
37.13 }
37.14 @@ -91,6 +95,18 @@
37.15 return mod(1, 2);
37.16 }
37.17
37.18 + @Compare public int negate() {
37.19 + return neg(123456);
37.20 + }
37.21 +
37.22 + @Compare public int negateMaxInt() {
37.23 + return neg(Integer.MAX_VALUE);
37.24 + }
37.25 +
37.26 + @Compare public int negateMinInt() {
37.27 + return neg(Integer.MIN_VALUE);
37.28 + }
37.29 +
37.30 @Compare public int sumTwoDimensions() {
37.31 int[][] matrix = createMatrix(4, 3);
37.32 matrix[0][0] += 10;
38.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Fri Feb 15 21:02:01 2013 +0100
38.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Fri Feb 15 21:14:49 2013 +0100
38.3 @@ -47,19 +47,90 @@
38.4 return (x % y);
38.5 }
38.6
38.7 + private static long neg(long x) {
38.8 + return (-x);
38.9 + }
38.10 +
38.11 + private static long shl(long x, int b) {
38.12 + return (x << b);
38.13 + }
38.14 +
38.15 + private static long shr(long x, int b) {
38.16 + return (x >> b);
38.17 + }
38.18 +
38.19 + private static long ushr(long x, int b) {
38.20 + return (x >>> b);
38.21 + }
38.22 +
38.23 + private static long and(long x, long y) {
38.24 + return (x & y);
38.25 + }
38.26 +
38.27 + private static long or(long x, long y) {
38.28 + return (x | y);
38.29 + }
38.30 +
38.31 + private static long xor(long x, long y) {
38.32 + return (x ^ y);
38.33 + }
38.34 +
38.35 + public static int compare(long x, long y, int zero) {
38.36 + final int xyResult = compareL(x, y, zero);
38.37 + final int yxResult = compareL(y, x, zero);
38.38 +
38.39 + return ((xyResult + yxResult) == 0) ? xyResult : -2;
38.40 + }
38.41 +
38.42 + private static int compareL(long x, long y, int zero) {
38.43 + int result = -2;
38.44 + int trueCount = 0;
38.45 +
38.46 + x += zero;
38.47 + if (x == y) {
38.48 + result = 0;
38.49 + ++trueCount;
38.50 + }
38.51 +
38.52 + x += zero;
38.53 + if (x < y) {
38.54 + result = -1;
38.55 + ++trueCount;
38.56 + }
38.57 +
38.58 + x += zero;
38.59 + if (x > y) {
38.60 + result = 1;
38.61 + ++trueCount;
38.62 + }
38.63 +
38.64 + return (trueCount == 1) ? result : -2;
38.65 + }
38.66 +
38.67 @Compare public long conversion() {
38.68 return Long.MAX_VALUE;
38.69 }
38.70
38.71 - /*
38.72 + @Compare public long negate1() {
38.73 + return neg(0x00fa37d7763e0ca1l);
38.74 + }
38.75 +
38.76 + @Compare public long negate2() {
38.77 + return neg(0x80fa37d7763e0ca1l);
38.78 + }
38.79 +
38.80 + @Compare public long negate3() {
38.81 + return neg(0xfffffffffffffeddl);
38.82 + }
38.83 +
38.84 @Compare public long addOverflow() {
38.85 return add(Long.MAX_VALUE, 1l);
38.86 }
38.87 -
38.88 +
38.89 @Compare public long subUnderflow() {
38.90 return sub(Long.MIN_VALUE, 1l);
38.91 }
38.92 -
38.93 +
38.94 @Compare public long addMaxLongAndMaxLong() {
38.95 return add(Long.MAX_VALUE, Long.MAX_VALUE);
38.96 }
38.97 @@ -68,6 +139,10 @@
38.98 return sub(Long.MIN_VALUE, Long.MIN_VALUE);
38.99 }
38.100
38.101 + @Compare public long subMinLongAndMaxLong() {
38.102 + return sub(Long.MIN_VALUE, Long.MAX_VALUE);
38.103 + }
38.104 +
38.105 @Compare public long multiplyMaxLong() {
38.106 return mul(Long.MAX_VALUE, 2l);
38.107 }
38.108 @@ -85,17 +160,172 @@
38.109 }
38.110
38.111 @Compare public long multiplyPrecision() {
38.112 - return mul(17638l, 1103l);
38.113 + return mul(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
38.114 }
38.115
38.116 - @Compare public long division() {
38.117 - return div(1l, 2l);
38.118 + @Compare public long divideSmallPositiveNumbers() {
38.119 + return div(0xabcdef, 0x123);
38.120 + }
38.121 +
38.122 + @Compare public long divideSmallNegativeNumbers() {
38.123 + return div(-0xabcdef, -0x123);
38.124 + }
38.125 +
38.126 + @Compare public long divideSmallMixedNumbers() {
38.127 + return div(0xabcdef, -0x123);
38.128 + }
38.129 +
38.130 + @Compare public long dividePositiveNumbersOneDigitDenom() {
38.131 + return div(0xabcdef0102ffffl, 0x654);
38.132 + }
38.133 +
38.134 + @Compare public long divideNegativeNumbersOneDigitDenom() {
38.135 + return div(-0xabcdef0102ffffl, -0x654);
38.136 + }
38.137 +
38.138 + @Compare public long divideMixedNumbersOneDigitDenom() {
38.139 + return div(-0xabcdef0102ffffl, 0x654);
38.140 + }
38.141 +
38.142 + @Compare public long dividePositiveNumbersMultiDigitDenom() {
38.143 + return div(0x7ffefc003322aabbl, 0x89ab1000l);
38.144 + }
38.145 +
38.146 + @Compare public long divideNegativeNumbersMultiDigitDenom() {
38.147 + return div(-0x7ffefc003322aabbl, -0x123489ab1001l);
38.148 + }
38.149 +
38.150 + @Compare public long divideMixedNumbersMultiDigitDenom() {
38.151 + return div(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
38.152 + }
38.153 +
38.154 + @Compare public long divideWithOverflow() {
38.155 + return div(0x8000fffe0000l, 0x8000ffffl);
38.156 + }
38.157 +
38.158 + @Compare public long divideWithCorrection() {
38.159 + return div(0x7fff800000000000l, 0x800000000001l);
38.160 + }
38.161 +
38.162 + @Compare public long moduloSmallPositiveNumbers() {
38.163 + return mod(0xabcdef, 0x123);
38.164 + }
38.165 +
38.166 + @Compare public long moduloSmallNegativeNumbers() {
38.167 + return mod(-0xabcdef, -0x123);
38.168 + }
38.169 +
38.170 + @Compare public long moduloSmallMixedNumbers() {
38.171 + return mod(0xabcdef, -0x123);
38.172 + }
38.173 +
38.174 + @Compare public long moduloPositiveNumbersOneDigitDenom() {
38.175 + return mod(0xabcdef0102ffffl, 0x654);
38.176 + }
38.177 +
38.178 + @Compare public long moduloNegativeNumbersOneDigitDenom() {
38.179 + return mod(-0xabcdef0102ffffl, -0x654);
38.180 + }
38.181 +
38.182 + @Compare public long moduloMixedNumbersOneDigitDenom() {
38.183 + return mod(-0xabcdef0102ffffl, 0x654);
38.184 + }
38.185 +
38.186 + @Compare public long moduloPositiveNumbersMultiDigitDenom() {
38.187 + return mod(0x7ffefc003322aabbl, 0x89ab1000l);
38.188 + }
38.189 +
38.190 + @Compare public long moduloNegativeNumbersMultiDigitDenom() {
38.191 + return mod(-0x7ffefc003322aabbl, -0x123489ab1001l);
38.192 + }
38.193 +
38.194 + @Compare public long moduloMixedNumbersMultiDigitDenom() {
38.195 + return mod(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
38.196 + }
38.197 +
38.198 + @Compare public long moduloWithOverflow() {
38.199 + return mod(0x8000fffe0000l, 0x8000ffffl);
38.200 + }
38.201 +
38.202 + @Compare public long moduloWithCorrection() {
38.203 + return mod(0x7fff800000000000l, 0x800000000001l);
38.204 }
38.205
38.206 - @Compare public long divisionReminder() {
38.207 - return mod(1l, 2l);
38.208 + @Compare public long shiftL1() {
38.209 + return shl(0x00fa37d7763e0ca1l, 5);
38.210 }
38.211 - */
38.212 +
38.213 + @Compare public long shiftL2() {
38.214 + return shl(0x00fa37d7763e0ca1l, 32);
38.215 + }
38.216 +
38.217 + @Compare public long shiftL3() {
38.218 + return shl(0x00fa37d7763e0ca1l, 45);
38.219 + }
38.220 +
38.221 + @Compare public long shiftR1() {
38.222 + return shr(0x00fa37d7763e0ca1l, 5);
38.223 + }
38.224 +
38.225 + @Compare public long shiftR2() {
38.226 + return shr(0x00fa37d7763e0ca1l, 32);
38.227 + }
38.228 +
38.229 + @Compare public long shiftR3() {
38.230 + return shr(0x00fa37d7763e0ca1l, 45);
38.231 + }
38.232 +
38.233 + @Compare public long uShiftR1() {
38.234 + return ushr(0x00fa37d7763e0ca1l, 5);
38.235 + }
38.236 +
38.237 + @Compare public long uShiftR2() {
38.238 + return ushr(0x00fa37d7763e0ca1l, 45);
38.239 + }
38.240 +
38.241 + @Compare public long uShiftR3() {
38.242 + return ushr(0xf0fa37d7763e0ca1l, 5);
38.243 + }
38.244 +
38.245 + @Compare public long uShiftR4() {
38.246 + return ushr(0xf0fa37d7763e0ca1l, 45);
38.247 + }
38.248 +
38.249 + @Compare public long and1() {
38.250 + return and(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
38.251 + }
38.252 +
38.253 + @Compare public long or1() {
38.254 + return or(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
38.255 + }
38.256 +
38.257 + @Compare public long xor1() {
38.258 + return xor(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
38.259 + }
38.260 +
38.261 + @Compare public long xor2() {
38.262 + return xor(0x00fa37d7763e0ca1l, 0x00000000ff00123el);
38.263 + }
38.264 +
38.265 + @Compare public long xor3() {
38.266 + return xor(0x00000000763e0ca1l, 0x00000000ff00123el);
38.267 + }
38.268 +
38.269 + @Compare public int compareSameNumbers() {
38.270 + return compare(0x0000000000000000l, 0x0000000000000000l, 0);
38.271 + }
38.272 +
38.273 + @Compare public int comparePositiveNumbers() {
38.274 + return compare(0x0000000000200000l, 0x0000000010000000l, 0);
38.275 + }
38.276 +
38.277 + @Compare public int compareNegativeNumbers() {
38.278 + return compare(0xffffffffffffffffl, 0xffffffff00000000l, 0);
38.279 + }
38.280 +
38.281 + @Compare public int compareMixedNumbers() {
38.282 + return compare(0x8000000000000000l, 0x7fffffffffffffffl, 0);
38.283 + }
38.284
38.285 @Factory
38.286 public static Object[] create() {