mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-17 08:51:34 +00:00
Stdlib preparations
This commit is contained in:
17
bin/asc.js
17
bin/asc.js
@ -1,6 +1,7 @@
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var minimist = require("minimist");
|
var minimist = require("minimist");
|
||||||
|
var glob = require("glob");
|
||||||
|
|
||||||
var assemblyscript;
|
var assemblyscript;
|
||||||
var isDev = true;
|
var isDev = true;
|
||||||
@ -88,6 +89,17 @@ function checkDiagnostics(parser) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Include standard library
|
||||||
|
if (!args.noLib) {
|
||||||
|
var stdlibDir = path.join(__dirname + "..", "std", "assembly");
|
||||||
|
glob.sync("*.ts", { cwd: stdlibDir }).forEach(file => {
|
||||||
|
var nextPath = "std/" + file;
|
||||||
|
var nextText = fs.readFileSync(path.join(stdlibDir, file), { encoding: "utf8" });
|
||||||
|
parser = assemblyscript.parseFile(nextText, nextPath, parser, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include entry files
|
||||||
args._.forEach(filename => {
|
args._.forEach(filename => {
|
||||||
var entryPath = filename.replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
|
var entryPath = filename.replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
|
||||||
var entryDir = path.dirname(entryPath);
|
var entryDir = path.dirname(entryPath);
|
||||||
@ -105,11 +117,12 @@ args._.forEach(filename => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parser = assemblyscript.parseFile(entryText, entryPath, parser, true);
|
|
||||||
|
|
||||||
var nextPath;
|
var nextPath;
|
||||||
var nextText;
|
var nextText;
|
||||||
|
|
||||||
|
// Load entry text
|
||||||
|
parser = assemblyscript.parseFile(entryText, entryPath, parser, true);
|
||||||
|
|
||||||
while ((nextPath = parser.nextFile()) != null) {
|
while ((nextPath = parser.nextFile()) != null) {
|
||||||
try {
|
try {
|
||||||
nextText = fs.readFileSync(nextPath + ".ts", { encoding: "utf8" });
|
nextText = fs.readFileSync(nextPath + ".ts", { encoding: "utf8" });
|
||||||
|
@ -47,6 +47,10 @@
|
|||||||
"desc": "Disables assertions.",
|
"desc": "Disables assertions.",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"noLib": {
|
||||||
|
"desc": "Does not include the standard library.",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"trapMode": {
|
"trapMode": {
|
||||||
"desc": [
|
"desc": [
|
||||||
"Sets the trap mode to use.",
|
"Sets the trap mode to use.",
|
||||||
|
23
package-lock.json
generated
23
package-lock.json
generated
@ -186,8 +186,7 @@
|
|||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
|
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"base64-js": {
|
"base64-js": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
@ -222,7 +221,6 @@
|
|||||||
"version": "1.1.8",
|
"version": "1.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
|
||||||
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
|
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"balanced-match": "1.0.0",
|
"balanced-match": "1.0.0",
|
||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
@ -427,8 +425,7 @@
|
|||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
|
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"console-browserify": {
|
"console-browserify": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
@ -852,8 +849,7 @@
|
|||||||
"fs.realpath": {
|
"fs.realpath": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
|
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"get-caller-file": {
|
"get-caller-file": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@ -871,7 +867,6 @@
|
|||||||
"version": "7.1.2",
|
"version": "7.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
||||||
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
|
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"fs.realpath": "1.0.0",
|
"fs.realpath": "1.0.0",
|
||||||
"inflight": "1.0.6",
|
"inflight": "1.0.6",
|
||||||
@ -970,7 +965,6 @@
|
|||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||||
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"once": "1.4.0",
|
"once": "1.4.0",
|
||||||
"wrappy": "1.0.2"
|
"wrappy": "1.0.2"
|
||||||
@ -979,8 +973,7 @@
|
|||||||
"inherits": {
|
"inherits": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
|
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"interpret": {
|
"interpret": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
@ -1326,7 +1319,6 @@
|
|||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "1.1.8"
|
"brace-expansion": "1.1.8"
|
||||||
}
|
}
|
||||||
@ -1462,7 +1454,6 @@
|
|||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"wrappy": "1.0.2"
|
"wrappy": "1.0.2"
|
||||||
}
|
}
|
||||||
@ -1560,8 +1551,7 @@
|
|||||||
"path-is-absolute": {
|
"path-is-absolute": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
|
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"path-key": {
|
"path-key": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
@ -2347,8 +2337,7 @@
|
|||||||
"wrappy": {
|
"wrappy": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"xtend": {
|
"xtend": {
|
||||||
"version": "4.0.1",
|
"version": "4.0.1",
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^8.0.58",
|
"@types/node": "^8.0.58",
|
||||||
"binaryen": "40.0.0-nightly.20171209",
|
"binaryen": "40.0.0-nightly.20171209",
|
||||||
|
"glob": "^7.1.2",
|
||||||
"minimist": "^1.2.0",
|
"minimist": "^1.2.0",
|
||||||
"source-map-support": "^0.5.0"
|
"source-map-support": "^0.5.0"
|
||||||
},
|
},
|
||||||
@ -24,7 +25,6 @@
|
|||||||
"@types/minimist": "^1.2.0",
|
"@types/minimist": "^1.2.0",
|
||||||
"chalk": "^2.3.0",
|
"chalk": "^2.3.0",
|
||||||
"diff": "^3.4.0",
|
"diff": "^3.4.0",
|
||||||
"glob": "^7.1.2",
|
|
||||||
"long": "^3.2.0",
|
"long": "^3.2.0",
|
||||||
"ts-loader": "^3.2.0",
|
"ts-loader": "^3.2.0",
|
||||||
"ts-node": "^3.3.0",
|
"ts-node": "^3.3.0",
|
||||||
|
59
src/ast.ts
59
src/ast.ts
@ -109,6 +109,7 @@ export enum NodeKind {
|
|||||||
SUPER,
|
SUPER,
|
||||||
THIS,
|
THIS,
|
||||||
TRUE,
|
TRUE,
|
||||||
|
CONSTRUCTOR,
|
||||||
UNARYPOSTFIX,
|
UNARYPOSTFIX,
|
||||||
UNARYPREFIX,
|
UNARYPREFIX,
|
||||||
|
|
||||||
@ -240,6 +241,12 @@ export abstract class Expression extends Node {
|
|||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static createConstructor(range: Range): ConstructorExpression {
|
||||||
|
const expr: ConstructorExpression = new ConstructorExpression();
|
||||||
|
expr.range = range;
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
|
||||||
static createElementAccess(expression: Expression, element: Expression, range: Range): ElementAccessExpression {
|
static createElementAccess(expression: Expression, element: Expression, range: Range): ElementAccessExpression {
|
||||||
const expr: ElementAccessExpression = new ElementAccessExpression();
|
const expr: ElementAccessExpression = new ElementAccessExpression();
|
||||||
expr.range = range;
|
expr.range = range;
|
||||||
@ -357,6 +364,16 @@ export abstract class Expression extends Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class IdentifierExpression extends Expression {
|
||||||
|
|
||||||
|
kind = NodeKind.IDENTIFIER;
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
serialize(sb: string[]): void {
|
||||||
|
sb.push(this.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const enum LiteralKind {
|
export const enum LiteralKind {
|
||||||
FLOAT,
|
FLOAT,
|
||||||
INTEGER,
|
INTEGER,
|
||||||
@ -459,6 +476,11 @@ export class CallExpression extends Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ConstructorExpression extends IdentifierExpression {
|
||||||
|
kind = NodeKind.CONSTRUCTOR;
|
||||||
|
name = "this";
|
||||||
|
}
|
||||||
|
|
||||||
export class ElementAccessExpression extends Expression {
|
export class ElementAccessExpression extends Expression {
|
||||||
|
|
||||||
kind = NodeKind.ELEMENTACCESS;
|
kind = NodeKind.ELEMENTACCESS;
|
||||||
@ -483,16 +505,6 @@ export class FloatLiteralExpression extends LiteralExpression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class IdentifierExpression extends Expression {
|
|
||||||
|
|
||||||
kind = NodeKind.IDENTIFIER;
|
|
||||||
name: string;
|
|
||||||
|
|
||||||
serialize(sb: string[]): void {
|
|
||||||
sb.push(this.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class IntegerLiteralExpression extends LiteralExpression {
|
export class IntegerLiteralExpression extends LiteralExpression {
|
||||||
|
|
||||||
literalKind = LiteralKind.INTEGER;
|
literalKind = LiteralKind.INTEGER;
|
||||||
@ -641,8 +653,9 @@ export enum ModifierKind {
|
|||||||
PUBLIC,
|
PUBLIC,
|
||||||
PRIVATE,
|
PRIVATE,
|
||||||
PROTECTED,
|
PROTECTED,
|
||||||
|
READONLY,
|
||||||
GET,
|
GET,
|
||||||
SET
|
SET,
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class Statement extends Node {
|
export abstract class Statement extends Node {
|
||||||
@ -1052,7 +1065,7 @@ export class ClassDeclaration extends DeclarationStatement {
|
|||||||
if (this._cachedInternalName !== null)
|
if (this._cachedInternalName !== null)
|
||||||
return this._cachedInternalName;
|
return this._cachedInternalName;
|
||||||
const globalDecorator: Decorator | null = this.decorators ? getDecoratorByName("global", this.decorators) : null;
|
const globalDecorator: Decorator | null = this.decorators ? getDecoratorByName("global", this.decorators) : null;
|
||||||
if (globalDecorator && globalDecorator.expression.kind == NodeKind.IDENTIFIER && (<IdentifierExpression>globalDecorator.expression).name == "global")
|
if (globalDecorator)
|
||||||
return this._cachedInternalName = this.identifier.name;
|
return this._cachedInternalName = this.identifier.name;
|
||||||
else
|
else
|
||||||
return this._cachedInternalName = mangleInternalName(this);
|
return this._cachedInternalName = mangleInternalName(this);
|
||||||
@ -1589,9 +1602,10 @@ export class Modifier extends Node {
|
|||||||
case ModifierKind.PRIVATE: sb.push("private"); break;
|
case ModifierKind.PRIVATE: sb.push("private"); break;
|
||||||
case ModifierKind.PROTECTED: sb.push("protected"); break;
|
case ModifierKind.PROTECTED: sb.push("protected"); break;
|
||||||
case ModifierKind.PUBLIC: sb.push("public"); break;
|
case ModifierKind.PUBLIC: sb.push("public"); break;
|
||||||
|
case ModifierKind.READONLY: sb.push("readonly"); break;
|
||||||
case ModifierKind.SET: sb.push("set"); break;
|
case ModifierKind.SET: sb.push("set"); break;
|
||||||
case ModifierKind.STATIC: sb.push("static"); break;
|
case ModifierKind.STATIC: sb.push("static"); break;
|
||||||
default: sb.push("INVALID"); break;
|
default: throw new Error("unexpected modifier kind");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1772,16 +1786,21 @@ export function hasModifier(kind: ModifierKind, modifiers: Modifier[] | null): b
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDecoratorByName(name: string, decorators: Decorator[]): Decorator | null {
|
function getDecoratorByName(name: string, decorators: Decorator[] | null): Decorator | null {
|
||||||
for (let i: i32 = 0, k: i32 = decorators.length; i < k; ++i) {
|
if (decorators)
|
||||||
const decorator: Decorator = decorators[i];
|
for (let i: i32 = 0, k: i32 = decorators.length; i < k; ++i) {
|
||||||
const expression: Expression = decorator.expression;
|
const decorator: Decorator = decorators[i];
|
||||||
if (expression.kind == NodeKind.IDENTIFIER && (<IdentifierExpression>expression).name == name)
|
const expression: Expression = decorator.expression;
|
||||||
return decorator;
|
if (expression.kind == NodeKind.IDENTIFIER && (<IdentifierExpression>expression).name == name)
|
||||||
}
|
return decorator;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hasDecorator(name: string, decorators: Decorator[] | null): bool {
|
||||||
|
return getDecoratorByName(name, decorators) != null;
|
||||||
|
}
|
||||||
|
|
||||||
export function serialize(node: Node, indent: i32 = 0): string {
|
export function serialize(node: Node, indent: i32 = 0): string {
|
||||||
const sb: string[] = new Array(); // shared builder could grow too much
|
const sb: string[] = new Array(); // shared builder could grow too much
|
||||||
node.serialize(sb);
|
node.serialize(sb);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Compiler, Target, ConversionKind, typeToNativeType, typeToNativeOne, typeToNativeZero } from "./compiler";
|
import { Compiler, Target, ConversionKind, typeToNativeType, typeToNativeOne, typeToNativeZero } from "./compiler";
|
||||||
import { DiagnosticCode } from "./diagnostics";
|
import { DiagnosticCode } from "./diagnostics";
|
||||||
import { Node, Expression } from "./ast";
|
import { Node, Expression, IdentifierExpression } from "./ast";
|
||||||
import { Type } from "./types";
|
import { Type } from "./types";
|
||||||
import { Module, ExpressionRef, UnaryOp, BinaryOp, HostOp, NativeType, FunctionTypeRef } from "./module";
|
import { Module, ExpressionRef, UnaryOp, BinaryOp, HostOp, NativeType, FunctionTypeRef } from "./module";
|
||||||
import { Program, ElementFlags, Element, Global, FunctionPrototype, Local } from "./program";
|
import { Program, ElementFlags, Element, Global, FunctionPrototype, Local } from "./program";
|
||||||
@ -9,6 +9,9 @@ import { Program, ElementFlags, Element, Global, FunctionPrototype, Local } from
|
|||||||
export function initialize(program: Program): void {
|
export function initialize(program: Program): void {
|
||||||
|
|
||||||
// math
|
// math
|
||||||
|
addConstant(program, "NaN", Type.f64);
|
||||||
|
addConstant(program, "Infinity", Type.f64);
|
||||||
|
|
||||||
addFunction(program, "isNaN", true);
|
addFunction(program, "isNaN", true);
|
||||||
addFunction(program, "isFinite", true);
|
addFunction(program, "isFinite", true);
|
||||||
addFunction(program, "clz", true);
|
addFunction(program, "clz", true);
|
||||||
@ -96,12 +99,24 @@ export function initialize(program: Program): void {
|
|||||||
if (program.target == Target.WASM64) {
|
if (program.target == Target.WASM64) {
|
||||||
program.elements.set("isize", <Element>program.elements.get("i64"));
|
program.elements.set("isize", <Element>program.elements.get("i64"));
|
||||||
program.elements.set("usize", <Element>program.elements.get("u64"));
|
program.elements.set("usize", <Element>program.elements.get("u64"));
|
||||||
|
addConstant(program, "HEAP_START", Type.usize64);
|
||||||
} else {
|
} else {
|
||||||
program.elements.set("isize", <Element>program.elements.get("i32"));
|
program.elements.set("isize", <Element>program.elements.get("i32"));
|
||||||
program.elements.set("usize", <Element>program.elements.get("u32"));
|
program.elements.set("usize", <Element>program.elements.get("u32"));
|
||||||
|
addConstant(program, "HEAP_START", Type.usize32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Adds a built-in global to the specified program. */
|
||||||
|
function addConstant(program: Program, name: string, type: Type): Global {
|
||||||
|
const global: Global = new Global(program, name, null, null);
|
||||||
|
global.isBuiltIn = true;
|
||||||
|
global.isConstant = true;
|
||||||
|
global.type = type;
|
||||||
|
program.elements.set(name, global);
|
||||||
|
return global;
|
||||||
|
}
|
||||||
|
|
||||||
/** Adds a built-in function to the specified program. */
|
/** Adds a built-in function to the specified program. */
|
||||||
function addFunction(program: Program, name: string, isGeneric: bool = false): FunctionPrototype {
|
function addFunction(program: Program, name: string, isGeneric: bool = false): FunctionPrototype {
|
||||||
let prototype: FunctionPrototype = new FunctionPrototype(program, name, name, null, null);
|
let prototype: FunctionPrototype = new FunctionPrototype(program, name, name, null, null);
|
||||||
@ -111,6 +126,29 @@ function addFunction(program: Program, name: string, isGeneric: bool = false): F
|
|||||||
return prototype;
|
return prototype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function compileGetGlobal(compiler: Compiler, global: Global): ExpressionRef {
|
||||||
|
switch (global.internalName) {
|
||||||
|
|
||||||
|
case "NaN":
|
||||||
|
if (compiler.currentType == Type.f32)
|
||||||
|
return compiler.module.createF32(NaN);
|
||||||
|
compiler.currentType = Type.f64;
|
||||||
|
return compiler.module.createF64(NaN);
|
||||||
|
|
||||||
|
case "Infinity":
|
||||||
|
if (compiler.currentType == Type.f32)
|
||||||
|
return compiler.module.createF32(Infinity);
|
||||||
|
compiler.currentType = Type.f64;
|
||||||
|
return compiler.module.createF64(Infinity);
|
||||||
|
|
||||||
|
case "HEAP_START": // never inlined
|
||||||
|
return compiler.module.createGetGlobal("HEAP_START", typeToNativeType(<Type>global.type));
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error("not implemented: " + global.internalName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Compiles a call to a built-in function. */
|
/** Compiles a call to a built-in function. */
|
||||||
export function compileCall(compiler: Compiler, prototype: FunctionPrototype, typeArguments: Type[], operands: Expression[], reportNode: Node): ExpressionRef {
|
export function compileCall(compiler: Compiler, prototype: FunctionPrototype, typeArguments: Type[], operands: Expression[], reportNode: Node): ExpressionRef {
|
||||||
const module: Module = compiler.module;
|
const module: Module = compiler.module;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { compileCall as compileBuiltinCall, initialize } from "./builtins";
|
import { compileCall as compileBuiltinCall, compileGetGlobal as compileBuiltinGetGlobal, initialize } from "./builtins";
|
||||||
import { PATH_DELIMITER } from "./constants";
|
import { PATH_DELIMITER } from "./constants";
|
||||||
import { DiagnosticCode, DiagnosticEmitter } from "./diagnostics";
|
import { DiagnosticCode, DiagnosticEmitter } from "./diagnostics";
|
||||||
import {
|
import {
|
||||||
@ -324,6 +324,10 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
compileGlobal(global: Global): bool {
|
compileGlobal(global: Global): bool {
|
||||||
if (global.isCompiled)
|
if (global.isCompiled)
|
||||||
return true;
|
return true;
|
||||||
|
if (global.isBuiltIn)
|
||||||
|
if (compileBuiltinGetGlobal(this, global))
|
||||||
|
return true;
|
||||||
|
|
||||||
const declaration: VariableLikeDeclarationStatement | null = global.declaration;
|
const declaration: VariableLikeDeclarationStatement | null = global.declaration;
|
||||||
let type: Type | null = global.type;
|
let type: Type | null = global.type;
|
||||||
if (!type) {
|
if (!type) {
|
||||||
@ -376,6 +380,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
initializer = typeToNativeZero(this.module, type);
|
initializer = typeToNativeZero(this.module, type);
|
||||||
} else
|
} else
|
||||||
throw new Error("unexpected missing declaration or constant value");
|
throw new Error("unexpected missing declaration or constant value");
|
||||||
|
|
||||||
const internalName: string = global.internalName;
|
const internalName: string = global.internalName;
|
||||||
if (initializeInStart) {
|
if (initializeInStart) {
|
||||||
this.module.addGlobal(internalName, nativeType, true, typeToNativeZero(this.module, type));
|
this.module.addGlobal(internalName, nativeType, true, typeToNativeZero(this.module, type));
|
||||||
@ -1606,14 +1611,15 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (element.kind == ElementKind.GLOBAL) {
|
if (element.kind == ElementKind.GLOBAL) {
|
||||||
this.compileGlobal(<Global>element);
|
if (!this.compileGlobal(<Global>element))
|
||||||
if (!(<Global>element).isMutable)
|
return this.module.createUnreachable();
|
||||||
|
this.currentType = <Type>(<Global>element).type;
|
||||||
|
if (!(<Global>element).isMutable) {
|
||||||
this.error(DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, expression.range, element.internalName);
|
this.error(DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, expression.range, element.internalName);
|
||||||
|
return this.module.createUnreachable();
|
||||||
|
}
|
||||||
if (tee) {
|
if (tee) {
|
||||||
if (!(<Global>element).type)
|
|
||||||
return this.module.createUnreachable();
|
|
||||||
const globalNativeType: NativeType = typeToNativeType(<Type>(<Global>element).type);
|
const globalNativeType: NativeType = typeToNativeType(<Type>(<Global>element).type);
|
||||||
this.currentType = <Type>(<Global>element).type;
|
|
||||||
return this.module.createBlock(null, [ // teeGlobal
|
return this.module.createBlock(null, [ // teeGlobal
|
||||||
this.module.createSetGlobal((<Global>element).internalName, valueWithCorrectType),
|
this.module.createSetGlobal((<Global>element).internalName, valueWithCorrectType),
|
||||||
this.module.createGetGlobal((<Global>element).internalName, globalNativeType)
|
this.module.createGetGlobal((<Global>element).internalName, globalNativeType)
|
||||||
@ -1759,22 +1765,6 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
this.error(DiagnosticCode._this_cannot_be_referenced_in_current_location, expression.range);
|
this.error(DiagnosticCode._this_cannot_be_referenced_in_current_location, expression.range);
|
||||||
this.currentType = this.options.target == Target.WASM64 ? Type.u64 : Type.u32;
|
this.currentType = this.options.target == Target.WASM64 ? Type.u64 : Type.u32;
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
|
|
||||||
case NodeKind.IDENTIFIER:
|
|
||||||
// TODO: some sort of resolveIdentifier maybe
|
|
||||||
if ((<IdentifierExpression>expression).name == "NaN") {
|
|
||||||
if (this.currentType == Type.f32)
|
|
||||||
return this.module.createF32(NaN);
|
|
||||||
this.currentType = Type.f64;
|
|
||||||
return this.module.createF64(NaN);
|
|
||||||
}
|
|
||||||
if ((<IdentifierExpression>expression).name == "Infinity") {
|
|
||||||
if (this.currentType == Type.f32)
|
|
||||||
return this.module.createF32(Infinity);
|
|
||||||
this.currentType = Type.f64;
|
|
||||||
return this.module.createF64(Infinity);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const element: Element | null = this.program.resolveElement(expression, this.currentFunction); // reports
|
const element: Element | null = this.program.resolveElement(expression, this.currentFunction); // reports
|
||||||
@ -1789,6 +1779,9 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// global
|
// global
|
||||||
if (element.kind == ElementKind.GLOBAL) {
|
if (element.kind == ElementKind.GLOBAL) {
|
||||||
|
if (element.isBuiltIn)
|
||||||
|
return compileBuiltinGetGlobal(this, <Global>element);
|
||||||
|
|
||||||
const global: Global = <Global>element;
|
const global: Global = <Global>element;
|
||||||
if (!this.compileGlobal(global)) // reports
|
if (!this.compileGlobal(global)) // reports
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
|
@ -66,6 +66,7 @@ export enum DiagnosticCode {
|
|||||||
Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures = 2349,
|
Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures = 2349,
|
||||||
The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access = 2357,
|
The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access = 2357,
|
||||||
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access = 2364,
|
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access = 2364,
|
||||||
|
Constructor_implementation_is_missing = 2390,
|
||||||
Function_implementation_is_missing_or_not_immediately_following_the_declaration = 2391,
|
Function_implementation_is_missing_or_not_immediately_following_the_declaration = 2391,
|
||||||
Duplicate_function_implementation = 2393,
|
Duplicate_function_implementation = 2393,
|
||||||
Export_declaration_conflicts_with_exported_declaration_of_0 = 2484,
|
Export_declaration_conflicts_with_exported_declaration_of_0 = 2484,
|
||||||
@ -145,6 +146,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string {
|
|||||||
case 2349: return "Cannot invoke an expression whose type lacks a call signature. Type '{0}' has no compatible call signatures.";
|
case 2349: return "Cannot invoke an expression whose type lacks a call signature. Type '{0}' has no compatible call signatures.";
|
||||||
case 2357: return "The operand of an increment or decrement operator must be a variable or a property access.";
|
case 2357: return "The operand of an increment or decrement operator must be a variable or a property access.";
|
||||||
case 2364: return "The left-hand side of an assignment expression must be a variable or a property access.";
|
case 2364: return "The left-hand side of an assignment expression must be a variable or a property access.";
|
||||||
|
case 2390: return "Constructor implementation is missing.";
|
||||||
case 2391: return "Function implementation is missing or not immediately following the declaration.";
|
case 2391: return "Function implementation is missing or not immediately following the declaration.";
|
||||||
case 2393: return "Duplicate function implementation.";
|
case 2393: return "Duplicate function implementation.";
|
||||||
case 2484: return "Export declaration conflicts with exported declaration of '{0}'.";
|
case 2484: return "Export declaration conflicts with exported declaration of '{0}'.";
|
||||||
|
@ -66,6 +66,7 @@
|
|||||||
"Cannot invoke an expression whose type lacks a call signature. Type '{0}' has no compatible call signatures.": 2349,
|
"Cannot invoke an expression whose type lacks a call signature. Type '{0}' has no compatible call signatures.": 2349,
|
||||||
"The operand of an increment or decrement operator must be a variable or a property access.": 2357,
|
"The operand of an increment or decrement operator must be a variable or a property access.": 2357,
|
||||||
"The left-hand side of an assignment expression must be a variable or a property access.": 2364,
|
"The left-hand side of an assignment expression must be a variable or a property access.": 2364,
|
||||||
|
"Constructor implementation is missing.": 2390,
|
||||||
"Function implementation is missing or not immediately following the declaration.": 2391,
|
"Function implementation is missing or not immediately following the declaration.": 2391,
|
||||||
"Duplicate function implementation.": 2393,
|
"Duplicate function implementation.": 2393,
|
||||||
"Export declaration conflicts with exported declaration of '{0}'.": 2484,
|
"Export declaration conflicts with exported declaration of '{0}'.": 2484,
|
||||||
|
@ -694,6 +694,9 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
else if (tn.skip(Token.ABSTRACT))
|
else if (tn.skip(Token.ABSTRACT))
|
||||||
modifiers = addModifier(Statement.createModifier(ModifierKind.ABSTRACT, tn.range()), modifiers);
|
modifiers = addModifier(Statement.createModifier(ModifierKind.ABSTRACT, tn.range()), modifiers);
|
||||||
|
|
||||||
|
if (tn.skip(Token.READONLY))
|
||||||
|
modifiers = addModifier(Statement.createModifier(ModifierKind.READONLY, tn.range()), modifiers);
|
||||||
|
|
||||||
let isGetter: bool = false;
|
let isGetter: bool = false;
|
||||||
let isSetter: bool = false;
|
let isSetter: bool = false;
|
||||||
if (tn.skip(Token.GET)) {
|
if (tn.skip(Token.GET)) {
|
||||||
@ -704,16 +707,23 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
isSetter = true;
|
isSetter = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER) || tn.skip(Token.CONSTRUCTOR)) {
|
||||||
const identifier: IdentifierExpression = Expression.createIdentifier(tn.readIdentifier(), tn.range());
|
const identifier: IdentifierExpression = tn.token == Token.CONSTRUCTOR
|
||||||
|
? Expression.createConstructor(tn.range())
|
||||||
|
: Expression.createIdentifier(tn.readIdentifier(), tn.range());
|
||||||
let typeParameters: TypeParameter[] | null;
|
let typeParameters: TypeParameter[] | null;
|
||||||
if (tn.skip(Token.LESSTHAN)) {
|
if (tn.skip(Token.LESSTHAN)) {
|
||||||
|
if (identifier.kind == NodeKind.CONSTRUCTOR)
|
||||||
|
this.error(DiagnosticCode.Type_parameters_cannot_appear_on_a_constructor_declaration, tn.range()); // recoverable
|
||||||
typeParameters = this.parseTypeParameters(tn);
|
typeParameters = this.parseTypeParameters(tn);
|
||||||
if (!typeParameters)
|
if (!typeParameters)
|
||||||
return null;
|
return null;
|
||||||
} else
|
} else
|
||||||
typeParameters = [];
|
typeParameters = [];
|
||||||
|
|
||||||
|
if (identifier.kind == NodeKind.CONSTRUCTOR && tn.peek() != Token.OPENPAREN)
|
||||||
|
this.error(DiagnosticCode.Constructor_implementation_is_missing, tn.range());
|
||||||
|
|
||||||
// method: '(' Parameters (':' Type)? '{' Statement* '}' ';'?
|
// method: '(' Parameters (':' Type)? '{' Statement* '}' ';'?
|
||||||
if (tn.skip(Token.OPENPAREN)) {
|
if (tn.skip(Token.OPENPAREN)) {
|
||||||
let parameters = this.parseParameters(tn);
|
let parameters = this.parseParameters(tn);
|
||||||
@ -729,14 +739,18 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
let returnType: TypeNode | null = null;
|
let returnType: TypeNode | null = null;
|
||||||
if (tn.skip(Token.COLON)) {
|
if (tn.skip(Token.COLON)) {
|
||||||
returnType = this.parseType(tn, isSetter);
|
if (identifier.kind == NodeKind.CONSTRUCTOR)
|
||||||
|
this.error(DiagnosticCode.Type_annotation_cannot_appear_on_a_constructor_declaration, tn.range());
|
||||||
|
else if (isSetter)
|
||||||
|
this.error(DiagnosticCode.A_set_accessor_cannot_have_a_return_type_annotation, tn.range());
|
||||||
|
returnType = this.parseType(tn, identifier.kind == NodeKind.CONSTRUCTOR || isSetter);
|
||||||
if (!returnType)
|
if (!returnType)
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
if (isSetter) {
|
if (isSetter) {
|
||||||
if (parameters.length)
|
if (parameters.length)
|
||||||
returnType = parameters[0].type;
|
returnType = parameters[0].type;
|
||||||
} else
|
} else if (identifier.kind != NodeKind.CONSTRUCTOR)
|
||||||
this.error(DiagnosticCode.Type_expected, tn.range()); // recoverable
|
this.error(DiagnosticCode.Type_expected, tn.range()); // recoverable
|
||||||
}
|
}
|
||||||
let statements: Statement[] | null = null;
|
let statements: Statement[] | null = null;
|
||||||
@ -1323,36 +1337,21 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
let p: Precedence = determinePrecedencePrefix(token);
|
let p: Precedence = determinePrecedencePrefix(token);
|
||||||
if (p != Precedence.INVALID) {
|
if (p != Precedence.INVALID) {
|
||||||
const operand: Expression | null = this.parseExpression(tn, p);
|
let operand: Expression | null
|
||||||
if (!operand)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
// TODO: SpreadExpression, YieldExpression (currently become unsupported UnaryPrefixExpressions)
|
// TODO: SpreadExpression, YieldExpression (currently become unsupported UnaryPrefixExpressions)
|
||||||
|
|
||||||
// NewExpression
|
// NewExpression
|
||||||
if (token == Token.NEW) {
|
if (token == Token.NEW) {
|
||||||
if (operand.kind == NodeKind.IDENTIFIER || operand.kind == NodeKind.PROPERTYACCESS) {
|
operand = this.parseExpression(tn, Precedence.CALL);
|
||||||
const args: Expression[] = new Array();
|
if (!operand)
|
||||||
if (tn.skip(Token.OPENPAREN)) {
|
|
||||||
if (tn.peek() != Token.CLOSEPAREN) {
|
|
||||||
do {
|
|
||||||
expr = this.parseExpression(tn, Precedence.COMMA + 1);
|
|
||||||
if (!expr)
|
|
||||||
return null;
|
|
||||||
args.push(expr);
|
|
||||||
} while (tn.skip(Token.COMMA));
|
|
||||||
}
|
|
||||||
if (!tn.skip(Token.CLOSEPAREN)) {
|
|
||||||
this.error(DiagnosticCode._0_expected, tn.range(), ")");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Expression.createNew(operand, [], args, tn.range(startPos, tn.pos));
|
|
||||||
} else {
|
|
||||||
this.error(DiagnosticCode.Identifier_expected, tn.range());
|
|
||||||
return null;
|
return null;
|
||||||
}
|
if (operand.kind == NodeKind.CALL)
|
||||||
}
|
return Expression.createNew((<CallExpression>operand).expression, (<CallExpression>operand).typeArguments, (<CallExpression>operand).arguments, tn.range(startPos, tn.pos));
|
||||||
|
this.error(DiagnosticCode.Operation_not_supported, tn.range());
|
||||||
|
return null;
|
||||||
|
} else
|
||||||
|
operand = this.parseExpression(tn, p);
|
||||||
|
|
||||||
// UnaryPrefixExpression
|
// UnaryPrefixExpression
|
||||||
if (token == Token.PLUS_PLUS || token == Token.MINUS_MINUS)
|
if (token == Token.PLUS_PLUS || token == Token.MINUS_MINUS)
|
||||||
@ -1406,7 +1405,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
this.error(DiagnosticCode._0_expected, tn.range(), ">");
|
this.error(DiagnosticCode._0_expected, tn.range(), ">");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
expr = this.parseExpressionPrefix(tn);
|
expr = this.parseExpression(tn, Precedence.CALL);
|
||||||
if (!expr)
|
if (!expr)
|
||||||
return null;
|
return null;
|
||||||
return Expression.createAssertion(AssertionKind.PREFIX, <Expression>expr, <TypeNode>toType, tn.range(startPos, tn.pos));
|
return Expression.createAssertion(AssertionKind.PREFIX, <Expression>expr, <TypeNode>toType, tn.range(startPos, tn.pos));
|
||||||
@ -1416,6 +1415,15 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
case Token.IDENTIFIER:
|
case Token.IDENTIFIER:
|
||||||
return Expression.createIdentifier(tn.readIdentifier(), tn.range(startPos, tn.pos));
|
return Expression.createIdentifier(tn.readIdentifier(), tn.range(startPos, tn.pos));
|
||||||
|
|
||||||
|
case Token.THIS:
|
||||||
|
return Expression.createThis(tn.range(startPos, tn.pos));
|
||||||
|
|
||||||
|
case Token.CONSTRUCTOR:
|
||||||
|
return Expression.createConstructor(tn.range(startPos, tn.pos));
|
||||||
|
|
||||||
|
case Token.SUPER:
|
||||||
|
return Expression.createSuper(tn.range(startPos, tn.pos));
|
||||||
|
|
||||||
// StringLiteralExpression
|
// StringLiteralExpression
|
||||||
case Token.STRINGLITERAL:
|
case Token.STRINGLITERAL:
|
||||||
return Expression.createStringLiteral(tn.readString(), tn.range(startPos, tn.pos));
|
return Expression.createStringLiteral(tn.readString(), tn.range(startPos, tn.pos));
|
||||||
|
@ -19,6 +19,7 @@ import {
|
|||||||
LiteralKind,
|
LiteralKind,
|
||||||
PropertyAccessExpression,
|
PropertyAccessExpression,
|
||||||
StringLiteralExpression,
|
StringLiteralExpression,
|
||||||
|
CallExpression,
|
||||||
|
|
||||||
ClassDeclaration,
|
ClassDeclaration,
|
||||||
DeclarationStatement,
|
DeclarationStatement,
|
||||||
@ -101,7 +102,9 @@ export class Program extends DiagnosticEmitter {
|
|||||||
["bool", Type.bool],
|
["bool", Type.bool],
|
||||||
["f32", Type.f32],
|
["f32", Type.f32],
|
||||||
["f64", Type.f64],
|
["f64", Type.f64],
|
||||||
["void", Type.void]
|
["void", Type.void],
|
||||||
|
["number", Type.f64],
|
||||||
|
["boolean", Type.bool]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
initializeBuiltins(this);
|
initializeBuiltins(this);
|
||||||
@ -779,27 +782,26 @@ export class Program extends DiagnosticEmitter {
|
|||||||
// static or instance property (incl. enum values) or method
|
// static or instance property (incl. enum values) or method
|
||||||
} else if (expression.kind == NodeKind.PROPERTYACCESS) {
|
} else if (expression.kind == NodeKind.PROPERTYACCESS) {
|
||||||
return this.resolvePropertyAccess(<PropertyAccessExpression>expression, contextualFunction);
|
return this.resolvePropertyAccess(<PropertyAccessExpression>expression, contextualFunction);
|
||||||
|
|
||||||
|
// instantiation
|
||||||
|
} else if (expression.kind == NodeKind.NEW) {
|
||||||
|
return this.resolveElement((<CallExpression>expression).expression, contextualFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error("not implemented: " + expression.kind);
|
throw new Error("not implemented: " + expression.kind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkGlobalDecorator(decorators: Decorator[]): string | null {
|
function hasDecorator(name: string, decorators: Decorator[] | null): bool {
|
||||||
for (let i: i32 = 0, k: i32 = decorators.length; i < k; ++i) {
|
if (decorators)
|
||||||
const decorator: Decorator = decorators[i];
|
for (let i: i32 = 0, k: i32 = decorators.length; i < k; ++i) {
|
||||||
const expression: Expression = decorator.expression;
|
const decorator: Decorator = decorators[i];
|
||||||
const args: Expression[] = decorator.arguments;
|
const expression: Expression = decorator.expression;
|
||||||
if (expression.kind == NodeKind.IDENTIFIER && args.length <= 1 && (<IdentifierExpression>expression).name == "global") {
|
const args: Expression[] = decorator.arguments;
|
||||||
if (args.length) {
|
if (expression.kind == NodeKind.IDENTIFIER && args.length <= 1 && (<IdentifierExpression>expression).name == name)
|
||||||
const firstArg: Expression = args[0];
|
return true;
|
||||||
if (firstArg.kind == NodeKind.LITERAL && (<LiteralExpression>firstArg).literalKind == LiteralKind.STRING)
|
|
||||||
return (<StringLiteralExpression>firstArg).value;
|
|
||||||
} else
|
|
||||||
return ""; // instead inherits declaration identifier
|
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Indicates the specific kind of an {@link Element}. */
|
/** Indicates the specific kind of an {@link Element}. */
|
||||||
@ -857,7 +859,11 @@ export enum ElementFlags {
|
|||||||
/** Is getter. */
|
/** Is getter. */
|
||||||
GETTER = 1 << 9,
|
GETTER = 1 << 9,
|
||||||
/** Is setter. */
|
/** Is setter. */
|
||||||
SETTER = 1 << 10
|
SETTER = 1 << 10,
|
||||||
|
/** Is global. */
|
||||||
|
GLOBAL = 1 << 11,
|
||||||
|
/** Is read-only. */
|
||||||
|
READONLY = 1 << 12
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Base class of all program elements. */
|
/** Base class of all program elements. */
|
||||||
@ -919,9 +925,13 @@ export abstract class Element {
|
|||||||
/** Whether an instance member or not. */
|
/** Whether an instance member or not. */
|
||||||
get isInstance(): bool { return (this.flags & ElementFlags.INSTANCE) != 0; }
|
get isInstance(): bool { return (this.flags & ElementFlags.INSTANCE) != 0; }
|
||||||
set isInstance(is: bool) { if (is) this.flags |= ElementFlags.INSTANCE; else this.flags &= ~ElementFlags.INSTANCE; }
|
set isInstance(is: bool) { if (is) this.flags |= ElementFlags.INSTANCE; else this.flags &= ~ElementFlags.INSTANCE; }
|
||||||
|
|
||||||
|
/** Whether a member of the global namespace or not. */
|
||||||
|
get isGlobal(): bool { return (this.flags & ElementFlags.GLOBAL) != 0; }
|
||||||
|
set isGlobal(is: bool) { if (is) this.flags |= ElementFlags.GLOBAL; else this.flags &= ~ElementFlags.GLOBAL; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A namespace. Also the base class of other namespace-like program elements. */
|
/** A namespace. */
|
||||||
export class Namespace extends Element {
|
export class Namespace extends Element {
|
||||||
|
|
||||||
kind = ElementKind.NAMESPACE;
|
kind = ElementKind.NAMESPACE;
|
||||||
@ -985,8 +995,7 @@ export class EnumValue extends Element {
|
|||||||
constructor(enm: Enum, program: Program, internalName: string, declaration: EnumValueDeclaration | null = null) {
|
constructor(enm: Enum, program: Program, internalName: string, declaration: EnumValueDeclaration | null = null) {
|
||||||
super(program, internalName);
|
super(program, internalName);
|
||||||
this.enum = enm;
|
this.enum = enm;
|
||||||
if (!(this.declaration = declaration))
|
this.declaration = declaration;
|
||||||
this.hasConstantValue = true; // built-ins have constant values
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1185,7 +1194,7 @@ export class FunctionPrototype extends Element {
|
|||||||
resolveInclTypeArguments(typeArgumentNodes: TypeNode[] | null, contextualTypeArguments: Map<string,Type> | null, alternativeReportNode: Node | null): Function | null {
|
resolveInclTypeArguments(typeArgumentNodes: TypeNode[] | null, contextualTypeArguments: Map<string,Type> | null, alternativeReportNode: Node | null): Function | null {
|
||||||
let resolvedTypeArguments: Type[] | null;
|
let resolvedTypeArguments: Type[] | null;
|
||||||
if (this.isGeneric) {
|
if (this.isGeneric) {
|
||||||
assert(typeArgumentNodes != null && typeArgumentNodes.length != 0);
|
assert(typeArgumentNodes != null && typeArgumentNodes.length != 0, "" + this);
|
||||||
if (!this.declaration)
|
if (!this.declaration)
|
||||||
throw new Error("missing declaration");
|
throw new Error("missing declaration");
|
||||||
resolvedTypeArguments = this.program.resolveTypeArguments(this.declaration.typeParameters, typeArgumentNodes, contextualTypeArguments, alternativeReportNode);
|
resolvedTypeArguments = this.program.resolveTypeArguments(this.declaration.typeParameters, typeArgumentNodes, contextualTypeArguments, alternativeReportNode);
|
||||||
@ -1372,11 +1381,17 @@ export class FieldPrototype extends Element {
|
|||||||
for (let i: i32 = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
for (let i: i32 = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||||
switch (this.declaration.modifiers[i].modifierKind) {
|
switch (this.declaration.modifiers[i].modifierKind) {
|
||||||
case ModifierKind.EXPORT: this.isExported = true; break;
|
case ModifierKind.EXPORT: this.isExported = true; break;
|
||||||
|
case ModifierKind.READONLY: this.isReadonly = true; break;
|
||||||
|
case ModifierKind.STATIC: break; // already handled
|
||||||
default: throw new Error("unexpected modifier");
|
default: throw new Error("unexpected modifier");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether the field is read-only or not. */
|
||||||
|
get isReadonly(): bool { return (this.flags & ElementFlags.READONLY) != 0; }
|
||||||
|
set isReadonly(is: bool) { if (is) this.flags |= ElementFlags.READONLY; else this.flags &= ~ElementFlags.READONLY; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A resolved instance field. */
|
/** A resolved instance field. */
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// 1. C-like with no 'length' or 'push'
|
// 1. C-like with no 'length' or 'push'
|
||||||
// 2. Descriptors that can be constructed from lower level arrays
|
// 2. Descriptors that can be constructed from lower level arrays
|
||||||
|
|
||||||
|
@global()
|
||||||
class Array<T> {
|
class Array<T> {
|
||||||
|
|
||||||
readonly capacity: i32;
|
readonly capacity: i32;
|
||||||
@ -33,4 +34,6 @@ class Array<T> {
|
|||||||
this.ptr = 0;
|
this.ptr = 0;
|
||||||
Heap.dispose(changetype<this,usize>(this));
|
Heap.dispose(changetype<this,usize>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static test(): void {}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ const ALIGN_MASK: usize = ALIGN_SIZE - 1;
|
|||||||
let HEAP_OFFSET: usize = HEAP_START; // HEAP_START is a constant generated by the compiler
|
let HEAP_OFFSET: usize = HEAP_START; // HEAP_START is a constant generated by the compiler
|
||||||
|
|
||||||
@global()
|
@global()
|
||||||
@struct()
|
|
||||||
class Heap {
|
class Heap {
|
||||||
|
|
||||||
static allocate(size: usize): usize {
|
static allocate(size: usize): usize {
|
||||||
@ -180,6 +179,4 @@ class Heap {
|
|||||||
}
|
}
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
private constructor() {}
|
|
||||||
}
|
}
|
||||||
|
@ -66,9 +66,12 @@ globalScope["sqrt"] = Math.sqrt;
|
|||||||
globalScope["trunc"] = Math.trunc;
|
globalScope["trunc"] = Math.trunc;
|
||||||
|
|
||||||
function UnreachableError() {
|
function UnreachableError() {
|
||||||
this.stack = new Error().stack;
|
if (Error.captureStackTrace)
|
||||||
|
Error.captureStackTrace(this, UnreachableError);
|
||||||
|
else
|
||||||
|
this.stack = this.name + ": " + this.message + "\n" + new Error().stack;
|
||||||
}
|
}
|
||||||
UnreachableError.prototype = new Error;
|
UnreachableError.prototype = Object.create(Error.prototype);
|
||||||
UnreachableError.prototype.name = "UnreachableError";
|
UnreachableError.prototype.name = "UnreachableError";
|
||||||
UnreachableError.prototype.message = "unreachable";
|
UnreachableError.prototype.message = "unreachable";
|
||||||
|
|
||||||
@ -76,9 +79,12 @@ globalScope["unreachable"] = function unreachable() { throw new UnreachableError
|
|||||||
|
|
||||||
function AssertionError(message) {
|
function AssertionError(message) {
|
||||||
this.message = message || "assertion failed";
|
this.message = message || "assertion failed";
|
||||||
this.stack = new Error().stack;
|
if (Error.captureStackTrace)
|
||||||
|
Error.captureStackTrace(this, AssertionError);
|
||||||
|
else
|
||||||
|
this.stack = this.name + ": " + this.message + "\n" + new Error().stack;
|
||||||
}
|
}
|
||||||
AssertionError.prototype = new Error;
|
AssertionError.prototype = Object.create(Error.prototype);
|
||||||
AssertionError.prototype.name = "AssertionError";
|
AssertionError.prototype.name = "AssertionError";
|
||||||
|
|
||||||
globalScope["assert"] = function assert(isTrue, message) { if (!isTrue) throw new AssertionError(message); };
|
globalScope["assert"] = function assert(isTrue, message) { if (!isTrue) throw new AssertionError(message); };
|
||||||
|
@ -5,7 +5,7 @@ var HEAP_OFFSET = 0;
|
|||||||
|
|
||||||
Object.defineProperties(globalScope["Heap"] = {
|
Object.defineProperties(globalScope["Heap"] = {
|
||||||
allocate: function allocate(size) {
|
allocate: function allocate(size) {
|
||||||
if (!size) return 0;
|
if (!(size >>>= 0)) return 0;
|
||||||
if (HEAP_OFFSET + size > HEAP.length) {
|
if (HEAP_OFFSET + size > HEAP.length) {
|
||||||
var oldHeap = HEAP;
|
var oldHeap = HEAP;
|
||||||
HEAP = new Uint8Array(Math.max(65536, HEAP.length + size, HEAP.length * 2));
|
HEAP = new Uint8Array(Math.max(65536, HEAP.length + size, HEAP.length * 2));
|
||||||
@ -18,7 +18,7 @@ Object.defineProperties(globalScope["Heap"] = {
|
|||||||
},
|
},
|
||||||
dispose: function dispose() { },
|
dispose: function dispose() { },
|
||||||
copy: function copy(dest, src, n) {
|
copy: function copy(dest, src, n) {
|
||||||
HEAP.set(HEAP.subarray(src, src + n), dest);
|
HEAP.set(HEAP.subarray(src >>> 0, (src + n) >>> 0), dest >>> 0);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
@ -26,9 +26,6 @@ Object.defineProperties(globalScope["Heap"] = {
|
|||||||
free: { get: function get_free() { return HEAP.length - HEAP_OFFSET; } },
|
free: { get: function get_free() { return HEAP.length - HEAP_OFFSET; } },
|
||||||
size: { get: function get_size() { return HEAP.length; } }
|
size: { get: function get_size() { return HEAP.length; } }
|
||||||
});
|
});
|
||||||
globalScope["store"] = function store(ptr, val) {
|
|
||||||
binaryen.HEAPU8[ptr] = val;
|
globalScope["store"] = function store(ptr, val) { binaryen.HEAPU8[ptr] = val; };
|
||||||
};
|
globalScope["load"] = function load(ptr) { return binaryen.HEAPU8[ptr]; };
|
||||||
globalScope["load"] = function load(ptr) {
|
|
||||||
return binaryen.HEAPU8[ptr];
|
|
||||||
};
|
|
||||||
|
@ -12,15 +12,25 @@ var Module = require("../src/module").Module;
|
|||||||
var Parser = require("../src/parser").Parser;
|
var Parser = require("../src/parser").Parser;
|
||||||
|
|
||||||
var isCreate = process.argv[2] === "--create";
|
var isCreate = process.argv[2] === "--create";
|
||||||
var filter = process.argv.length > 2 && !isCreate ? "*" + process.argv[2] + "*.ts" : "*.ts";
|
var filter = process.argv.length > 2 && !isCreate ? "**/" + process.argv[2] + ".ts" : "**/*.ts";
|
||||||
|
|
||||||
|
var stdFiles = glob.sync("*.ts", { cwd: __dirname + "/../std/assembly" });
|
||||||
|
|
||||||
glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
|
glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
|
||||||
if (filename.charAt(0) == "_" || filename.endsWith(".fixture.ts"))
|
if (filename.charAt(0) == "_")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
console.log(chalk.default.whiteBright("Testing compiler/" + filename));
|
console.log(chalk.default.whiteBright("Testing compiler/" + filename));
|
||||||
|
|
||||||
|
var fixture = path.basename(filename, ".ts");
|
||||||
var parser = new Parser();
|
var parser = new Parser();
|
||||||
|
if (filename.startsWith("std/")) {
|
||||||
|
stdFiles.forEach(file => {
|
||||||
|
parser.parseFile(fs.readFileSync(__dirname + "/../std/assembly/" + file, { encoding: "utf8" }), file, false);
|
||||||
|
});
|
||||||
|
fixture = "std/" + fixture;
|
||||||
|
}
|
||||||
|
|
||||||
var sourceText = fs.readFileSync(__dirname + "/compiler/" + filename, { encoding: "utf8" });
|
var sourceText = fs.readFileSync(__dirname + "/compiler/" + filename, { encoding: "utf8" });
|
||||||
parser.parseFile(sourceText, filename, true);
|
parser.parseFile(sourceText, filename, true);
|
||||||
var nextFile;
|
var nextFile;
|
||||||
@ -38,7 +48,6 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
|
|||||||
var actual = module.toText() + "(;\n[program.elements]\n " + iterate(program.elements.keys()).join("\n ") + "\n[program.exports]\n " + iterate(program.exports.keys()).join("\n ") + "\n;)\n";
|
var actual = module.toText() + "(;\n[program.elements]\n " + iterate(program.elements.keys()).join("\n ") + "\n[program.exports]\n " + iterate(program.exports.keys()).join("\n ") + "\n;)\n";
|
||||||
var actualOptimized = null;
|
var actualOptimized = null;
|
||||||
var actualInlined = null;
|
var actualInlined = null;
|
||||||
var fixture = path.basename(filename, ".ts") + ".wast";
|
|
||||||
|
|
||||||
if (module.validate()) {
|
if (module.validate()) {
|
||||||
console.log(chalk.default.green("validate OK"));
|
console.log(chalk.default.green("validate OK"));
|
||||||
@ -59,27 +68,27 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isCreate) {
|
if (isCreate) {
|
||||||
fs.writeFileSync(__dirname + "/compiler/" + fixture, actual, { encoding: "utf8" });
|
fs.writeFileSync(__dirname + "/compiler/" + fixture + ".wast", actual, { encoding: "utf8" });
|
||||||
console.log("Created");
|
console.log("Created");
|
||||||
if (actualOptimized != null) {
|
if (actualOptimized != null) {
|
||||||
fs.writeFileSync(__dirname + "/compiler/" + path.basename(filename, ".ts") + ".optimized.wast", actualOptimized, { encoding: "utf8" });
|
fs.writeFileSync(__dirname + "/compiler/" + fixture + ".optimized.wast", actualOptimized, { encoding: "utf8" });
|
||||||
console.log("Created optimized");
|
console.log("Created optimized");
|
||||||
}
|
}
|
||||||
if (actualInlined != null) {
|
if (actualInlined != null) {
|
||||||
if (actualInlined != actualOptimized) {
|
if (actualInlined != actualOptimized) {
|
||||||
fs.writeFileSync(__dirname + "/compiler/" + path.basename(filename, ".ts") + ".optimized-inlined.wast", actualInlined, { encoding: "utf8" });
|
fs.writeFileSync(__dirname + "/compiler/" + fixture + ".optimized-inlined.wast", actualInlined, { encoding: "utf8" });
|
||||||
console.log("Created optimized & inlined");
|
console.log("Created optimized & inlined");
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(__dirname + "/compiler/" + path.basename(filename, ".ts") + ".optimized-inlined.wast");
|
fs.unlinkSync(__dirname + "/compiler/" + fixture + ".optimized-inlined.wast");
|
||||||
console.log("Deleted optimized & inlined");
|
console.log("Deleted optimized & inlined");
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
var expected = fs.readFileSync(__dirname + "/compiler/" + fixture, { encoding: "utf8" });
|
var expected = fs.readFileSync(__dirname + "/compiler/" + fixture + ".wast", { encoding: "utf8" });
|
||||||
var diffs = diff("compiler/" + fixture, expected, actual);
|
var diffs = diff(filename + ".wast", expected, actual);
|
||||||
if (diffs !== null) {
|
if (diffs !== null) {
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
console.log(diffs);
|
console.log(diffs);
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -56,6 +58,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
[program.exports]
|
[program.exports]
|
||||||
|
|
||||||
;)
|
;)
|
||||||
|
@ -818,6 +818,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -859,6 +861,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
binary/b
|
binary/b
|
||||||
binary/i
|
binary/i
|
||||||
binary/I
|
binary/I
|
||||||
|
@ -1035,6 +1035,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -1076,6 +1078,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
builtins/b
|
builtins/b
|
||||||
builtins/i
|
builtins/i
|
||||||
builtins/I
|
builtins/I
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -84,6 +86,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
class/Animal
|
class/Animal
|
||||||
class/Animal.MAX
|
class/Animal.MAX
|
||||||
class/Animal.add
|
class/Animal.add
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -49,6 +51,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
declare/external
|
declare/external
|
||||||
[program.exports]
|
[program.exports]
|
||||||
declare/external
|
declare/external
|
||||||
|
@ -53,6 +53,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -94,6 +96,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
do/loopDo
|
do/loopDo
|
||||||
do/loopDoInDo
|
do/loopDoInDo
|
||||||
[program.exports]
|
[program.exports]
|
||||||
|
@ -38,6 +38,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -79,6 +81,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
enum/Implicit
|
enum/Implicit
|
||||||
enum/Explicit
|
enum/Explicit
|
||||||
enum/Mixed
|
enum/Mixed
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -73,6 +75,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
export/add
|
export/add
|
||||||
export/sub
|
export/sub
|
||||||
export/a
|
export/a
|
||||||
|
@ -149,6 +149,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -190,6 +192,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
for/i
|
for/i
|
||||||
[program.exports]
|
[program.exports]
|
||||||
|
|
||||||
|
@ -310,6 +310,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -351,6 +353,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
../../examples/game-of-life/assembly/game-of-life/w
|
../../examples/game-of-life/assembly/game-of-life/w
|
||||||
../../examples/game-of-life/assembly/game-of-life/h
|
../../examples/game-of-life/assembly/game-of-life/h
|
||||||
../../examples/game-of-life/assembly/game-of-life/s
|
../../examples/game-of-life/assembly/game-of-life/s
|
||||||
|
@ -1191,6 +1191,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -1232,6 +1234,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
../../examples/i64-polyfill/assembly/i64/lo
|
../../examples/i64-polyfill/assembly/i64/lo
|
||||||
../../examples/i64-polyfill/assembly/i64/hi
|
../../examples/i64-polyfill/assembly/i64/hi
|
||||||
../../examples/i64-polyfill/assembly/i64/getLo
|
../../examples/i64-polyfill/assembly/i64/getLo
|
||||||
|
@ -48,6 +48,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -89,6 +91,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
if/ifThenElse
|
if/ifThenElse
|
||||||
if/ifThen
|
if/ifThen
|
||||||
if/ifThenElseBlock
|
if/ifThenElseBlock
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -84,6 +86,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
export/add
|
export/add
|
||||||
export/sub
|
export/sub
|
||||||
export/a
|
export/a
|
||||||
|
@ -109,6 +109,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -150,6 +152,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
[program.exports]
|
[program.exports]
|
||||||
|
|
||||||
;)
|
;)
|
||||||
|
@ -141,6 +141,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -182,6 +184,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
[program.exports]
|
[program.exports]
|
||||||
|
|
||||||
;)
|
;)
|
||||||
|
@ -257,6 +257,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -298,6 +300,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
logical/i
|
logical/i
|
||||||
logical/I
|
logical/I
|
||||||
logical/f
|
logical/f
|
||||||
|
@ -2055,6 +2055,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -2096,6 +2098,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
memcpy/memcpy
|
memcpy/memcpy
|
||||||
memcpy/base
|
memcpy/base
|
||||||
memcpy/dest
|
memcpy/dest
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -60,6 +62,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
namespace/Outer
|
namespace/Outer
|
||||||
namespace/Outer.Inner
|
namespace/Outer.Inner
|
||||||
namespace/Outer.Inner.aVar
|
namespace/Outer.Inner.aVar
|
||||||
|
@ -331,6 +331,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -372,6 +374,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
portable-conversions/i
|
portable-conversions/i
|
||||||
portable-conversions/I
|
portable-conversions/I
|
||||||
portable-conversions/f
|
portable-conversions/f
|
||||||
|
@ -48,6 +48,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -89,6 +91,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
export/add
|
export/add
|
||||||
export/sub
|
export/sub
|
||||||
export/a
|
export/a
|
||||||
|
11
tests/compiler/std/array.optimized-inlined.wast
Normal file
11
tests/compiler/std/array.optimized-inlined.wast
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
(module
|
||||||
|
(type $v (func))
|
||||||
|
(memory $0 1)
|
||||||
|
(export "memory" (memory $0))
|
||||||
|
(start $start)
|
||||||
|
(func $start (; 0 ;) (type $v)
|
||||||
|
(block $__inlined_func$Array.test
|
||||||
|
(nop)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
12
tests/compiler/std/array.optimized.wast
Normal file
12
tests/compiler/std/array.optimized.wast
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
(module
|
||||||
|
(type $v (func))
|
||||||
|
(memory $0 1)
|
||||||
|
(export "memory" (memory $0))
|
||||||
|
(start $start)
|
||||||
|
(func $Array.test (; 0 ;) (type $v)
|
||||||
|
(nop)
|
||||||
|
)
|
||||||
|
(func $start (; 1 ;) (type $v)
|
||||||
|
(call $Array.test)
|
||||||
|
)
|
||||||
|
)
|
2
tests/compiler/std/array.ts
Normal file
2
tests/compiler/std/array.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Array.fromPtr<i32>(1);
|
||||||
|
Array.test();
|
75
tests/compiler/std/array.wast
Normal file
75
tests/compiler/std/array.wast
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
(module
|
||||||
|
(type $v (func))
|
||||||
|
(global $HEAP_START i32 (i32.const 4))
|
||||||
|
(memory $0 1)
|
||||||
|
(export "memory" (memory $0))
|
||||||
|
(start $start)
|
||||||
|
(func $Array.test (; 0 ;) (type $v)
|
||||||
|
)
|
||||||
|
(func $start (; 1 ;) (type $v)
|
||||||
|
(call $Array.test)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(;
|
||||||
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
|
isNaN
|
||||||
|
isFinite
|
||||||
|
clz
|
||||||
|
ctz
|
||||||
|
popcnt
|
||||||
|
rotl
|
||||||
|
rotr
|
||||||
|
abs
|
||||||
|
max
|
||||||
|
min
|
||||||
|
ceil
|
||||||
|
floor
|
||||||
|
copysign
|
||||||
|
nearest
|
||||||
|
reinterpret
|
||||||
|
sqrt
|
||||||
|
trunc
|
||||||
|
load
|
||||||
|
store
|
||||||
|
sizeof
|
||||||
|
select
|
||||||
|
unreachable
|
||||||
|
current_memory
|
||||||
|
grow_memory
|
||||||
|
parseInt
|
||||||
|
parseFloat
|
||||||
|
changetype
|
||||||
|
assert
|
||||||
|
i8
|
||||||
|
i16
|
||||||
|
i32
|
||||||
|
i64
|
||||||
|
u8
|
||||||
|
u16
|
||||||
|
u32
|
||||||
|
u64
|
||||||
|
bool
|
||||||
|
f32
|
||||||
|
f64
|
||||||
|
isize
|
||||||
|
usize
|
||||||
|
HEAP_START
|
||||||
|
Array
|
||||||
|
Array.fromPtr
|
||||||
|
Array.test
|
||||||
|
heap/ALIGN_LOG2
|
||||||
|
heap/ALIGN_SIZE
|
||||||
|
heap/ALIGN_MASK
|
||||||
|
heap/HEAP_OFFSET
|
||||||
|
Heap
|
||||||
|
Heap.allocate
|
||||||
|
Heap.dispose
|
||||||
|
Heap.get_used
|
||||||
|
Heap.get_free
|
||||||
|
Heap.get_size
|
||||||
|
Heap.copy
|
||||||
|
[program.exports]
|
||||||
|
|
||||||
|
;)
|
119
tests/compiler/std/heap.optimized-inlined.wast
Normal file
119
tests/compiler/std/heap.optimized-inlined.wast
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
(module
|
||||||
|
(type $ii (func (param i32) (result i32)))
|
||||||
|
(type $iv (func (param i32)))
|
||||||
|
(type $v (func))
|
||||||
|
(global $heap/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||||
|
(global $std/heap/ptr (mut i32) (i32.const 0))
|
||||||
|
(global $HEAP_START i32 (i32.const 4))
|
||||||
|
(memory $0 1)
|
||||||
|
(export "memory" (memory $0))
|
||||||
|
(start $start)
|
||||||
|
(func $Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32)
|
||||||
|
(local $1 i32)
|
||||||
|
(local $2 i32)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $1
|
||||||
|
(current_memory)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.gt_u
|
||||||
|
(i32.add
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
(i32.shl
|
||||||
|
(get_local $1)
|
||||||
|
(i32.const 16)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.lt_s
|
||||||
|
(grow_memory
|
||||||
|
(select
|
||||||
|
(tee_local $2
|
||||||
|
(i32.trunc_s/f64
|
||||||
|
(f64.ceil
|
||||||
|
(f64.div
|
||||||
|
(f64.convert_u/i32
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
(f64.const 65536)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(tee_local $1
|
||||||
|
(i32.sub
|
||||||
|
(i32.mul
|
||||||
|
(get_local $1)
|
||||||
|
(i32.const 2)
|
||||||
|
)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.gt_s
|
||||||
|
(get_local $2)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
(unreachable)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $1
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(block (result i32)
|
||||||
|
(set_global $heap/HEAP_OFFSET
|
||||||
|
(i32.add
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.and
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
(i32.const 7)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_global $heap/HEAP_OFFSET
|
||||||
|
(i32.add
|
||||||
|
(i32.or
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
(i32.const 7)
|
||||||
|
)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
(func $start (; 1 ;) (type $v)
|
||||||
|
(local $0 i32)
|
||||||
|
(set_global $heap/HEAP_OFFSET
|
||||||
|
(get_global $HEAP_START)
|
||||||
|
)
|
||||||
|
(set_global $std/heap/ptr
|
||||||
|
(call $Heap.allocate
|
||||||
|
(i32.const 10)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(block $__inlined_func$Heap.dispose
|
||||||
|
(set_local $0
|
||||||
|
(get_global $std/heap/ptr)
|
||||||
|
)
|
||||||
|
(nop)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
116
tests/compiler/std/heap.optimized.wast
Normal file
116
tests/compiler/std/heap.optimized.wast
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
(module
|
||||||
|
(type $ii (func (param i32) (result i32)))
|
||||||
|
(type $iv (func (param i32)))
|
||||||
|
(type $v (func))
|
||||||
|
(global $heap/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||||
|
(global $std/heap/ptr (mut i32) (i32.const 0))
|
||||||
|
(global $HEAP_START i32 (i32.const 4))
|
||||||
|
(memory $0 1)
|
||||||
|
(export "memory" (memory $0))
|
||||||
|
(start $start)
|
||||||
|
(func $Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32)
|
||||||
|
(local $1 i32)
|
||||||
|
(local $2 i32)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $1
|
||||||
|
(current_memory)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.gt_u
|
||||||
|
(i32.add
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
(i32.shl
|
||||||
|
(get_local $1)
|
||||||
|
(i32.const 16)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.lt_s
|
||||||
|
(grow_memory
|
||||||
|
(select
|
||||||
|
(tee_local $2
|
||||||
|
(i32.trunc_s/f64
|
||||||
|
(f64.ceil
|
||||||
|
(f64.div
|
||||||
|
(f64.convert_u/i32
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
(f64.const 65536)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(tee_local $1
|
||||||
|
(i32.sub
|
||||||
|
(i32.mul
|
||||||
|
(get_local $1)
|
||||||
|
(i32.const 2)
|
||||||
|
)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.gt_s
|
||||||
|
(get_local $2)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
(unreachable)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $1
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(block (result i32)
|
||||||
|
(set_global $heap/HEAP_OFFSET
|
||||||
|
(i32.add
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.and
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
(i32.const 7)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_global $heap/HEAP_OFFSET
|
||||||
|
(i32.add
|
||||||
|
(i32.or
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
(i32.const 7)
|
||||||
|
)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
(func $Heap.dispose (; 1 ;) (type $iv) (param $0 i32)
|
||||||
|
(nop)
|
||||||
|
)
|
||||||
|
(func $start (; 2 ;) (type $v)
|
||||||
|
(set_global $heap/HEAP_OFFSET
|
||||||
|
(get_global $HEAP_START)
|
||||||
|
)
|
||||||
|
(set_global $std/heap/ptr
|
||||||
|
(call $Heap.allocate
|
||||||
|
(i32.const 10)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call $Heap.dispose
|
||||||
|
(get_global $std/heap/ptr)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
2
tests/compiler/std/heap.ts
Normal file
2
tests/compiler/std/heap.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
let ptr: usize = Heap.allocate(10);
|
||||||
|
Heap.dispose(ptr);
|
191
tests/compiler/std/heap.wast
Normal file
191
tests/compiler/std/heap.wast
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
(module
|
||||||
|
(type $i (func (result i32)))
|
||||||
|
(type $ii (func (param i32) (result i32)))
|
||||||
|
(type $iv (func (param i32)))
|
||||||
|
(type $v (func))
|
||||||
|
(global $heap/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||||
|
(global $heap/ALIGN_LOG2 i32 (i32.const 3))
|
||||||
|
(global $heap/ALIGN_SIZE i32 (i32.const 8))
|
||||||
|
(global $heap/ALIGN_MASK i32 (i32.const 7))
|
||||||
|
(global $std/heap/ptr (mut i32) (i32.const 0))
|
||||||
|
(global $HEAP_START i32 (i32.const 4))
|
||||||
|
(memory $0 1)
|
||||||
|
(export "memory" (memory $0))
|
||||||
|
(start $start)
|
||||||
|
(func $Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32)
|
||||||
|
(local $1 i32)
|
||||||
|
(local $2 i32)
|
||||||
|
(local $3 i32)
|
||||||
|
(local $4 i32)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $1
|
||||||
|
(current_memory)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.gt_u
|
||||||
|
(i32.add
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
(i32.shl
|
||||||
|
(get_local $1)
|
||||||
|
(i32.const 16)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.lt_s
|
||||||
|
(grow_memory
|
||||||
|
(select
|
||||||
|
(tee_local $2
|
||||||
|
(i32.trunc_s/f64
|
||||||
|
(f64.ceil
|
||||||
|
(f64.div
|
||||||
|
(f64.convert_u/i32
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
(f64.const 65536)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(tee_local $3
|
||||||
|
(i32.sub
|
||||||
|
(i32.mul
|
||||||
|
(get_local $1)
|
||||||
|
(i32.const 2)
|
||||||
|
)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.gt_s
|
||||||
|
(get_local $2)
|
||||||
|
(get_local $3)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
(unreachable)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $4
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.and
|
||||||
|
(block (result i32)
|
||||||
|
(set_global $heap/HEAP_OFFSET
|
||||||
|
(i32.add
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
)
|
||||||
|
(i32.const 7)
|
||||||
|
)
|
||||||
|
(set_global $heap/HEAP_OFFSET
|
||||||
|
(i32.add
|
||||||
|
(i32.or
|
||||||
|
(get_global $heap/HEAP_OFFSET)
|
||||||
|
(i32.const 7)
|
||||||
|
)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(get_local $4)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(func $Heap.dispose (; 1 ;) (type $iv) (param $0 i32)
|
||||||
|
)
|
||||||
|
(func $start (; 2 ;) (type $v)
|
||||||
|
(set_global $heap/HEAP_OFFSET
|
||||||
|
(get_global $HEAP_START)
|
||||||
|
)
|
||||||
|
(set_global $std/heap/ptr
|
||||||
|
(call $Heap.allocate
|
||||||
|
(i32.const 10)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call $Heap.dispose
|
||||||
|
(get_global $std/heap/ptr)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(;
|
||||||
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
|
isNaN
|
||||||
|
isFinite
|
||||||
|
clz
|
||||||
|
ctz
|
||||||
|
popcnt
|
||||||
|
rotl
|
||||||
|
rotr
|
||||||
|
abs
|
||||||
|
max
|
||||||
|
min
|
||||||
|
ceil
|
||||||
|
floor
|
||||||
|
copysign
|
||||||
|
nearest
|
||||||
|
reinterpret
|
||||||
|
sqrt
|
||||||
|
trunc
|
||||||
|
load
|
||||||
|
store
|
||||||
|
sizeof
|
||||||
|
select
|
||||||
|
unreachable
|
||||||
|
current_memory
|
||||||
|
grow_memory
|
||||||
|
parseInt
|
||||||
|
parseFloat
|
||||||
|
changetype
|
||||||
|
assert
|
||||||
|
i8
|
||||||
|
i16
|
||||||
|
i32
|
||||||
|
i64
|
||||||
|
u8
|
||||||
|
u16
|
||||||
|
u32
|
||||||
|
u64
|
||||||
|
bool
|
||||||
|
f32
|
||||||
|
f64
|
||||||
|
isize
|
||||||
|
usize
|
||||||
|
HEAP_START
|
||||||
|
Array
|
||||||
|
Array.fromPtr
|
||||||
|
Array.test
|
||||||
|
heap/ALIGN_LOG2
|
||||||
|
heap/ALIGN_SIZE
|
||||||
|
heap/ALIGN_MASK
|
||||||
|
heap/HEAP_OFFSET
|
||||||
|
Heap
|
||||||
|
Heap.allocate
|
||||||
|
Heap.dispose
|
||||||
|
Heap.get_used
|
||||||
|
Heap.get_free
|
||||||
|
Heap.get_size
|
||||||
|
Heap.copy
|
||||||
|
std/heap/ptr
|
||||||
|
[program.exports]
|
||||||
|
|
||||||
|
;)
|
@ -147,6 +147,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -188,6 +190,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
switch/doSwitch
|
switch/doSwitch
|
||||||
switch/doSwitchDefaultFirst
|
switch/doSwitchDefaultFirst
|
||||||
switch/doSwitchDefaultOmitted
|
switch/doSwitchDefaultOmitted
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -76,6 +78,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
ternary/a
|
ternary/a
|
||||||
[program.exports]
|
[program.exports]
|
||||||
|
|
||||||
|
@ -330,6 +330,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -371,6 +373,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
tlsf/fls
|
tlsf/fls
|
||||||
tlsf/ffs
|
tlsf/ffs
|
||||||
tlsf/ALIGN_SIZE_LOG2
|
tlsf/ALIGN_SIZE_LOG2
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../std/assembly.json",
|
"extends": "../../std/assembly.json",
|
||||||
"include": [
|
"include": [
|
||||||
"./*.ts"
|
"./**/*.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -623,6 +623,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -664,6 +666,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
unary/i
|
unary/i
|
||||||
unary/I
|
unary/I
|
||||||
unary/f
|
unary/f
|
||||||
|
@ -62,6 +62,8 @@
|
|||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
[program.elements]
|
[program.elements]
|
||||||
|
NaN
|
||||||
|
Infinity
|
||||||
isNaN
|
isNaN
|
||||||
isFinite
|
isFinite
|
||||||
clz
|
clz
|
||||||
@ -103,6 +105,7 @@
|
|||||||
f64
|
f64
|
||||||
isize
|
isize
|
||||||
usize
|
usize
|
||||||
|
HEAP_START
|
||||||
while/loopWhile
|
while/loopWhile
|
||||||
while/loopWhileInWhile
|
while/loopWhileInWhile
|
||||||
[program.exports]
|
[program.exports]
|
||||||
|
Reference in New Issue
Block a user