diff options
Diffstat (limited to 'web/server/h2o/libh2o/misc/oktavia/testdata')
5 files changed, 0 insertions, 454 deletions
diff --git a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_literal.txt b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_literal.txt deleted file mode 100644 index 7415d7468..000000000 --- a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_literal.txt +++ /dev/null @@ -1,65 +0,0 @@ -Literals - -Keywords - -The table lists the keyword literals of JSX. In contrary to JavaScript, there is no distinction between undefined and null. - -Table 1. List of Keyword Literals -Keyword Description -null [: type] declares null, may have the type annotated. The type is deducted (if possible) if the type annotation does not exist. -false a boolean constant -true a boolean constant -Number Literal - -Identical to JavaScript. - -String Literal - -Identical to JavaScript. - -RegExp Literal - -Identical to JavaScript. - -Function Literal - -Type annotations against arguments and return types are required for function declaration, unless the type can be deducted by the surrounding expression. - -// a function that takes no arguments, and returns void -function () : void {} - -// a function that takes one argument (of number), -// and returns a number that in incremented by one -function (n : number) : number { - return n + 1; -} - -// the argument types and return types may be omitted -// (if it is deductable from the outer expression) -var sum = 0; -[ 1, 2, 3 ].forEach(function (e) { - sum += e; -}); -log sum; // 6 - -// short-handed -var sum = 0; -[ 1, 2, 3 ].forEach((e) -> { sum += e; }); -log sum; // 6 - -// short-handed, single-statement function expression -var s = "a0b1c".replace(/[a-z]/g, (ch) -> ch.toUpperCase()); -log s; // A0B1C -A statement starting with function is parsed as inner function declaration, as is by JavaScript. Surround the function declaration with () if your intention is to create an anonymous function and call it immediately. - -// inner function declaration (when used within a function declaration) -function innerFunc() : void { - ...; -} - -// create an anonymous function and execute immediately -(function () : void { - ...; -})(); -See also: Member Function in Class, Interface, and Mixin. - diff --git a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_operator.txt b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_operator.txt deleted file mode 100644 index 7b79f9324..000000000 --- a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_operator.txt +++ /dev/null @@ -1,68 +0,0 @@ -Operators - -The operators of JSX are the same to those in JavaScript (ECMA-262 3rd edition) except for the following changes. - -types of the operands accepted by the operators are more restrictive -logical operators (&& ||) return boolean -binary ?: operator has been introduced (to cover the use of || in JavaScript to return non-boolean values) -introduction of the as operator -delete is a statement instead of an operator -The table below lists the operators supported by JSX. - -Table 1. List of Operators by Precedence -Operator Returned Type Operand Type(s) -(x)[1] typeof x -func(...) return type of the function -obj.prop typeof obj.prop obj: any object type -array[index] Nullable.<T> array: Array.<T> -index: number -map[key] Nullable.<T> map: Map.<T> -key: string -x++ -x-- typeof x number or int -obj instanceof type boolean obj: any object type -type: a Class, Interface, or Mixin -x as type[2] -x as __noconvert__ type[3] type -++x ---x typeof x number or int -+x --x typeof x number or int -~x int number or int -! x boolean any -typeof x string variant -x * y -x % y number or int[4] number or int -x / y number number or int -x + y -x - y number or int[4] number or int -x + y string string -x << y -x >> y -x >>> y int number or int -x < y -x<= y -x > y -x >= y boolean number, int, string[5] -x in y boolean x: string -y: Map.<T> -x == y -x != y boolean any except variant[5] -x & y int number or int -x ^ y int number or int -x | y int number or int -x && y boolean any -x || y boolean any -x ? y : z typeof y any[6] -x ?: y typeof x any[5] -x = y typeof x any[7] -x op[8]= y typeof x same as op -x, y typeof y any -grouping operator -cast operator -cast operator (without run-time type check) -int is returned if both operands are int -types of x and y should be equal, or either should be convertible to the other -types of y and z should be equal, or either should be convertible to the other -type of y should be convertible to type of x -any of: * / % + - << >> >>> & ^ | diff --git a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_primitive_type.txt b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_primitive_type.txt deleted file mode 100644 index c55778dc1..000000000 --- a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_primitive_type.txt +++ /dev/null @@ -1,68 +0,0 @@ -Primitive Types - -JSX provides the following four primitive types. Primitive types are non-nullable. Int exists as a type, but would be equal to or slower than using number in some cases (the definition of int is: an integral number between -231 to 231-1, or NaN, or +-Infinity). - -boolean -number -string -(int) -Nullable Primitive Types - -A nullable counterpart exists for each primitive type. Values of the types are returned by [] operators of Array.<primitive_type> and Map.<primitive_type>. - -Nullable.<boolean> -Nullable.<number> -Nullable.<string> -(Nullable.<int>) -Variant Type - -A variant can hold any type of data (including null). To use the data, explicit cast to other data types is necessary. - -Built-in Object Types - -Object - -Object class is the root class for all objects. - -Array.<T> - -The class represents an array, by providing the [] operator that takes a number as the argument, length property and other methods to manipulate the array. In contrast to JavaScript, the array is typed. An instance of Array.<T> class may only store elements of type T or null. - -The size of the array automatically grows. null is returned when an element out of the current boundary is requested. - -There are two ways to create an array object; one is to use the new opreator, the other is to use the array initialiser. The type of the array returned by an array initialiser is deducted from the type of the elements. Type information should be annotated in cases where such deduction is impossible (such as when initializing an empty array). - -new Array.<number>; // creates an empty array of numbers -new Array.<number>(length); // creates an array of given length (elements are initialized to null) -[] : Array.<number>; // creates an empty array of numbers -[ 1, 2, 3 ]; // creates an array of numbers with three elements: 1, 2, 3 -Map.<T> - -The class represents an associative array (collection of key-values pairs), mapping strings to values of type T or null. - -Operator [] (that takes a string as the argument) is provided for registering / retreiving a keyed value. for..in statement can be used for iterating the keys. hasOwnProperty method is provided for checking whether or not a key-value pair of a particular name is registered. The delete statement can be used for unregistering a key-value pair. - -Map objects can be created in two ways; by using the new operator or by using the map initialiser. - -new Map.<number>; // creates an empty map of strings to numbers -{} : Map.<number>; // same as above -{ a: 1 }; // creates a map of strings to numbers that has one pair: ("a" => 1) -Boolean, Number, String - -Internal types used for applying methods against primitives. - -These types of objects are instantiated when applying the dot operator against the primitives. For exmaple, the following code snippet applies the operator against string "abc", that returns a String object wrapping the primitive value. Then the charAt method of the object is called and "a" (of type string) is returned. - -"abc".charAt(0) // returns "a" -Although being possible, it is discouraged to instantiate and store these values of the types (e.g. var s = new String("abc")). Use of the primitive types (or nullable primitive types) is preferable for performance and debugging reasons. - -Number and String classes also provide some useful class methods and constants, e.g. Number.parseInt(:string):number, String.encodeURIComponent(:string):string. - -JSX - -The class provides some methods for controlling the runtime environment. - -User-defined Types - -Users may define a new class by extending the Object class, or by declaring an interface or a mixin. See Class, Interface and Mixin. - diff --git a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_tutorial.txt b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_tutorial.txt deleted file mode 100644 index 538238a39..000000000 --- a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_tutorial.txt +++ /dev/null @@ -1,213 +0,0 @@ -Background - -JSX is a statically-typed, object-oriented programming language compiling to standalone JavaScript. The reason why JSX was developed is our need for a more robust programming language than JavaScript. However, JSX is fairly close to JavaScript especially in its statements and expressions. - -Statically-typed programming language is robust because certain sorts of problems, for example typos in variable names or missing function definitions, are detected at compile-time. This is important especially in middle- to large-scale software development in which a number of engineers may be engaged. - -Therefore, JSX is designed as a statically-typed language. All the values and variables have a static type and you can only assign a correctly-typed value to a variable. In addition, all the functions including closures have types which are determined by the types of parameters and the return values, where you cannot call a function with incorrectly typed arguments. - -Also, another important reason why JSX was developed is to boost JavaScript performance. JavaScript itself is not so slow but large-scale development tends to have many abstraction layers, e.g. proxy classes and accessor methods, which often have negative impact on performance. JSX boosts performance by inline expansion: function bodies are expanded to where they are being called, if the functions being called could be determined at compile-time. This is the power of the statically-typed language in terms of performance. - -Run "Hello, World!" - -Let's start by running our first JSX program: hello.jsx. We use the jsx command, which is the JSX compiler in the JSX distribution, to compile JSX source code to JavaScript. - -Type as follows in the JSX distribution and/or repository, and then you will see it saying "Hello, world!". - -$ bin/jsx --run example/hello.jsx -We will look into the hello.jsx source code in the next section. - -Program Structure - -Here is hello.jsx, the source code of the "Hello world!" example. You can see several features of JSX in this program, namely, static types and class structure within the source code. - -class _Main { - static function main(args : string[]) : void { - log "Hello, world!"; - } -} -Class _Main has a static member function (a.k.a. a class method) named main, that takes an array of strings and returns nothing. _Main.main(:string[]):void is the entry point of JSX applications that is called when a user invokes an application from command line. JSX, like Java, does not allow top-level statements or functions. - -The log statement is mapped to console.log() in JavaScript, which displays the arguments to stdout with a newline. - -Next, we look into another typical library class, Point: - -class Point { - var x = 0; - var y = 0; - - function constructor() { - } - - function constructor(x : number, y : number) { - this.set(x, y); - } - - function constructor(other : Point) { - this.set(other); - } - - function set(x : number, y : number) : void { - this.x = x; - this.y = y; - } - - function set(other : Point) : void { - this.x = other.x; - this.y = other.y; - } -} -As you can see, member variables of Point, var x and var y, are declared without types, but their types are deducted from their initial values to be number. - -You might be surprised at multiple definition of member functions: one takes no parameters and the others take parameters. They are overloaded by their types of parameters. When you construct the class with new Point(), the first constructor, which takes no parameters, is called. The second with two parameters will be called on new Point(2, 3) and the third with one parameter will be called as a copy constructor. Other forms of construction, e.g. new Point(42) or new Point("foo", "bar") will cause compilation errors of mismatching signatures. The Point#set() functions are also overloaded and the compiler know how to call the correct one. - -Static Types - -Basic type concept will be described in this section. Primitive types, object types, variant type, and Nullable types exist in JSX. - -Primitive types, e.g. string, boolean, or number are non-nullable, immutable types. - -var s : string = "hello"; -var n : number = 42; -var b : boolean = true; -Object types, e.g. string[] (array of string), functions or Date, are nullable, mutable types. - -var d : Date = new Date(); // Date -var f : function():void = function() : void { log "Hi!"; }; -var a : string[] = ["foo"]; // the same as Array.<string>; -Variant type, which means "no static type information," is used for interacting with existing JavaScript APIs. Some JavaScript libraries may return a variant value, which type cannot be determined at compile time. All you can do on variant values is to check equality of a variant value to another variant value. You have to cast it to another type before doing anything else on the value. - -Nullable type is a meta type which indicates a value may be null. For example, the return type of Array.<string>#shift() is Nullable.<string>. When you use a Nullable value, you have to make sure of the value is not null. Only primitive types can be marked Nullable. Object types and variants are nullable by default. - -function shiftOrReturnEmptyString(args : string[]) : string { - if (args.length > 0) - return args.shift(); - else - return ""; -} -When the source code is compiled in debug mode (which is the default), the compiler will insert run-time type-checking code. An exception will be raised (or the debugger will be activated) when misuse of a null value as actual value is detected. Run-time type checks can be omitted by compiling the source code with the --release option. -Classes and Interfaces - -JSX is a class-based object-oriented language, and its class model is similar to Java. - -a class may extend another class (single inheritance) -a class may implement multiple interfaces -all classes share a single root class: the Object class -interface Flyable { - abstract function fly() : void; -} - -abstract class Animal { - function eat() : void { - log "An animal is eating!"; - } -} - -class Bat extends Animal implements Flyable { - override function fly() : void { - log "A bat is flying!"; - } -} - -abstract class Insect { -} - -class Bee extends Insect implements Flyable { - override function fly() : void { - log "A bee is flying!"; - } -} - -class _Main { - - static function main(args : string[]) : void { - // fo bar - var bat = new Bat(); - - var animal : Animal = bat; // OK. A bat is an animal. - animal.eat(); - - var flyable : Flyable = bat; // OK. A bat can fly - flyable.fly(); - - // for Bee - var bee = new Bee(); - - flyable = bee; // A bee is also flyable - flyable.fly(); - } -} -In the example, the Bat class extends the Animal class, so it inherits the Animal#eat() member function, and it can be assigned to a variable typed to Animal. The class also implements the Flyable interface overriding the Flyable#fly() member function, so it can be assigned to a variable typed Flyable. There's also another flyable class, Bee. By using the Flyable interface, it is possible to deal with both classes as a flyable being, even if the organ of a bee is completely different from that of a bat. - -When overriding a member function, the use the override keyword is mandatory. Otherwise the compiler will report an error. In other words, you are saved from unexpected interface changes in the base classes which cause compilation errors in derived classes instead of undesirable runtime errors. -Functions and Closures - -In JSX, functions are first-class objects and they have static types. You can declare a variable of a function type like var f : function(arg : number) : number, a function that takes a number as an argument and returns another number (or, just returns the same value as the argument; but it's not important here). The variable f can be called as f(42) from which you will get a number value. - -It is possible to define closures (or anonymous functions). They are typically used to implement event listeners, which are popular in GUI programming. Closures are similar to JavaScript except for what this points at: when a closure is defined within a member function, it refers to the receiver of the member function. See the following example. -class _Main { - var foo = 42; - - function constructor() { - var f = function() : void { - log this.foo; - }; - - f(); // says 42 - } - - static function main(args : string[]) : void { - var o = new _Main(); - } -} -Modules - -JSX has a module system. You can reuse JSX class libraries by the import statement. For example, the following program uses timer.jsx module, which exports the Timer class. - -import "timer.jsx"; - -class _Main { - - static function main(args : string[]) : void { - Timer.setTimeout(function() : void { - log "Hello, world!"; - }, 1000); - } - -} -A module may export multiple classes, but you can specify what modules you import or name a namespace which the module is imported into. - -Interface to Web Browsers - -The js/web.jsx module provides the interface to web browser APIs, e.g. the window object and DOM APIs. The example below shows how to insert a text node into an HTML. - -// hello.jsx -import "js/web.jsx"; - -class _Main { - - static function main(args : string[]) : void { - var document = dom.window.document; - - var text = document.createTextNode("Hello, world!"); - document.getElementById("hello").appendChild(text); - } - -} -<!DOCTYPE html> -<html> - <head> - <title>Hello, world!</title> - <script src="hello.jsx.js"></script> - </head> - <body> - <p id="hello"></p> - </body> -</html> -Once you compile hello.jsx by the following command, then you can access the HTML and you will see it saying "Hello, world!." - -$ bin/jsx --executable web --output hello.jsx.js hello.jsx -Further Learning - -More documents can be found on the wiki. -If you are looking for examples, please refer to the examples on this web site, the example directory of the distribution, or to the links on Resouces page of the wiki. diff --git a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_typeconversion.txt b/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_typeconversion.txt deleted file mode 100644 index ec138bb32..000000000 --- a/web/server/h2o/libh2o/misc/oktavia/testdata/jsx_typeconversion.txt +++ /dev/null @@ -1,40 +0,0 @@ -Documents > Type Conversion -Type Conversion - -The as operator is used for: conversion between primitive types (including Nullable and variant), down-casting of object types. - -The conversion rules between primitive types are defined as follows. If the source type is a Nullable type and if the value is null, a run-time exception is raised under debug builds. The behavior is unspecified for release builds. - -The result of conversion from a variant type depends on the result of the typeof operator applied to the variant. - -Down-casting of an object type returns a reference to the casted object if successful, otherwise null. - -Table 1. Conversion between the Primitive Types using the As Operator -Source Type Destination Type Result -boolean number 0 if false, 1 if true -boolean int same as above -boolean string "false" if false, "true" if true -number boolean false if 0 or NaN, otherwise true -number int fractional part is removed, becomes 0 if NaN, may get rounded to between -231 and 231-1 -number string converted to string representation -int boolean false if 0, otherwise true -int number converted to number of same value -int string converted to string representation -string boolean false if the string is empty, otherwise true -string number 0 if the string is empty, a number if the string can be parsed as a string, otherwise NaN -string int equivalent to: as number as int -Table 2. Conversion from Variant using the As Operator -Result of typeof(variant) Destination Type Result -"undefined" boolean false -"undefined" number NaN -"undefined" int 0 -"undefined" string "undefined" -"null" boolean false -"null" number 0 -"null" int 0 -"null" string "null" -"boolean" any primitive type equivalent to the result of: boolean as type -"number" any primitive type equivalent to the result of: number as type -"string" any primitive type equivalent to the result of: string as type -"object" any primitive type depends on the actual type of the value -"object" any object type reference to the object if the value is an object of the specified type, otherwise null |