Builtins rewrite with type parameter inference; Small integer math optimizations; Switchify

This commit is contained in:
dcodeIO 2018-01-10 13:09:05 +01:00
parent 0de05b543b
commit fc777b3a89
64 changed files with 4894 additions and 1620 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@ export enum DiagnosticCode {
Structs_cannot_extend_classes_and_vice_versa = 107,
Structs_cannot_implement_interfaces = 108,
Invalid_regular_expression_flags = 109,
Type_0_cannot_be_reinterpreted_as_type_1 = 110,
Unterminated_string_literal = 1002,
Identifier_expected = 1003,
_0_expected = 1005,
@ -97,6 +98,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string {
case 107: return "Structs cannot extend classes and vice-versa.";
case 108: return "Structs cannot implement interfaces.";
case 109: return "Invalid regular expression flags.";
case 110: return "Type '{0}' cannot be reinterpreted as type '{1}'.";
case 1002: return "Unterminated string literal.";
case 1003: return "Identifier expected.";
case 1005: return "'{0}' expected.";

View File

@ -9,6 +9,7 @@
"Structs cannot extend classes and vice-versa.": 107,
"Structs cannot implement interfaces.": 108,
"Invalid regular expression flags.": 109,
"Type '{0}' cannot be reinterpreted as type '{1}'.": 110,
"Unterminated string literal.": 1002,
"Identifier expected.": 1003,

View File

@ -351,6 +351,8 @@ export class Range {
}
}
declare function parseFloat(str: string): f64;
export class Tokenizer extends DiagnosticEmitter {
source: Source;

View File

@ -58,8 +58,10 @@ export class Type {
functionType: Function | null;
/** Whether nullable or not. */
isNullable: bool = false;
/** Respective nullable type, if nullable. */
/** Respective nullable type, if non-nullable. */
nullableType: Type | null = null;
/** Respective non-nullable type, if nullable. */
nonNullableType: Type;
/** Constructs a new resolved type. */
constructor(kind: TypeKind, size: i32) {
@ -67,6 +69,7 @@ export class Type {
this.size = size;
this.byteSize = <i32>ceil<f64>(<f64>size / 8);
this.classType = null;
this.nonNullableType = this;
}
/** Sign-extending 32-bit shift, if a small signed integer. */
@ -75,23 +78,157 @@ export class Type {
get smallIntegerMask(): i32 { return -1 >>> (32 - this.size); }
/** Tests if this type is of any integer kind. */
get isAnyInteger(): bool { return this.kind >= TypeKind.I8 && this.kind <= TypeKind.BOOL; }
/** Tests if this type is of any small integer kind. */
get isSmallInteger(): bool { return this.size != 0 && this.size < 32; }
/** Tests if this type is of any long integer kind. */
get isLongInteger(): bool { return this.size == 64 && this.kind != TypeKind.F64; }
get isAnyInteger(): bool {
switch (this.kind) {
case TypeKind.I8:
case TypeKind.I16:
case TypeKind.I32:
case TypeKind.I64:
case TypeKind.ISIZE:
case TypeKind.U8:
case TypeKind.U16:
case TypeKind.U32:
case TypeKind.U64:
case TypeKind.USIZE:
case TypeKind.BOOL:
return true;
default:
return false;
}
}
/** Tests if this type is of any unsigned integer kind. */
get isUnsignedInteger(): bool { return this.kind >= TypeKind.U8 && this.kind <= TypeKind.BOOL; }
get isAnyUnsignedInteger(): bool {
switch (this.kind) {
case TypeKind.U8:
case TypeKind.U16:
case TypeKind.U32:
case TypeKind.U64:
case TypeKind.USIZE:
case TypeKind.BOOL:
return true;
default:
return false;
}
}
/** Tests if this type is of any signed integer kind. */
get isSignedInteger(): bool { return this.kind >= TypeKind.I8 && this.kind <= TypeKind.ISIZE; }
/** Tests if this type is of any size kind, i.e., `isize` or `usize`. */
get isAnySize(): bool { return this.kind == TypeKind.ISIZE || this.kind == TypeKind.USIZE; }
get isAnySignedInteger(): bool {
switch (this.kind) {
case TypeKind.I8:
case TypeKind.I16:
case TypeKind.I32:
case TypeKind.I64:
case TypeKind.ISIZE:
return true;
default:
return false;
}
}
/** Tests if this type is of any small integer kind. */
get isSmallInteger(): bool {
switch (this.kind) {
case TypeKind.I8:
case TypeKind.I16:
case TypeKind.U8:
case TypeKind.U16:
case TypeKind.BOOL:
return true;
default:
return false;
}
}
/** Tests if this type is of any small signed integer kind. */
get isSmallSignedInteger(): bool {
switch (this.kind) {
case TypeKind.I8:
case TypeKind.I16:
return true;
default:
return false;
}
}
/** Tests if this type is of any small unsigned integer kind. */
get isSmallUnsignedInteger(): bool {
switch (this.kind) {
case TypeKind.U8:
case TypeKind.U16:
case TypeKind.BOOL:
return true;
default:
return false;
}
}
/** Tests if this type is of any long integer kind. */
get isLongInteger(): bool {
switch (this.kind) {
case TypeKind.I64:
case TypeKind.U64:
return true;
case TypeKind.ISIZE:
case TypeKind.USIZE:
return this.size == 64;
default:
return false;
}
}
/** Tests if this type is of any long signed integer kind. */
get isLongSignedInteger(): bool {
switch (this.kind) {
case TypeKind.I64:
return true;
case TypeKind.ISIZE:
return this.size == 64;
default:
return false;
}
}
/** Tests if this type is of any long unsigned integer kind. */
get isLongUnsignedInteger(): bool {
switch (this.kind) {
case TypeKind.U64:
return true;
case TypeKind.USIZE:
return this.size == 64;
default:
return false;
}
}
/** Tests if this type is of any size kind, that is `isize` or `usize`. */
get isAnySize(): bool {
switch (this.kind) {
case TypeKind.ISIZE:
case TypeKind.USIZE:
return true;
default:
return false;
}
}
/** Tests if this type is of any float kind, i.e., `f32` or `f64`. */
get isAnyFloat(): bool { return this.kind == TypeKind.F32 || this.kind == TypeKind.F64; }
get isAnyFloat(): bool {
switch (this.kind) {
case TypeKind.F32:
case TypeKind.F64:
return true;
default:
return false;
}
}
/** Tests if this type is a class type. */
get isClass(): bool { return this.classType != null; }
/** Tests if this type is a function type. */
get isFunction(): bool { return this.functionType != null; }
/** Tests if this type is a reference type. */
get isReference(): bool { return this.classType != null || this.functionType != null; }
/** Composes a class type from this type and a class. */
asClass(classType: Class): Type {
@ -103,7 +240,7 @@ export class Type {
/** Composes a function type from this type and a function. */
asFunction(functionType: Function): Type {
assert(this.kind == TypeKind.USIZE);
assert(this.kind == TypeKind.USIZE && !this.isReference);
var ret = new Type(this.kind, this.size);
ret.functionType = functionType;
return ret;
@ -111,9 +248,12 @@ export class Type {
/** Composes the respective nullable type of this type. */
asNullable(): Type | null {
assert(this.kind == TypeKind.USIZE);
if (this.isNullable && !this.nullableType)
assert(this.kind == TypeKind.USIZE && !this.isReference);
if (this.isNullable && !this.nullableType) {
(this.nullableType = new Type(this.kind, this.size)).isNullable = true;
this.nullableType.classType = this.classType;
this.nullableType.functionType = this.functionType;
}
return this.nullableType;
}
@ -226,6 +366,34 @@ export class Type {
}
}
/** Converts this type to its native `-1` value. */
toNativeNegOne(module: Module): ExpressionRef {
switch (this.kind) {
case TypeKind.VOID:
assert(false);
default:
return module.createI32(-1);
case TypeKind.ISIZE:
case TypeKind.USIZE:
if (this.size != 64)
return module.createI32(-1);
// fall-through
case TypeKind.I64:
case TypeKind.U64:
return module.createI64(-1, -1);
case TypeKind.F32:
return module.createF32(-1);
case TypeKind.F64:
return module.createF64(-1);
}
}
/** Converts this type to its signature string. */
toSignatureString(): string {
switch (this.kind) {

6
std/assembly.d.ts vendored
View File

@ -173,14 +173,14 @@ declare const Infinity: f32 | f64;
declare const HEAP_BASE: usize;
/** Determines the byte size of the specified core or class type. Compiles to a constant. */
declare function sizeof<T>(): usize;
/** Changes the type of a value to another one. Useful for casting class instances to their pointer values and vice-versa. */
/** Changes the type of any value of `usize` kind to another one of `usize` kind. Useful for casting class instances to their pointer values and vice-versa. Beware that this is unsafe.*/
declare function changetype<T>(value: any): T;
/** Tests if a 32-bit or 64-bit float is `NaN`. */
declare function isNaN<T = f32 | f64>(value: T): bool;
/** Tests if a 32-bit or 64-bit float is finite, that is not `NaN` or +/-`Infinity`. */
declare function isFinite<T = f32 | f64>(value: T): bool;
/** Traps if the specified value evaluates to `false`. */
declare function assert(isTrue: bool, message?: string): void;
/** Traps if the specified value is not true-ish, otherwise returns the value. */
declare function assert<T>(isTrueish: T, message?: string): T & object; // any better way to model `: T != null`?
/** Parses an integer string to a 64-bit float. */
declare function parseInt(str: string, radix?: i32): f64;
/** Parses a string to a 64-bit float. */

13
std/assembly/regexp.ts Normal file
View File

@ -0,0 +1,13 @@
@global
class RegExp {
// @binding(CALL_NEW, [ STRING, STRING], OBJECT_HANDLE)
constructor(pattern: string, flags: string = "") { throw new Error("unreachable"); }
// @binding(CALL_THIS, [ STRING ], PASS_THRU)
test(search: string): bool { throw new Error("unreachable"); }
// @binding(CALL_THIS, [], STRING)
toString(): string { throw new Error("unreachable"); }
}

View File

@ -196,3 +196,15 @@ function isWhiteSpaceOrLineTerminator(c: u16): bool {
return false;
}
}
// @global
// @binding(CALL, [ STRING, PASS_THRU ], PASS_THRU)
export function parseInt(str: string, radix: i32 = 10): f64 {
throw new Error("not implemented");
}
// @global
// @binding(CALL, [ STRING ], PASS_THRU)
export function parseFloat(str: string): f64 {
throw new Error("not implemented");
}

6
std/portable.d.ts vendored
View File

@ -123,10 +123,10 @@ declare function store<T = u8>(offset: usize, value: T): void;
/** Emits an unreachable operation that results in a runtime error when executed. */
declare function unreachable(): any; // sic
/** Changes the type of a value to another one. Useful for casting class instances to their pointer values and vice-versa. */
/** Changes the type of any value of `usize` kind to another one of `usize` kind. Useful for casting class instances to their pointer values and vice-versa. Beware that this is unsafe.*/
declare function changetype<T>(value: any): T;
/** Traps if the specified value evaluates to `false`. */
declare function assert(isTrue: bool, message?: string): void;
/** Traps if the specified value is not true-ish, otherwise returns the value. */
declare function assert<T>(isTrueish: T, message?: string): T & object; // any better way to model `: T != null`?
/** Parses an integer string to a 64-bit float. */
declare function parseInt(str: string, radix?: i32): f64;
/** Parses a floating point string to a 64-bit float. */

View File

@ -93,7 +93,7 @@ function AssertionError(message) {
AssertionError.prototype = Object.create(Error.prototype);
AssertionError.prototype.name = "AssertionError";
globalScope["assert"] = function assert(isTrue, message) { if (!isTrue) throw new AssertionError(message); };
globalScope["assert"] = function assert(isTrueish, message) { if (isTrueish) return isTrueish; throw new AssertionError(message); };
globalScope["changetype"] = function changetype(value) { return value; }
String["fromCharCodes"] = function fromCharCodes(arr) { return String.fromCharCode.apply(String, arr); }

View File

@ -17,13 +17,17 @@ var filter = process.argv.length > 2 && !isCreate ? "**/" + process.argv[2] + ".
var stdFiles = glob.sync("*.ts", { cwd: __dirname + "/../std/assembly" });
var success = 0;
var failures = 0;
glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
if (filename.charAt(0) == "_")
return;
console.log(chalk.default.whiteBright("Testing compiler/" + filename));
console.log(chalk.whiteBright("Testing compiler/" + filename));
var fixture = path.basename(filename, ".ts");
var startTime = process.hrtime();
var parser = new Parser();
if (filename.startsWith("std/")) {
stdFiles.forEach(file => {
@ -45,18 +49,24 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
parser.parseFile(nextSourceText, nextFile, false);
}
var program = parser.finish();
var parseTime = process.hrtime(startTime);
startTime = process.hrtime();
var module = Compiler.compile(program);
var compileTime = process.hrtime(startTime);
var actual = module.toText() + "(;\n[program.elements]\n " + elements(program.elements)
+ "\n[program.exports]\n " + elements(program.exports)
+ "\n;)\n";
var actualOptimized = null;
var actualInlined = null;
console.log("parse incl. I/O: " + ((parseTime[0] * 1e9 + parseTime[1]) / 1e6).toFixed(3) + "ms / compile: " + ((compileTime[0] * 1e9 + compileTime[1]) / 1e6).toFixed(3) + "ms");
var failed = false;
if (module.validate()) {
console.log(chalk.default.green("validate OK"));
console.log(chalk.green("validate OK"));
try {
module.interpret();
console.log(chalk.default.green("interpret OK"));
console.log(chalk.green("interpret OK"));
try {
var binary = module.toBinary();
var wasmModule = new WebAssembly.Module(binary);
@ -70,22 +80,22 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
externalConst: 2
}
});
console.log(chalk.default.green("instantiate OK"));
console.log(chalk.green("instantiate OK"));
} catch (e) {
process.exitCode = 1;
console.log(chalk.default.red("instantiate ERROR: ") + e);
failed = true;
console.log(chalk.red("instantiate ERROR: ") + e);
}
} catch (e) {
process.exitCode = 1;
console.log(chalk.default.red("interpret ERROR:") + e);
failed = true;
console.log(chalk.red("interpret ERROR:") + e);
}
module.optimize();
actualOptimized = module.toText();
module.runPasses([ "inlining" ]);
actualInlined = module.toText();
} else {
process.exitCode = 1;
console.log(chalk.default.red("validate ERROR"));
failed = true;
console.log(chalk.red("validate ERROR"));
}
if (isCreate) {
@ -107,25 +117,25 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
}
}
} else {
var expected;
try {
var expected = fs.readFileSync(__dirname + "/compiler/" + fixture + ".wast", { encoding: "utf8" });
var diffs = diff(filename + ".wast", expected, actual);
if (diffs !== null) {
process.exitCode = 1;
console.log(diffs);
console.log(chalk.default.red("diff ERROR"));
} else {
console.log(chalk.default.green("diff OK"));
}
expected = fs.readFileSync(__dirname + "/compiler/" + fixture + ".wast", { encoding: "utf8" });
} catch (e) {
process.exitCode = 1;
console.log(e.message);
console.log(chalk.default.red("diff ERROR"));
expected = e.message + "\n";
}
var diffs = diff(filename + ".wast", expected, actual);
if (diffs !== null) {
console.log(diffs);
console.log(chalk.red("diff ERROR"));
failed = true;
} else
console.log(chalk.green("diff OK"));
}
module.dispose();
console.log();
if (failed)
++failures;
});
function elements(map) {
@ -135,3 +145,9 @@ function elements(map) {
});
return arr.join("\n ");
}
if (failures) {
process.exitCode = 1;
console.log(chalk.red("ERROR: ") + failures + " compiler tests failed");
} else
console.log(chalk.whiteBright("SUCCESS"));

View File

@ -4,6 +4,18 @@
(export "memory" (memory $0))
(start $start)
(func $start (; 0 ;) (type $v)
(nop)
(local $0 i32)
(if
(i32.eqz
(if (result i32)
(tee_local $0
(i32.const 1)
)
(get_local $0)
(unreachable)
)
)
(unreachable)
)
)
)

View File

@ -1,3 +1,11 @@
assert(true);
assert(1 == 1);
assert(1);
assert(1 > 0);
assert(0.5);
assert(0.5 > 0.4);
assert(0x100000000);
assert(0x100000000 > 1);
// can be used as an expression
if (!assert(true, "must be true"))
unreachable();

View File

@ -5,6 +5,7 @@
(export "memory" (memory $0))
(start $start)
(func $start (; 0 ;) (type $v)
(local $0 i32)
(if
(i32.eqz
(i32.const 1)
@ -13,13 +14,26 @@
)
(if
(i32.eqz
(i32.eq
(i32.const 1)
(i32.const 1)
)
(unreachable)
)
(if
(i32.eqz
(i32.gt_s
(i32.const 1)
(i32.const 0)
)
)
(unreachable)
)
(if
(f64.eq
(f64.const 0.5)
(f64.const 0)
)
(unreachable)
)
(if
(i32.eqz
(f64.gt
@ -29,6 +43,35 @@
)
(unreachable)
)
(if
(i64.eqz
(i64.const 4294967296)
)
(unreachable)
)
(if
(i32.eqz
(i64.gt_s
(i64.const 4294967296)
(i64.const 1)
)
)
(unreachable)
)
(if
(i32.eqz
(if (result i32)
(i32.eqz
(tee_local $0
(i32.const 1)
)
)
(unreachable)
(get_local $0)
)
)
(unreachable)
)
)
)
(;
@ -59,8 +102,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -844,8 +844,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -65,14 +65,14 @@
)
(set_global $builtins/i
(select
(tee_local $2
(i32.const -42)
)
(i32.sub
(i32.const 0)
(tee_local $2
(i32.const -42)
)
(get_local $2)
)
(get_local $2)
(i32.lt_s
(i32.gt_s
(get_local $2)
(i32.const 0)
)
@ -144,14 +144,14 @@
)
(set_global $builtins/I
(select
(tee_local $4
(i64.const -42)
)
(i64.sub
(i64.const 0)
(tee_local $4
(i64.const -42)
)
(get_local $4)
)
(get_local $4)
(i64.lt_s
(i64.gt_s
(get_local $4)
(i64.const 0)
)

View File

@ -77,17 +77,17 @@
)
(drop
(select
(i32.sub
(i32.const 0)
(tee_local $0
(i32.sub
(i32.const 0)
(i32.const 42)
)
(tee_local $0
(i32.sub
(i32.const 0)
(i32.const 42)
)
)
(get_local $0)
(i32.lt_s
(i32.sub
(i32.const 0)
(get_local $0)
)
(i32.gt_s
(get_local $0)
(i32.const 0)
)
@ -150,17 +150,17 @@
)
(set_global $builtins/i
(select
(i32.sub
(i32.const 0)
(tee_local $0
(i32.sub
(i32.const 0)
(i32.const 42)
)
(tee_local $0
(i32.sub
(i32.const 0)
(i32.const 42)
)
)
(get_local $0)
(i32.lt_s
(i32.sub
(i32.const 0)
(get_local $0)
)
(i32.gt_s
(get_local $0)
(i32.const 0)
)
@ -250,17 +250,17 @@
)
(drop
(select
(i64.sub
(i64.const 0)
(tee_local $2
(i64.sub
(i64.const 0)
(i64.const 42)
)
(tee_local $2
(i64.sub
(i64.const 0)
(i64.const 42)
)
)
(get_local $2)
(i64.lt_s
(i64.sub
(i64.const 0)
(get_local $2)
)
(i64.gt_s
(get_local $2)
(i64.const 0)
)
@ -295,17 +295,17 @@
)
(set_global $builtins/I
(select
(i64.sub
(i64.const 0)
(tee_local $2
(i64.sub
(i64.const 0)
(i64.const 42)
)
(tee_local $2
(i64.sub
(i64.const 0)
(i64.const 42)
)
)
(get_local $2)
(i64.lt_s
(i64.sub
(i64.const 0)
(get_local $2)
)
(i64.gt_s
(get_local $2)
(i64.const 0)
)
@ -1370,8 +1370,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -53,8 +53,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -25,8 +25,8 @@ export function test(animal: Animal<f64>): Animal<f64> {
animal.three;
animal.one = 0 + 1;
animal.two = 1 + 1;
animal.three = 1 + 1 + 1;
animal.two = 1 + 1; // checks overflow
animal.three = 1 + 1 + 1; // checks overflow (once)
var ptr = changetype<usize>(animal);
var cls = changetype<Animal<f64>>(ptr);

View File

@ -100,19 +100,31 @@
)
(i32.store16 offset=4
(get_local $0)
(i32.add
(i32.const 1)
(i32.const 1)
(i32.shr_s
(i32.shl
(i32.add
(i32.const 1)
(i32.const 1)
)
(i32.const 16)
)
(i32.const 16)
)
)
(i32.store8 offset=6
(get_local $0)
(i32.add
(i32.add
(i32.const 1)
(i32.const 1)
(i32.shr_s
(i32.shl
(i32.add
(i32.add
(i32.const 1)
(i32.const 1)
)
(i32.const 1)
)
(i32.const 24)
)
(i32.const 1)
(i32.const 24)
)
)
(block
@ -184,8 +196,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -47,18 +47,10 @@
(unreachable)
)
(block
(drop
(block (result i32)
(set_local $0
(get_global $comma/a)
)
(set_global $comma/a
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $comma/a
(i32.add
(get_global $comma/a)
(i32.const 1)
)
)
(set_global $comma/b
@ -93,18 +85,10 @@
)
(set_global $comma/b
(block (result i32)
(drop
(block (result i32)
(set_local $0
(get_global $comma/a)
)
(set_global $comma/a
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $comma/a
(i32.add
(get_global $comma/a)
(i32.const 1)
)
)
(get_global $comma/a)
@ -130,18 +114,10 @@
)
(set_global $comma/a
(block (result i32)
(drop
(block (result i32)
(set_local $0
(get_global $comma/a)
)
(set_global $comma/a
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $comma/a
(i32.add
(get_global $comma/a)
(i32.const 1)
)
)
(block (result i32)
@ -185,32 +161,16 @@
(block
(nop)
(block
(drop
(block (result i32)
(set_local $0
(get_global $comma/a)
)
(set_global $comma/a
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $comma/a
(i32.sub
(get_global $comma/a)
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $0
(get_local $1)
)
(set_local $1
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_local $1
(i32.add
(get_local $1)
(i32.const 1)
)
)
)
@ -269,8 +229,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -47,8 +47,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -12,32 +12,16 @@
(block $break|0
(loop $continue|0
(block
(drop
(block (result i32)
(set_local $0
(get_global $do/n)
)
(set_global $do/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $do/n
(i32.sub
(get_global $do/n)
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $do/m)
)
(set_global $do/m
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $do/m
(i32.add
(get_global $do/m)
(i32.const 1)
)
)
)
@ -107,63 +91,31 @@
(block $break|2
(loop $continue|2
(block
(drop
(block (result i32)
(set_local $0
(get_global $do/n)
)
(set_global $do/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $do/n
(i32.sub
(get_global $do/n)
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $do/m)
)
(set_global $do/m
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $do/m
(i32.add
(get_global $do/m)
(i32.const 1)
)
)
(block $break|3
(loop $continue|3
(block
(drop
(block (result i32)
(set_local $0
(get_global $do/n)
)
(set_global $do/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $do/n
(i32.sub
(get_global $do/n)
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $do/o)
)
(set_global $do/o
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $do/o
(i32.add
(get_global $do/o)
(i32.const 1)
)
)
)
@ -253,8 +205,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -31,8 +31,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -76,8 +76,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -64,8 +64,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -174,14 +174,14 @@
)
(i64.shl
(get_local $2)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $3)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -231,14 +231,14 @@
)
(i64.shl
(get_local $5)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $6)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -372,14 +372,14 @@
)
(i64.shr_u
(get_local $2)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $3)
)
(i32.const 1)
)
(i64.const 1)
)
)
)

View File

@ -188,14 +188,14 @@
(set_local $2
(i64.shl
(get_local $2)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $4)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -265,14 +265,14 @@
(set_local $3
(i64.shl
(get_local $3)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $5)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -348,18 +348,10 @@
)
)
)
(drop
(block (result i32)
(set_local $8
(get_local $4)
)
(set_local $4
(i32.sub
(get_local $8)
(i32.const 1)
)
)
(get_local $8)
(set_local $4
(i32.sub
(get_local $4)
(i32.const 1)
)
)
(br $continue|2)
@ -455,14 +447,14 @@
(set_local $2
(i64.shr_u
(get_local $2)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $4)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -1076,8 +1068,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -175,8 +175,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -193,8 +193,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -87,28 +87,39 @@
)
(block
(set_local $2
(i32.add
(i32.and
(i32.add
(i32.add
(i32.add
(i32.add
(i32.add
(i32.add
(i32.load8_u
(i32.add
(i32.mul
(get_local $3)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(tee_local $2
(select
(i32.sub
(get_local $1)
(i32.const 1)
)
(get_local $6)
(get_local $1)
(i32.add
(i32.load8_u
(i32.add
(i32.mul
(get_local $3)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(tee_local $2
(select
(i32.sub
(get_local $1)
(i32.const 1)
)
(get_local $6)
(get_local $1)
)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $3)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $1)
)
)
)
@ -118,29 +129,29 @@
(get_local $3)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $1)
(tee_local $7
(select
(i32.const 0)
(i32.add
(get_local $1)
(i32.const 1)
)
(i32.eq
(get_local $1)
(get_local $6)
)
)
)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $3)
(get_local $0)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(tee_local $7
(select
(i32.const 0)
(i32.add
(get_local $1)
(i32.const 1)
)
(i32.eq
(get_local $1)
(get_local $6)
)
)
)
(get_local $2)
)
)
)
@ -150,17 +161,17 @@
(get_local $0)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $2)
(get_local $7)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $0)
(get_local $4)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $7)
(get_local $2)
)
)
)
@ -170,7 +181,7 @@
(get_local $4)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $2)
(get_local $1)
)
)
)
@ -180,19 +191,11 @@
(get_local $4)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $1)
(get_local $7)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $4)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $7)
)
)
(i32.const 255)
)
)
(if

View File

@ -133,20 +133,31 @@
)
(block
(set_local $8
(i32.add
(i32.and
(i32.add
(i32.add
(i32.add
(i32.add
(i32.add
(i32.add
(i32.load8_u
(i32.add
(i32.mul
(get_local $3)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
(i32.add
(i32.load8_u
(i32.add
(i32.mul
(get_local $3)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $6)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $3)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $5)
)
(get_local $6)
)
)
(i32.load8_u
@ -155,17 +166,17 @@
(get_local $3)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $5)
(get_local $7)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $3)
(get_local $2)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $7)
(get_local $6)
)
)
)
@ -175,17 +186,17 @@
(get_local $2)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $6)
(get_local $7)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $2)
(get_local $4)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $7)
(get_local $6)
)
)
)
@ -195,7 +206,7 @@
(get_local $4)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $6)
(get_local $5)
)
)
)
@ -205,19 +216,11 @@
(get_local $4)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $5)
(get_local $7)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $4)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $7)
)
)
(i32.const 255)
)
)
)
@ -334,8 +337,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -83,8 +83,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -1217,8 +1217,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -74,8 +74,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -72,8 +72,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -1,10 +1,10 @@
const i = 10;
const i = 10; // infers i32 because
i;
const I = 0x100000000;
const I = 0x100000000; // infers i64 because the value doesn't fit into 32 bits
I;
const F = 1.5;
const F = 1.5; // infers f64 because of float notation
F;
function locals(): void {

View File

@ -168,8 +168,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -56,8 +56,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -135,8 +135,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -167,8 +167,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -253,8 +253,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -64,18 +64,10 @@
)
)
)
(drop
(block (result i32)
(set_local $7
(get_local $2)
)
(set_local $2
(i32.sub
(get_local $7)
(i32.const 1)
)
)
(get_local $7)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 1)
)
)
)
@ -2079,8 +2071,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -62,8 +62,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -357,8 +357,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -60,8 +60,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -77,8 +77,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -0,0 +1,731 @@
(module
(type $iiv (func (param i32 i32)))
(type $v (func))
(global $retain-i32/si (mut i32) (i32.const 0))
(global $retain-i32/ui (mut i32) (i32.const 0))
(memory $0 1)
(export "memory" (memory $0))
(start $start)
(func $retain-i32/test (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32)
(if
(i32.ne
(i32.and
(i32.add
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.add
(i32.shr_s
(i32.shl
(get_local $0)
(i32.const 24)
)
(i32.const 24)
)
(i32.shr_s
(i32.shl
(get_local $1)
(i32.const 24)
)
(i32.const 24)
)
)
(i32.const 255)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.sub
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.sub
(i32.shr_s
(i32.shl
(get_local $0)
(i32.const 24)
)
(i32.const 24)
)
(i32.shr_s
(i32.shl
(get_local $1)
(i32.const 24)
)
(i32.const 24)
)
)
(i32.const 255)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.mul
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.mul
(i32.shr_s
(i32.shl
(get_local $0)
(i32.const 24)
)
(i32.const 24)
)
(i32.shr_s
(i32.shl
(get_local $1)
(i32.const 24)
)
(i32.const 24)
)
)
(i32.const 255)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.and
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.and
(i32.shr_s
(i32.shl
(get_local $0)
(i32.const 24)
)
(i32.const 24)
)
(i32.shr_s
(i32.shl
(get_local $1)
(i32.const 24)
)
(i32.const 24)
)
)
(i32.const 255)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.or
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.or
(i32.shr_s
(i32.shl
(get_local $0)
(i32.const 24)
)
(i32.const 24)
)
(i32.shr_s
(i32.shl
(get_local $1)
(i32.const 24)
)
(i32.const 24)
)
)
(i32.const 255)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.xor
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.xor
(i32.shr_s
(i32.shl
(get_local $0)
(i32.const 24)
)
(i32.const 24)
)
(i32.shr_s
(i32.shl
(get_local $1)
(i32.const 24)
)
(i32.const 24)
)
)
(i32.const 255)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.shl
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.shl
(i32.shr_s
(i32.shl
(get_local $0)
(i32.const 24)
)
(i32.const 24)
)
(i32.shr_s
(i32.shl
(get_local $1)
(i32.const 24)
)
(i32.const 24)
)
)
(i32.const 255)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.add
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.add
(i32.and
(get_local $0)
(i32.const 255)
)
(i32.and
(get_local $1)
(i32.const 255)
)
)
(i32.const 255)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.sub
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.sub
(i32.and
(get_local $0)
(i32.const 255)
)
(i32.and
(get_local $1)
(i32.const 255)
)
)
(i32.const 255)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.mul
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.mul
(i32.and
(get_local $0)
(i32.const 255)
)
(i32.and
(get_local $1)
(i32.const 255)
)
)
(i32.const 255)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.and
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.and
(get_local $0)
(i32.const 255)
)
(i32.and
(get_local $1)
(i32.const 255)
)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.or
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.or
(i32.and
(get_local $0)
(i32.const 255)
)
(i32.and
(get_local $1)
(i32.const 255)
)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.xor
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.xor
(i32.and
(get_local $0)
(i32.const 255)
)
(i32.and
(get_local $1)
(i32.const 255)
)
)
)
(unreachable)
)
(if
(i32.ne
(i32.and
(i32.shl
(get_local $0)
(get_local $1)
)
(i32.const 255)
)
(i32.and
(i32.shl
(i32.and
(get_local $0)
(i32.const 255)
)
(i32.and
(get_local $1)
(i32.const 255)
)
)
(i32.const 255)
)
)
(unreachable)
)
)
(func $start (; 1 ;) (type $v)
(local $0 i32)
(call $retain-i32/test
(i32.const 0)
(i32.const 127)
)
(call $retain-i32/test
(i32.const 127)
(i32.const 0)
)
(call $retain-i32/test
(i32.const 1)
(i32.const 127)
)
(call $retain-i32/test
(i32.const 127)
(i32.const 1)
)
(call $retain-i32/test
(i32.const -1)
(i32.const 127)
)
(call $retain-i32/test
(i32.const 127)
(i32.const -1)
)
(call $retain-i32/test
(i32.const 0)
(i32.const -128)
)
(call $retain-i32/test
(i32.const -128)
(i32.const 0)
)
(call $retain-i32/test
(i32.const 1)
(i32.const -128)
)
(call $retain-i32/test
(i32.const -128)
(i32.const 1)
)
(call $retain-i32/test
(i32.const -1)
(i32.const -128)
)
(call $retain-i32/test
(i32.const -128)
(i32.const -1)
)
(call $retain-i32/test
(i32.const 127)
(i32.const 127)
)
(call $retain-i32/test
(i32.const -128)
(i32.const -128)
)
(call $retain-i32/test
(i32.const 127)
(i32.const -128)
)
(call $retain-i32/test
(i32.const -128)
(i32.const 127)
)
(call $retain-i32/test
(i32.const 0)
(i32.const 255)
)
(call $retain-i32/test
(i32.const 255)
(i32.const 0)
)
(call $retain-i32/test
(i32.const 1)
(i32.const 255)
)
(call $retain-i32/test
(i32.const 255)
(i32.const 1)
)
(call $retain-i32/test
(i32.const -1)
(i32.const 255)
)
(call $retain-i32/test
(i32.const 255)
(i32.const -1)
)
(call $retain-i32/test
(i32.const 255)
(i32.const 255)
)
(set_local $0
(i32.const -128)
)
(loop $continue|0
(if
(i32.le_s
(get_local $0)
(i32.const 255)
)
(block
(call $retain-i32/test
(i32.const 0)
(get_local $0)
)
(call $retain-i32/test
(i32.const 1)
(get_local $0)
)
(call $retain-i32/test
(i32.const -1)
(get_local $0)
)
(call $retain-i32/test
(i32.const -128)
(get_local $0)
)
(call $retain-i32/test
(i32.const 127)
(get_local $0)
)
(call $retain-i32/test
(i32.const 255)
(get_local $0)
)
(call $retain-i32/test
(i32.const -32768)
(get_local $0)
)
(call $retain-i32/test
(i32.const 32767)
(get_local $0)
)
(call $retain-i32/test
(i32.const 65535)
(get_local $0)
)
(call $retain-i32/test
(i32.const 2147483647)
(get_local $0)
)
(call $retain-i32/test
(i32.const -2147483648)
(get_local $0)
)
(call $retain-i32/test
(i32.const -1)
(get_local $0)
)
(set_local $0
(i32.add
(get_local $0)
(i32.const 1)
)
)
(br $continue|0)
)
)
)
(set_global $retain-i32/si
(i32.const -1)
)
(if
(i32.ne
(get_global $retain-i32/si)
(i32.const -1)
)
(unreachable)
)
(set_global $retain-i32/si
(i32.const -1)
)
(if
(i32.ne
(get_global $retain-i32/si)
(i32.const -1)
)
(unreachable)
)
(set_global $retain-i32/si
(i32.const -2)
)
(if
(i32.ne
(get_global $retain-i32/si)
(i32.const -2)
)
(unreachable)
)
(set_global $retain-i32/si
(i32.const -128)
)
(if
(i32.ne
(get_global $retain-i32/si)
(i32.const -128)
)
(unreachable)
)
(set_global $retain-i32/si
(i32.const -128)
)
(if
(i32.ne
(get_global $retain-i32/si)
(i32.const -128)
)
(unreachable)
)
(set_global $retain-i32/si
(i32.const -127)
)
(if
(i32.ne
(get_global $retain-i32/si)
(i32.const -127)
)
(unreachable)
)
(set_global $retain-i32/si
(i32.const -128)
)
(if
(i32.ne
(get_global $retain-i32/si)
(i32.const -128)
)
(unreachable)
)
(set_global $retain-i32/si
(i32.const 1)
)
(if
(i32.ne
(get_global $retain-i32/si)
(i32.const 1)
)
(unreachable)
)
(set_global $retain-i32/si
(i32.const 1)
)
(if
(i32.ne
(get_global $retain-i32/si)
(i32.const 1)
)
(unreachable)
)
(set_global $retain-i32/si
(i32.const 0)
)
(if
(get_global $retain-i32/si)
(unreachable)
)
(set_global $retain-i32/si
(i32.const 1)
)
(if
(i32.ne
(get_global $retain-i32/si)
(i32.const 1)
)
(unreachable)
)
(set_global $retain-i32/ui
(i32.const 255)
)
(if
(i32.ne
(get_global $retain-i32/ui)
(i32.const 255)
)
(unreachable)
)
(set_global $retain-i32/ui
(i32.const 255)
)
(if
(i32.ne
(get_global $retain-i32/ui)
(i32.const 255)
)
(unreachable)
)
(set_global $retain-i32/ui
(i32.const 254)
)
(if
(i32.ne
(get_global $retain-i32/ui)
(i32.const 254)
)
(unreachable)
)
(set_global $retain-i32/ui
(i32.const 1)
)
(if
(i32.ne
(get_global $retain-i32/ui)
(i32.const 1)
)
(unreachable)
)
(set_global $retain-i32/ui
(i32.const 1)
)
(if
(i32.ne
(get_global $retain-i32/ui)
(i32.const 1)
)
(unreachable)
)
(set_global $retain-i32/ui
(i32.const 1)
)
(if
(i32.ne
(get_global $retain-i32/ui)
(i32.const 1)
)
(unreachable)
)
(set_global $retain-i32/ui
(i32.const 0)
)
(if
(get_global $retain-i32/ui)
(unreachable)
)
)
)

View File

@ -0,0 +1,131 @@
function test(a: i32, b: i32): void {
// signed
assert(<i8>(a + b) == <i8>(<i8>a + <i8>b));
assert(<i8>(a - b) == <i8>(<i8>a - <i8>b));
assert(<i8>(a * b) == <i8>(<i8>a * <i8>b));
assert(<i8>(a & b) == <i8>(<i8>a & <i8>b));
assert(<i8>(a | b) == <i8>(<i8>a | <i8>b));
assert(<i8>(a ^ b) == <i8>(<i8>a ^ <i8>b));
assert(<i8>(a << b) == <i8>(<i8>a << <i8>b));
// unsigned
assert(<u8>(a + b) == <u8>(<u8>a + <u8>b));
assert(<u8>(a - b) == <u8>(<u8>a - <u8>b));
assert(<u8>(a * b) == <u8>(<u8>a * <u8>b));
assert(<u8>(a & b) == <u8>(<u8>a & <u8>b));
assert(<u8>(a | b) == <u8>(<u8>a | <u8>b));
assert(<u8>(a ^ b) == <u8>(<u8>a ^ <u8>b));
assert(<u8>(a << b) == <u8>(<u8>a << <u8>b));
}
// signed
test(0, i8.MAX_VALUE);
test(i8.MAX_VALUE, 0);
test(1, i8.MAX_VALUE);
test(i8.MAX_VALUE, 1);
test(-1, i8.MAX_VALUE);
test(i8.MAX_VALUE, -1);
test(0, i8.MIN_VALUE);
test(i8.MIN_VALUE, 0);
test(1, i8.MIN_VALUE);
test(i8.MIN_VALUE, 1);
test(-1, i8.MIN_VALUE);
test(i8.MIN_VALUE, -1);
test(i8.MAX_VALUE, i8.MAX_VALUE);
test(i8.MIN_VALUE, i8.MIN_VALUE);
test(i8.MAX_VALUE, i8.MIN_VALUE);
test(i8.MIN_VALUE, i8.MAX_VALUE);
// unsigned
test(0, u8.MAX_VALUE);
test(u8.MAX_VALUE, 0);
test(1, u8.MAX_VALUE);
test(u8.MAX_VALUE, 1);
test(-1, u8.MAX_VALUE);
test(u8.MAX_VALUE, -1);
test(u8.MAX_VALUE, u8.MAX_VALUE);
// various
for (var i: i32 = i8.MIN_VALUE; i <= u8.MAX_VALUE; ++i) {
test(0, i);
test(1, i);
test(-1, i);
test(i8.MIN_VALUE, i);
test(i8.MAX_VALUE, i);
test(u8.MAX_VALUE, i);
test(i16.MIN_VALUE, i);
test(i16.MAX_VALUE, i);
test(u16.MAX_VALUE, i);
test(i32.MAX_VALUE, i);
test(i32.MIN_VALUE, i);
test(u32.MAX_VALUE, i);
}
// visually
var si: i8;
si = 127 + 127 + 1; // sign-extends exactly once
assert(si == -1);
si = 127 - 1 - 127; // sign-extends exactly once
assert(si == -1);
si = 127 * 2; // sign-extends exactly once
assert(si == -2);
si = -(-128); // -MIN_VALUE == MIN_VALUE
assert(si == -128);
si = -128 * -1; // -MIN_VALUE == MIN_VALUE
assert(si == -128);
si = 127 / -1;
assert(si == -127);
si = -128 / -1; // -MIN_VALUE == MIN_VALUE
assert(si == -128);
si = 127 % 2;
assert(si == 1);
si = 1 % 127;
assert(si == 1);
si = -128 % 2;
assert(si == 0);
si = 1 % -128;
assert(si == 1);
var ui: u8;
ui = 255 + 255 + 1;
assert(ui == 255);
ui = 255 - 1 - 255;
assert(ui == 255);
ui = 255 * 2;
assert(ui == 254);
ui = 255 * 255;
assert(ui == 1);
ui = 255 / 255;
assert(ui == 1);
ui = 255 % 2;
assert(ui == 1);
ui = 255 % 255;
assert(ui == 0);

File diff suppressed because it is too large Load Diff

View File

@ -1806,14 +1806,14 @@
)
(i64.shl
(get_local $2)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $3)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -1863,14 +1863,14 @@
)
(i64.shl
(get_local $5)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $6)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -2004,14 +2004,14 @@
)
(i64.shr_u
(get_local $2)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $3)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -3443,14 +3443,14 @@
)
(set_global $builtins/i
(select
(tee_local $2
(i32.const -42)
)
(i32.sub
(i32.const 0)
(tee_local $2
(i32.const -42)
)
(get_local $2)
)
(get_local $2)
(i32.lt_s
(i32.gt_s
(get_local $2)
(i32.const 0)
)
@ -3522,14 +3522,14 @@
)
(set_global $builtins/I
(select
(tee_local $3
(i64.const -42)
)
(i64.sub
(i64.const 0)
(tee_local $3
(i64.const -42)
)
(get_local $3)
)
(get_local $3)
(i64.lt_s
(i64.gt_s
(get_local $3)
(i64.const 0)
)

View File

@ -1827,14 +1827,14 @@
)
(i64.shl
(get_local $2)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $3)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -1884,14 +1884,14 @@
)
(i64.shl
(get_local $5)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $6)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -2025,14 +2025,14 @@
)
(i64.shr_u
(get_local $2)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $3)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -3465,14 +3465,14 @@
)
(set_global $builtins/i
(select
(tee_local $2
(i32.const -42)
)
(i32.sub
(i32.const 0)
(tee_local $2
(i32.const -42)
)
(get_local $2)
)
(get_local $2)
(i32.lt_s
(i32.gt_s
(get_local $2)
(i32.const 0)
)
@ -3544,14 +3544,14 @@
)
(set_global $builtins/I
(select
(tee_local $3
(i64.const -42)
)
(i64.sub
(i64.const 0)
(tee_local $3
(i64.const -42)
)
(get_local $3)
)
(get_local $3)
(i64.lt_s
(i64.gt_s
(get_local $3)
(i64.const 0)
)

View File

@ -172,18 +172,10 @@
)
)
)
(drop
(block (result i32)
(set_local $7
(get_local $2)
)
(set_local $2
(i32.sub
(get_local $7)
(i32.const 1)
)
)
(get_local $7)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 1)
)
)
)
@ -2114,14 +2106,14 @@
(set_local $2
(i64.shl
(get_local $2)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $4)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -2191,14 +2183,14 @@
(set_local $3
(i64.shl
(get_local $3)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $5)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -2274,18 +2266,10 @@
)
)
)
(drop
(block (result i32)
(set_local $8
(get_local $4)
)
(set_local $4
(i32.sub
(get_local $8)
(i32.const 1)
)
)
(get_local $8)
(set_local $4
(i32.sub
(get_local $4)
(i32.const 1)
)
)
(br $continue|2)
@ -2381,14 +2365,14 @@
(set_local $2
(i64.shr_u
(get_local $2)
(i64.add
(i64.sub
(i64.const 0)
(i64.extend_u/i32
(i64.extend_u/i32
(i32.add
(i32.sub
(i32.const 0)
(get_local $4)
)
(i32.const 1)
)
(i64.const 1)
)
)
)
@ -2943,32 +2927,16 @@
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $unary/i)
)
(set_global $unary/i
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $unary/i
(i32.add
(get_global $unary/i)
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $unary/i)
)
(set_global $unary/i
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $unary/i
(i32.sub
(get_global $unary/i)
(i32.const 1)
)
)
(set_global $unary/i
@ -3093,32 +3061,16 @@
(i64.const 1)
)
)
(drop
(block (result i64)
(set_local $1
(get_global $unary/I)
)
(set_global $unary/I
(i64.add
(get_local $1)
(i64.const 1)
)
)
(get_local $1)
(set_global $unary/I
(i64.add
(get_global $unary/I)
(i64.const 1)
)
)
(drop
(block (result i64)
(set_local $1
(get_global $unary/I)
)
(set_global $unary/I
(i64.sub
(get_local $1)
(i64.const 1)
)
)
(get_local $1)
(set_global $unary/I
(i64.sub
(get_global $unary/I)
(i64.const 1)
)
)
(set_global $unary/I
@ -3132,8 +3084,8 @@
)
(set_global $unary/I
(i64.extend_s/i32
(i32.eqz
(i32.const 1)
(i64.eqz
(i64.const 1)
)
)
)
@ -3241,32 +3193,16 @@
(f32.const 1)
)
)
(drop
(block (result f32)
(set_local $2
(get_global $unary/f)
)
(set_global $unary/f
(f32.add
(get_local $2)
(f32.const 1)
)
)
(get_local $2)
(set_global $unary/f
(f32.add
(get_global $unary/f)
(f32.const 1)
)
)
(drop
(block (result f32)
(set_local $2
(get_global $unary/f)
)
(set_global $unary/f
(f32.sub
(get_local $2)
(f32.const 1)
)
)
(get_local $2)
(set_global $unary/f
(f32.sub
(get_global $unary/f)
(f32.const 1)
)
)
(set_global $unary/f
@ -3373,32 +3309,16 @@
(f64.const 1)
)
)
(drop
(block (result f64)
(set_local $3
(get_global $unary/F)
)
(set_global $unary/F
(f64.add
(get_local $3)
(f64.const 1)
)
)
(get_local $3)
(set_global $unary/F
(f64.add
(get_global $unary/F)
(f64.const 1)
)
)
(drop
(block (result f64)
(set_local $3
(get_global $unary/F)
)
(set_global $unary/F
(f64.sub
(get_local $3)
(f64.const 1)
)
)
(get_local $3)
(set_global $unary/F
(f64.sub
(get_global $unary/F)
(f64.const 1)
)
)
(set_global $unary/F
@ -4528,17 +4448,17 @@
)
(drop
(select
(i32.sub
(i32.const 0)
(tee_local $0
(i32.sub
(i32.const 0)
(i32.const 42)
)
(tee_local $0
(i32.sub
(i32.const 0)
(i32.const 42)
)
)
(get_local $0)
(i32.lt_s
(i32.sub
(i32.const 0)
(get_local $0)
)
(i32.gt_s
(get_local $0)
(i32.const 0)
)
@ -4601,17 +4521,17 @@
)
(set_global $builtins/i
(select
(i32.sub
(i32.const 0)
(tee_local $0
(i32.sub
(i32.const 0)
(i32.const 42)
)
(tee_local $0
(i32.sub
(i32.const 0)
(i32.const 42)
)
)
(get_local $0)
(i32.lt_s
(i32.sub
(i32.const 0)
(get_local $0)
)
(i32.gt_s
(get_local $0)
(i32.const 0)
)
@ -4701,17 +4621,17 @@
)
(drop
(select
(i64.sub
(i64.const 0)
(tee_local $1
(i64.sub
(i64.const 0)
(i64.const 42)
)
(tee_local $1
(i64.sub
(i64.const 0)
(i64.const 42)
)
)
(get_local $1)
(i64.lt_s
(i64.sub
(i64.const 0)
(get_local $1)
)
(i64.gt_s
(get_local $1)
(i64.const 0)
)
@ -4746,17 +4666,17 @@
)
(set_global $builtins/I
(select
(i64.sub
(i64.const 0)
(tee_local $1
(i64.sub
(i64.const 0)
(i64.const 42)
)
(tee_local $1
(i64.sub
(i64.const 0)
(i64.const 42)
)
)
(get_local $1)
(i64.lt_s
(i64.sub
(i64.const 0)
(get_local $1)
)
(i64.gt_s
(get_local $1)
(i64.const 0)
)
@ -6319,8 +6239,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -31,8 +31,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8
@ -73,12 +71,16 @@
FUNCTION_PROTOTYPE: std:heap/Heap.compare
CLASS_PROTOTYPE: std:map/Map
CLASS_PROTOTYPE: Map
CLASS_PROTOTYPE: std:regexp/RegExp
CLASS_PROTOTYPE: RegExp
CLASS_PROTOTYPE: std:set/Set
CLASS_PROTOTYPE: Set
GLOBAL: std:string/EMPTY
CLASS_PROTOTYPE: std:string/String
CLASS_PROTOTYPE: String
FUNCTION_PROTOTYPE: std:string/isWhiteSpaceOrLineTerminator
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: std:string/parseFloat
[program.exports]
CLASS_PROTOTYPE: std:array/Array
CLASS_PROTOTYPE: std:array/CArray
@ -88,4 +90,6 @@
CLASS_PROTOTYPE: std:map/Map
CLASS_PROTOTYPE: std:set/Set
CLASS_PROTOTYPE: std:string/String
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: std:string/parseFloat
;)

View File

@ -565,18 +565,10 @@
)
)
)
(drop
(block (result i32)
(set_local $6
(get_local $2)
)
(set_local $2
(i32.sub
(get_local $6)
(i32.const 1)
)
)
(get_local $6)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 1)
)
)
)
@ -2330,7 +2322,6 @@
)
)
(func $std:heap/Heap.compare (; 3 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(if
(i32.eq
(get_local $0)
@ -2357,46 +2348,22 @@
)
(block
(block
(drop
(block (result i32)
(set_local $3
(get_local $2)
)
(set_local $2
(i32.sub
(get_local $3)
(i32.const 1)
)
)
(get_local $3)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $3
(get_local $0)
)
(set_local $0
(i32.add
(get_local $3)
(i32.const 1)
)
)
(get_local $3)
(set_local $0
(i32.add
(get_local $0)
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $3
(get_local $1)
)
(set_local $1
(i32.add
(get_local $3)
(i32.const 1)
)
)
(get_local $3)
(set_local $1
(i32.add
(get_local $1)
(i32.const 1)
)
)
)
@ -2580,8 +2547,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8
@ -2622,12 +2587,16 @@
FUNCTION_PROTOTYPE: std:heap/Heap.compare
CLASS_PROTOTYPE: std:map/Map
CLASS_PROTOTYPE: Map
CLASS_PROTOTYPE: std:regexp/RegExp
CLASS_PROTOTYPE: RegExp
CLASS_PROTOTYPE: std:set/Set
CLASS_PROTOTYPE: Set
GLOBAL: std:string/EMPTY
CLASS_PROTOTYPE: std:string/String
CLASS_PROTOTYPE: String
FUNCTION_PROTOTYPE: std:string/isWhiteSpaceOrLineTerminator
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: std:string/parseFloat
GLOBAL: std/heap/size
GLOBAL: std/heap/ptr1
GLOBAL: std/heap/ptr2
@ -2641,4 +2610,6 @@
CLASS_PROTOTYPE: std:map/Map
CLASS_PROTOTYPE: std:set/Set
CLASS_PROTOTYPE: std:string/String
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: std:string/parseFloat
;)

View File

@ -173,8 +173,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -86,8 +86,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -364,8 +364,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -43,8 +43,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -79,32 +79,16 @@
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $unary/i)
)
(set_global $unary/i
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $unary/i
(i32.add
(get_global $unary/i)
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $unary/i)
)
(set_global $unary/i
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $unary/i
(i32.sub
(get_global $unary/i)
(i32.const 1)
)
)
(set_global $unary/i
@ -229,32 +213,16 @@
(i64.const 1)
)
)
(drop
(block (result i64)
(set_local $1
(get_global $unary/I)
)
(set_global $unary/I
(i64.add
(get_local $1)
(i64.const 1)
)
)
(get_local $1)
(set_global $unary/I
(i64.add
(get_global $unary/I)
(i64.const 1)
)
)
(drop
(block (result i64)
(set_local $1
(get_global $unary/I)
)
(set_global $unary/I
(i64.sub
(get_local $1)
(i64.const 1)
)
)
(get_local $1)
(set_global $unary/I
(i64.sub
(get_global $unary/I)
(i64.const 1)
)
)
(set_global $unary/I
@ -268,8 +236,8 @@
)
(set_global $unary/I
(i64.extend_s/i32
(i32.eqz
(i32.const 1)
(i64.eqz
(i64.const 1)
)
)
)
@ -377,32 +345,16 @@
(f32.const 1)
)
)
(drop
(block (result f32)
(set_local $2
(get_global $unary/f)
)
(set_global $unary/f
(f32.add
(get_local $2)
(f32.const 1)
)
)
(get_local $2)
(set_global $unary/f
(f32.add
(get_global $unary/f)
(f32.const 1)
)
)
(drop
(block (result f32)
(set_local $2
(get_global $unary/f)
)
(set_global $unary/f
(f32.sub
(get_local $2)
(f32.const 1)
)
)
(get_local $2)
(set_global $unary/f
(f32.sub
(get_global $unary/f)
(f32.const 1)
)
)
(set_global $unary/f
@ -509,32 +461,16 @@
(f64.const 1)
)
)
(drop
(block (result f64)
(set_local $3
(get_global $unary/F)
)
(set_global $unary/F
(f64.add
(get_local $3)
(f64.const 1)
)
)
(get_local $3)
(set_global $unary/F
(f64.add
(get_global $unary/F)
(f64.const 1)
)
)
(drop
(block (result f64)
(set_local $3
(get_global $unary/F)
)
(set_global $unary/F
(f64.sub
(get_local $3)
(f64.const 1)
)
)
(get_local $3)
(set_global $unary/F
(f64.sub
(get_global $unary/F)
(f64.const 1)
)
)
(set_global $unary/F
@ -649,8 +585,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -15,32 +15,16 @@
(get_global $while/n)
(block
(block
(drop
(block (result i32)
(set_local $0
(get_global $while/n)
)
(set_global $while/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $while/n
(i32.sub
(get_global $while/n)
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $while/m)
)
(set_global $while/m
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $while/m
(i32.add
(get_global $while/m)
(i32.const 1)
)
)
)
@ -79,32 +63,16 @@
(get_global $while/n)
(block
(block
(drop
(block (result i32)
(set_local $0
(get_global $while/n)
)
(set_global $while/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $while/n
(i32.sub
(get_global $while/n)
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $while/m)
)
(set_global $while/m
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $while/m
(i32.add
(get_global $while/m)
(i32.const 1)
)
)
(block $break|2
@ -113,32 +81,16 @@
(get_global $while/n)
(block
(block
(drop
(block (result i32)
(set_local $0
(get_global $while/n)
)
(set_global $while/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $while/n
(i32.sub
(get_global $while/n)
(i32.const 1)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $while/o)
)
(set_global $while/o
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(set_global $while/o
(i32.add
(get_global $while/o)
(i32.const 1)
)
)
)
@ -291,8 +243,6 @@
FUNCTION_PROTOTYPE: unreachable
FUNCTION_PROTOTYPE: current_memory
FUNCTION_PROTOTYPE: grow_memory
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: changetype
FUNCTION_PROTOTYPE: assert
FUNCTION_PROTOTYPE: i8

View File

@ -10,6 +10,7 @@ var Parser = require("../src/parser").Parser;
var isCreate = process.argv[2] === "--create";
var filter = process.argv.length > 2 && !isCreate ? "*" + process.argv[2] + "*.ts" : "**.ts";
var failures = 0;
glob.sync(filter, { cwd: __dirname + "/parser" }).forEach(filename => {
if (filename.charAt(0) == "_" || filename.endsWith(".fixture.ts"))
@ -17,6 +18,7 @@ glob.sync(filter, { cwd: __dirname + "/parser" }).forEach(filename => {
console.log(chalk.default.whiteBright("Testing parser/" + filename));
var failed = false;
var parser = new Parser();
parser.silentDiagnostics = true;
var sourceText = fs.readFileSync(__dirname + "/parser/" + filename, { encoding: "utf8" }).replace(/\r?\n/g, "\n").replace(/^\/\/.*\r?\n/mg, "");
@ -34,7 +36,7 @@ glob.sync(filter, { cwd: __dirname + "/parser" }).forEach(filename => {
var expected = fs.readFileSync(__dirname + "/parser/" + fixture, { encoding: "utf8" });
var diffs = diff("parser/" + fixture, expected, actual);
if (diffs !== null) {
process.exitCode = 1;
failed = true;
console.log(diffs);
console.log(chalk.default.red("diff ERROR"));
} else {
@ -43,4 +45,12 @@ glob.sync(filter, { cwd: __dirname + "/parser" }).forEach(filename => {
}
console.log();
if (failed)
++failures;
});
if (failures) {
process.exitCode = 1;
console.log(chalk.red("ERROR: ") + failures + " parser tests failed");
} else
console.log(chalk.whiteBright("SUCCESS"));

View File

@ -2,7 +2,7 @@ var JsDiff = require("diff");
var chalk = require("chalk");
module.exports = function diff(filename, expected, actual) {
var diff = JsDiff.structuredPatch(filename, filename, expected, actual, "expected", "actual", { context: 2 });
var diff = JsDiff.structuredPatch(filename, filename, expected, actual, "expected", "actual", { context: 5 });
if (!diff.hunks.length)
return null;