Added test files and the infamous jet/Library.jet

This commit is contained in:
Pavel Talanov
2011-11-09 16:34:32 +04:00
parent c811814037
commit 1bf6efce87
21 changed files with 7246 additions and 0 deletions
+670
View File
@@ -0,0 +1,670 @@
namespace jet
namespace typeinfo {
class TypeInfo<T> {
fun isSubtypeOf(other : TypeInfo<*>) : Boolean
fun isInstance(obj : Any?) : Boolean
}
fun typeinfo<T>() : TypeInfo<T>
fun typeinfo<T>(expression : T) : TypeInfo<out T>
}
namespace io {
fun print(message : Any?)
fun print(message : Int)
fun print(message : Long)
fun print(message : Byte)
fun print(message : Short)
fun print(message : Char)
fun print(message : Boolean)
fun print(message : Float)
fun print(message : Double)
fun println(message : Any?)
fun println(message : Int)
fun println(message : Long)
fun println(message : Byte)
fun println(message : Short)
fun println(message : Char)
fun println(message : Boolean)
fun println(message : Float)
fun println(message : Double)
fun readLine() : String?
}
// Can't write a body due to a bootstrapping problem (see JET-74)
fun Any?.equals(other : Any?) : Boolean// = this === other
// Returns "null" for null
fun Any?.toString() : String// = this === other
fun String?.plus(other: Any?) : String
trait Iterator<out T> {
fun next() : T
val hasNext : Boolean
}
trait Iterable<out T> {
fun iterator() : Iterator<T>
}
class Array<T>(val size : Int, init : fun(Int) : T = null ) {
fun get(index : Int) : T
fun set(index : Int, value : T) : Unit
fun iterator() : Iterator<T>
val indices : IntRange
}
class ByteArray(val size : Int) {
fun get(index : Int) : Byte
fun set(index : Int, value : Byte) : Unit
fun iterator() : Iterator<Byte>
val indices : IntRange
}
class ShortArray(val size : Int) {
fun get(index : Int) : Short
fun set(index : Int, value : Short) : Unit
fun iterator() : Iterator<Short>
val indices : IntRange
}
class IntArray(val size : Int) {
fun get(index : Int) : Int
fun set(index : Int, value : Int) : Unit
fun iterator() : Iterator<Int>
val indices : IntRange
}
class LongArray(val size : Int) {
fun get(index : Int) : Long
fun set(index : Int, value : Long) : Unit
fun iterator() : Iterator<Long>
val indices : IntRange
}
class FloatArray(val size : Int) {
fun get(index : Int) : Float
fun set(index : Int, value : Float) : Unit
fun iterator() : Iterator<Float>
val indices : IntRange
}
class DoubleArray(val size : Int) {
fun get(index : Int) : Double
fun set(index : Int, value : Double) : Unit
fun iterator() : Iterator<Double>
val indices : IntRange
}
class CharArray(val size : Int) {
fun get(index : Int) : Char
fun set(index : Int, value : Char) : Unit
fun iterator() : Iterator<Char>
val indices : IntRange
}
class BooleanArray(val size : Int) {
fun get(index : Int) : Boolean
fun set(index : Int, value : Boolean) : Unit
fun iterator() : Iterator<Boolean>
val indices : IntRange
}
trait Comparable<in T> {
fun compareTo(other : T) : Int
}
trait Hashable {
fun hashCode() : Int
fun equals(other : Any?) : Boolean
}
class Boolean : Comparable<Boolean> {
fun not() : Boolean
fun xor(other : Boolean) : Boolean
fun equals(other : Any?) : Boolean
}
class String() : Comparable<String> {
fun get(index : Int) : Char
val length : Int
fun plus(other : Any?) : String
fun equals(other : Any?) : Boolean
fun equalsIgnoreCase(other: String?) : Boolean
fun substring(start: Int): String
fun substring(start: Int, end: Int): String
fun startsWith(prefix: String, toffset: Int): Boolean
fun startsWith(prefix: String): Boolean
fun endsWith(suffix: String): Boolean
fun trim(): String
}
trait Range<in T : Comparable<T>> {
fun contains(item : T) : Boolean
}
class IntRange(val start : Int, size : Int, reversed : Boolean = false) : Range<Int>, Iterable<Int> {
fun iterator () : Iterator<Int>
fun contains (elem: Int) : Boolean
val size : Int
val end : Int
val reversed : Boolean
}
class LongRange(val start : Long, size : Long, reversed : Boolean = false) : Range<Long>, Iterable<Long> {
fun iterator () : Iterator<Long>
fun contains (elem: Long) : Boolean
val size : Long
val end : Long
val reversed : Boolean
}
abstract class Number : Hashable {
abstract val dbl : Double
abstract val flt : Float
abstract val lng : Long
abstract val int : Int
abstract val chr : Char
abstract val sht : Short
abstract val byt : Byte
// fun equals(other : Double) : Boolean
// fun equals(other : Float) : Boolean
// fun equals(other : Long) : Boolean
// fun equals(other : Byte) : Boolean
// fun equals(other : Int) : Boolean
// fun equals(other : Short) : Boolean
// fun equals(other : Char) : Boolean
}
class Double : Number, Comparable<Double> {
override fun compareTo(other : Double) : Int
fun compareTo(other : Float) : Int
fun compareTo(other : Long) : Int
fun compareTo(other : Int) : Int
fun compareTo(other : Short) : Int
fun compareTo(other : Byte) : Int
fun compareTo(other : Char) : Int
fun plus(other : Double) : Double
fun plus(other : Float) : Double
fun plus(other : Long) : Double
fun plus(other : Int) : Double
fun plus(other : Short) : Double
fun plus(other : Byte) : Double
fun plus(other : Char) : Double
fun minus(other : Double) : Double
fun minus(other : Float) : Double
fun minus(other : Long) : Double
fun minus(other : Int) : Double
fun minus(other : Short) : Double
fun minus(other : Byte) : Double
fun minus(other : Char) : Double
fun times(other : Double) : Double
fun times(other : Float) : Double
fun times(other : Long) : Double
fun times(other : Int) : Double
fun times(other : Short) : Double
fun times(other : Byte) : Double
fun times(other : Char) : Double
fun div(other : Double) : Double
fun div(other : Float) : Double
fun div(other : Long) : Double
fun div(other : Int) : Double
fun div(other : Short) : Double
fun div(other : Byte) : Double
fun div(other : Char) : Double
fun mod(other : Double) : Double
fun mod(other : Float) : Double
fun mod(other : Long) : Double
fun mod(other : Int) : Double
fun mod(other : Short) : Double
fun mod(other : Byte) : Double
fun rangeTo(other : Double) : Range<Double>
fun rangeTo(other : Float) : Range<Double>
fun rangeTo(other : Long) : Range<Double>
fun rangeTo(other : Int) : Range<Double>
fun rangeTo(other : Short) : Range<Double>
fun rangeTo(other : Byte) : Range<Double>
fun rangeTo(other : Char) : Range<Double>
fun inc() : Double
fun dec() : Double
fun plus() : Double
fun minus() : Double
}
class Float : Number, Comparable<Float> {
fun compareTo(other : Double) : Int
override fun compareTo(other : Float) : Int
fun compareTo(other : Long) : Int
fun compareTo(other : Int) : Int
fun compareTo(other : Short) : Int
fun compareTo(other : Byte) : Int
fun compareTo(other : Char) : Int
fun plus(other : Double) : Double
fun plus(other : Float) : Float
fun plus(other : Long) : Float
fun plus(other : Int) : Float
fun plus(other : Short) : Float
fun plus(other : Byte) : Float
fun plus(other : Char) : Float
fun minus(other : Double) : Double
fun minus(other : Float) : Float
fun minus(other : Long) : Float
fun minus(other : Int) : Float
fun minus(other : Short) : Float
fun minus(other : Byte) : Float
fun minus(other : Char) : Float
fun times(other : Double) : Double
fun times(other : Float) : Float
fun times(other : Long) : Float
fun times(other : Int) : Float
fun times(other : Short) : Float
fun times(other : Byte) : Float
fun times(other : Char) : Float
fun div(other : Double) : Double
fun div(other : Float) : Float
fun div(other : Long) : Float
fun div(other : Int) : Float
fun div(other : Short) : Float
fun div(other : Byte) : Float
fun div(other : Char) : Float
fun mod(other : Double) : Double
fun mod(other : Float) : Float
fun mod(other : Long) : Float
fun mod(other : Int) : Float
fun mod(other : Short) : Float
fun mod(other : Byte) : Float
fun mod(other : Char) : Float
fun rangeTo(other : Double) : Range<Double>
fun rangeTo(other : Float) : Range<Float>
fun rangeTo(other : Long) : Range<Double>
fun rangeTo(other : Int) : Range<Double>
fun rangeTo(other : Short) : Range<Float>
fun rangeTo(other : Byte) : Range<Float>
fun rangeTo(other : Char) : Range<Float>
fun inc() : Float
fun dec() : Float
fun plus() : Float
fun minus() : Float
}
class Long : Number, Comparable<Long> {
fun compareTo(other : Double) : Int
fun compareTo(other : Float) : Int
override fun compareTo(other : Long) : Int
fun compareTo(other : Int) : Int
fun compareTo(other : Short) : Int
fun compareTo(other : Byte) : Int
fun compareTo(other : Char) : Int
fun plus(other : Double) : Double
fun plus(other : Float) : Float
fun plus(other : Long) : Long
fun plus(other : Int) : Long
fun plus(other : Short) : Long
fun plus(other : Byte) : Long
fun plus(other : Char) : Long
fun minus(other : Double) : Double
fun minus(other : Float) : Float
fun minus(other : Long) : Long
fun minus(other : Int) : Long
fun minus(other : Short) : Long
fun minus(other : Byte) : Long
fun minus(other : Char) : Long
fun times(other : Double) : Double
fun times(other : Float) : Float
fun times(other : Long) : Long
fun times(other : Int) : Long
fun times(other : Short) : Long
fun times(other : Byte) : Long
fun times(other : Char) : Long
fun div(other : Double) : Double
fun div(other : Float) : Float
fun div(other : Long) : Long
fun div(other : Int) : Long
fun div(other : Short) : Long
fun div(other : Byte) : Long
fun div(other : Char) : Long
fun mod(other : Double) : Double
fun mod(other : Float) : Float
fun mod(other : Long) : Long
fun mod(other : Int) : Long
fun mod(other : Short) : Long
fun mod(other : Byte) : Long
fun mod(other : Char) : Long
fun rangeTo(other : Double) : Range<Double>
fun rangeTo(other : Float) : Range<Double>
fun rangeTo(other : Long) : LongRange
fun rangeTo(other : Int) : LongRange
fun rangeTo(other : Short) : LongRange
fun rangeTo(other : Byte) : LongRange
fun rangeTo(other : Char) : LongRange
fun inc() : Long
fun dec() : Long
fun plus() : Long
fun minus() : Long
fun shl(bits : Int) : Long
fun shr(bits : Int) : Long
fun ushr(bits : Int) : Long
fun and(other : Long) : Long
fun or(other : Long) : Long
fun xor(other : Long) : Long
fun inv() : Long
}
class Int : Number, Comparable<Int> {
fun compareTo(other : Double) : Int
fun compareTo(other : Float) : Int
fun compareTo(other : Long) : Int
override fun compareTo(other : Int) : Int
fun compareTo(other : Short) : Int
fun compareTo(other : Byte) : Int
fun compareTo(other : Char) : Int
fun plus(other : Double) : Double
fun plus(other : Float) : Float
fun plus(other : Long) : Long
fun plus(other : Int) : Int
fun plus(other : Short) : Int
fun plus(other : Byte) : Int
fun plus(other : Char) : Int
fun minus(other : Double) : Double
fun minus(other : Float) : Float
fun minus(other : Long) : Long
fun minus(other : Int) : Int
fun minus(other : Short) : Int
fun minus(other : Byte) : Int
fun minus(other : Char) : Int
fun times(other : Double) : Double
fun times(other : Float) : Float
fun times(other : Long) : Long
fun times(other : Int) : Int
fun times(other : Short) : Int
fun times(other : Byte) : Int
fun times(other : Char) : Int
fun div(other : Double) : Double
fun div(other : Float) : Float
fun div(other : Long) : Long
fun div(other : Int) : Int
fun div(other : Short) : Int
fun div(other : Byte) : Int
fun div(other : Char) : Int
fun mod(other : Double) : Double
fun mod(other : Float) : Float
fun mod(other : Long) : Long
fun mod(other : Int) : Int
fun mod(other : Short) : Int
fun mod(other : Byte) : Int
fun mod(other : Char) : Int
fun rangeTo(other : Double) : Range<Double>
fun rangeTo(other : Float) : Range<Double>
fun rangeTo(other : Long) : LongRange
fun rangeTo(other : Int) : IntRange
fun rangeTo(other : Short) : IntRange
fun rangeTo(other : Byte) : IntRange
fun rangeTo(other : Char) : IntRange
fun inc() : Int
fun dec() : Int
fun plus() : Int
fun minus() : Int
fun shl(bits : Int) : Int
fun shr(bits : Int) : Int
fun ushr(bits : Int) : Int
fun and(other : Int) : Int
fun or(other : Int) : Int
fun xor(other : Int) : Int
fun inv() : Int
}
class Char : Number, Comparable<Char> {
fun compareTo(other : Double) : Int
fun compareTo(other : Float) : Int
fun compareTo(other : Long) : Int
fun compareTo(other : Int) : Int
fun compareTo(other : Short) : Int
override fun compareTo(other : Char) : Int
fun compareTo(other : Byte) : Int
fun plus(other : Double) : Double
fun plus(other : Float) : Float
fun plus(other : Long) : Long
fun plus(other : Int) : Int
fun plus(other : Short) : Int
fun plus(other : Byte) : Int
fun plus(other : Char) : Int
fun minus(other : Double) : Double
fun minus(other : Float) : Float
fun minus(other : Long) : Long
fun minus(other : Int) : Int
fun minus(other : Short) : Int
fun minus(other : Byte) : Int
fun minus(other : Char) : Int
fun times(other : Double) : Double
fun times(other : Float) : Float
fun times(other : Long) : Long
fun times(other : Int) : Int
fun times(other : Short) : Int
fun times(other : Byte) : Int
fun times(other : Char) : Int
fun div(other : Double) : Double
fun div(other : Float) : Float
fun div(other : Long) : Long
fun div(other : Int) : Int
fun div(other : Short) : Int
fun div(other : Byte) : Int
fun div(other : Char) : Int
fun mod(other : Double) : Double
fun mod(other : Float) : Float
fun mod(other : Long) : Long
fun mod(other : Int) : Int
fun mod(other : Short) : Int
fun mod(other : Byte) : Int
fun mod(other : Char) : Int
fun rangeTo(other : Double) : Range<Double>
fun rangeTo(other : Float) : Range<Float>
fun rangeTo(other : Long) : LongRange
fun rangeTo(other : Int) : IntRange
fun rangeTo(other : Short) : IntRange
fun rangeTo(other : Byte) : IntRange
fun rangeTo(other : Char) : IntRange
fun inc() : Char
fun dec() : Char
fun plus() : Int
fun minus() : Int
}
class Short : Number, Comparable<Short> {
fun compareTo(other : Double) : Int
fun compareTo(other : Float) : Int
fun compareTo(other : Long) : Int
fun compareTo(other : Int) : Int
override fun compareTo(other : Short) : Int
fun compareTo(other : Byte) : Int
fun compareTo(other : Char) : Int
fun plus(other : Double) : Double
fun plus(other : Float) : Float
fun plus(other : Long) : Long
fun plus(other : Int) : Int
fun plus(other : Short) : Int
fun plus(other : Byte) : Int
fun plus(other : Char) : Int
fun minus(other : Double) : Double
fun minus(other : Float) : Float
fun minus(other : Long) : Long
fun minus(other : Int) : Int
fun minus(other : Short) : Int
fun minus(other : Byte) : Int
fun minus(other : Char) : Int
fun times(other : Double) : Double
fun times(other : Float) : Float
fun times(other : Long) : Long
fun times(other : Int) : Int
fun times(other : Short) : Int
fun times(other : Byte) : Int
fun times(other : Char) : Int
fun div(other : Double) : Double
fun div(other : Float) : Float
fun div(other : Long) : Long
fun div(other : Int) : Int
fun div(other : Short) : Int
fun div(other : Byte) : Int
fun div(other : Char) : Int
fun mod(other : Double) : Double
fun mod(other : Float) : Float
fun mod(other : Long) : Long
fun mod(other : Int) : Int
fun mod(other : Short) : Int
fun mod(other : Byte) : Int
fun mod(other : Char) : Int
fun rangeTo(other : Double) : Range<Double>
fun rangeTo(other : Float) : Range<Float>
fun rangeTo(other : Long) : LongRange
fun rangeTo(other : Int) : IntRange
fun rangeTo(other : Short) : IntRange
fun rangeTo(other : Byte) : IntRange
fun rangeTo(other : Char) : IntRange
fun inc() : Short
fun dec() : Short
fun plus() : Int
fun minus() : Int
}
class Byte : Number, Comparable<Byte> {
fun compareTo(other : Double) : Int
fun compareTo(other : Float) : Int
fun compareTo(other : Long) : Int
fun compareTo(other : Int) : Int
fun compareTo(other : Short) : Int
fun compareTo(other : Char) : Int
override fun compareTo(other : Byte) : Int
fun plus(other : Double) : Double
fun plus(other : Float) : Float
fun plus(other : Long) : Long
fun plus(other : Int) : Int
fun plus(other : Short) : Int
fun plus(other : Byte) : Int
fun plus(other : Char) : Int
fun minus(other : Double) : Double
fun minus(other : Float) : Float
fun minus(other : Long) : Long
fun minus(other : Int) : Int
fun minus(other : Short) : Int
fun minus(other : Byte) : Int
fun minus(other : Char) : Int
fun times(other : Double) : Double
fun times(other : Float) : Float
fun times(other : Long) : Long
fun times(other : Int) : Int
fun times(other : Short) : Int
fun times(other : Byte) : Int
fun times(other : Char) : Int
fun div(other : Double) : Double
fun div(other : Float) : Float
fun div(other : Long) : Long
fun div(other : Int) : Int
fun div(other : Short) : Int
fun div(other : Byte) : Int
fun div(other : Char) : Int
fun mod(other : Double) : Double
fun mod(other : Float) : Float
fun mod(other : Long) : Long
fun mod(other : Int) : Int
fun mod(other : Short) : Int
fun mod(other : Byte) : Int
fun mod(other : Char) : Int
fun rangeTo(other : Double) : Range<Double>
fun rangeTo(other : Float) : Range<Float>
fun rangeTo(other : Long) : LongRange
fun rangeTo(other : Int) : IntRange
fun rangeTo(other : Short) : IntRange
fun rangeTo(other : Byte) : IntRange
fun rangeTo(other : Char) : IntRange
fun inc() : Byte
fun dec() : Byte
fun plus() : Int
fun minus() : Int
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,50 @@
package org.jetbrains.k2js.test;
import org.jetbrains.k2js.translate.TranslationContext;
import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import java.io.FileReader;
import static org.junit.Assert.assertTrue;
/**
* @author Talanov Pavel
*/
public final class ClassTest extends TranslationTest {
private final String KOTLIN_JS_LIB = TEST_DIR + "kotlin_lib.js";
@Override
protected void runWithRhino(String inputFile, String namespaceName,
String functionName, Object expectedResult) throws Exception {
Context cx = Context.enter();
FileReader testFileReader = new FileReader(inputFile);
FileReader libReader = new FileReader(KOTLIN_JS_LIB);
try {
Scriptable scope = cx.initStandardObjects();
cx.evaluateReader(scope, libReader, "lib", 1, null);
cx.evaluateReader(scope, testFileReader, "test case", 1, null);
Object result = extractAndCallFunctionObject(namespaceName, functionName, cx, scope);
assertTrue(result.equals(expectedResult));
String report = namespaceName + "." + functionName + "() = " + Context.toString(result);
System.out.println(report);
} finally {
Context.exit();
testFileReader.close();
}
}
@Test
public void kotlinJsLibRunsWithRhino() throws Exception {
runWithRhino(TEST_DIR + "testKotlinLib.js", "foo", "box", true);
}
@Test
public void classInstantiation() throws Exception {
testFooBoxIsTrue("classInstantiation.kt");
}
}
@@ -0,0 +1,30 @@
package org.jetbrains.k2js.test;
import org.junit.Test;
/**
* @author Talanov Pavel
*/
public final class FunctionTest extends TranslationTest {
@Test
public void currentTest() throws Exception {
testFooBoxIsTrue("test.kt");
}
@Test
public void testAssign() throws Exception {
performTest("assign.jet", "foo", "f", 2.0);
}
@Test
public void namespaceProperties() throws Exception {
performTest("localProperty.jet", "foo", "box", 50);
}
@Test
public void comparison() throws Exception {
testFooBoxIsTrue("comparison.kt");
}
}
@@ -0,0 +1,66 @@
package org.jetbrains.k2js.test;
import org.jetbrains.k2js.K2JSTranslator;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.NativeObject;
import org.mozilla.javascript.Scriptable;
import java.io.FileReader;
import static org.junit.Assert.*;
/**
* @author Talanov Pavel
*/
public class TranslationTest {
protected final static String TEST_DIR = "test_files/test_cases/";
protected void performTest(String inputFile, String namespaceName,
String functionName, Object expectedResult) throws Exception {
K2JSTranslator.Arguments args = new K2JSTranslator.Arguments();
args.src = TEST_DIR + inputFile;
args.outputDir = getOutputFilename(TEST_DIR + inputFile);
K2JSTranslator.translate(args);
runWithRhino(args.outputDir, namespaceName, functionName, expectedResult);
}
private String getOutputFilename(String inputFile) {
return inputFile.substring(0, inputFile.lastIndexOf('.')) + ".js";
}
protected void runWithRhino(String inputFile, String namespaceName,
String functionName, Object expectedResult) throws Exception {
Context cx = Context.enter();
FileReader reader = new FileReader(inputFile);
try {
Scriptable scope = cx.initStandardObjects();
cx.evaluateReader(scope, reader, "test case", 1, null);
Object result = extractAndCallFunctionObject(namespaceName, functionName, cx, scope);
assertTrue(result.equals(expectedResult));
String report = namespaceName + "." + functionName + "() = " + Context.toString(result);
System.out.println(report);
} finally {
Context.exit();
reader.close();
}
}
protected Object extractAndCallFunctionObject(String namespaceName, String functionName,
Context cx, Scriptable scope) {
Object foo = scope.get(namespaceName, scope);
assertTrue(foo instanceof NativeObject);
NativeObject namespaceObject = (NativeObject)foo;
Object box = namespaceObject.get(functionName, namespaceObject);
assertTrue(box instanceof Function);
Object functionArgs[] = {};
Function function = (Function)box;
return function.call(cx, scope, scope, functionArgs);
}
protected void testFooBoxIsTrue(String filename) throws Exception {
performTest(filename, "foo", "box", true);
}
}
@@ -0,0 +1,7 @@
namespace foo
fun f(): Int {
var x: Int = 1
x = x + 1
return x
}
@@ -0,0 +1,10 @@
foo = {};
(function(foo){
foo.f = function(){
var x = 1;
x = x + 1;
return x;
}
;
}
(foo));
@@ -0,0 +1,12 @@
foo = {};
(function(foo){
foo.Test = Class.create({initialize:function(){
}
});
foo.box = function(){
var test = foo.Test();
return true;
}
;
}
(foo));
@@ -0,0 +1,9 @@
namespace foo
class Test() {
}
fun box() : Boolean {
var test = Test()
return true
}
@@ -0,0 +1,11 @@
foo = {};
(function(foo){
foo.box = function(){
var a = 2;
var b = 3;
var c = 4;
return a < c;
}
;
}
(foo));
@@ -0,0 +1,9 @@
namespace foo
fun box() : Boolean {
val a = 2;
val b = 3;
var c = 4;
return (a < c)
}
@@ -0,0 +1,14 @@
class Slot() {
var vitality: Int = 10000
fun increaseVitality(delta: Int) {
vitality += delta
if (vitality > 65535) vitality = 65535;
}
}
fun box(): Boolean {
val s = Slot()
s.increaseVitality(1000)
return (s.vitality == 11000)
}
@@ -0,0 +1,288 @@
function $A(iterable) {
if (!iterable) return [];
if ('toArray' in Object(iterable)) return iterable.toArray();
var length = iterable.length || 0, results = new Array(length);
while (length--) results[length] = iterable[length];
return results;
}
var emptyFunction = function() {}
var Class = (function() {
var IS_DONTENUM_BUGGY = (function(){
for (var p in { toString: 1 }) {
if (p === 'toString') return false;
}
return true;
})();
function subclass() {};
function create() {
var parent = null, properties = $A(arguments);
if (Object.isFunction(properties[0]))
parent = properties.shift();
function klass() {
this.initialize.apply(this, arguments);
}
Object.extend(klass, Class.Methods);
klass.superclass = parent;
klass.subclasses = [];
if (parent) {
subclass.prototype = parent.prototype;
klass.prototype = new subclass;
parent.subclasses.push(klass);
}
for (var i = 0, length = properties.length; i < length; i++)
klass.addMethods(properties[i]);
if (!klass.prototype.initialize)
klass.prototype.initialize = emptyFunction;
klass.prototype.constructor = klass;
return klass;
}
function addMethods(source) {
var ancestor = this.superclass && this.superclass.prototype,
properties = Object.keys(source);
if (IS_DONTENUM_BUGGY) {
if (source.toString != Object.prototype.toString)
properties.push("toString");
if (source.valueOf != Object.prototype.valueOf)
properties.push("valueOf");
}
for (var i = 0, length = properties.length; i < length; i++) {
var property = properties[i], value = source[property];
if (ancestor && Object.isFunction(value) &&
value.argumentNames()[0] == "$super") {
var method = value;
value = (function(m) {
return function() { return ancestor[m].apply(this, arguments); };
})(property).wrap(method);
value.valueOf = method.valueOf.bind(method);
value.toString = method.toString.bind(method);
}
this.prototype[property] = value;
}
return this;
}
return {
create: create,
Methods: {
addMethods: addMethods
}
};
})();
(function() {
var _toString = Object.prototype.toString,
NULL_TYPE = 'Null',
UNDEFINED_TYPE = 'Undefined',
BOOLEAN_TYPE = 'Boolean',
NUMBER_TYPE = 'Number',
STRING_TYPE = 'String',
OBJECT_TYPE = 'Object',
FUNCTION_CLASS = '[object Function]',
BOOLEAN_CLASS = '[object Boolean]',
NUMBER_CLASS = '[object Number]',
STRING_CLASS = '[object String]',
ARRAY_CLASS = '[object Array]',
DATE_CLASS = '[object Date]';
function Type(o) {
switch(o) {
case null: return NULL_TYPE;
case (void 0): return UNDEFINED_TYPE;
}
var type = typeof o;
switch(type) {
case 'boolean': return BOOLEAN_TYPE;
case 'number': return NUMBER_TYPE;
case 'string': return STRING_TYPE;
}
return OBJECT_TYPE;
}
function extend(destination, source) {
for (var property in source)
destination[property] = source[property];
return destination;
}
function inspect(object) {
try {
if (isUndefined(object)) return 'undefined';
if (object === null) return 'null';
return object.inspect ? object.inspect() : String(object);
} catch (e) {
if (e instanceof RangeError) return '...';
throw e;
}
}
function toJSON(value) {
return Str('', { '': value }, []);
}
function Str(key, holder, stack) {
var value = holder[key],
type = typeof value;
if (Type(value) === OBJECT_TYPE && typeof value.toJSON === 'function') {
value = value.toJSON(key);
}
var _class = _toString.call(value);
switch (_class) {
case NUMBER_CLASS:
case BOOLEAN_CLASS:
case STRING_CLASS:
value = value.valueOf();
}
switch (value) {
case null: return 'null';
case true: return 'true';
case false: return 'false';
}
type = typeof value;
switch (type) {
case 'string':
return value.inspect(true);
case 'number':
return isFinite(value) ? String(value) : 'null';
case 'object':
for (var i = 0, length = stack.length; i < length; i++) {
if (stack[i] === value) { throw new TypeError(); }
}
stack.push(value);
var partial = [];
if (_class === ARRAY_CLASS) {
for (var i = 0, length = value.length; i < length; i++) {
var str = Str(i, value, stack);
partial.push(typeof str === 'undefined' ? 'null' : str);
}
partial = '[' + partial.join(',') + ']';
} else {
var keys = Object.keys(value);
for (var i = 0, length = keys.length; i < length; i++) {
var key = keys[i], str = Str(key, value, stack);
if (typeof str !== "undefined") {
partial.push(key.inspect(true)+ ':' + str);
}
}
partial = '{' + partial.join(',') + '}';
}
stack.pop();
return partial;
}
}
function stringify(object) {
return JSON.stringify(object);
}
function toQueryString(object) {
return $H(object).toQueryString();
}
function toHTML(object) {
return object && object.toHTML ? object.toHTML() : String.interpret(object);
}
function keys(object) {
if (Type(object) !== OBJECT_TYPE) { throw new TypeError(); }
var results = [];
for (var property in object) {
if (object.hasOwnProperty(property)) {
results.push(property);
}
}
return results;
}
function values(object) {
var results = [];
for (var property in object)
results.push(object[property]);
return results;
}
function clone(object) {
return extend({ }, object);
}
function isElement(object) {
return !!(object && object.nodeType == 1);
}
function isArray(object) {
return _toString.call(object) === ARRAY_CLASS;
}
var hasNativeIsArray = (typeof Array.isArray == 'function')
&& Array.isArray([]) && !Array.isArray({});
if (hasNativeIsArray) {
isArray = Array.isArray;
}
function isHash(object) {
return object instanceof Hash;
}
function isFunction(object) {
return _toString.call(object) === FUNCTION_CLASS;
}
function isString(object) {
return _toString.call(object) === STRING_CLASS;
}
function isNumber(object) {
return _toString.call(object) === NUMBER_CLASS;
}
function isDate(object) {
return _toString.call(object) === DATE_CLASS;
}
function isUndefined(object) {
return typeof object === "undefined";
}
extend(Object, {
extend: extend,
inspect: inspect,
toQueryString: toQueryString,
toHTML: toHTML,
keys: Object.keys || keys,
values: values,
clone: clone,
isElement: isElement,
isArray: isArray,
isHash: isHash,
isFunction: isFunction,
isString: isString,
isNumber: isNumber,
isDate: isDate,
isUndefined: isUndefined
});
})();
@@ -0,0 +1,15 @@
namespace foo
val y = 3
fun f(a:Int) : Int {
val x = 42
val y = 50
return y
}
fun box() : Int
{
return f(y)
}
@@ -0,0 +1,15 @@
foo = {};
(function(foo){
foo.y = 3;
foo.f = function(a){
var x = 42;
var y = 50;
return y;
}
;
foo.box = function(){
return foo.f(foo.y);
}
;
}
(foo));
File diff suppressed because it is too large Load Diff
+11
View File
@@ -0,0 +1,11 @@
foo = {};
(function(foo){
foo.box = function(){
var a = 2;
var b = 3;
var c = 4;
return a < c;
}
;
}
(foo));
+9
View File
@@ -0,0 +1,9 @@
namespace foo
fun box() : Boolean {
val a = 2;
val b = 3;
var c = 4;
return (a < c)
}
@@ -0,0 +1,12 @@
foo = {};
(function(foo){
foo.Test = Class.create({initialize:function(){
}
});
foo.box = function(){
var test = new foo.Test();
return true;
}
;
}
(foo));