Initial GC integration (#196)

This commit is contained in:
Daniel Wirtz 2018-08-02 18:23:02 +02:00 committed by GitHub
parent 671121bf70
commit dc0f271fc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
139 changed files with 7370 additions and 5016 deletions

View File

@ -90,11 +90,6 @@
"no-unsafe-any": {
"severity": "error"
},
"no-unused-variable": {
"options": [{
"ignore-pattern": "^_"
}]
},
"no-void-expression": {
"severity": "error"
},

View File

@ -65,7 +65,7 @@ Instances are automatically populated with useful utility:
```js
import "allocator/tlsf";
export { allocate_memory, free_memory };
export { memory };
```
* **getString**(ptr: `number`): `string`<br />
@ -126,7 +126,7 @@ var str = "Hello world!";
var ptr = module.newString(str);
// Disposing a string that is no longer needed (requires free_memory to be exported)
module.free_memory(ptr);
module.memory.free(ptr);
// Obtaining a string, i.e. as returned by an export
var ptrToString = ...;

View File

@ -44,8 +44,8 @@ export declare function instantiate<T extends {}>(module: WebAssembly.Module, im
/** Instantiates an AssemblyScript module from a buffer using the specified imports. */
export declare function instantiateBuffer<T extends {}>(buffer: Uint8Array, imports?: ImportsObject): ASUtil & T;
/** Instantiates an AssemblyScript module from a response using the sspecified imports. */
export declare function instantiateStreaming<T extends {}>(response: Response, imports?: ImportsObject): Promise<ASUtil & T>;
/** Instantiates an AssemblyScript module from a response using the specified imports. */
export declare function instantiateStreaming<T extends {}>(result: Promise<Response>, imports?: ImportsObject): Promise<ASUtil & T>;
/** Demangles an AssemblyScript module's exports to a friendly object structure. */
export declare function demangle<T extends {}>(exports: {}): T;

View File

@ -45,7 +45,7 @@ function instantiate(module, imports) {
/** Allocates a new string in the module's memory and returns its pointer. */
function newString(str) {
var dataLength = str.length;
var ptr = exports.allocate_memory(4 + (dataLength << 1));
var ptr = exports["memory.allocate"](4 + (dataLength << 1));
var dataOffset = (4 + ptr) >>> 1;
checkMem();
U32[ptr >>> 2] = dataLength;

View File

@ -4,6 +4,7 @@
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test:build": "asc tests/assembly/index.ts -b tests/build/untouched.wasm",
"test": "node tests"
},
"files": [

View File

@ -1,5 +1,7 @@
import "allocator/arena";
export { memory };
export const COLOR: string = "red";
export function strlen(str: string): i32 {
@ -14,7 +16,7 @@ export namespace math {
export class Car {
static readonly MAX_DOORS: i32 = 5;
static usualDoors: i32 = 3;
static readonly usualDoors: i32 = 3;
numDoors: i32;
private doorsOpen: bool = false;
@ -42,5 +44,3 @@ export class Car {
memory.free(changetype<usize>(this));
}
}
export { memory };

View File

@ -23,6 +23,7 @@ assert(typeof proto.getString === "function");
// should export memory
assert(module.memory instanceof WebAssembly.Memory);
assert(typeof module.memory.free === "function");
// should be able to get an exported string
assert.strictEqual(module.getString(module.COLOR), "red");

197
package-lock.json generated
View File

@ -66,9 +66,9 @@
"dev": true
},
"@types/node": {
"version": "10.5.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.2.tgz",
"integrity": "sha512-m9zXmifkZsMHZBOyxZWilMwmTlpC8x5Ty360JKTiXvlXZfBWYpsg9ZZvP/Ye+iZUh+Q+MxDLjItVTWIsfwz+8Q==",
"version": "10.5.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.4.tgz",
"integrity": "sha512-8TqvB0ReZWwtcd3LXq3YSrBoLyXFgBX/sBZfGye9+YS8zH7/g+i6QRIuiDmwBoTzcQ/pk89nZYTYU4c5akKkzw==",
"dev": true
},
"@types/shelljs": {
@ -664,9 +664,9 @@
"dev": true
},
"binaryen": {
"version": "49.0.0-nightly.20180718",
"resolved": "https://registry.npmjs.org/binaryen/-/binaryen-49.0.0-nightly.20180718.tgz",
"integrity": "sha512-r7gYKbwYYF5DBTN2fSomv1BNUNYSPros20eTng5MV/Bsv7V6DfJtrvietJ35p+jqI797P83vnJ0PEB1vTZ9qoQ=="
"version": "49.0.0-nightly.20180731",
"resolved": "https://registry.npmjs.org/binaryen/-/binaryen-49.0.0-nightly.20180731.tgz",
"integrity": "sha512-uZ7bizGTMbEOzIwZmGbXIcGFy8IkZjDoNOy+nPnIv7Dy1MiURItE0PRMnpXO2GPOOq6ZALW8pb5xb9MShD0zQQ=="
},
"bluebird": {
"version": "3.5.1",
@ -1053,9 +1053,9 @@
"dev": true
},
"commander": {
"version": "2.13.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz",
"integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==",
"version": "2.16.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.16.0.tgz",
"integrity": "sha512-sVXqklSaotK9at437sFlFpyOcJonxe0yST/AG9DkQKUdIE6IqGIMv4SfAQSKaJbSdVEJYItASCrBiVQHq1HQew==",
"dev": true
},
"commondir": {
@ -1231,7 +1231,8 @@
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
"integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=",
"dev": true
"dev": true,
"optional": true
},
"decode-uri-component": {
"version": "0.2.0",
@ -1382,9 +1383,9 @@
"dev": true
},
"eslint-scope": {
"version": "3.7.3",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.3.tgz",
"integrity": "sha512-W+B0SvF4gamyCTmUc+uITPY0989iXVfKvhwtmJocTaYoc/3khEHmEmvfY/Gn9HA9VV75jrQECsHizkNw1b68FA==",
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.0.tgz",
"integrity": "sha512-1G6UTDi7Jc1ELFwnR58HV4fK9OQK4S6N985f166xqXxpjU6plxFISJa2Ba9KCQuFa8RCnj/lSFJbHo7UFDBnUA==",
"dev": true,
"requires": {
"esrecurse": "^4.1.0",
@ -1392,9 +1393,9 @@
}
},
"esprima": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz",
"integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==",
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
"dev": true
},
"esrecurse": {
@ -2252,9 +2253,9 @@
}
},
"get-caller-file": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.2.tgz",
"integrity": "sha1-9wLmMSfn4jHBYKgMFVSstw1QR+U=",
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz",
"integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==",
"dev": true
},
"get-stream": {
@ -2305,9 +2306,9 @@
}
},
"global-modules-path": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/global-modules-path/-/global-modules-path-2.1.0.tgz",
"integrity": "sha512-3DrmGj2TP+96cABk9TfMp6f3knH/Y46dqvWznTU3Tf6/bDGLDAn15tFluQ7BcloykOcdY16U0WGq0BQblYOxJQ==",
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/global-modules-path/-/global-modules-path-2.3.0.tgz",
"integrity": "sha512-HchvMJNYh9dGSCy8pOQ2O8u/hoXaL+0XhnrwH0RyLiSXMMTl9W3N6KUU73+JFOg5PGjtzl6VZzUQsnrpm7Szag==",
"dev": true
},
"graceful-fs": {
@ -2771,9 +2772,9 @@
"dev": true
},
"js-yaml": {
"version": "3.11.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.11.0.tgz",
"integrity": "sha512-saJstZWv7oNeOyBh3+Dx1qWzhW0+e6/8eDzo7p5rDFqxntSztloLtuKu+Ejhtq82jsilwOIZYsCz+lIjthg1Hw==",
"version": "3.12.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz",
"integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==",
"dev": true,
"requires": {
"argparse": "^1.0.7",
@ -3728,9 +3729,9 @@
}
},
"rxjs": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.2.1.tgz",
"integrity": "sha512-OwMxHxmnmHTUpgO+V7dZChf3Tixf4ih95cmXjzzadULziVl/FKhHScGLj4goEw9weePVOH2Q0+GcCBUhKCZc/g==",
"version": "6.2.2",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.2.2.tgz",
"integrity": "sha512-0MI8+mkKAXZUF9vMrEoPnaoHkfzBPP4IGwUYRJhIRJF6/w3uByO1e91bEHn8zd43RdkTMKiooYKmwz7RH6zfOQ==",
"dev": true,
"requires": {
"tslib": "^1.9.0"
@ -4074,9 +4075,9 @@
}
},
"stream-each": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/stream-each/-/stream-each-1.2.2.tgz",
"integrity": "sha512-mc1dbFhGBxvTM3bIWmAAINbqiuAk9TATcfIQC8P+/+HJefgaiTlMn2dHvkX8qlI12KeYKSQ1Ua9RrIqrn1VPoA==",
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/stream-each/-/stream-each-1.2.3.tgz",
"integrity": "sha512-vlMC2f8I2u/bZGqkdfLQW/13Zihpej/7PmSiMQsbYddxuTsJp8vRe2x2FvVExZg7FaOds43ROAuFJwPR4MTZLw==",
"dev": true,
"requires": {
"end-of-stream": "^1.1.0",
@ -4280,15 +4281,15 @@
}
},
"tslib": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.0.tgz",
"integrity": "sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==",
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==",
"dev": true
},
"tslint": {
"version": "5.10.0",
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.10.0.tgz",
"integrity": "sha1-EeJrzLiK+gLdDZlWyuPUVAtfVMM=",
"version": "5.11.0",
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.11.0.tgz",
"integrity": "sha1-mPMMAurjzecAYgHkwzywi0hYHu0=",
"dev": true,
"requires": {
"babel-code-frame": "^6.22.0",
@ -4302,13 +4303,13 @@
"resolve": "^1.3.2",
"semver": "^5.3.0",
"tslib": "^1.8.0",
"tsutils": "^2.12.1"
"tsutils": "^2.27.2"
}
},
"tsutils": {
"version": "2.26.2",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.26.2.tgz",
"integrity": "sha512-uzwnhmrSbyinPCiwfzGsOY3IulBTwoky7r83HmZdz9QNCjhSCzavkh47KLWuU0zF2F2WbpmmzoJUIEiYyd+jEQ==",
"version": "2.29.0",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz",
"integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==",
"dev": true,
"requires": {
"tslib": "^1.8.1"
@ -4366,15 +4367,15 @@
"dev": true
},
"typedoc-plugin-external-module-name": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/typedoc-plugin-external-module-name/-/typedoc-plugin-external-module-name-1.1.1.tgz",
"integrity": "sha512-Erc0MyKDGYIN7kSlIjgifVieZEogg8YwOH8bjW6RXb0y44hVeTER0UoW6Rh+n8leg6rvlPdnH092aFfcd8kRlA==",
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/typedoc-plugin-external-module-name/-/typedoc-plugin-external-module-name-1.1.3.tgz",
"integrity": "sha512-/VMawTW4NnUUsgq0o8O37y9MmXFaOCDrH1dvDg7SZUS5ZSpUPSILVWwGJP+7g4I8vKZ5bBKZKHfPIEA4xUC+PQ==",
"dev": true
},
"typescript": {
"version": "2.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==",
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.0.1.tgz",
"integrity": "sha512-zQIMOmC+372pC/CCVLqnQ0zSBiY7HHodU7mpQdjiZddek4GMj31I3dUJ7gAs9o65X7mnRma6OokOkc6f9jjfBg==",
"dev": true
},
"uglify-es": {
@ -4387,6 +4388,12 @@
"source-map": "~0.6.1"
},
"dependencies": {
"commander": {
"version": "2.13.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz",
"integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==",
"dev": true
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
@ -4615,9 +4622,9 @@
}
},
"webpack": {
"version": "4.16.0",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-4.16.0.tgz",
"integrity": "sha512-oNx9djAd6uAcccyfqN3hyXLNMjZHiRySZmBQ4c8FNmf1SNJGhx7n9TSvHNyXxgToRdH65g/Q97s94Ip9N6F7xg==",
"version": "4.16.3",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-4.16.3.tgz",
"integrity": "sha512-3VcrVoFgzSz1IYgga71YpU3HO89Al5bSnDOj9RJQPsy+FNyI1sFsUyJITn3pktNuaRBlQT0usvKZE3GgkPGAIw==",
"dev": true,
"requires": {
"@webassemblyjs/ast": "1.5.13",
@ -4631,7 +4638,7 @@
"ajv-keywords": "^3.1.0",
"chrome-trace-event": "^1.0.0",
"enhanced-resolve": "^4.1.0",
"eslint-scope": "^3.7.1",
"eslint-scope": "^4.0.0",
"json-parse-better-errors": "^1.0.2",
"loader-runner": "^2.3.0",
"loader-utils": "^1.1.0",
@ -4661,9 +4668,9 @@
}
},
"webpack-cli": {
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/webpack-cli/-/webpack-cli-3.0.8.tgz",
"integrity": "sha512-KnRLJ0BUaYRqrhAMb9dv3gzdmhmgIMKo0FmdsnmfqbPGtLnnZ6tORZAvmmKfr+A0VgiVpqC60Gv7Ofg0R2CHtQ==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/webpack-cli/-/webpack-cli-3.1.0.tgz",
"integrity": "sha512-p5NeKDtYwjZozUWq6kGNs9w+Gtw/CPvyuXjXn2HMdz8Tie+krjEg8oAtonvIyITZdvpF7XG9xDHwscLr2c+ugQ==",
"dev": true,
"requires": {
"chalk": "^2.4.1",
@ -4676,7 +4683,7 @@
"loader-utils": "^1.1.0",
"supports-color": "^5.4.0",
"v8-compile-cache": "^2.0.0",
"yargs": "^11.1.0"
"yargs": "^12.0.1"
}
},
"webpack-sources": {
@ -4772,6 +4779,12 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
},
"xregexp": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/xregexp/-/xregexp-4.0.0.tgz",
"integrity": "sha512-PHyM+sQouu7xspQQwELlGwwd05mXUFqwFYfqPO0cC7x4fxyHnnuetmQr6CjJiafIDoH4MogHb9dOoJzR/Y4rFg==",
"dev": true
},
"xtend": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
@ -4791,14 +4804,14 @@
"dev": true
},
"yargs": {
"version": "11.1.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-11.1.0.tgz",
"integrity": "sha512-NwW69J42EsCSanF8kyn5upxvjp5ds+t3+udGBeTbFnERA+lF541DDpMawzo4z6W/QrzNM18D+BPMiOBibnFV5A==",
"version": "12.0.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.1.tgz",
"integrity": "sha512-B0vRAp1hRX4jgIOWFtjfNjd9OA9RWYZ6tqGA9/I/IrTMsxmKvtWy+ersM+jzpQqbC3YfLzeABPdeTgcJ9eu1qQ==",
"dev": true,
"requires": {
"cliui": "^4.0.0",
"decamelize": "^1.1.1",
"find-up": "^2.1.0",
"decamelize": "^2.0.0",
"find-up": "^3.0.0",
"get-caller-file": "^1.0.1",
"os-locale": "^2.0.0",
"require-directory": "^2.1.1",
@ -4806,22 +4819,68 @@
"set-blocking": "^2.0.0",
"string-width": "^2.0.0",
"which-module": "^2.0.0",
"y18n": "^3.2.1",
"yargs-parser": "^9.0.2"
"y18n": "^3.2.1 || ^4.0.0",
"yargs-parser": "^10.1.0"
},
"dependencies": {
"y18n": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz",
"integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE=",
"decamelize": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-2.0.0.tgz",
"integrity": "sha512-Ikpp5scV3MSYxY39ymh45ZLEecsTdv/Xj2CaQfI8RLMuwi7XvjX9H/fhraiSuU+C5w5NTDu4ZU72xNiZnurBPg==",
"dev": true,
"requires": {
"xregexp": "4.0.0"
}
},
"find-up": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz",
"integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==",
"dev": true,
"requires": {
"locate-path": "^3.0.0"
}
},
"locate-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz",
"integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==",
"dev": true,
"requires": {
"p-locate": "^3.0.0",
"path-exists": "^3.0.0"
}
},
"p-limit": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.0.0.tgz",
"integrity": "sha512-fl5s52lI5ahKCernzzIyAP0QAZbGIovtVHGwpcu1Jr/EpzLVDI2myISHwGqK7m8uQFugVWSrbxH7XnhGtvEc+A==",
"dev": true,
"requires": {
"p-try": "^2.0.0"
}
},
"p-locate": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz",
"integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==",
"dev": true,
"requires": {
"p-limit": "^2.0.0"
}
},
"p-try": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz",
"integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==",
"dev": true
}
}
},
"yargs-parser": {
"version": "9.0.2",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-9.0.2.tgz",
"integrity": "sha1-nM9qQ0YP5O1Aqbto9I1DuKaMwHc=",
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-10.1.0.tgz",
"integrity": "sha512-VCIyR1wJoEBZUqk5PA+oOBF6ypbwh5aNB3I50guxAL/quggdfs4TtNHQrSazFA3fYZ+tEqfs0zIGlv0c/rgjbQ==",
"dev": true,
"requires": {
"camelcase": "^4.1.0"

View File

@ -12,22 +12,22 @@
},
"dependencies": {
"@protobufjs/utf8": "^1.1.0",
"binaryen": "49.0.0-nightly.20180718",
"binaryen": "49.0.0-nightly.20180731",
"long": "^4.0.0"
},
"devDependencies": {
"@types/node": "^10.5.2",
"@types/node": "^10.5.4",
"browser-process-hrtime": "^0.1.2",
"diff": "^3.5.0",
"glob": "^7.1.2",
"ts-loader": "^4.4.2",
"ts-node": "^6.2.0",
"tslint": "^5.10.0",
"tslint": "^5.11.0",
"typedoc": "^0.11.1",
"typedoc-plugin-external-module-name": "^1.1.1",
"typescript": "^2.9.2",
"webpack": "^4.16.0",
"webpack-cli": "^3.0.8"
"typedoc-plugin-external-module-name": "^1.1.3",
"typescript": "^3.0.1",
"webpack": "^4.16.3",
"webpack-cli": "^3.1.0"
},
"main": "index.js",
"types": "index.d.ts",

View File

@ -134,7 +134,7 @@ export function compileCall(
compiler.currentType = Type.bool;
if (!type) return module.createUnreachable();
let classType = type.classReference;
return classType != null && classType.lookupOverload(OperatorKind.INDEXED_GET) != null
return classType !== null && classType.lookupOverload(OperatorKind.INDEXED_GET) !== null
? module.createI32(1)
: module.createI32(0);
}
@ -175,6 +175,19 @@ export function compileCall(
compiler.currentType = Type.bool;
return module.createI32(getExpressionId(expr) == ExpressionId.Const ? 1 : 0);
}
case "isManaged": { // isManaged<T>() -> bool
if (!compiler.program.hasGC) {
compiler.currentType = Type.bool;
return module.createI32(0);
}
let type = evaluateConstantType(compiler, typeArguments, operands, reportNode);
compiler.currentType = Type.bool;
if (!type) return module.createUnreachable();
let classType = type.classReference;
return classType !== null && !classType.hasDecorator(DecoratorFlags.UNMANAGED)
? module.createI32(1)
: module.createI32(0);
}
// math
@ -2881,25 +2894,46 @@ export function compileAllocate(
assert(classInstance.program == program);
var module = compiler.module;
var options = compiler.options;
var allocateInstance = program.memoryAllocateInstance;
if (!allocateInstance) {
program.error(
DiagnosticCode.Cannot_find_name_0,
reportNode.range, "memory.allocate"
);
return module.createUnreachable();
}
if (!compiler.compileFunction(allocateInstance)) return module.createUnreachable();
compiler.currentType = classInstance.type;
return module.createCall(
allocateInstance.internalName, [
options.isWasm64
? module.createI64(classInstance.currentMemoryOffset)
: module.createI32(classInstance.currentMemoryOffset)
],
options.nativeSizeType
);
// __gc_allocate(size, markFn)
if (program.hasGC && classInstance.type.isManaged(program)) {
let allocateInstance = assert(program.gcAllocateInstance);
if (!compiler.compileFunction(allocateInstance)) return module.createUnreachable();
compiler.currentType = classInstance.type;
return module.createCall(
allocateInstance.internalName, [
options.isWasm64
? module.createI64(classInstance.currentMemoryOffset)
: module.createI32(classInstance.currentMemoryOffset),
module.createI32(
ensureGCHook(compiler, classInstance)
)
],
options.nativeSizeType
);
// memory.allocate(size)
} else {
let allocateInstance = program.memoryAllocateInstance;
if (!allocateInstance) {
program.error(
DiagnosticCode.Cannot_find_name_0,
reportNode.range, "memory.allocate"
);
return module.createUnreachable();
}
if (!compiler.compileFunction(allocateInstance)) return module.createUnreachable();
compiler.currentType = classInstance.type;
return module.createCall(
allocateInstance.internalName, [
options.isWasm64
? module.createI64(classInstance.currentMemoryOffset)
: module.createI32(classInstance.currentMemoryOffset)
],
options.nativeSizeType
);
}
}
/** Compiles an abort wired to the conditionally imported 'abort' function. */
@ -2921,7 +2955,7 @@ export function compileAbort(
? compiler.compileExpression(message, stringType, ConversionKind.IMPLICIT, WrapMode.NONE)
: stringType.toNativeZero(module);
var filenameArg = compiler.compileStaticString(reportNode.range.source.normalizedPath);
var filenameArg = compiler.ensureStaticString(reportNode.range.source.normalizedPath);
compiler.currentType = Type.void;
return module.createBlock(null, [
@ -2988,3 +3022,122 @@ export function compileIterateRoots(compiler: Compiler): void {
: module.createNop()
);
}
/** Ensures that the specified class's GC hook exists and returns its function table index. */
export function ensureGCHook(
compiler: Compiler,
classInstance: Class
): u32 {
var program = compiler.program;
assert(classInstance.type.isManaged(program));
// check if the GC hook has already been created
{
let existingIndex = classInstance.gcHookIndex;
if (existingIndex != <u32>-1) return existingIndex;
}
// check if the class implements a custom GC function (only valid for internals)
var members = classInstance.members;
if (classInstance.prototype.declaration.range.source.isLibrary) {
if (members !== null && members.has("__gc")) {
let gcPrototype = assert(members.get("__gc"));
assert(gcPrototype.kind == ElementKind.FUNCTION_PROTOTYPE);
let gcInstance = assert(program.resolver.resolveFunction(<FunctionPrototype>gcPrototype, null));
assert(gcInstance.is(CommonFlags.PRIVATE | CommonFlags.INSTANCE));
assert(!gcInstance.isAny(CommonFlags.AMBIENT | CommonFlags.VIRTUAL));
assert(gcInstance.signature.parameterTypes.length == 0);
assert(gcInstance.signature.returnType == Type.void);
gcInstance.internalName = classInstance.internalName + "~gc";
assert(compiler.compileFunction(gcInstance));
let index = compiler.ensureFunctionTableEntry(gcInstance);
classInstance.gcHookIndex = index;
return index;
}
}
var module = compiler.module;
var options = compiler.options;
var nativeSizeType = options.nativeSizeType;
var nativeSizeSize = options.usizeType.byteSize;
var body = new Array<ExpressionRef>();
// nothing to mark if 'this' is null
body.push(
module.createIf(
module.createUnary(
options.isWasm64
? UnaryOp.EqzI64
: UnaryOp.EqzI32,
module.createGetLocal(0, nativeSizeType)
),
module.createReturn()
)
);
// remember the function index so we don't recurse infinitely
var functionTable = compiler.functionTable;
var gcHookIndex = functionTable.length;
functionTable.push(0);
classInstance.gcHookIndex = gcHookIndex;
// if the class extends a base class, call its hook first (calls mark)
var baseInstance = classInstance.base;
if (baseInstance) {
assert(baseInstance.type.isManaged(program));
body.push(
module.createCallIndirect(
module.createI32(
ensureGCHook(compiler, <Class>baseInstance.type.classReference)
),
[
module.createGetLocal(0, nativeSizeType)
],
nativeSizeType == NativeType.I64 ? "Iv" : "iv"
)
);
// if this class is the top-most base class, mark the instance
} else {
body.push(
module.createCall(assert(program.gcMarkInstance).internalName, [
module.createGetLocal(0, nativeSizeType)
], NativeType.None)
);
}
// mark instances assigned to own fields that are again references
if (members) {
for (let member of members.values()) {
if (member.kind == ElementKind.FIELD) {
if ((<Field>member).parent === classInstance) {
let type = (<Field>member).type;
if (type.isManaged(program)) {
let offset = (<Field>member).memoryOffset;
assert(offset >= 0);
body.push(
module.createCall(assert(program.gcMarkInstance).internalName, [
module.createLoad(
nativeSizeSize,
false,
module.createGetLocal(0, nativeSizeType),
nativeSizeType,
offset
)
], NativeType.None)
);
}
}
}
}
}
// add the function to the module and return its table index
functionTable[gcHookIndex] = module.addFunction(
classInstance.internalName + "~gc",
compiler.ensureFunctionType(null, Type.void, options.usizeType),
null,
module.createBlock(null, body)
);
return gcHookIndex;
}

View File

@ -36,7 +36,8 @@ import {
getGetLocalIndex,
getBlockChildCount,
getBlockChild,
getBlockName
getBlockName,
needsExplicitUnreachable
} from "./module";
import {
@ -74,7 +75,7 @@ import {
} from "./program";
import {
Resolver
Resolver, ReportMode
} from "./resolver";
import {
@ -155,6 +156,8 @@ import {
} from "./types";
import {
writeI8,
writeI16,
writeI32,
writeI64,
writeF32,
@ -282,7 +285,7 @@ export class Compiler extends DiagnosticEmitter {
/** Map of already compiled static string segments. */
stringSegments: Map<string,MemorySegment> = new Map();
/** Function table being compiled. */
functionTable: Function[] = [];
functionTable: FunctionRef[] = [];
/** Argument count helper global. */
argcVar: GlobalRef = 0;
/** Argument count helper setter. */
@ -391,11 +394,7 @@ export class Compiler extends DiagnosticEmitter {
var functionTableSize = functionTable.length;
var functionTableExported = false;
if (functionTableSize) {
let entries = new Array<FunctionRef>(functionTableSize);
for (let i = 0; i < functionTableSize; ++i) {
entries[i] = functionTable[i].ref;
}
module.setFunctionTable(entries);
module.setFunctionTable(functionTable);
module.addTableExport("0", "table");
functionTableExported = true;
}
@ -1474,7 +1473,7 @@ export class Compiler extends DiagnosticEmitter {
// insert the trampoline if the function has optional parameters
func = this.ensureTrampoline(func);
}
functionTable.push(func);
functionTable.push(func.ref);
func.functionTableIndex = index;
return index;
}
@ -1581,7 +1580,10 @@ export class Compiler extends DiagnosticEmitter {
default: stmts.push(stmt);
case ExpressionId.Nop:
}
if (flow.isAny(FlowFlags.ANY_TERMINATING)) break;
if (flow.isAny(FlowFlags.ANY_TERMINATING)) {
if (needsExplicitUnreachable(stmt)) stmts.push(this.module.createUnreachable());
break;
}
}
return stmts;
}
@ -1682,7 +1684,7 @@ export class Compiler extends DiagnosticEmitter {
);
parentFlow.inherit(flow);
return module.createBlock(breakLabel, [
var block: ExpressionRef[] = [
module.createLoop(continueLabel,
terminated
? body // skip trailing continue if unnecessary
@ -1691,7 +1693,9 @@ export class Compiler extends DiagnosticEmitter {
module.createBreak(continueLabel, condExpr)
], NativeType.None)
)
], terminated ? NativeType.Unreachable : NativeType.None);
];
if (terminated) block.push(module.createUnreachable());
return module.createBlock(breakLabel, block);
}
compileEmptyStatement(statement: EmptyStatement): ExpressionRef {
@ -1754,7 +1758,10 @@ export class Compiler extends DiagnosticEmitter {
var incrExpr = statement.incrementor
? this.compileExpression(<Expression>statement.incrementor, Type.void, ConversionKind.IMPLICIT, WrapMode.NONE)
: 0;
var bodyExpr = this.compileStatement(statement.statement);
var bodyStatement = statement.statement;
var bodyExpr = bodyStatement.kind == NodeKind.BLOCK && (<BlockStatement>bodyStatement).statements.length == 1
? this.compileStatement((<BlockStatement>bodyStatement).statements[0])
: this.compileStatement(bodyStatement);
// Switch back to the parent flow
currentFunction.flow = flow.free();
@ -1766,7 +1773,6 @@ export class Compiler extends DiagnosticEmitter {
FlowFlags.CONTINUES |
FlowFlags.CONDITIONALLY_CONTINUES
);
var terminated = alwaysTrue && flow.isAny(FlowFlags.ANY_TERMINATING);
if (alwaysTrue) parentFlow.inherit(flow);
else parentFlow.inheritConditional(flow);
@ -1793,18 +1799,10 @@ export class Compiler extends DiagnosticEmitter {
);
breakBlock.push(
module.createLoop(repeatLabel,
module.createBlock(null, repeatBlock, NativeType.None)
)
module.createLoop(repeatLabel, module.createBlock(null, repeatBlock, NativeType.None))
);
return module.createBlock(
breakLabel,
breakBlock,
terminated
? NativeType.Unreachable
: NativeType.None
);
return module.createBlock(breakLabel, breakBlock);
}
compileIfStatement(statement: IfStatement): ExpressionRef {
@ -2249,7 +2247,6 @@ export class Compiler extends DiagnosticEmitter {
var body = this.compileStatement(statement.statement);
var alwaysTrue = false; // TODO
var alwaysReturns = alwaysTrue && flow.is(FlowFlags.RETURNS);
var terminated = flow.isAny(FlowFlags.ANY_TERMINATING);
// Switch back to the parent flow
@ -2264,7 +2261,7 @@ export class Compiler extends DiagnosticEmitter {
if (alwaysTrue) parentFlow.inherit(flow);
else parentFlow.inheritConditional(flow);
var expr = module.createBlock(breakLabel, [
return module.createBlock(breakLabel, [
module.createLoop(continueLabel,
module.createIf(condExpr,
terminated
@ -2275,8 +2272,7 @@ export class Compiler extends DiagnosticEmitter {
], NativeType.None)
)
)
], alwaysReturns ? NativeType.Unreachable : NativeType.None);
return expr;
]);
}
// expressions
@ -4808,6 +4804,7 @@ export class Compiler extends DiagnosticEmitter {
);
let tempLocalIndex = tempLocal.index;
// TODO: simplify if valueWithCorrectType has no side effects
// TODO: call __gc_link here if a GC is present
return module.createBlock(null, [
module.createSetLocal(tempLocalIndex, valueWithCorrectType),
module.createStore(
@ -4820,6 +4817,7 @@ export class Compiler extends DiagnosticEmitter {
module.createGetLocal(tempLocalIndex, nativeType)
], nativeType);
} else {
// TODO: call __gc_link here if a GC is present
return module.createStore(
type.byteSize,
thisExpr,
@ -5107,7 +5105,11 @@ export class Compiler extends DiagnosticEmitter {
// indirect call: index argument with signature (non-generic, can't be inlined)
case ElementKind.LOCAL: {
if (signature = (<Local>target).type.signatureReference) {
indexArg = module.createGetLocal((<Local>target).index, NativeType.I32);
if ((<Local>target).is(CommonFlags.INLINED)) {
indexArg = module.createI32(i64_low((<Local>target).constantIntegerValue));
} else {
indexArg = module.createGetLocal((<Local>target).index, NativeType.I32);
}
break;
} else {
this.error(
@ -6094,6 +6096,7 @@ export class Compiler extends DiagnosticEmitter {
return this.compileArrayLiteral(
assert(classType.typeArguments)[0],
(<ArrayLiteralExpression>expression).elementExpressions,
false, // TODO: isConst?
expression
);
}
@ -6204,7 +6207,7 @@ export class Compiler extends DiagnosticEmitter {
}
case LiteralKind.STRING: {
assert(!implicitNegate);
return this.compileStaticString((<StringLiteralExpression>expression).value);
return this.compileStringLiteral(<StringLiteralExpression>expression);
}
case LiteralKind.OBJECT: {
assert(!implicitNegate);
@ -6220,241 +6223,282 @@ export class Compiler extends DiagnosticEmitter {
return module.createUnreachable();
}
compileStaticString(stringValue: string): ExpressionRef {
/** Ensures that the specified string exists in static memory and returns a pointer to it. */
ensureStaticString(stringValue: string): ExpressionRef {
var program = this.program;
var module = this.module;
var options = this.options;
var stringSegments = this.stringSegments;
var needsGCHeader = program.hasGC;
var stringSegment: MemorySegment | null = stringSegments.get(stringValue);
if (!stringSegment) {
var stringSegment: MemorySegment;
var stringOffset: I64;
if (!stringSegments.has(stringValue)) {
let stringLength = stringValue.length;
let stringBuffer = new Uint8Array(4 + stringLength * 2);
stringBuffer[0] = stringLength & 0xff;
stringBuffer[1] = (stringLength >>> 8) & 0xff;
stringBuffer[2] = (stringLength >>> 16) & 0xff;
stringBuffer[3] = (stringLength >>> 24) & 0xff;
let stringSize = 4 + stringLength * 2;
let offset = 0;
let gcHeaderSize = program.gcHeaderSize;
if (needsGCHeader) {
stringSize += gcHeaderSize;
offset += gcHeaderSize;
}
let stringBuffer = new Uint8Array(stringSize);
stringBuffer[offset ] = stringLength & 0xff;
stringBuffer[offset + 1] = (stringLength >>> 8) & 0xff;
stringBuffer[offset + 2] = (stringLength >>> 16) & 0xff;
stringBuffer[offset + 3] = (stringLength >>> 24) & 0xff;
for (let i = 0; i < stringLength; ++i) {
stringBuffer[4 + i * 2] = stringValue.charCodeAt(i) & 0xff;
stringBuffer[5 + i * 2] = (stringValue.charCodeAt(i) >>> 8) & 0xff;
stringBuffer[offset + 4 + i * 2] = stringValue.charCodeAt(i) & 0xff;
stringBuffer[offset + 5 + i * 2] = (stringValue.charCodeAt(i) >>> 8) & 0xff;
}
stringSegment = this.addMemorySegment(stringBuffer, options.usizeType.byteSize);
stringSegments.set(stringValue, stringSegment);
if (needsGCHeader) {
stringOffset = i64_add(stringSegment.offset, i64_new(gcHeaderSize, 0));
} else {
stringOffset = stringSegment.offset;
}
} else {
stringSegment = <MemorySegment>stringSegments.get(stringValue);
stringOffset = stringSegment.offset;
}
if (program.typesLookup.has("string")) {
let stringType = <Type>program.typesLookup.get("string");
this.currentType = stringType;
} else {
this.currentType = options.usizeType;
}
var stringOffset = stringSegment.offset;
var stringType = this.program.typesLookup.get("string");
this.currentType = stringType ? stringType : options.usizeType;
if (options.isWasm64) {
return module.createI64(i64_low(stringOffset), i64_high(stringOffset));
} else {
assert(i64_is_i32(stringOffset));
return module.createI32(i64_low(stringOffset));
}
assert(i64_is_i32(stringOffset));
return module.createI32(i64_low(stringOffset));
}
compileArrayLiteral(elementType: Type, expressions: (Expression | null)[], reportNode: Node): ExpressionRef {
var isStatic = true;
compileStringLiteral(expression: StringLiteralExpression): ExpressionRef {
return this.ensureStaticString(expression.value);
}
/** Ensures that the specified array exists in static memory and returns a pointer to it. */
ensureStaticArray(elementType: Type, values: ExpressionRef[]): ExpressionRef {
var length = values.length;
var byteSize = elementType.byteSize;
var byteLength = length * byteSize;
var usizeTypeSize = this.options.usizeType.byteSize;
// determine the size of the Array header
var arrayHeaderSize = (usizeTypeSize + 4 + 7) & ~7; // .buffer_ + .length_ + alignment
var arrayTotalSize = arrayHeaderSize;
// determine the size of the ArrayBuffer
var bufferHeaderSize = (4 + 7) & ~7; // .byteLength + alignment
var bufferTotalSize = 1 << (32 - clz(byteLength + bufferHeaderSize - 1)); // see internals
var program = this.program;
var needsGC = program.hasGC;
var gcHeaderSize = program.gcHeaderSize;
var offset = 0;
if (needsGC) {
offset += gcHeaderSize; // start writing after GC header
arrayTotalSize += gcHeaderSize;
bufferTotalSize += gcHeaderSize;
}
// create a compound segment holding both the the Array header and the ArrayBuffer
var buffer = new Uint8Array(arrayHeaderSize + bufferTotalSize);
var segment = this.addMemorySegment(buffer);
// write the Array header first
if (usizeTypeSize == 8) {
writeI64(i64_add(segment.offset, i64_new(arrayHeaderSize)), buffer, offset); // .buffer_
offset += 8;
} else {
assert(i64_is_u32(segment.offset));
writeI32(i64_low(segment.offset) + arrayHeaderSize, buffer, offset); // .buffer_
offset += 4;
}
writeI32(length, buffer, offset); // .length_
offset += 4;
assert(((offset + 7) & ~7) == arrayTotalSize); // incl. GC header if applicable
// append the ArrayBuffer
offset = arrayTotalSize;
if (needsGC) offset += gcHeaderSize;
writeI32(byteLength, buffer, offset); // .byteLength
offset += bufferHeaderSize; // align
var nativeType = elementType.toNativeType();
switch (nativeType) {
case NativeType.I32: {
switch (byteSize) {
case 1: {
for (let i = 0; i < length; ++i) {
let value = values[i];
assert(getExpressionType(value) == nativeType);
assert(getExpressionId(value) == ExpressionId.Const);
writeI8(getConstValueI32(value), buffer, offset);
offset += 1;
}
break;
}
case 2: {
for (let i = 0; i < length; ++i) {
let value = values[i];
assert(getExpressionType(value) == nativeType);
assert(getExpressionId(value) == ExpressionId.Const);
writeI16(getConstValueI32(value), buffer, offset);
offset += 2;
}
break;
}
case 4: {
for (let i = 0; i < length; ++i) {
let value = values[i];
assert(getExpressionType(value) == nativeType);
assert(getExpressionId(value) == ExpressionId.Const);
writeI32(getConstValueI32(value), buffer, offset);
offset += 4;
}
break;
}
default: assert(false);
}
break;
}
case NativeType.I64: {
for (let i = 0; i < length; ++i) {
let value = values[i];
assert(getExpressionType(value) == nativeType);
assert(getExpressionId(value) == ExpressionId.Const);
writeI64(i64_new(getConstValueI64Low(value), getConstValueI64High(value)), buffer, offset);
offset += 8;
}
break;
}
case NativeType.F32: {
for (let i = 0; i < length; ++i) {
let value = values[i];
assert(getExpressionType(value) == nativeType);
assert(getExpressionId(value) == ExpressionId.Const);
writeF32(getConstValueF32(value), buffer, offset);
offset += 4;
}
break;
}
case NativeType.F64: {
for (let i = 0; i < length; ++i) {
let value = values[i];
assert(getExpressionType(value) == nativeType);
assert(getExpressionId(value) == ExpressionId.Const);
writeF64(getConstValueF64(value), buffer, offset);
offset += 8;
}
break;
}
default: assert(false);
}
assert(offset <= arrayTotalSize + bufferTotalSize); // might have empty trailing space
var arrayPrototype = this.program.arrayPrototype;
if (arrayPrototype) {
let arrayInstance = this.resolver.resolveClass(arrayPrototype, [ elementType ], null, ReportMode.REPORT);
if (!arrayInstance) {
this.currentType = this.options.usizeType;
return this.module.createUnreachable();
}
this.currentType = arrayInstance.type;
} else {
this.currentType = this.options.usizeType;
}
// return a pointer at the array header (skip GC header if present)
var address = segment.offset;
if (needsGC) address = i64_add(address, i64_new(gcHeaderSize, 0));
if (usizeTypeSize == 8) {
return this.module.createI64(i64_low(address), i64_high(address));
} else {
assert(i64_is_u32(address));
return this.module.createI32(i64_low(address));
}
}
compileArrayLiteral(
elementType: Type,
expressions: (Expression | null)[],
isConst: bool,
reportNode: Node
): ExpressionRef {
var module = this.module;
// obtain the array type
// find out whether all elements are constant (array is static)
var length = expressions.length;
var values = new Array<ExpressionRef>(length);
var nativeElementType = elementType.toNativeType();
var isStatic = true;
for (let i = 0; i < length; ++i) {
values[i] = expressions[i]
? this.compileExpression(<Expression>expressions[i], elementType, ConversionKind.IMPLICIT, WrapMode.NONE)
: elementType.toNativeZero(module);
if (isStatic) {
let expr = module.precomputeExpression(values[i]);
if (getExpressionId(expr) == ExpressionId.Const) {
assert(getExpressionType(expr) == nativeElementType);
} else {
if (isConst) {
this.warning(
DiagnosticCode.Compiling_constant_with_non_constant_initializer_as_mutable,
reportNode.range
);
}
isStatic = false;
}
}
}
// make a static array if possible
if (isStatic) return this.ensureStaticArray(elementType, values);
// otherwise obtain the array type
var arrayPrototype = assert(this.program.arrayPrototype);
if (!arrayPrototype || arrayPrototype.kind != ElementKind.CLASS_PROTOTYPE) return module.createUnreachable();
var arrayInstance = this.resolver.resolveClass(<ClassPrototype>arrayPrototype, [ elementType ]);
if (!arrayInstance) return module.createUnreachable();
var arrayType = arrayInstance.type;
var elementCount = expressions.length;
if (elementCount) { // non-empty static or dynamic
let nativeElementType = elementType.toNativeType();
let values: usize;
let byteLength: usize;
switch (nativeElementType) {
case NativeType.I32: {
values = changetype<usize>(new Int32Array(elementCount));
byteLength = elementCount * 4;
break;
}
case NativeType.I64: {
values = changetype<usize>(new Array<I64>(elementCount));
byteLength = elementCount * 8;
break;
}
case NativeType.F32: {
values = changetype<usize>(new Float32Array(elementCount));
byteLength = elementCount * 4;
break;
}
case NativeType.F64: {
values = changetype<usize>(new Float64Array(elementCount));
byteLength = elementCount * 8;
break;
}
default: {
assert(false);
return module.createUnreachable();
}
}
// precompute value expressions
let exprs = new Array<ExpressionRef>(elementCount);
let expr: BinaryenExpressionRef;
for (let i = 0; i < elementCount; ++i) {
exprs[i] = expressions[i]
? this.compileExpression(<Expression>expressions[i], elementType, ConversionKind.IMPLICIT, WrapMode.NONE)
: elementType.toNativeZero(module);
if (isStatic) {
expr = module.precomputeExpression(exprs[i]);
if (getExpressionId(expr) == ExpressionId.Const) {
assert(getExpressionType(expr) == nativeElementType);
switch (nativeElementType) {
case NativeType.I32: {
changetype<i32[]>(values)[i] = getConstValueI32(expr);
break;
}
case NativeType.I64: {
changetype<I64[]>(values)[i] = i64_new(
getConstValueI64Low(expr),
getConstValueI64High(expr)
);
break;
}
case NativeType.F32: {
changetype<f32[]>(values)[i] = getConstValueF32(expr);
break;
}
case NativeType.F64: {
changetype<f64[]>(values)[i] = getConstValueF64(expr);
break;
}
default: assert(false); // checked above
}
} else {
// TODO: emit a warning if declared 'const'
// if (isConst) {
// this.warn(
// DiagnosticCode.Compiling_constant_with_non_constant_initializer_as_mutable,
// reportNode.range
// );
// }
isStatic = false;
}
}
}
let usizeTypeSize = this.options.usizeType.byteSize;
if (isStatic) { // non-empty, all elements can be precomputed
// Create a combined static memory segment composed of:
// Array struct + ArrayBuffer struct + aligned ArrayBuffer data
let arraySize = usizeTypeSize + 4; // buffer_ & length_
let bufferHeaderSize = (4 + 7) & ~7; // aligned byteLength (8)
let bufferTotalSize = 1 << (32 - clz(byteLength + bufferHeaderSize - 1)); // see internals
let data = new Uint8Array(arraySize + bufferTotalSize);
let segment = this.addMemorySegment(data);
let offset = 0;
// write Array struct
if (usizeTypeSize == 8) {
writeI64(i64_add(segment.offset, i64_new(arraySize)), data, offset); // buffer_ @ segment[arSize]
offset += 8;
} else {
assert(i64_high(segment.offset) == 0);
writeI32(i64_low(segment.offset) + arraySize, data, offset); // buffer_ @ segment[arSize]
offset += 4;
}
writeI32(elementCount, data, offset); // length_
offset += 4;
assert(offset == arraySize);
// write ArrayBuffer struct
writeI32(byteLength, data, offset);
offset += bufferHeaderSize; // incl. alignment
// write ArrayBuffer data
switch (nativeElementType) {
case NativeType.I32: {
for (let i = 0; i < elementCount; ++i) {
writeI32(changetype<i32[]>(values)[i], data, offset); offset += 4;
}
break;
}
case NativeType.I64: {
for (let i = 0; i < elementCount; ++i) {
writeI64(changetype<I64[]>(values)[i], data, offset); offset += 8;
}
break;
}
case NativeType.F32: {
for (let i = 0; i < elementCount; ++i) {
writeF32(changetype<f32[]>(values)[i], data, offset); offset += 4;
}
break;
}
case NativeType.F64: {
for (let i = 0; i < elementCount; ++i) {
writeF64(changetype<f64[]>(values)[i], data, offset); offset += 8;
}
break;
}
default: {
assert(false);
return module.createUnreachable();
}
}
assert(offset <= arraySize + bufferTotalSize);
this.currentType = arrayType;
return usizeTypeSize == 8
? module.createI64(
i64_low(segment.offset),
i64_high(segment.offset)
)
: module.createI32(
i64_low(segment.offset)
);
} else { // non-empty, some elements can't be precomputed
this.currentType = arrayType;
let setter = arrayInstance.lookupOverload(OperatorKind.INDEXED_SET, true);
if (!setter) {
this.error(
DiagnosticCode.Index_signature_in_type_0_only_permits_reading,
reportNode.range, arrayInstance.internalName
);
return module.createUnreachable();
}
let nativeArrayType = arrayType.toNativeType();
let currentFunction = this.currentFunction;
let tempLocal = currentFunction.getTempLocal(arrayType, false);
let stmts = new Array<ExpressionRef>(2 + elementCount);
let index = 0;
stmts[index++] = module.createSetLocal(tempLocal.index,
this.makeCallDirect(assert(arrayInstance.constructorInstance), [
module.createI32(0), // this
module.createI32(elementCount)
])
);
for (let i = 0; i < elementCount; ++i) {
stmts[index++] = this.makeCallDirect(setter, [
module.createGetLocal(tempLocal.index, nativeArrayType), // this
module.createI32(i),
exprs[i]
]);
}
assert(index + 1 == stmts.length);
stmts[index] = module.createGetLocal(tempLocal.index, nativeArrayType);
currentFunction.freeTempLocal(tempLocal);
this.currentType = arrayType;
return module.createBlock(null, stmts, nativeArrayType);
}
} else { // empty, TBD: cache this somehow?
this.currentType = arrayType;
return this.makeCallDirect(assert(arrayInstance.constructorInstance), [
// and compile an explicit instantiation
this.currentType = arrayType;
var setter = arrayInstance.lookupOverload(OperatorKind.INDEXED_SET, true);
if (!setter) {
this.error(
DiagnosticCode.Index_signature_in_type_0_only_permits_reading,
reportNode.range, arrayInstance.internalName
);
return module.createUnreachable();
}
var nativeArrayType = arrayType.toNativeType();
var currentFunction = this.currentFunction;
var tempLocal = currentFunction.getTempLocal(arrayType, false);
var stmts = new Array<ExpressionRef>(2 + length);
var index = 0;
stmts[index++] = module.createSetLocal(tempLocal.index,
this.makeCallDirect(assert(arrayInstance.constructorInstance), [
module.createI32(0), // this
module.createI32(0)
module.createI32(length)
])
);
for (let i = 0; i < length; ++i) {
stmts[index++] = this.makeCallDirect(setter, [
module.createGetLocal(tempLocal.index, nativeArrayType), // this
module.createI32(i),
values[i]
]);
}
assert(index + 1 == stmts.length);
stmts[index] = module.createGetLocal(tempLocal.index, nativeArrayType);
currentFunction.freeTempLocal(tempLocal);
this.currentType = arrayType;
return module.createBlock(null, stmts, nativeArrayType);
}
compileObjectLiteral(expression: ObjectLiteralExpression, contextualType: Type): ExpressionRef {

View File

@ -16,14 +16,14 @@ export type ImportRef = usize;
export type ExportRef = usize;
export type Index = u32;
export enum NativeType {
None = _BinaryenTypeNone(),
I32 = _BinaryenTypeInt32(),
I64 = _BinaryenTypeInt64(),
F32 = _BinaryenTypeFloat32(),
F64 = _BinaryenTypeFloat64(),
Unreachable = _BinaryenTypeUnreachable(),
Auto = _BinaryenTypeAuto()
export const enum NativeType {
None = 0, // _BinaryenTypeNone(),
I32 = 1, // _BinaryenTypeInt32(),
I64 = 2, // _BinaryenTypeInt64(),
F32 = 3, // _BinaryenTypeFloat32(),
F64 = 4, // _BinaryenTypeFloat64(),
Unreachable = 5, // _BinaryenTypeUnreachable(),
Auto = -1 // _BinaryenTypeAuto()
}
export enum ExpressionId {
@ -1580,3 +1580,26 @@ export class BinaryModule {
/** Source map, if generated. */
sourceMap: string | null;
}
/** Tests if an expression needs an explicit 'unreachable' when it is the terminating statement. */
export function needsExplicitUnreachable(expr: ExpressionRef): bool {
// not applicable if pushing a value to the stack
switch (_BinaryenExpressionGetType(expr)) {
case NativeType.I32:
case NativeType.I64:
case NativeType.F32:
case NativeType.F64: return false;
}
switch (_BinaryenExpressionGetId(expr)) {
case ExpressionId.Unreachable:
case ExpressionId.Return: return false;
case ExpressionId.Break: return _BinaryenBreakGetCondition(expr) != 0;
case ExpressionId.Block: {
if (!_BinaryenBlockGetName(expr)) { // can't break out of it
let numChildren = _BinaryenBlockGetNumChildren(expr); // last child needs unreachable
return numChildren > 0 && needsExplicitUnreachable(_BinaryenBlockGetChild(expr, numChildren - 1));
}
}
}
return true;
}

View File

@ -341,6 +341,17 @@ export class Program extends DiagnosticEmitter {
/** Memory allocation function. */
memoryAllocateInstance: Function | null = null;
/** Whether a garbage collector is present or not. */
hasGC: bool = false;
/** Garbage collector allocation function. */
gcAllocateInstance: Function | null = null;
/** Garbage collector link function called when a managed object is referenced from a parent. */
gcLinkInstance: Function | null = null;
/** Garbage collector mark function called to on reachable managed objects. */
gcMarkInstance: Function | null = null;
/** Size of a managed object header. */
gcHeaderSize: u32 = 0;
/** Currently processing filespace. */
currentFilespace: Filespace;
@ -658,6 +669,48 @@ export class Program extends DiagnosticEmitter {
}
}
}
// register GC hooks if present
if (
this.elementsLookup.has("__gc_allocate") &&
this.elementsLookup.has("__gc_link") &&
this.elementsLookup.has("__gc_mark")
) {
// __gc_allocate(usize, (ref: usize) => void): usize
let element = <Element>this.elementsLookup.get("__gc_allocate");
assert(element.kind == ElementKind.FUNCTION_PROTOTYPE);
let gcAllocateInstance = assert(this.resolver.resolveFunction(<FunctionPrototype>element, null));
let signature = gcAllocateInstance.signature;
assert(signature.parameterTypes.length == 2);
assert(signature.parameterTypes[0] == this.options.usizeType);
assert(signature.parameterTypes[1].signatureReference);
assert(signature.returnType == this.options.usizeType);
// __gc_link(usize, usize): void
element = <Element>this.elementsLookup.get("__gc_link");
assert(element.kind == ElementKind.FUNCTION_PROTOTYPE);
let gcLinkInstance = assert(this.resolver.resolveFunction(<FunctionPrototype>element, null));
signature = gcLinkInstance.signature;
assert(signature.parameterTypes.length == 2);
assert(signature.parameterTypes[0] == this.options.usizeType);
assert(signature.parameterTypes[1] == this.options.usizeType);
assert(signature.returnType == Type.void);
// __gc_mark(usize): void
element = <Element>this.elementsLookup.get("__gc_mark");
assert(element.kind == ElementKind.FUNCTION_PROTOTYPE);
let gcMarkInstance = assert(this.resolver.resolveFunction(<FunctionPrototype>element, null));
signature = gcMarkInstance.signature;
assert(signature.parameterTypes.length == 1);
assert(signature.parameterTypes[0] == this.options.usizeType);
assert(signature.returnType == Type.void);
this.gcAllocateInstance = gcAllocateInstance;
this.gcLinkInstance = gcLinkInstance;
this.gcMarkInstance = gcMarkInstance;
this.gcHeaderSize = (2 * options.usizeType.byteSize + 4 + 7) & ~7; // TODO: hardcoded atm
this.hasGC = true;
}
}
/** Sets a constant integer value. */
@ -2771,6 +2824,8 @@ export class Class extends Element {
constructorInstance: Function | null = null;
/** Operator overloads. */
overloads: Map<OperatorKind,Function> | null = null;
/** Function index of the GC hook. */
gcHookIndex: u32 = <u32>-1;
/** Constructs a new class. */
constructor(

View File

@ -377,7 +377,9 @@ export class Resolver extends DiagnosticEmitter {
case ElementKind.GLOBAL:
case ElementKind.LOCAL:
case ElementKind.FIELD: {
let classReference = (<VariableLikeElement>target).type.classReference;
let type = (<VariableLikeElement>target).type;
assert(type != Type.void);
let classReference = type.classReference;
if (!classReference) {
this.error(
DiagnosticCode.Property_0_does_not_exist_on_type_1,

View File

@ -5,7 +5,9 @@
import {
Class,
FunctionTarget
FunctionTarget,
Program,
DecoratorFlags
} from "./program";
import {
@ -134,6 +136,15 @@ export class Type {
}
}
/** Tests if this is a managed type that needs GC hooks. */
isManaged(program: Program): bool {
if (program.hasGC) {
let classReference = this.classReference;
return classReference !== null && !classReference.hasDecorator(DecoratorFlags.UNMANAGED);
}
return false;
}
/** Computes the sign-extending shift in the target type. */
computeSmallIntegerShift(targetType: Type): u32 {
return targetType.size - this.size;

View File

@ -1,5 +1,27 @@
/** @module util *//***/
/** Reads an 8-bit integer from the specified buffer. */
export function readI8(buffer: Uint8Array, offset: i32): i32 {
return buffer[offset];
}
/** Writes an 8-bit integer to the specified buffer. */
export function writeI8(value: i32, buffer: Uint8Array, offset: i32): void {
buffer[offset] = value;
}
/** Reads a 16-bit integer from the specified buffer. */
export function readI16(buffer: Uint8Array, offset: i32): i32 {
return buffer[offset ]
| buffer[offset + 1] << 8;
}
/** Writes a 16-bit integer to the specified buffer. */
export function writeI16(value: i32, buffer: Uint8Array, offset: i32): void {
buffer[offset ] = value;
buffer[offset + 1] = value >>> 8;
}
/** Reads a 32-bit integer from the specified buffer. */
export function readI32(buffer: Uint8Array, offset: i32): i32 {
return buffer[offset ]

View File

@ -1,8 +1,8 @@
import {
MAX_BLENGTH,
HEADER_SIZE as HEADER_SIZE_AB,
allocUnsafe,
reallocUnsafe,
HEADER_SIZE,
allocateUnsafe,
reallocateUnsafe,
loadUnsafe,
storeUnsafe
} from "./internal/arraybuffer";
@ -22,11 +22,11 @@ export class Array<T> {
const MAX_LENGTH = MAX_BLENGTH >>> alignof<T>();
if (<u32>length > <u32>MAX_LENGTH) throw new RangeError("Invalid array length");
var byteLength = length << alignof<T>();
var buffer = allocUnsafe(byteLength);
var buffer = allocateUnsafe(byteLength);
this.buffer_ = buffer;
this.length_ = length;
memory.fill(
changetype<usize>(buffer) + HEADER_SIZE_AB,
changetype<usize>(buffer) + HEADER_SIZE,
0,
<usize>byteLength
);
@ -42,7 +42,7 @@ export class Array<T> {
if (<u32>length > <u32>capacity) {
const MAX_LENGTH = MAX_BLENGTH >>> alignof<T>();
if (<u32>length > <u32>MAX_LENGTH) throw new RangeError("Invalid array length");
buffer = reallocUnsafe(buffer, length << alignof<T>());
buffer = reallocateUnsafe(buffer, length << alignof<T>());
this.buffer_ = buffer;
}
this.length_ = length;
@ -84,16 +84,18 @@ export class Array<T> {
if (<u32>index >= <u32>capacity) {
const MAX_LENGTH = MAX_BLENGTH >>> alignof<T>();
if (<u32>index >= <u32>MAX_LENGTH) throw new Error("Invalid array length");
buffer = reallocUnsafe(buffer, (index + 1) << alignof<T>());
buffer = reallocateUnsafe(buffer, (index + 1) << alignof<T>());
this.buffer_ = buffer;
this.length_ = index + 1;
}
storeUnsafe<T,T>(buffer, index, value);
if (isManaged<T>()) __gc_link(changetype<usize>(this), changetype<usize>(value)); // tslint:disable-line
}
@operator("{}=")
private __unchecked_set(index: i32, value: T): void {
storeUnsafe<T,T>(this.buffer_, index, value);
if (isManaged<T>()) __gc_link(changetype<usize>(this), changetype<usize>(value)); // tslint:disable-line
}
includes(searchElement: T, fromIndex: i32 = 0): bool {
@ -141,11 +143,12 @@ export class Array<T> {
if (<u32>length >= <u32>capacity) {
const MAX_LENGTH = MAX_BLENGTH >>> alignof<T>();
if (<u32>length >= <u32>MAX_LENGTH) throw new Error("Invalid array length");
buffer = reallocUnsafe(buffer, newLength << alignof<T>());
buffer = reallocateUnsafe(buffer, newLength << alignof<T>());
this.buffer_ = buffer;
}
this.length_ = newLength;
storeUnsafe<T,T>(buffer, length, element);
if (isManaged<T>()) __gc_link(changetype<usize>(this), changetype<usize>(element)); // tslint:disable-line
return newLength;
}
@ -217,8 +220,8 @@ export class Array<T> {
var element = loadUnsafe<T,T>(buffer, 0);
var lastIndex = length - 1;
memory.copy(
changetype<usize>(buffer) + HEADER_SIZE_AB,
changetype<usize>(buffer) + HEADER_SIZE_AB + sizeof<T>(),
changetype<usize>(buffer) + HEADER_SIZE,
changetype<usize>(buffer) + HEADER_SIZE + sizeof<T>(),
<usize>lastIndex << alignof<T>()
);
storeUnsafe<T,T>(buffer, lastIndex, <T>null);
@ -242,17 +245,18 @@ export class Array<T> {
if (<u32>length >= <u32>capacity) {
const MAX_LENGTH = MAX_BLENGTH >>> alignof<T>();
if (<u32>length >= <u32>MAX_LENGTH) throw new Error("Invalid array length");
buffer = reallocUnsafe(buffer, newLength << alignof<T>());
buffer = reallocateUnsafe(buffer, newLength << alignof<T>());
capacity = buffer.byteLength >>> alignof<T>();
this.buffer_ = buffer;
}
memory.copy(
changetype<usize>(buffer) + HEADER_SIZE_AB + sizeof<T>(),
changetype<usize>(buffer) + HEADER_SIZE_AB,
changetype<usize>(buffer) + HEADER_SIZE + sizeof<T>(),
changetype<usize>(buffer) + HEADER_SIZE,
<usize>(capacity - 1) << alignof<T>()
);
storeUnsafe<T,T>(buffer, 0, element);
this.length_ = newLength;
if (isManaged<T>()) __gc_link(changetype<usize>(this), changetype<usize>(element)); // tslint:disable-line
return newLength;
}
@ -268,8 +272,8 @@ export class Array<T> {
var sliced = new Array<T>(newLength);
if (newLength) {
memory.copy(
changetype<usize>(sliced.buffer_) + HEADER_SIZE_AB,
changetype<usize>(this.buffer_) + HEADER_SIZE_AB + (<usize>begin << alignof<T>()),
changetype<usize>(sliced.buffer_) + HEADER_SIZE,
changetype<usize>(this.buffer_) + HEADER_SIZE + (<usize>begin << alignof<T>()),
<usize>newLength << alignof<T>()
);
}
@ -284,8 +288,8 @@ export class Array<T> {
deleteCount = min(deleteCount, length - start);
var buffer = this.buffer_;
memory.copy(
changetype<usize>(buffer) + HEADER_SIZE_AB + (<usize>start << alignof<T>()),
changetype<usize>(buffer) + HEADER_SIZE_AB + (<usize>(start + deleteCount) << alignof<T>()),
changetype<usize>(buffer) + HEADER_SIZE + (<usize>start << alignof<T>()),
changetype<usize>(buffer) + HEADER_SIZE + (<usize>(start + deleteCount) << alignof<T>()),
<usize>deleteCount << alignof<T>()
);
this.length_ = length - deleteCount;
@ -328,4 +332,16 @@ export class Array<T> {
);
}
}
private __gc(): void {
if (isManaged<T>()) {
let buffer = this.buffer_;
let offset: usize = 0;
let end = <usize>this.length_ << alignof<usize>();
while (offset < end) {
__gc_mark(load<usize>(changetype<usize>(buffer) + offset, HEADER_SIZE)); // tslint:disable-line
offset += sizeof<usize>();
}
}
}
}

View File

@ -1,7 +1,7 @@
import {
HEADER_SIZE,
MAX_BLENGTH,
allocUnsafe
allocateUnsafe
} from "./internal/arraybuffer";
@sealed
@ -11,7 +11,7 @@ export class ArrayBuffer {
constructor(length: i32, unsafe: bool = false) {
if (<u32>length > <u32>MAX_BLENGTH) throw new RangeError("Invalid array buffer length");
var buffer = allocUnsafe(length);
var buffer = allocateUnsafe(length);
if (!unsafe) memory.fill(changetype<usize>(buffer) + HEADER_SIZE, 0, <usize>length);
return buffer;
}
@ -23,7 +23,7 @@ export class ArrayBuffer {
if (end < 0) end = max(len + end, 0);
else end = min(end, len);
var newLen = max(end - begin, 0);
var buffer = allocUnsafe(newLen);
var buffer = allocateUnsafe(newLen);
memory.copy(changetype<usize>(buffer) + HEADER_SIZE, changetype<usize>(this) + HEADER_SIZE + begin, newLen);
return buffer;
}

View File

@ -2,7 +2,6 @@
@builtin @inline export const NaN: f64 = 0 / 0;
@builtin @inline export const Infinity: f64 = 1 / 0;
@builtin export declare const HEAP_BASE: usize;
@builtin export declare function isInteger<T>(value?: T): bool;
@builtin export declare function isFloat<T>(value?: T): bool;
@ -12,6 +11,7 @@
@builtin export declare function isArray<T>(value?: T): bool;
@builtin export declare function isDefined(expression: void): bool;
@builtin export declare function isConstant(expression: void): bool;
@builtin export declare function isManaged<T>(value?: T): bool;
@inline export function isNaN<T>(value: T): bool { return value != value; }
@inline export function isFinite<T>(value: T): bool { return value - value == 0; }
@ -190,9 +190,3 @@ export namespace f64 {
}
@builtin export declare function start(): void;
@builtin export declare function ERROR(message?: void): void;
@builtin export declare function WARNING(message?: void): void;
@builtin export declare function INFO(message?: void): void;
@builtin export declare function __gc_iterate_roots(fn: (ref: usize) => void): void;

View File

@ -4,18 +4,15 @@
* @module std/assembly/collector/itcm
*//***/
// Largely based on the Bach Le's μgc, see: https://github.com/bullno1/ugc
// Largely based on Bach Le's μgc, see: https://github.com/bullno1/ugc
const TRACE = false;
import {
AL_MASK,
MAX_SIZE_32
} from "../internal/allocator";
/** Size of a managed object header. */
export const HEADER_SIZE: usize = (offsetof<ManagedObject>() + AL_MASK) & ~AL_MASK;
import {
iterateRoots
} from "../gc";
import { AL_MASK, MAX_SIZE_32 } from "../internal/allocator";
import { iterateRoots } from "../gc";
/** Collector states. */
const enum State {
@ -35,8 +32,8 @@ var state = State.INIT;
var white = 0;
// From and to spaces
var from: ManagedObjectList;
var to: ManagedObjectList;
var fromSpace: ManagedObjectList;
var toSpace: ManagedObjectList;
var iter: ManagedObject;
// ╒═══════════════ Managed object layout (32-bit) ════════════════╕
@ -47,15 +44,14 @@ var iter: ManagedObject;
// ├─────────────────────────────────────────────────────────┴─┴───┤ │ usize
// │ prev │ ◄─┘
// ├───────────────────────────────────────────────────────────────┤
// │ visitFn
// │ hookFn
// ╞═══════════════════════════════════════════════════════════════╡ SIZE ┘ ◄─ user-space reference
// │ ... data ... │
// └───────────────────────────────────────────────────────────────┘
// C: color
/** Represents a managed object in memory, consisting of a header followed by the object's data. */
@unmanaged
class ManagedObject {
@unmanaged class ManagedObject {
/** Pointer to the next object with color flags stored in the alignment bits. */
nextWithColor: usize;
@ -63,11 +59,8 @@ class ManagedObject {
/** Pointer to the previous object. */
prev: ManagedObject;
/** Visitor function called with the user-space reference. */
visitFn: (ref: usize) => void;
/** Size of a managed object after alignment. */
static readonly SIZE: usize = (offsetof<ManagedObject>() + AL_MASK) & ~AL_MASK;
/** Class-specific hook function called with the user-space reference. */
hookFn: (ref: usize) => void;
/** Gets the pointer to the next object. */
get next(): ManagedObject {
@ -104,14 +97,13 @@ class ManagedObject {
const gray = 2;
if (this == iter) iter = this.prev;
this.unlink();
to.push(this);
toSpace.push(this);
this.nextWithColor = (this.nextWithColor & ~3) | gray;
}
}
/** A list of managed objects. Used for the from and to spaces. */
@unmanaged
class ManagedObjectList extends ManagedObject {
@unmanaged class ManagedObjectList extends ManagedObject {
/** Inserts an object. */
push(obj: ManagedObject): void {
@ -137,13 +129,13 @@ function step(): void {
switch (state) {
case State.INIT: {
if (TRACE) trace("gc~step/INIT");
from = changetype<ManagedObjectList>(memory.allocate(ManagedObject.SIZE));
from.visitFn = changetype<(ref: usize) => void>(<u32>-1); // would error
from.clear();
to = changetype<ManagedObjectList>(memory.allocate(ManagedObject.SIZE));
to.visitFn = changetype<(ref: usize) => void>(<u32>-1); // would error
to.clear();
iter = to;
fromSpace = changetype<ManagedObjectList>(memory.allocate(HEADER_SIZE));
fromSpace.hookFn = changetype<(ref: usize) => void>(<u32>-1); // would error
fromSpace.clear();
toSpace = changetype<ManagedObjectList>(memory.allocate(HEADER_SIZE));
toSpace.hookFn = changetype<(ref: usize) => void>(<u32>-1); // would error
toSpace.clear();
iter = toSpace;
state = State.IDLE;
if (TRACE) trace("gc~state = IDLE");
// fall-through
@ -157,21 +149,21 @@ function step(): void {
}
case State.MARK: {
obj = iter.next;
if (obj !== to) {
if (obj !== toSpace) {
if (TRACE) trace("gc~step/MARK iterate", 1, objToRef(obj));
iter = obj;
obj.color = <i32>!white;
obj.visitFn(objToRef(obj));
obj.hookFn(objToRef(obj));
} else {
if (TRACE) trace("gc~step/MARK finish");
iterateRoots(__gc_mark);
obj = iter.next;
if (obj === to) {
let prevFrom = from;
from = to;
to = prevFrom;
if (obj === toSpace) {
let from = fromSpace;
fromSpace = toSpace;
toSpace = from;
white = <i32>!white;
iter = prevFrom.next;
iter = from.next;
state = State.SWEEP;
if (TRACE) trace("gc~state = SWEEP");
}
@ -180,13 +172,13 @@ function step(): void {
}
case State.SWEEP: {
obj = iter;
if (obj !== to) {
if (obj !== toSpace) {
if (TRACE) trace("gc~step/SWEEP free", 1, objToRef(obj));
iter = obj.next;
memory.free(changetype<usize>(obj));
if (changetype<usize>(obj) >= HEAP_BASE) memory.free(changetype<usize>(obj));
} else {
if (TRACE) trace("gc~step/SWEEP finish");
to.clear();
toSpace.clear();
state = State.IDLE;
if (TRACE) trace("gc~state = IDLE");
}
@ -196,26 +188,26 @@ function step(): void {
}
@inline function refToObj(ref: usize): ManagedObject {
return changetype<ManagedObject>(ref - ManagedObject.SIZE);
return changetype<ManagedObject>(ref - HEADER_SIZE);
}
@inline function objToRef(obj: ManagedObject): usize {
return changetype<usize>(obj) + ManagedObject.SIZE;
return changetype<usize>(obj) + HEADER_SIZE;
}
// Garbage collector interface
@global export function __gc_allocate(
size: usize,
visitFn: (ref: usize) => void
markFn: (ref: usize) => void
): usize {
if (TRACE) trace("gc.allocate", 1, size);
if (size > MAX_SIZE_32 - ManagedObject.SIZE) unreachable();
if (size > MAX_SIZE_32 - HEADER_SIZE) unreachable();
step(); // also makes sure it's initialized
var obj = changetype<ManagedObject>(memory.allocate(ManagedObject.SIZE + size));
obj.visitFn = visitFn;
var obj = changetype<ManagedObject>(memory.allocate(HEADER_SIZE + size));
obj.hookFn = markFn;
obj.color = white;
from.push(obj);
fromSpace.push(obj);
return objToRef(obj);
}

View File

@ -0,0 +1,5 @@
/* tslint:disable */
@builtin export declare function ERROR(message?: void): void;
@builtin export declare function WARNING(message?: void): void;
@builtin export declare function INFO(message?: void): void;

View File

@ -1,28 +1,12 @@
@builtin export declare function iterateRoots(fn: (ref: usize) => void): void; // tslint:disable-line
/* tslint:disable */
@builtin export declare function iterateRoots(fn: (ref: usize) => void): void;
export namespace gc {
export function allocate(size: usize, visitFn: (ref: usize) => void): usize {
if (isDefined(__gc_allocate)) return __gc_allocate(size, visitFn); // tslint:disable-line
WARNING("Calling 'gc.allocate' requires a garbage collector to be present.");
return <usize>unreachable();
}
export function collect(): void {
if (isDefined(__gc_collect)) { __gc_collect(); return; } // tslint:disable-line
if (isDefined(__gc_collect)) { __gc_collect(); return; }
WARNING("Calling 'gc.collect' requires a garbage collector to be present.");
unreachable();
}
export function link(parentRef: usize, childRef: usize): void {
if (isDefined(__gc_link)) { __gc_link(parentRef, childRef); return; } // tslint:disable-line
WARNING("Calling 'gc.link' requires a garbage collector to be present.");
unreachable();
}
export function mark(ref: usize): void {
if (isDefined(__gc_mark)) { __gc_mark(ref); return; } // tslint:disable-line
WARNING("Calling 'gc.mark' requires a garbage collector to be present.");
unreachable();
}
}

View File

@ -132,6 +132,8 @@ declare function isArray<T>(value?: any): value is Array<any>;
declare function isDefined(expression: any): bool;
/** Tests if the specified expression evaluates to a constant value. Compiles to a constant. */
declare function isConstant(expression: any): bool;
/** Tests if the specified type *or* expression is of a managed type. Compiles to a constant. */
declare function isManaged<T>(value?: any): bool;
/** Traps if the specified value is not true-ish, otherwise returns the (non-nullable) 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. */
@ -354,10 +356,6 @@ declare namespace gc {
export function allocate(size: usize, visitFn: (ref: usize) => void): usize;
/** Performs a full garbage collection cycle. */
export function collect(): void;
/** Must be called when a managed object becomes a child of another one. */
export function link(parentRef: usize, childRef: usize): void;
/** Must be called when a managed object is found reachable. */
export function mark(ref: usize): void;
}
/** Table operations. */

View File

@ -1,11 +1,8 @@
/** Number of alignment bits. */
export const AL_BITS: u32 = 3;
/** Number of possible alignment values. */
export const AL_SIZE: usize = 1 << <usize>AL_BITS;
/** Mask to obtain just the alignment bits. */
export const AL_MASK: usize = AL_SIZE - 1;
/** Maximum 32-bit allocation size. */
export const MAX_SIZE_32: usize = 1 << 30; // 1GB

View File

@ -1,19 +1,12 @@
import {
loadUnsafe,
storeUnsafe
} from "./arraybuffer";
import { loadUnsafe, storeUnsafe } from "./arraybuffer";
import { Array } from "../array";
import {
Array
} from "../array";
/** Obtains the default comparator for the specified type. */
@inline
export function defaultComparator<T>(): (a: T, b: T) => i32 {
return (a: T, b: T): i32 => (<i32>(a > b) - <i32>(a < b)); // compiles to a constant table index
return function compare(a: T, b: T): i32 {
return (<i32>(a > b) - <i32>(a < b));
};
}
/** Sorts an Array with the 'Insertion Sort' algorithm. */
export function insertionSort<T>(arr: Array<T>, comparator: (a: T, b: T) => i32): Array<T> {
var buffer = arr.buffer_;
for (let i: i32 = 0, length: i32 = arr.length; i < length; i++) {
@ -30,7 +23,6 @@ export function insertionSort<T>(arr: Array<T>, comparator: (a: T, b: T) => i32)
return arr;
}
/** Sorts an Array with the 'Weak Heap Sort' algorithm. */
export function weakHeapSort<T>(arr: Array<T>, comparator: (a: T, b: T) => i32): Array<T> {
const shift32 = alignof<u32>();

View File

@ -2,12 +2,10 @@ import { AL_MASK, MAX_SIZE_32 } from "./allocator";
/** Size of an ArrayBuffer header. */
export const HEADER_SIZE: usize = (offsetof<ArrayBuffer>() + AL_MASK) & ~AL_MASK;
/** Maximum byte length of an ArrayBuffer. */
export const MAX_BLENGTH: i32 = <i32>MAX_SIZE_32 - HEADER_SIZE;
/** Computes an ArrayBuffer's size in memory. */
export function computeSize(byteLength: i32): usize {
function computeSize(byteLength: i32): usize {
// round up to power of 2, with HEADER_SIZE=8:
// 0 -> 2^3 = 8
// 1..8 -> 2^4 = 16
@ -17,16 +15,23 @@ export function computeSize(byteLength: i32): usize {
return <usize>1 << <usize>(<u32>32 - clz<u32>(byteLength + HEADER_SIZE - 1));
}
/** Allocates a raw ArrayBuffer. Contents remain uninitialized. */
export function allocUnsafe(byteLength: i32): ArrayBuffer {
// Low-level utility
function __gc(ref: usize): void {}
export function allocateUnsafe(byteLength: i32): ArrayBuffer {
assert(<u32>byteLength <= <u32>MAX_BLENGTH);
var buffer = memory.allocate(computeSize(byteLength));
var buffer: usize;
if (isManaged<ArrayBuffer>()) {
buffer = __gc_allocate(computeSize(byteLength), __gc); // tslint:disable-line
} else {
buffer = memory.allocate(computeSize(byteLength));
}
store<i32>(buffer, byteLength, offsetof<ArrayBuffer>("byteLength"));
return changetype<ArrayBuffer>(buffer);
}
/** Reallocates an ArrayBuffer, resizing it as requested. Tries to modify the buffer in place. */
export function reallocUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuffer {
export function reallocateUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuffer {
var oldByteLength = buffer.byteLength;
if (newByteLength > oldByteLength) {
assert(newByteLength <= MAX_BLENGTH);
@ -38,7 +43,7 @@ export function reallocUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuf
<usize>(newByteLength - oldByteLength)
);
} else { // slow path: copy to new buffer
let newBuffer = allocUnsafe(newByteLength);
let newBuffer = allocateUnsafe(newByteLength);
memory.copy(
changetype<usize>(newBuffer) + HEADER_SIZE,
changetype<usize>(buffer) + HEADER_SIZE,
@ -59,22 +64,18 @@ export function reallocUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuf
return buffer;
}
@inline
export function loadUnsafe<T,V>(buffer: ArrayBuffer, index: i32): V {
@inline export function loadUnsafe<T,V>(buffer: ArrayBuffer, index: i32): V {
return <V>load<T>(changetype<usize>(buffer) + (<usize>index << alignof<T>()), HEADER_SIZE);
}
@inline
export function storeUnsafe<T,V>(buffer: ArrayBuffer, index: i32, value: V): void {
@inline export function storeUnsafe<T,V>(buffer: ArrayBuffer, index: i32, value: V): void {
store<T>(changetype<usize>(buffer) + (<usize>index << alignof<T>()), value, HEADER_SIZE);
}
@inline
export function loadUnsafeWithOffset<T,V>(buffer: ArrayBuffer, index: i32, byteOffset: i32): V {
@inline export function loadUnsafeWithOffset<T,V>(buffer: ArrayBuffer, index: i32, byteOffset: i32): V {
return <V>load<T>(changetype<usize>(buffer) + <usize>byteOffset + (<usize>index << alignof<T>()), HEADER_SIZE);
}
@inline
export function storeUnsafeWithOffset<T,V>(buffer: ArrayBuffer, index: i32, value: V, byteOffset: i32): void {
@inline export function storeUnsafeWithOffset<T,V>(buffer: ArrayBuffer, index: i32, value: V, byteOffset: i32): void {
store<T>(changetype<usize>(buffer) + <usize>byteOffset + (<usize>index << alignof<T>()), value, HEADER_SIZE);
}

View File

@ -1,5 +1,5 @@
import {
HEADER_SIZE as HEADER_SIZE_STR
HEADER_SIZE as STRING_HEADER_SIZE
} from "./string";
/** Computes the 32-bit hash of a value of any type. */
@ -66,7 +66,7 @@ function hash64(key: u64): u32 {
function hashStr(key: string): u32 {
var v = FNV_OFFSET;
for (let i: usize = 0, k: usize = key.length << 1; i < k; ++i) {
v = (v ^ <u32>load<u8>(changetype<usize>(key) + i, HEADER_SIZE_STR)) * FNV_PRIME;
v = (v ^ <u32>load<u8>(changetype<usize>(key) + i, STRING_HEADER_SIZE)) * FNV_PRIME;
}
return v;
}

View File

@ -1,7 +1,7 @@
import {
CharCode,
allocate as allocateString,
allocateUnsafe as allocateUnsafeString,
HEADER_SIZE as STRING_HEADER_SIZE
} from "./string";
@ -194,7 +194,7 @@ export function utoa32(value: u32): string {
if (!value) return "0";
var decimals = decimalCountU32(value);
var buffer = allocateString(decimals);
var buffer = allocateUnsafeString(decimals);
utoa32_core(changetype<usize>(buffer), value, decimals);
return changetype<string>(buffer);
@ -207,7 +207,7 @@ export function itoa32(value: i32): string {
if (isneg) value = -value;
var decimals = decimalCountU32(value) + <i32>isneg;
var buffer = allocateString(decimals);
var buffer = allocateUnsafeString(decimals);
utoa32_core(changetype<usize>(buffer), value, decimals);
if (isneg) store<u16>(changetype<usize>(buffer), CharCode.MINUS, STRING_HEADER_SIZE);
@ -222,11 +222,11 @@ export function utoa64(value: u64): string {
if (value <= u32.MAX_VALUE) {
let value32 = <u32>value;
let decimals = decimalCountU32(value32);
buffer = allocateString(decimals);
buffer = allocateUnsafeString(decimals);
utoa32_core(changetype<usize>(buffer), value32, decimals);
} else {
let decimals = decimalCountU64(value);
buffer = allocateString(decimals);
buffer = allocateUnsafeString(decimals);
utoa64_core(changetype<usize>(buffer), value, decimals);
}
@ -243,11 +243,11 @@ export function itoa64(value: i64): string {
if (<u64>value <= <u64>u32.MAX_VALUE) {
let value32 = <u32>value;
let decimals = decimalCountU32(value32) + <i32>isneg;
buffer = allocateString(decimals);
buffer = allocateUnsafeString(decimals);
utoa32_core(changetype<usize>(buffer), value32, decimals);
} else {
let decimals = decimalCountU64(value) + <i32>isneg;
buffer = allocateString(decimals);
buffer = allocateUnsafeString(decimals);
utoa64_core(changetype<usize>(buffer), value, decimals);
}
if (isneg) store<u16>(changetype<usize>(buffer), CharCode.MINUS, STRING_HEADER_SIZE);

View File

@ -0,0 +1,254 @@
// this function will go away once `memory.copy` becomes an intrinsic
export function memcpy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memcpy.c
var w: u32, x: u32;
// copy 1 byte each until src is aligned to 4 bytes
while (n && (src & 3)) {
store<u8>(dest++, load<u8>(src++));
n--;
}
// if dst is aligned to 4 bytes as well, copy 4 bytes each
if ((dest & 3) == 0) {
while (n >= 16) {
store<u32>(dest , load<u32>(src ));
store<u32>(dest + 4, load<u32>(src + 4));
store<u32>(dest + 8, load<u32>(src + 8));
store<u32>(dest + 12, load<u32>(src + 12));
src += 16; dest += 16; n -= 16;
}
if (n & 8) {
store<u32>(dest , load<u32>(src ));
store<u32>(dest + 4, load<u32>(src + 4));
dest += 8; src += 8;
}
if (n & 4) {
store<u32>(dest, load<u32>(src));
dest += 4; src += 4;
}
if (n & 2) { // drop to 2 bytes each
store<u16>(dest, load<u16>(src));
dest += 2; src += 2;
}
if (n & 1) { // drop to 1 byte
store<u8>(dest++, load<u8>(src++));
}
return;
}
// if dst is not aligned to 4 bytes, use alternating shifts to copy 4 bytes each
// doing shifts if faster when copying enough bytes (here: 32 or more)
if (n >= 32) {
switch (dest & 3) {
// known to be != 0
case 1: {
w = load<u32>(src);
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
n -= 3;
while (n >= 17) {
x = load<u32>(src + 1);
store<u32>(dest, w >> 24 | x << 8);
w = load<u32>(src + 5);
store<u32>(dest + 4, x >> 24 | w << 8);
x = load<u32>(src + 9);
store<u32>(dest + 8, w >> 24 | x << 8);
w = load<u32>(src + 13);
store<u32>(dest + 12, x >> 24 | w << 8);
src += 16; dest += 16; n -= 16;
}
break;
}
case 2: {
w = load<u32>(src);
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
n -= 2;
while (n >= 18) {
x = load<u32>(src + 2);
store<u32>(dest, w >> 16 | x << 16);
w = load<u32>(src + 6);
store<u32>(dest + 4, x >> 16 | w << 16);
x = load<u32>(src + 10);
store<u32>(dest + 8, w >> 16 | x << 16);
w = load<u32>(src + 14);
store<u32>(dest + 12, x >> 16 | w << 16);
src += 16; dest += 16; n -= 16;
}
break;
}
case 3: {
w = load<u32>(src);
store<u8>(dest++, load<u8>(src++));
n -= 1;
while (n >= 19) {
x = load<u32>(src + 3);
store<u32>(dest, w >> 8 | x << 24);
w = load<u32>(src + 7);
store<u32>(dest + 4, x >> 8 | w << 24);
x = load<u32>(src + 11);
store<u32>(dest + 8, w >> 8 | x << 24);
w = load<u32>(src + 15);
store<u32>(dest + 12, x >> 8 | w << 24);
src += 16; dest += 16; n -= 16;
}
break;
}
}
}
// copy remaining bytes one by one
if (n & 16) {
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
}
if (n & 8) {
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
}
if (n & 4) {
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
}
if (n & 2) {
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
}
if (n & 1) {
store<u8>(dest++, load<u8>(src++));
}
}
// this function will go away once `memory.copy` becomes an intrinsic
export function memmove(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c
if (dest == src) return;
if (src + n <= dest || dest + n <= src) {
memcpy(dest, src, n);
return;
}
if (dest < src) {
if ((src & 7) == (dest & 7)) {
while (dest & 7) {
if (!n) return;
--n;
store<u8>(dest++, load<u8>(src++));
}
while (n >= 8) {
store<u64>(dest, load<u64>(src));
n -= 8;
dest += 8;
src += 8;
}
}
while (n) {
store<u8>(dest++, load<u8>(src++));
--n;
}
} else {
if ((src & 7) == (dest & 7)) {
while ((dest + n) & 7) {
if (!n) return;
store<u8>(dest + --n, load<u8>(src + n));
}
while (n >= 8) {
n -= 8;
store<u64>(dest + n, load<u64>(src + n));
}
}
while (n) {
store<u8>(dest + --n, load<u8>(src + n));
}
}
}
// this function will go away once `memory.fill` becomes an intrinsic
export function memset(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset
// fill head and tail with minimal branching
if (!n) return;
store<u8>(dest, c);
store<u8>(dest + n - 1, c);
if (n <= 2) return;
store<u8>(dest + 1, c);
store<u8>(dest + 2, c);
store<u8>(dest + n - 2, c);
store<u8>(dest + n - 3, c);
if (n <= 6) return;
store<u8>(dest + 3, c);
store<u8>(dest + n - 4, c);
if (n <= 8) return;
// advance pointer to align it at 4-byte boundary
var k: usize = -dest & 3;
dest += k;
n -= k;
n &= -4;
var c32: u32 = <u32>-1 / 255 * c;
// fill head/tail up to 28 bytes each in preparation
store<u32>(dest, c32);
store<u32>(dest + n - 4, c32);
if (n <= 8) return;
store<u32>(dest + 4, c32);
store<u32>(dest + 8, c32);
store<u32>(dest + n - 12, c32);
store<u32>(dest + n - 8, c32);
if (n <= 24) return;
store<u32>(dest + 12, c32);
store<u32>(dest + 16, c32);
store<u32>(dest + 20, c32);
store<u32>(dest + 24, c32);
store<u32>(dest + n - 28, c32);
store<u32>(dest + n - 24, c32);
store<u32>(dest + n - 20, c32);
store<u32>(dest + n - 16, c32);
// align to a multiple of 8
k = 24 + (dest & 4);
dest += k;
n -= k;
// copy 32 bytes each
var c64: u64 = <u64>c32 | (<u64>c32 << 32);
while (n >= 32) {
store<u64>(dest, c64);
store<u64>(dest + 8, c64);
store<u64>(dest + 16, c64);
store<u64>(dest + 24, c64);
n -= 32;
dest += 32;
}
}
export function memcmp(vl: usize, vr: usize, n: usize): i32 { // see: musl/src/string/memcmp.c
if (vl == vr) return 0;
while (n != 0 && load<u8>(vl) == load<u8>(vr)) {
n--; vl++; vr++;
}
return n ? <i32>load<u8>(vl) - <i32>load<u8>(vr) : 0;
}

View File

@ -1,34 +1,27 @@
import {
MAX_SIZE_32
} from "./allocator";
import {
String
} from "../string";
import { MAX_SIZE_32 } from "./allocator";
import { String } from "../string";
/** Size of a String header. */
export const HEADER_SIZE = (offsetof<String>() + 1) & ~1; // 2 byte aligned
/** Maximum length of a String. */
export const MAX_LENGTH = (<i32>MAX_SIZE_32 - HEADER_SIZE) >>> 1;
/** Singleton empty String. */
export const EMPTY = changetype<String>(""); // TODO: is this a bad idea with '===' in place?
// Low-level utility
@inline
export function clamp<T>(val: T, lo: T, hi: T): T {
return min<T>(max<T>(val, lo), hi);
}
function __gc(ref: usize): void {}
/** Allocates a raw String with uninitialized contents. */
export function allocate(length: i32): String {
export function allocateUnsafe(length: i32): String {
assert(length > 0 && length <= MAX_LENGTH);
var buffer = memory.allocate(HEADER_SIZE + (<usize>length << 1));
var buffer: usize;
if (isManaged<String>()) {
buffer = __gc_allocate(HEADER_SIZE + (<usize>length << 1), __gc); // tslint:disable-line
} else {
buffer = memory.allocate(HEADER_SIZE + (<usize>length << 1));
}
store<i32>(buffer, length);
return changetype<String>(buffer);
}
@inline
export function copyUnsafe(dest: String, destOffset: usize, src: String, srcOffset: usize, len: usize): void {
memory.copy(
changetype<usize>(dest) + (destOffset << 1) + HEADER_SIZE,
@ -37,120 +30,6 @@ export function copyUnsafe(dest: String, destOffset: usize, src: String, srcOffs
);
}
export function isWhiteSpaceOrLineTerminator(c: u16): bool {
switch (c) {
case 10: // <LF>
case 13: // <CR>
case 8232: // <LS>
case 8233: // <PS>
case 9: // <TAB>
case 11: // <VT>
case 12: // <FF>
case 32: // <SP>
case 160: // <NBSP>
case 65279: { // <ZWNBSP>
return true;
}
default: return false;
}
}
export const enum CharCode {
PLUS = 0x2B,
MINUS = 0x2D,
DOT = 0x2E,
_0 = 0x30,
_1 = 0x31,
_2 = 0x32,
_3 = 0x33,
_4 = 0x34,
_5 = 0x35,
_6 = 0x36,
_7 = 0x37,
_8 = 0x38,
_9 = 0x39,
A = 0x41,
B = 0x42,
E = 0x45,
O = 0x4F,
X = 0x58,
Z = 0x5a,
a = 0x61,
b = 0x62,
e = 0x65,
o = 0x6F,
x = 0x78,
z = 0x7A
}
export function parse<T>(str: String, radix: i32 = 0): T {
var len: i32 = str.length;
if (!len) return <T>NaN;
var ptr = changetype<usize>(str) /* + HEAD -> offset */;
var code = <i32>load<u16>(ptr, HEADER_SIZE);
// determine sign
var sign: T;
if (code == CharCode.MINUS) {
if (!--len) return <T>NaN;
code = <i32>load<u16>(ptr += 2, HEADER_SIZE);
sign = -1;
} else if (code == CharCode.PLUS) {
if (!--len) return <T>NaN;
code = <i32>load<u16>(ptr += 2, HEADER_SIZE);
sign = 1;
} else {
sign = 1;
}
// determine radix
if (!radix) {
if (code == CharCode._0 && len > 2) {
switch (<i32>load<u16>(ptr + 2, HEADER_SIZE)) {
case CharCode.B:
case CharCode.b: {
ptr += 4; len -= 2;
radix = 2;
break;
}
case CharCode.O:
case CharCode.o: {
ptr += 4; len -= 2;
radix = 8;
break;
}
case CharCode.X:
case CharCode.x: {
ptr += 4; len -= 2;
radix = 16;
break;
}
default: radix = 10;
}
} else radix = 10;
} else if (radix < 2 || radix > 36) {
return <T>NaN;
}
// calculate value
var num: T = 0;
while (len--) {
code = <i32>load<u16>(ptr, HEADER_SIZE);
if (code >= CharCode._0 && code <= CharCode._9) {
code -= CharCode._0;
} else if (code >= CharCode.A && code <= CharCode.Z) {
code -= CharCode.A - 10;
} else if (code >= CharCode.a && code <= CharCode.z) {
code -= CharCode.a - 10;
} else break;
if (code >= radix) break;
num = (num * radix) + code;
ptr += 2;
}
return sign * num;
}
export function compareUnsafe(str1: String, offset1: usize, str2: String, offset2: usize, len: usize): i32 {
var cmp: i32 = 0;
var ptr1 = changetype<usize>(str1) + (offset1 << 1);
@ -219,3 +98,118 @@ export function repeatUnsafe(dest: String, destOffset: usize, src: String, count
}
}
}
// Helpers
export const enum CharCode {
PLUS = 0x2B,
MINUS = 0x2D,
DOT = 0x2E,
_0 = 0x30,
_1 = 0x31,
_2 = 0x32,
_3 = 0x33,
_4 = 0x34,
_5 = 0x35,
_6 = 0x36,
_7 = 0x37,
_8 = 0x38,
_9 = 0x39,
A = 0x41,
B = 0x42,
E = 0x45,
O = 0x4F,
X = 0x58,
Z = 0x5a,
a = 0x61,
b = 0x62,
e = 0x65,
o = 0x6F,
x = 0x78,
z = 0x7A
}
export function isWhiteSpaceOrLineTerminator(c: u16): bool {
switch (c) {
case 10: // <LF>
case 13: // <CR>
case 8232: // <LS>
case 8233: // <PS>
case 9: // <TAB>
case 11: // <VT>
case 12: // <FF>
case 32: // <SP>
case 160: // <NBSP>
case 65279: return true; // <ZWNBSP>
default: return false;
}
}
/** Parses a string to an integer (usually), using the specified radix. */
export function parse<T>(str: String, radix: i32 = 0): T {
var len: i32 = str.length;
if (!len) return <T>NaN;
var ptr = changetype<usize>(str) /* + HEAD -> offset */;
var code = <i32>load<u16>(ptr, HEADER_SIZE);
// determine sign
var sign: T;
if (code == CharCode.MINUS) {
if (!--len) return <T>NaN;
code = <i32>load<u16>(ptr += 2, HEADER_SIZE);
sign = -1;
} else if (code == CharCode.PLUS) {
if (!--len) return <T>NaN;
code = <i32>load<u16>(ptr += 2, HEADER_SIZE);
sign = 1;
} else {
sign = 1;
}
// determine radix
if (!radix) {
if (code == CharCode._0 && len > 2) {
switch (<i32>load<u16>(ptr + 2, HEADER_SIZE)) {
case CharCode.B:
case CharCode.b: {
ptr += 4; len -= 2;
radix = 2;
break;
}
case CharCode.O:
case CharCode.o: {
ptr += 4; len -= 2;
radix = 8;
break;
}
case CharCode.X:
case CharCode.x: {
ptr += 4; len -= 2;
radix = 16;
break;
}
default: radix = 10;
}
} else radix = 10;
} else if (radix < 2 || radix > 36) {
return <T>NaN;
}
// calculate value
var num: T = 0;
while (len--) {
code = <i32>load<u16>(ptr, HEADER_SIZE);
if (code >= CharCode._0 && code <= CharCode._9) {
code -= CharCode._0;
} else if (code >= CharCode.A && code <= CharCode.Z) {
code -= CharCode.A - 10;
} else if (code >= CharCode.a && code <= CharCode.z) {
code -= CharCode.a - 10;
} else break;
if (code >= radix) break;
num = (num * radix) + code;
ptr += 2;
}
return sign * num;
}

View File

@ -1,7 +1,7 @@
import {
HEADER_SIZE as HEADER_SIZE_AB,
MAX_BLENGTH,
allocUnsafe,
HEADER_SIZE as AB_HEADER_SIZE,
MAX_BLENGTH as AB_MAX_BLENGTH,
allocateUnsafe,
loadUnsafeWithOffset,
storeUnsafeWithOffset
} from "./arraybuffer";
@ -14,11 +14,11 @@ export abstract class TypedArray<T,V> {
readonly byteLength: i32;
constructor(length: i32) {
const MAX_LENGTH = <u32>MAX_BLENGTH / sizeof<T>();
const MAX_LENGTH = <u32>AB_MAX_BLENGTH / sizeof<T>();
if (<u32>length > MAX_LENGTH) throw new RangeError("Invalid typed array length");
var byteLength = length << alignof<T>();
var buffer = allocUnsafe(byteLength);
memory.fill(changetype<usize>(buffer) + HEADER_SIZE_AB, 0, <usize>byteLength);
var buffer = allocateUnsafe(byteLength);
memory.fill(changetype<usize>(buffer) + AB_HEADER_SIZE, 0, <usize>byteLength);
this.buffer = buffer;
this.byteOffset = 0;
this.byteLength = byteLength;

View File

@ -114,6 +114,8 @@ export class Map<K,V> {
let bucketPtrBase = changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE;
entry.taggedNext = load<usize>(bucketPtrBase, HEADER_SIZE_AB);
store<usize>(bucketPtrBase, changetype<usize>(entry), HEADER_SIZE_AB);
if (isManaged<K>()) __gc_link(changetype<usize>(this), changetype<usize>(key)); // tslint:disable-line
if (isManaged<V>()) __gc_link(changetype<usize>(this), changetype<usize>(value)); // tslint:disable-line
}
}
@ -162,4 +164,22 @@ export class Map<K,V> {
this.entriesCapacity = newEntriesCapacity;
this.entriesOffset = this.entriesCount;
}
private __gc(): void {
if (isManaged<K>() || isManaged<V>()) {
let entries = this.entries;
let offset: usize = 0;
let end: usize = this.entriesOffset * ENTRY_SIZE<K,V>();
while (offset < end) {
let entry = changetype<MapEntry<K,V>>(
changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K,V>()
);
if (!(entry.taggedNext & EMPTY)) {
if (isManaged<K>()) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line
if (isManaged<V>()) __gc_mark(changetype<usize>(entry.value)); // tslint:disable-line
}
offset += ENTRY_SIZE<K,V>();
}
}
}
}

View File

@ -1,21 +1,27 @@
import { memcmp, memmove, memset } from "./internal/memory";
@builtin export declare const HEAP_BASE: usize; // tslint:disable-line
/* tslint:disable */
export namespace memory {
@builtin export declare function size(): i32; // tslint:disable-line
@builtin export declare function size(): i32;
@builtin export declare function grow(pages: i32): i32; // tslint:disable-line
@builtin export declare function grow(pages: i32): i32;
export function fill(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset
if (isDefined(__memory_fill)) { __memory_fill(dest, c, n); return; } // tslint:disable-line
@inline export function fill(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset
if (isDefined(__memory_fill)) { __memory_fill(dest, c, n); return; }
memset(dest, c, n);
}
export function copy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c
if (isDefined(__memory_copy)) { __memory_copy(dest, src, n); return; } // tslint:disable-line
@inline export function copy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c
if (isDefined(__memory_copy)) { __memory_copy(dest, src, n); return; }
memmove(dest, src, n);
}
export function compare(vl: usize, vr: usize, n: usize): i32 { // see: musl/src/string/memcmp.c
if (isDefined(__memory_compare)) return __memory_compare(vl, vr, n); // tslint:disable-line
@inline export function compare(vl: usize, vr: usize, n: usize): i32 { // see: musl/src/string/memcmp.c
if (isDefined(__memory_compare)) return __memory_compare(vl, vr, n);
return memcmp(vl, vr, n);
}
@ -31,275 +37,20 @@ export namespace memory {
// Allocator
export function allocate(size: usize): usize {
if (isDefined(__memory_allocate)) return __memory_allocate(size); // tslint:disable-line
@inline export function allocate(size: usize): usize {
if (isDefined(__memory_allocate)) return __memory_allocate(size);
WARNING("Calling 'memory.allocate' requires a memory manager to be present.");
return <usize>unreachable();
}
export function free(ptr: usize): void {
if (isDefined(__memory_free)) { __memory_free(ptr); return; } // tslint:disable-line
@inline export function free(ptr: usize): void {
if (isDefined(__memory_free)) { __memory_free(ptr); return; }
WARNING("Calling 'memory.free' requires a memory manager to be present.");
unreachable();
}
export function reset(): void {
if (isDefined(__memory_reset)) { __memory_reset(); return; } // tslint:disable-line
@inline export function reset(): void {
if (isDefined(__memory_reset)) { __memory_reset(); return; }
unreachable();
}
}
// this function will go away once `memory.copy` becomes an intrinsic
function memcpy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memcpy.c
var w: u32, x: u32;
// copy 1 byte each until src is aligned to 4 bytes
while (n && (src & 3)) {
store<u8>(dest++, load<u8>(src++));
n--;
}
// if dst is aligned to 4 bytes as well, copy 4 bytes each
if ((dest & 3) == 0) {
while (n >= 16) {
store<u32>(dest , load<u32>(src ));
store<u32>(dest + 4, load<u32>(src + 4));
store<u32>(dest + 8, load<u32>(src + 8));
store<u32>(dest + 12, load<u32>(src + 12));
src += 16; dest += 16; n -= 16;
}
if (n & 8) {
store<u32>(dest , load<u32>(src ));
store<u32>(dest + 4, load<u32>(src + 4));
dest += 8; src += 8;
}
if (n & 4) {
store<u32>(dest, load<u32>(src));
dest += 4; src += 4;
}
if (n & 2) { // drop to 2 bytes each
store<u16>(dest, load<u16>(src));
dest += 2; src += 2;
}
if (n & 1) { // drop to 1 byte
store<u8>(dest++, load<u8>(src++));
}
return;
}
// if dst is not aligned to 4 bytes, use alternating shifts to copy 4 bytes each
// doing shifts if faster when copying enough bytes (here: 32 or more)
if (n >= 32) {
switch (dest & 3) {
// known to be != 0
case 1: {
w = load<u32>(src);
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
n -= 3;
while (n >= 17) {
x = load<u32>(src + 1);
store<u32>(dest, w >> 24 | x << 8);
w = load<u32>(src + 5);
store<u32>(dest + 4, x >> 24 | w << 8);
x = load<u32>(src + 9);
store<u32>(dest + 8, w >> 24 | x << 8);
w = load<u32>(src + 13);
store<u32>(dest + 12, x >> 24 | w << 8);
src += 16; dest += 16; n -= 16;
}
break;
}
case 2: {
w = load<u32>(src);
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
n -= 2;
while (n >= 18) {
x = load<u32>(src + 2);
store<u32>(dest, w >> 16 | x << 16);
w = load<u32>(src + 6);
store<u32>(dest + 4, x >> 16 | w << 16);
x = load<u32>(src + 10);
store<u32>(dest + 8, w >> 16 | x << 16);
w = load<u32>(src + 14);
store<u32>(dest + 12, x >> 16 | w << 16);
src += 16; dest += 16; n -= 16;
}
break;
}
case 3: {
w = load<u32>(src);
store<u8>(dest++, load<u8>(src++));
n -= 1;
while (n >= 19) {
x = load<u32>(src + 3);
store<u32>(dest, w >> 8 | x << 24);
w = load<u32>(src + 7);
store<u32>(dest + 4, x >> 8 | w << 24);
x = load<u32>(src + 11);
store<u32>(dest + 8, w >> 8 | x << 24);
w = load<u32>(src + 15);
store<u32>(dest + 12, x >> 8 | w << 24);
src += 16; dest += 16; n -= 16;
}
break;
}
}
}
// copy remaining bytes one by one
if (n & 16) {
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
}
if (n & 8) {
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
}
if (n & 4) {
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
}
if (n & 2) {
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
}
if (n & 1) {
store<u8>(dest++, load<u8>(src++));
}
}
// this function will go away once `memory.copy` becomes an intrinsic
function memmove(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c
if (dest == src) return;
if (src + n <= dest || dest + n <= src) {
memcpy(dest, src, n);
return;
}
if (dest < src) {
if ((src & 7) == (dest & 7)) {
while (dest & 7) {
if (!n) return;
--n;
store<u8>(dest++, load<u8>(src++));
}
while (n >= 8) {
store<u64>(dest, load<u64>(src));
n -= 8;
dest += 8;
src += 8;
}
}
while (n) {
store<u8>(dest++, load<u8>(src++));
--n;
}
} else {
if ((src & 7) == (dest & 7)) {
while ((dest + n) & 7) {
if (!n) return;
store<u8>(dest + --n, load<u8>(src + n));
}
while (n >= 8) {
n -= 8;
store<u64>(dest + n, load<u64>(src + n));
}
}
while (n) {
store<u8>(dest + --n, load<u8>(src + n));
}
}
}
// this function will go away once `memory.fill` becomes an intrinsic
function memset(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset
// fill head and tail with minimal branching
if (!n) return;
store<u8>(dest, c);
store<u8>(dest + n - 1, c);
if (n <= 2) return;
store<u8>(dest + 1, c);
store<u8>(dest + 2, c);
store<u8>(dest + n - 2, c);
store<u8>(dest + n - 3, c);
if (n <= 6) return;
store<u8>(dest + 3, c);
store<u8>(dest + n - 4, c);
if (n <= 8) return;
// advance pointer to align it at 4-byte boundary
var k: usize = -dest & 3;
dest += k;
n -= k;
n &= -4;
var c32: u32 = <u32>-1 / 255 * c;
// fill head/tail up to 28 bytes each in preparation
store<u32>(dest, c32);
store<u32>(dest + n - 4, c32);
if (n <= 8) return;
store<u32>(dest + 4, c32);
store<u32>(dest + 8, c32);
store<u32>(dest + n - 12, c32);
store<u32>(dest + n - 8, c32);
if (n <= 24) return;
store<u32>(dest + 12, c32);
store<u32>(dest + 16, c32);
store<u32>(dest + 20, c32);
store<u32>(dest + 24, c32);
store<u32>(dest + n - 28, c32);
store<u32>(dest + n - 24, c32);
store<u32>(dest + n - 20, c32);
store<u32>(dest + n - 16, c32);
// align to a multiple of 8
k = 24 + (dest & 4);
dest += k;
n -= k;
// copy 32 bytes each
var c64: u64 = <u64>c32 | (<u64>c32 << 32);
while (n >= 32) {
store<u64>(dest, c64);
store<u64>(dest + 8, c64);
store<u64>(dest + 16, c64);
store<u64>(dest + 24, c64);
n -= 32;
dest += 32;
}
}
function memcmp(vl: usize, vr: usize, n: usize): i32 { // see: musl/src/string/memcmp.c
if (vl == vr) return 0;
while (n != 0 && load<u8>(vl) == load<u8>(vr)) {
n--; vl++; vr++;
}
return n ? <i32>load<u8>(vl) - <i32>load<u8>(vr) : 0;
}

View File

@ -104,6 +104,7 @@ export class Set<K> {
let bucketPtrBase = changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE;
entry.taggedNext = load<usize>(bucketPtrBase, HEADER_SIZE_AB);
store<usize>(bucketPtrBase, changetype<usize>(entry), HEADER_SIZE_AB);
if (isManaged<K>()) __gc_link(changetype<usize>(this), changetype<usize>(key)); // tslint:disable-line
}
}
@ -151,4 +152,19 @@ export class Set<K> {
this.entriesCapacity = newEntriesCapacity;
this.entriesOffset = this.entriesCount;
}
private __gc(): void {
if (isManaged<K>()) {
let entries = this.entries;
let offset: usize = 0;
let end: usize = this.entriesOffset * ENTRY_SIZE<K>();
while (offset < end) {
let entry = changetype<SetEntry<K>>(
changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K>()
);
if (!(entry.taggedNext & EMPTY)) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line
offset += ENTRY_SIZE<K>();
}
}
}
}

View File

@ -1,9 +1,7 @@
import {
HEADER_SIZE,
MAX_LENGTH,
EMPTY,
clamp,
allocate,
allocateUnsafe,
compareUnsafe,
repeatUnsafe,
copyUnsafe,
@ -20,7 +18,7 @@ export class String {
// TODO Add and handle second argument
static fromCharCode(code: i32): String {
if (!code) return changetype<String>("\0");
var out = allocate(1);
var out = allocateUnsafe(1);
store<u16>(
changetype<usize>(out),
<u16>code,
@ -33,7 +31,7 @@ export class String {
assert(<u32>code <= 0x10FFFF); // Invalid code point range
if (!code) return changetype<String>("\0");
var sur = code > 0xFFFF;
var out = allocate(<i32>sur + 1);
var out = allocateUnsafe(<i32>sur + 1);
if (!sur) {
store<u16>(
changetype<usize>(out),
@ -57,11 +55,9 @@ export class String {
charAt(pos: i32): String {
assert(this !== null);
if (<u32>pos >= <u32>this.length) {
return EMPTY;
}
if (<u32>pos >= <u32>this.length) return changetype<String>("");
var out = allocate(1);
var out = allocateUnsafe(1);
store<u16>(
changetype<usize>(out),
load<u16>(
@ -115,8 +111,8 @@ export class String {
var thisLen: isize = this.length;
var otherLen: isize = other.length;
var outLen: usize = thisLen + otherLen;
if (outLen == 0) return EMPTY;
var out = allocate(outLen);
if (outLen == 0) return changetype<String>("");
var out = allocateUnsafe(outLen);
copyUnsafe(out, 0, this, 0, thisLen);
copyUnsafe(out, thisLen, other, 0, otherLen);
return out;
@ -125,7 +121,7 @@ export class String {
endsWith(searchString: String, endPosition: i32 = MAX_LENGTH): bool {
assert(this !== null);
if (searchString === null) return false;
var end = clamp<isize>(endPosition, 0, this.length);
var end = min(max(endPosition, 0), this.length);
var searchLength: isize = searchString.length;
var start: isize = end - searchLength;
if (start < 0) return false;
@ -218,7 +214,7 @@ export class String {
if (!searchLen) return 0;
var len: isize = this.length;
if (!len) return -1;
var start = clamp<isize>(fromIndex, 0, len);
var start = min<isize>(max<isize>(fromIndex, 0), len);
len -= searchLen;
for (let k: isize = start; k <= len; ++k) {
if (!compareUnsafe(this, k, searchString, 0, searchLen)) return <i32>k;
@ -234,7 +230,7 @@ export class String {
var searchLen: isize = searchString.length;
if (!searchLen) return len;
if (!len) return -1;
var start = clamp<isize>(fromIndex, 0, len - searchLen);
var start = min<isize>(max(fromIndex, 0), len - searchLen);
for (let k = start; k >= 0; --k) {
if (!compareUnsafe(this, k, searchString, 0, searchLen)) return <i32>k;
}
@ -247,7 +243,7 @@ export class String {
var pos: isize = position;
var len: isize = this.length;
var start = clamp<isize>(pos, 0, len);
var start = min(max(pos, 0), len);
var searchLength: isize = searchString.length;
if (searchLength + start > len) return false;
return !compareUnsafe(this, start, searchString, 0, searchLength);
@ -258,10 +254,10 @@ export class String {
var intStart: isize = start;
var end: isize = length;
var size: isize = this.length;
if (intStart < 0) intStart = max<isize>(size + intStart, 0);
var resultLength = clamp<isize>(end, 0, size - intStart);
if (resultLength <= 0) return EMPTY;
var out = allocate(resultLength);
if (intStart < 0) intStart = max(size + intStart, 0);
var resultLength = min(max(end, 0), size - intStart);
if (resultLength <= 0) return changetype<String>("");
var out = allocateUnsafe(resultLength);
copyUnsafe(out, 0, this, intStart, resultLength);
return out;
}
@ -269,14 +265,14 @@ export class String {
substring(start: i32, end: i32 = i32.MAX_VALUE): String {
assert(this !== null);
var len = this.length;
var finalStart = clamp<isize>(start, 0, len);
var finalEnd = clamp<isize>(end, 0, len);
var finalStart = min(max(start, 0), len);
var finalEnd = min(max(end, 0), len);
var from = min<i32>(finalStart, finalEnd);
var to = max<i32>(finalStart, finalEnd);
len = to - from;
if (!len) return EMPTY;
if (!len) return changetype<String>("");
if (!from && to == this.length) return this;
var out = allocate(len);
var out = allocateUnsafe(len);
copyUnsafe(out, 0, this, from, len);
return out;
}
@ -302,9 +298,9 @@ export class String {
) {
++start, --length;
}
if (!length) return EMPTY;
if (!length) return changetype<String>("");
if (!start && length == this.length) return this;
var out = allocate(length);
var out = allocateUnsafe(length);
copyUnsafe(out, 0, this, start, length);
return out;
}
@ -323,8 +319,8 @@ export class String {
}
if (!start) return this;
var outLen = len - start;
if (!outLen) return EMPTY;
var out = allocate(outLen);
if (!outLen) return changetype<String>("");
var out = allocateUnsafe(outLen);
copyUnsafe(out, 0, this, start, outLen);
return out;
}
@ -340,9 +336,9 @@ export class String {
) {
--len;
}
if (len <= 0) return EMPTY;
if (len <= 0) return changetype<String>("");
if (<i32>len == this.length) return this;
var out = allocate(len);
var out = allocateUnsafe(len);
copyUnsafe(out, 0, this, 0, len);
return out;
}
@ -353,7 +349,7 @@ export class String {
var padLen = padString.length;
if (targetLength < length || !padLen) return this;
var len = targetLength - length;
var out = allocate(targetLength);
var out = allocateUnsafe(targetLength);
if (len > padLen) {
let count = (len - 1) / padLen;
let base = count * padLen;
@ -373,7 +369,7 @@ export class String {
var padLen = padString.length;
if (targetLength < length || !padLen) return this;
var len = targetLength - length;
var out = allocate(targetLength);
var out = allocateUnsafe(targetLength);
if (length) copyUnsafe(out, 0, this, 0, length);
if (len > padLen) {
let count = (len - 1) / padLen;
@ -396,10 +392,10 @@ export class String {
throw new RangeError("Invalid count value");
}
if (count === 0 || !length) return EMPTY;
if (count === 0 || !length) return changetype<String>("");
if (count === 1) return this;
var result = allocate(length * count);
var result = allocateUnsafe(length * count);
repeatUnsafe(result, 0, this, count);
return result;
}

View File

@ -12,16 +12,16 @@
(export "exportedExported" (func $abi/exportedExported))
(export "exportedInternal" (func $abi/exportedInternal))
(start $start)
(func $abi/exported (; 1 ;) (type $i) (result i32)
(func $abi/exported (; 1 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const -128)
)
(func $abi/exportedExported (; 2 ;) (type $i) (result i32)
(func $abi/exportedExported (; 2 ;) (; has Stack IR ;) (type $i) (result i32)
(call $abi/exported)
)
(func $abi/internal (; 3 ;) (type $i) (result i32)
(func $abi/internal (; 3 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 128)
)
(func $abi/exportedInternal (; 4 ;) (type $i) (result i32)
(func $abi/exportedInternal (; 4 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.shr_s
(i32.shl
(call $abi/internal)
@ -30,7 +30,7 @@
(i32.const 24)
)
)
(func $start (; 5 ;) (type $v)
(func $start (; 5 ;) (; has Stack IR ;) (type $v)
(drop
(call $abi/internal)
)

View File

@ -12,7 +12,7 @@
(memory $0 0)
(export "memory" (memory $0))
(start $start)
(func $~lib/math/NativeMath.scalbn (; 0 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64)
(func $~lib/math/NativeMath.scalbn (; 0 ;) (; has Stack IR ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64)
(local $2 f64)
(set_local $2
(get_local $0)
@ -126,7 +126,7 @@
)
)
)
(func $~lib/math/NativeMath.pow (; 1 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(func $~lib/math/NativeMath.pow (; 1 ;) (; has Stack IR ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(local $2 f64)
(local $3 f64)
(local $4 i32)
@ -1553,7 +1553,7 @@
(f64.const 1.e+300)
)
)
(func $~lib/math/NativeMathf.mod (; 2 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(func $~lib/math/NativeMathf.mod (; 2 ;) (; has Stack IR ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
@ -1901,7 +1901,7 @@
(get_local $0)
)
)
(func $~lib/math/NativeMathf.scalbn (; 3 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32)
(func $~lib/math/NativeMathf.scalbn (; 3 ;) (; has Stack IR ;) (type $fif) (param $0 f32) (param $1 i32) (result f32)
(local $2 f32)
(set_local $2
(get_local $0)
@ -2013,7 +2013,7 @@
)
)
)
(func $~lib/math/NativeMathf.pow (; 4 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(func $~lib/math/NativeMathf.pow (; 4 ;) (; has Stack IR ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(local $2 f32)
(local $3 f32)
(local $4 i32)
@ -3200,7 +3200,7 @@
(f32.const 1.0000000031710769e-30)
)
)
(func $~lib/math/NativeMath.mod (; 5 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(func $~lib/math/NativeMath.mod (; 5 ;) (; has Stack IR ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(local $2 i64)
(local $3 i32)
(local $4 i64)
@ -3575,7 +3575,7 @@
(get_local $0)
)
)
(func $start (; 6 ;) (type $v)
(func $start (; 6 ;) (; has Stack IR ;) (type $v)
(drop
(i32.rem_s
(get_global $binary/i)

View File

@ -409,48 +409,51 @@
(get_local $8)
(i32.const 2146435072)
)
(if
(i32.eq
(i32.or
(i32.sub
(block
(if
(i32.eq
(i32.or
(i32.sub
(get_local $7)
(i32.const 1072693248)
)
(get_local $4)
)
(i32.const 0)
)
(return
(f64.const nan:0x8000000000000)
)
(if
(i32.ge_s
(get_local $7)
(i32.const 1072693248)
)
(get_local $4)
)
(i32.const 0)
)
(return
(f64.const nan:0x8000000000000)
)
(if
(i32.ge_s
(get_local $7)
(i32.const 1072693248)
)
(return
(if (result f64)
(i32.ge_s
(get_local $5)
(i32.const 0)
)
(get_local $1)
(f64.const 0)
)
)
(return
(if (result f64)
(i32.ge_s
(get_local $5)
(i32.const 0)
)
(f64.const 0)
(f64.neg
(return
(if (result f64)
(i32.ge_s
(get_local $5)
(i32.const 0)
)
(get_local $1)
(f64.const 0)
)
)
(return
(if (result f64)
(i32.ge_s
(get_local $5)
(i32.const 0)
)
(f64.const 0)
(f64.neg
(get_local $1)
)
)
)
)
)
(unreachable)
)
)
(if
@ -2394,42 +2397,45 @@
(get_local $5)
(i32.const 2139095040)
)
(if
(i32.eq
(get_local $4)
(i32.const 1065353216)
)
(return
(f32.const nan:0x400000)
)
(block
(if
(i32.gt_s
(i32.eq
(get_local $4)
(i32.const 1065353216)
)
(return
(if (result f32)
(i32.ge_s
(get_local $3)
(i32.const 0)
)
(get_local $1)
(f32.const 0)
)
(f32.const nan:0x400000)
)
(return
(if (result f32)
(i32.ge_s
(get_local $3)
(i32.const 0)
)
(f32.const 0)
(f32.neg
(if
(i32.gt_s
(get_local $4)
(i32.const 1065353216)
)
(return
(if (result f32)
(i32.ge_s
(get_local $3)
(i32.const 0)
)
(get_local $1)
(f32.const 0)
)
)
(return
(if (result f32)
(i32.ge_s
(get_local $3)
(i32.const 0)
)
(f32.const 0)
(f32.neg
(get_local $1)
)
)
)
)
)
(unreachable)
)
)
(if

View File

@ -21,13 +21,13 @@
(export "table" (table $0))
(export "test" (func $builtins/test))
(start $start)
(func $start~anonymous|0 (; 1 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $start~anonymous|0 (; 1 ;) (; has Stack IR ;) (type $iiv) (param $0 i32) (param $1 i32)
(nop)
)
(func $builtins/test (; 2 ;) (type $v)
(func $builtins/test (; 2 ;) (; has Stack IR ;) (type $v)
(nop)
)
(func $start (; 3 ;) (type $v)
(func $start (; 3 ;) (; has Stack IR ;) (type $v)
(set_global $builtins/i
(i32.const 31)
)

View File

@ -9,16 +9,16 @@
(data (i32.const 8) "\10\00\00\00c\00a\00l\00l\00-\00i\00n\00f\00e\00r\00r\00e\00d\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $call-inferred/foo<i32> (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $call-inferred/foo<i32> (; 1 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(get_local $0)
)
(func $call-inferred/foo<f64> (; 2 ;) (type $FF) (param $0 f64) (result f64)
(func $call-inferred/foo<f64> (; 2 ;) (; has Stack IR ;) (type $FF) (param $0 f64) (result f64)
(get_local $0)
)
(func $call-inferred/foo<f32> (; 3 ;) (type $ff) (param $0 f32) (result f32)
(func $call-inferred/foo<f32> (; 3 ;) (; has Stack IR ;) (type $ff) (param $0 f32) (result f32)
(get_local $0)
)
(func $start (; 4 ;) (type $v)
(func $start (; 4 ;) (; has Stack IR ;) (type $v)
(if
(i32.ne
(call $call-inferred/foo<i32>

View File

@ -12,7 +12,7 @@
(export "memory" (memory $0))
(export "table" (table $0))
(start $start)
(func $call-optional/opt (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $call-optional/opt (; 1 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(i32.add
(i32.add
(get_local $0)
@ -21,7 +21,7 @@
(get_local $2)
)
)
(func $call-optional/opt|trampoline (; 2 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $call-optional/opt|trampoline (; 2 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(block $2of2
(block $1of2
(block $0of2
@ -49,7 +49,7 @@
(get_local $2)
)
)
(func $start (; 3 ;) (type $v)
(func $start (; 3 ;) (; has Stack IR ;) (type $v)
(set_global $~argc
(i32.const 1)
)

View File

@ -3,7 +3,7 @@
(memory $0 0)
(export "memory" (memory $0))
(export "test" (func $class-extends/test))
(func $class-extends/test (; 0 ;) (type $iv) (param $0 i32)
(func $class-extends/test (; 0 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(drop
(i32.load
(get_local $0)

View File

@ -5,15 +5,15 @@
(export "memory" (memory $0))
(export "test" (func $class-overloading/test))
(start $start)
(func $class-overloading/Foo#baz (; 0 ;) (type $iv) (param $0 i32)
(func $class-overloading/Foo#baz (; 0 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(nop)
)
(func $class-overloading/test (; 1 ;) (type $iv) (param $0 i32)
(func $class-overloading/test (; 1 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(call $class-overloading/Foo#baz
(get_local $0)
)
)
(func $start (; 2 ;) (type $v)
(func $start (; 2 ;) (; has Stack IR ;) (type $v)
(call $class-overloading/test
(i32.const 0)
)

View File

@ -3,7 +3,7 @@
(memory $0 0)
(export "memory" (memory $0))
(export "test" (func $class-with-boolean-field/test))
(func $class-with-boolean-field/test (; 0 ;) (type $i) (result i32)
(func $class-with-boolean-field/test (; 0 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.store8
(i32.const 0)
(i32.const 1)

View File

@ -11,7 +11,7 @@
(export "memory" (memory $0))
(export "test" (func $class/test))
(start $start)
(func $class/Animal.add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $class/Animal.add (; 0 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(i32.add
(get_local $0)
@ -20,7 +20,7 @@
(get_global $class/Animal.ONE)
)
)
(func $class/Animal.sub<f32> (; 1 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(func $class/Animal.sub<f32> (; 1 ;) (; has Stack IR ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(f32.add
(f32.sub
(get_local $0)
@ -31,7 +31,7 @@
)
)
)
(func $class/Animal<f64>#instanceAdd (; 2 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $class/Animal<f64>#instanceAdd (; 2 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(i32.add
(i32.add
(get_local $1)
@ -40,7 +40,7 @@
(get_global $class/Animal.ONE)
)
)
(func $class/Animal<f64>#instanceSub<f32> (; 3 ;) (type $ifff) (param $0 i32) (param $1 f32) (param $2 f32) (result f32)
(func $class/Animal<f64>#instanceSub<f32> (; 3 ;) (; has Stack IR ;) (type $ifff) (param $0 i32) (param $1 f32) (param $2 f32) (result f32)
(f32.add
(f32.sub
(get_local $1)
@ -51,7 +51,7 @@
)
)
)
(func $class/test (; 4 ;) (type $ii) (param $0 i32) (result i32)
(func $class/test (; 4 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(drop
(call $class/Animal<f64>#instanceAdd
(get_local $0)
@ -95,7 +95,7 @@
)
(get_local $0)
)
(func $start (; 5 ;) (type $v)
(func $start (; 5 ;) (; has Stack IR ;) (type $v)
(drop
(call $class/Animal.add
(i32.const 1)

View File

@ -8,7 +8,7 @@
(data (i32.const 8) "\08\00\00\00c\00o\00m\00m\00a\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $start (; 1 ;) (type $v)
(func $start (; 1 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(set_global $comma/a
(i32.add

View File

@ -10,7 +10,7 @@
(data (i32.const 8) "\n\00\00\00d\00e\00c\00l\00a\00r\00e\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $start (; 3 ;) (type $v)
(func $start (; 3 ;) (; has Stack IR ;) (type $v)
(call $declare/externalFunction)
(if
(i32.ne

View File

@ -9,7 +9,7 @@
(data (i32.const 8) "\05\00\00\00d\00o\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $start (; 1 ;) (type $v)
(func $start (; 1 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(loop $continue|0
(set_global $do/n

View File

@ -34,10 +34,10 @@
(export "SelfReference.ZERO" (global $enum/SelfReference.ZERO))
(export "SelfReference.ONE" (global $enum/SelfReference.ONE))
(start $start)
(func $enum/getZero (; 0 ;) (type $i) (result i32)
(func $enum/getZero (; 0 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 0)
)
(func $start (; 1 ;) (type $v)
(func $start (; 1 ;) (; has Stack IR ;) (type $v)
(set_global $enum/NonConstant.ZERO
(call $enum/getZero)
)

View File

@ -13,25 +13,25 @@
(export "b" (global $export/b))
(export "renamed_c" (global $export/c))
(export "ns.two" (func $export/ns.two))
(func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $export/add (; 0 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(get_local $0)
(get_local $1)
)
)
(func $export/sub (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $export/sub (; 1 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.sub
(get_local $0)
(get_local $1)
)
)
(func $export/mul (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $export/mul (; 2 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.mul
(get_local $0)
(get_local $1)
)
)
(func $export/ns.two (; 3 ;) (type $v)
(func $export/ns.two (; 3 ;) (; has Stack IR ;) (type $v)
(nop)
)
)

View File

@ -43,22 +43,22 @@
(export "vehicles.Car#openDoors" (func $exports/Car#openDoors))
(export "outer.inner.a" (global $exports/outer.inner.a))
(start $start)
(func $exports/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $exports/add (; 0 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(get_local $0)
(get_local $1)
)
)
(func $exports/subOpt (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $exports/subOpt (; 1 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.sub
(get_local $0)
(get_local $1)
)
)
(func $exports/Car.getNumTires (; 2 ;) (type $i) (result i32)
(func $exports/Car.getNumTires (; 2 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 4)
)
(func $~lib/allocator/arena/__memory_allocate (; 3 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/allocator/arena/__memory_allocate (; 3 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -144,12 +144,12 @@
)
(i32.const 0)
)
(func $~lib/memory/memory.allocate (; 4 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/memory/memory.allocate (; 4 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
(func $exports/Car#constructor (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $exports/Car#constructor (; 5 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(if
(i32.eqz
(get_local $0)
@ -169,21 +169,21 @@
)
(get_local $0)
)
(func $exports/Car#get:numDoors (; 6 ;) (type $ii) (param $0 i32) (result i32)
(func $exports/Car#get:numDoors (; 6 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(i32.load
(get_local $0)
)
)
(func $exports/Car#set:numDoors (; 7 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $exports/Car#set:numDoors (; 7 ;) (; has Stack IR ;) (type $iiv) (param $0 i32) (param $1 i32)
(i32.store
(get_local $0)
(get_local $1)
)
)
(func $exports/Car#openDoors (; 8 ;) (type $iv) (param $0 i32)
(func $exports/Car#openDoors (; 8 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(nop)
)
(func $start (; 9 ;) (type $v)
(func $start (; 9 ;) (; has Stack IR ;) (type $v)
(set_global $~lib/allocator/arena/startOffset
(i32.const 8)
)
@ -191,7 +191,7 @@
(get_global $~lib/allocator/arena/startOffset)
)
)
(func $exports/subOpt|trampoline (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $exports/subOpt|trampoline (; 10 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(block $1of1
(block $0of1
(block $outOfRange
@ -213,12 +213,12 @@
(get_local $1)
)
)
(func $~setargc (; 11 ;) (type $iv) (param $0 i32)
(func $~setargc (; 11 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(set_global $~argc
(get_local $0)
)
)
(func $exports/Car#constructor|trampoline (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $exports/Car#constructor|trampoline (; 12 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(block $1of1
(block $0of1
(block $outOfRange

View File

@ -7,7 +7,7 @@
(data (i32.const 8) "\06\00\00\00f\00o\00r\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $start (; 1 ;) (type $v)
(func $start (; 1 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(local $1 i32)
(block $break|0

View File

@ -16,16 +16,16 @@
(export "memory" (memory $0))
(export "table" (table $0))
(start $start)
(func $start~anonymous|0 (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $start~anonymous|0 (; 1 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(get_local $0)
)
(func $start~someName|2 (; 2 ;) (type $v)
(func $start~someName|2 (; 2 ;) (; has Stack IR ;) (type $v)
(nop)
)
(func $start~anonymous|3 (; 3 ;) (type $i) (result i32)
(func $start~anonymous|3 (; 3 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 1)
)
(func $start (; 4 ;) (type $v)
(func $start (; 4 ;) (; has Stack IR ;) (type $v)
(set_global $~argc
(i32.const 1)
)

View File

@ -17,34 +17,34 @@
(export "memory" (memory $0))
(export "table" (table $0))
(start $start)
(func $function-types/makeAdder<i32>~anonymous|0 (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $function-types/makeAdder<i32>~anonymous|0 (; 1 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(get_local $0)
(get_local $1)
)
)
(func $function-types/makeAdder<i32> (; 2 ;) (type $i) (result i32)
(func $function-types/makeAdder<i32> (; 2 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 0)
)
(func $function-types/makeAdder<i64>~anonymous|1 (; 3 ;) (type $III) (param $0 i64) (param $1 i64) (result i64)
(func $function-types/makeAdder<i64>~anonymous|1 (; 3 ;) (; has Stack IR ;) (type $III) (param $0 i64) (param $1 i64) (result i64)
(i64.add
(get_local $0)
(get_local $1)
)
)
(func $function-types/makeAdder<i64> (; 4 ;) (type $i) (result i32)
(func $function-types/makeAdder<i64> (; 4 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 1)
)
(func $function-types/makeAdder<f64>~anonymous|2 (; 5 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(func $function-types/makeAdder<f64>~anonymous|2 (; 5 ;) (; has Stack IR ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(f64.add
(get_local $0)
(get_local $1)
)
)
(func $function-types/makeAdder<f64> (; 6 ;) (type $i) (result i32)
(func $function-types/makeAdder<f64> (; 6 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 2)
)
(func $function-types/doAddWithFn<i32> (; 7 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $function-types/doAddWithFn<i32> (; 7 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(set_global $~argc
(i32.const 2)
)
@ -54,7 +54,7 @@
(get_local $2)
)
)
(func $function-types/doAdd<i32> (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $function-types/doAdd<i32> (; 8 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(set_global $~argc
(i32.const 2)
)
@ -64,7 +64,7 @@
(call $function-types/makeAdder<i32>)
)
)
(func $function-types/makeAndAdd<i32>|trampoline (; 9 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $function-types/makeAndAdd<i32>|trampoline (; 9 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(block $1of1
(block $0of1
(block $outOfRange
@ -87,7 +87,7 @@
(get_local $2)
)
)
(func $start (; 10 ;) (type $v)
(func $start (; 10 ;) (; has Stack IR ;) (type $v)
(set_global $function-types/i32Adder
(call $function-types/makeAdder<i32>)
)

View File

@ -17,46 +17,46 @@
(memory $0 0)
(export "memory" (memory $0))
(start $start)
(func $function/v (; 0 ;) (type $v)
(func $function/v (; 0 ;) (; has Stack IR ;) (type $v)
(nop)
)
(func $function/i (; 1 ;) (type $i) (result i32)
(func $function/i (; 1 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 0)
)
(func $function/I (; 2 ;) (type $I) (result i64)
(func $function/I (; 2 ;) (; has Stack IR ;) (type $I) (result i64)
(i64.const 0)
)
(func $function/f (; 3 ;) (type $f) (result f32)
(func $function/f (; 3 ;) (; has Stack IR ;) (type $f) (result f32)
(f32.const 0)
)
(func $function/F (; 4 ;) (type $F) (result f64)
(func $function/F (; 4 ;) (; has Stack IR ;) (type $F) (result f64)
(f64.const 0)
)
(func $function/iv (; 5 ;) (type $iv) (param $0 i32)
(func $function/iv (; 5 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(nop)
)
(func $function/ii (; 6 ;) (type $ii) (param $0 i32) (result i32)
(func $function/ii (; 6 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(get_local $0)
)
(func $function/II (; 7 ;) (type $II) (param $0 i64) (result i64)
(func $function/II (; 7 ;) (; has Stack IR ;) (type $II) (param $0 i64) (result i64)
(get_local $0)
)
(func $function/ff (; 8 ;) (type $ff) (param $0 f32) (result f32)
(func $function/ff (; 8 ;) (; has Stack IR ;) (type $ff) (param $0 f32) (result f32)
(get_local $0)
)
(func $function/FF (; 9 ;) (type $FF) (param $0 f64) (result f64)
(func $function/FF (; 9 ;) (; has Stack IR ;) (type $FF) (param $0 f64) (result f64)
(get_local $0)
)
(func $function/iiv (; 10 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $function/iiv (; 10 ;) (; has Stack IR ;) (type $iiv) (param $0 i32) (param $1 i32)
(nop)
)
(func $function/iii (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $function/iii (; 11 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(get_local $0)
(get_local $1)
)
)
(func $function/III (; 12 ;) (type $IiI) (param $0 i64) (param $1 i32) (result i64)
(func $function/III (; 12 ;) (; has Stack IR ;) (type $IiI) (param $0 i64) (param $1 i32) (result i64)
(i64.add
(get_local $0)
(i64.extend_s/i32
@ -64,19 +64,19 @@
)
)
)
(func $function/fff (; 13 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(func $function/fff (; 13 ;) (; has Stack IR ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(f32.add
(get_local $0)
(get_local $1)
)
)
(func $function/FFF (; 14 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(func $function/FFF (; 14 ;) (; has Stack IR ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(f64.add
(get_local $0)
(get_local $1)
)
)
(func $start (; 15 ;) (type $v)
(func $start (; 15 ;) (; has Stack IR ;) (type $v)
(call $function/v)
(drop
(call $function/i)

View File

@ -9,15 +9,15 @@
(data (i32.const 8) "\10\00\00\00g\00e\00t\00t\00e\00r\00-\00s\00e\00t\00t\00e\00r\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $getter-setter/Foo.get:bar (; 1 ;) (type $i) (result i32)
(func $getter-setter/Foo.get:bar (; 1 ;) (; has Stack IR ;) (type $i) (result i32)
(get_global $getter-setter/Foo._bar)
)
(func $getter-setter/Foo.set:bar (; 2 ;) (type $iv) (param $0 i32)
(func $getter-setter/Foo.set:bar (; 2 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(set_global $getter-setter/Foo._bar
(get_local $0)
)
)
(func $start (; 3 ;) (type $v)
(func $start (; 3 ;) (; has Stack IR ;) (type $v)
(if
(call $getter-setter/Foo.get:bar)
(block

View File

@ -37,13 +37,13 @@
(export "gt_u" (func $../../examples/i64-polyfill/assembly/i64/gt_u))
(export "ge_s" (func $../../examples/i64-polyfill/assembly/i64/ge_s))
(export "ge_u" (func $../../examples/i64-polyfill/assembly/i64/ge_u))
(func $../../examples/i64-polyfill/assembly/i64/getHi (; 0 ;) (type $i) (result i32)
(func $../../examples/i64-polyfill/assembly/i64/getHi (; 0 ;) (; has Stack IR ;) (type $i) (result i32)
(get_global $../../examples/i64-polyfill/assembly/i64/hi)
)
(func $../../examples/i64-polyfill/assembly/i64/getLo (; 1 ;) (type $i) (result i32)
(func $../../examples/i64-polyfill/assembly/i64/getLo (; 1 ;) (; has Stack IR ;) (type $i) (result i32)
(get_global $../../examples/i64-polyfill/assembly/i64/lo)
)
(func $../../examples/i64-polyfill/assembly/i64/clz (; 2 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $../../examples/i64-polyfill/assembly/i64/clz (; 2 ;) (; has Stack IR ;) (type $iiv) (param $0 i32) (param $1 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
(i64.clz
@ -65,7 +65,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/ctz (; 3 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $../../examples/i64-polyfill/assembly/i64/ctz (; 3 ;) (; has Stack IR ;) (type $iiv) (param $0 i32) (param $1 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
(i64.ctz
@ -87,7 +87,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/popcnt (; 4 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $../../examples/i64-polyfill/assembly/i64/popcnt (; 4 ;) (; has Stack IR ;) (type $iiv) (param $0 i32) (param $1 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
(i64.popcnt
@ -109,7 +109,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/eqz (; 5 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $../../examples/i64-polyfill/assembly/i64/eqz (; 5 ;) (; has Stack IR ;) (type $iiv) (param $0 i32) (param $1 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i64.eqz
(i64.or
@ -129,7 +129,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/add (; 6 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/add (; 6 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -170,7 +170,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/sub (; 7 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/sub (; 7 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -211,7 +211,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/mul (; 8 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/mul (; 8 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -252,7 +252,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/div_s (; 9 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/div_s (; 9 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -293,7 +293,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/div_u (; 10 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/div_u (; 10 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -334,7 +334,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/rem_s (; 11 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/rem_s (; 11 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -375,7 +375,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/rem_u (; 12 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/rem_u (; 12 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -416,7 +416,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/and (; 13 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/and (; 13 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -457,7 +457,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/or (; 14 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/or (; 14 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -498,7 +498,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/xor (; 15 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/xor (; 15 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -539,7 +539,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/shl (; 16 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/shl (; 16 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -580,7 +580,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/shr_s (; 17 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/shr_s (; 17 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -621,7 +621,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/shr_u (; 18 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/shr_u (; 18 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -662,7 +662,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/rotl (; 19 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/rotl (; 19 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -703,7 +703,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/rotr (; 20 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/rotr (; 20 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 i64)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i32.wrap/i64
@ -744,7 +744,7 @@
)
)
)
(func $../../examples/i64-polyfill/assembly/i64/eq (; 21 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/eq (; 21 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i64.eq
(i64.or
@ -775,7 +775,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/ne (; 22 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/ne (; 22 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i64.ne
(i64.or
@ -806,7 +806,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/lt_s (; 23 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/lt_s (; 23 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i64.lt_s
(i64.or
@ -837,7 +837,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/lt_u (; 24 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/lt_u (; 24 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i64.lt_u
(i64.or
@ -868,7 +868,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/le_s (; 25 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/le_s (; 25 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i64.le_s
(i64.or
@ -899,7 +899,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/le_u (; 26 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/le_u (; 26 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i64.le_u
(i64.or
@ -930,7 +930,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/gt_s (; 27 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/gt_s (; 27 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i64.gt_s
(i64.or
@ -961,7 +961,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/gt_u (; 28 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/gt_u (; 28 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i64.gt_u
(i64.or
@ -992,7 +992,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/ge_s (; 29 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/ge_s (; 29 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i64.ge_s
(i64.or
@ -1023,7 +1023,7 @@
(i32.const 0)
)
)
(func $../../examples/i64-polyfill/assembly/i64/ge_u (; 30 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/i64-polyfill/assembly/i64/ge_u (; 30 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(set_global $../../examples/i64-polyfill/assembly/i64/lo
(i64.ge_u
(i64.or

View File

@ -11,14 +11,14 @@
(export "ifThenElseBlock" (func $if/ifThenElse))
(export "ifAlwaysReturns" (func $if/ifAlwaysReturns))
(start $start)
(func $if/ifThenElse (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $if/ifThenElse (; 1 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(if (result i32)
(get_local $0)
(i32.const 1)
(i32.const 0)
)
)
(func $if/ifThen (; 2 ;) (type $ii) (param $0 i32) (result i32)
(func $if/ifThen (; 2 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(if
(get_local $0)
(return
@ -27,7 +27,7 @@
)
(i32.const 0)
)
(func $if/ifAlwaysReturns (; 3 ;) (type $ii) (param $0 i32) (result i32)
(func $if/ifAlwaysReturns (; 3 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(if
(get_local $0)
(return
@ -44,7 +44,7 @@
)
)
)
(func $start (; 4 ;) (type $v)
(func $start (; 4 ;) (; has Stack IR ;) (type $v)
(if
(call $if/ifThenElse
(i32.const 0)

View File

@ -22,6 +22,7 @@
(i32.const 0)
)
)
(unreachable)
)
(func $if/ifThen (; 2 ;) (type $ii) (param $0 i32) (result i32)
(if
@ -42,6 +43,7 @@
(i32.const 0)
)
)
(unreachable)
)
(func $if/ifAlwaysReturns (; 4 ;) (type $ii) (param $0 i32) (result i32)
(if
@ -59,6 +61,7 @@
(unreachable)
)
)
(unreachable)
)
(func $start (; 5 ;) (type $v)
(if

View File

@ -4,28 +4,28 @@
(memory $0 0)
(export "memory" (memory $0))
(start $start)
(func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $export/add (; 0 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(get_local $0)
(get_local $1)
)
)
(func $export/sub (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $export/sub (; 1 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.sub
(get_local $0)
(get_local $1)
)
)
(func $export/mul (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $export/mul (; 2 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.mul
(get_local $0)
(get_local $1)
)
)
(func $export/ns.two (; 3 ;) (type $v)
(func $export/ns.two (; 3 ;) (; has Stack IR ;) (type $v)
(nop)
)
(func $start (; 4 ;) (type $v)
(func $start (; 4 ;) (; has Stack IR ;) (type $v)
(drop
(i32.add
(i32.add

View File

@ -12,22 +12,22 @@
(data (i32.const 8) "\0d\00\00\00i\00n\00f\00e\00r\00-\00t\00y\00p\00e\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $infer-type/locals (; 0 ;) (type $v)
(func $infer-type/locals (; 0 ;) (; has Stack IR ;) (type $v)
(nop)
)
(func $infer-type/reti (; 1 ;) (type $i) (result i32)
(func $infer-type/reti (; 1 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 0)
)
(func $infer-type/retI (; 2 ;) (type $I) (result i64)
(func $infer-type/retI (; 2 ;) (; has Stack IR ;) (type $I) (result i64)
(i64.const 0)
)
(func $infer-type/retf (; 3 ;) (type $f) (result f32)
(func $infer-type/retf (; 3 ;) (; has Stack IR ;) (type $f) (result f32)
(f32.const 0)
)
(func $infer-type/refF (; 4 ;) (type $F) (result f64)
(func $infer-type/refF (; 4 ;) (; has Stack IR ;) (type $F) (result f64)
(f64.const 0)
)
(func $start (; 5 ;) (type $v)
(func $start (; 5 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(call $infer-type/locals)
(set_global $infer-type/ri

View File

@ -5,13 +5,13 @@
(export "foo" (func $inlining-recursive/foo))
(export "bar" (func $inlining-recursive/bar))
(export "baz" (func $inlining-recursive/baz))
(func $inlining-recursive/foo (; 0 ;) (type $v)
(func $inlining-recursive/foo (; 0 ;) (; has Stack IR ;) (type $v)
(call $inlining-recursive/foo)
)
(func $inlining-recursive/baz (; 1 ;) (type $v)
(func $inlining-recursive/baz (; 1 ;) (; has Stack IR ;) (type $v)
(call $inlining-recursive/bar)
)
(func $inlining-recursive/bar (; 2 ;) (type $v)
(func $inlining-recursive/bar (; 2 ;) (; has Stack IR ;) (type $v)
(call $inlining-recursive/baz)
)
)

View File

@ -13,13 +13,13 @@
(export "table" (table $0))
(export "test" (func $inlining/test))
(start $start)
(func $inlining/test (; 1 ;) (type $i) (result i32)
(func $inlining/test (; 1 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 3)
)
(func $inlining/test_funcs~anonymous|0 (; 2 ;) (type $ii) (param $0 i32) (result i32)
(func $inlining/test_funcs~anonymous|0 (; 2 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(get_local $0)
)
(func $inlining/test_funcs (; 3 ;) (type $v)
(func $inlining/test_funcs (; 3 ;) (; has Stack IR ;) (type $v)
(set_global $~argc
(i32.const 1)
)
@ -42,7 +42,7 @@
)
)
)
(func $start (; 4 ;) (type $v)
(func $start (; 4 ;) (; has Stack IR ;) (type $v)
(if
(i32.ne
(call $inlining/test)

View File

@ -9,16 +9,16 @@
(data (i32.const 8) "\0d\00\00\00i\00n\00s\00t\00a\00n\00c\00e\00o\00f\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $instanceof/isI32<i32> (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $instanceof/isI32<i32> (; 1 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(i32.const 1)
)
(func $instanceof/isI32<f64> (; 2 ;) (type $Fi) (param $0 f64) (result i32)
(func $instanceof/isI32<f64> (; 2 ;) (; has Stack IR ;) (type $Fi) (param $0 f64) (result i32)
(i32.const 0)
)
(func $instanceof/isI32<u32> (; 3 ;) (type $ii) (param $0 i32) (result i32)
(func $instanceof/isI32<u32> (; 3 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(i32.const 0)
)
(func $start (; 4 ;) (type $v)
(func $start (; 4 ;) (; has Stack IR ;) (type $v)
(if
(i32.eqz
(call $instanceof/isI32<i32>

View File

@ -10,7 +10,7 @@
(data (i32.const 8) "\n\00\00\00l\00o\00g\00i\00c\00a\00l\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $start (; 1 ;) (type $v)
(func $start (; 1 ;) (; has Stack IR ;) (type $v)
(set_global $logical/i
(i32.const 2)
)

View File

@ -6,7 +6,7 @@
(memory $0 0)
(export "memory" (memory $0))
(export "main" (func $main/main))
(func $main/main (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $main/main (; 0 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(if
(i32.eqz
(get_global $~started)
@ -20,7 +20,7 @@
)
(get_global $main/code)
)
(func $start (; 1 ;) (type $v)
(func $start (; 1 ;) (; has Stack IR ;) (type $v)
(set_global $main/code
(i32.const 1)
)

View File

@ -6,7 +6,7 @@
(memory $0 0)
(export "memory" (memory $0))
(export "computeLine" (func $../../examples/mandelbrot/assembly/index/computeLine))
(func $~lib/math/NativeMath.log (; 0 ;) (type $FF) (param $0 f64) (result f64)
(func $~lib/math/NativeMath.log (; 0 ;) (; has Stack IR ;) (type $FF) (param $0 f64) (result f64)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -268,7 +268,7 @@
)
)
)
(func $~lib/builtins/isFinite<f64> (; 1 ;) (type $Fi) (param $0 f64) (result i32)
(func $~lib/builtins/isFinite<f64> (; 1 ;) (; has Stack IR ;) (type $Fi) (param $0 f64) (result i32)
(f64.eq
(f64.sub
(get_local $0)
@ -277,7 +277,7 @@
(f64.const 0)
)
)
(func $../../examples/mandelbrot/assembly/index/clamp<f64> (; 2 ;) (type $FFFF) (param $0 f64) (param $1 f64) (param $2 f64) (result f64)
(func $../../examples/mandelbrot/assembly/index/clamp<f64> (; 2 ;) (; has Stack IR ;) (type $FFFF) (param $0 f64) (param $1 f64) (param $2 f64) (result f64)
(f64.min
(f64.max
(get_local $0)
@ -286,7 +286,7 @@
(get_local $2)
)
)
(func $../../examples/mandelbrot/assembly/index/computeLine (; 3 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $../../examples/mandelbrot/assembly/index/computeLine (; 3 ;) (; has Stack IR ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 f64)
(local $5 f64)
(local $6 f64)

View File

@ -9,10 +9,10 @@
(export "testI32" (func $many-locals/testI32))
(export "testI8" (func $many-locals/testI8))
(start $start)
(func $many-locals/testI32 (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $many-locals/testI32 (; 1 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(get_local $0)
)
(func $many-locals/testI8 (; 2 ;) (type $ii) (param $0 i32) (result i32)
(func $many-locals/testI8 (; 2 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(i32.shr_s
(i32.shl
(get_local $0)
@ -21,7 +21,7 @@
(i32.const 24)
)
)
(func $start (; 3 ;) (type $v)
(func $start (; 3 ;) (; has Stack IR ;) (type $v)
(if
(i32.ne
(call $many-locals/testI32

View File

@ -9,7 +9,7 @@
(export "memory" (memory $0))
(export "memcpy" (func $memcpy/memcpy))
(start $start)
(func $memcpy/memcpy (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $memcpy/memcpy (; 1 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
@ -1402,7 +1402,7 @@
)
(get_local $6)
)
(func $start (; 2 ;) (type $v)
(func $start (; 2 ;) (; has Stack IR ;) (type $v)
(i64.store
(i32.const 8)
(i64.const 1229782938247303441)

View File

@ -8,7 +8,7 @@
(data (i32.const 8) "\n\00\00\00m\00e\00m\00m\00o\00v\00e\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $memmove/memmove (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $memmove/memmove (; 1 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
@ -278,7 +278,7 @@
)
(get_local $4)
)
(func $start (; 2 ;) (type $v)
(func $start (; 2 ;) (; has Stack IR ;) (type $v)
(i64.store
(i32.const 8)
(i64.const 1229782938247303441)

View File

@ -8,7 +8,7 @@
(data (i32.const 8) "\t\00\00\00m\00e\00m\00s\00e\00t\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $memset/memset (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $memset/memset (; 1 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(local $5 i64)
@ -342,7 +342,7 @@
)
(get_local $3)
)
(func $start (; 2 ;) (type $v)
(func $start (; 2 ;) (; has Stack IR ;) (type $v)
(set_global $memset/dest
(i32.const 32)
)

View File

@ -3,7 +3,7 @@
(memory $0 0)
(export "memory" (memory $0))
(export "default" (func $named-export-default/get3))
(func $named-export-default/get3 (; 0 ;) (type $i) (result i32)
(func $named-export-default/get3 (; 0 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 3)
)
)

View File

@ -3,10 +3,10 @@
(memory $0 0)
(export "memory" (memory $0))
(export "getValue" (func $named-import-default/getValue))
(func $named-export-default/get3 (; 0 ;) (type $i) (result i32)
(func $named-export-default/get3 (; 0 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 3)
)
(func $named-import-default/getValue (; 1 ;) (type $i) (result i32)
(func $named-import-default/getValue (; 1 ;) (; has Stack IR ;) (type $i) (result i32)
(call $named-export-default/get3)
)
)

View File

@ -5,13 +5,13 @@
(memory $0 0)
(export "memory" (memory $0))
(start $start)
(func $namespace/Outer.Inner.aFunc (; 0 ;) (type $i) (result i32)
(func $namespace/Outer.Inner.aFunc (; 0 ;) (; has Stack IR ;) (type $i) (result i32)
(get_global $namespace/Outer.Inner.aVar)
)
(func $namespace/Joined.anotherFunc (; 1 ;) (type $i) (result i32)
(func $namespace/Joined.anotherFunc (; 1 ;) (; has Stack IR ;) (type $i) (result i32)
(i32.const 3)
)
(func $start (; 2 ;) (type $v)
(func $start (; 2 ;) (; has Stack IR ;) (type $v)
(drop
(call $namespace/Outer.Inner.aFunc)
)

View File

@ -4,10 +4,10 @@
(memory $0 0)
(export "memory" (memory $0))
(export "test" (func $new-without-allocator/test))
(func $~lib/memory/memory.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/memory/memory.allocate (; 0 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(unreachable)
)
(func $new-without-allocator/test (; 1 ;) (type $i) (result i32)
(func $new-without-allocator/test (; 1 ;) (; has Stack IR ;) (type $i) (result i32)
(drop
(call $~lib/memory/memory.allocate
(i32.const 0)

View File

@ -13,7 +13,7 @@
(data (i32.const 36) "\11\00\00\00o\00b\00j\00e\00c\00t\00-\00l\00i\00t\00e\00r\00a\00l\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $~lib/allocator/arena/__memory_allocate (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/allocator/arena/__memory_allocate (; 1 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -99,12 +99,12 @@
)
(i32.const 0)
)
(func $~lib/memory/memory.allocate (; 2 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/memory/memory.allocate (; 2 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
(func $~lib/internal/string/compareUnsafe (; 3 ;) (type $iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32)
(func $~lib/internal/string/compareUnsafe (; 3 ;) (; has Stack IR ;) (type $iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32)
(local $5 i32)
(set_local $1
(i32.add
@ -169,7 +169,7 @@
)
(get_local $5)
)
(func $~lib/string/String.__eq (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/string/String.__eq (; 4 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(if
(i32.eq
@ -225,7 +225,7 @@
)
)
)
(func $object-literal/bar (; 5 ;) (type $iv) (param $0 i32)
(func $object-literal/bar (; 5 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(if
(i32.ne
(i32.load
@ -263,7 +263,7 @@
)
)
)
(func $object-literal/bar2 (; 6 ;) (type $iv) (param $0 i32)
(func $object-literal/bar2 (; 6 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(if
(i32.ne
(i32.load
@ -282,7 +282,7 @@
)
)
)
(func $object-literal/Foo2#test (; 7 ;) (type $iv) (param $0 i32)
(func $object-literal/Foo2#test (; 7 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(if
(i32.ne
(i32.load
@ -301,7 +301,7 @@
)
)
)
(func $start (; 8 ;) (type $v)
(func $start (; 8 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(set_global $~lib/allocator/arena/startOffset
(i32.const 80)

View File

@ -5,7 +5,7 @@
(memory $0 0)
(export "memory" (memory $0))
(start $start)
(func $start (; 0 ;) (type $v)
(func $start (; 0 ;) (; has Stack IR ;) (type $v)
(drop
(i32.trunc_s/f32
(get_global $portable-conversions/f)

View File

@ -3,7 +3,7 @@
(memory $0 0)
(export "memory" (memory $0))
(export "fib" (func $recursive/fib))
(func $recursive/fib (; 0 ;) (type $ii) (param $0 i32) (result i32)
(func $recursive/fib (; 0 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(if
(i32.le_s
(get_local $0)

View File

@ -18,28 +18,28 @@
(export "rerenamed_sub" (func $export/mul))
(export "renamed_ns.two" (func $export/ns.two))
(start $start)
(func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $export/add (; 0 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(get_local $0)
(get_local $1)
)
)
(func $export/sub (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $export/sub (; 1 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.sub
(get_local $0)
(get_local $1)
)
)
(func $export/mul (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $export/mul (; 2 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.mul
(get_local $0)
(get_local $1)
)
)
(func $export/ns.two (; 3 ;) (type $v)
(func $export/ns.two (; 3 ;) (; has Stack IR ;) (type $v)
(nop)
)
(func $start (; 4 ;) (type $v)
(func $start (; 4 ;) (; has Stack IR ;) (type $v)
(drop
(i32.add
(call $export/add

View File

@ -9,10 +9,10 @@
(data (i32.const 8) "\0d\00\00\00r\00e\00t\00a\00i\00n\00-\00i\003\002\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $retain-i32/test (; 1 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $retain-i32/test (; 1 ;) (; has Stack IR ;) (type $iiv) (param $0 i32) (param $1 i32)
(nop)
)
(func $start (; 2 ;) (type $v)
(func $start (; 2 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(call $retain-i32/test
(i32.const 0)

View File

@ -4,10 +4,10 @@
(memory $0 0)
(export "memory" (memory $0))
(start $start)
(func $scoped/fn (; 0 ;) (type $iv) (param $0 i32)
(func $scoped/fn (; 0 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(nop)
)
(func $start (; 1 ;) (type $v)
(func $start (; 1 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(block $break|0
(loop $repeat|0

View File

@ -8,10 +8,10 @@
(data (i32.const 8) "\0e\00\00\00s\00t\00a\00t\00i\00c\00-\00t\00h\00i\00s\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $static-this/Foo.getBar (; 1 ;) (type $i) (result i32)
(func $static-this/Foo.getBar (; 1 ;) (; has Stack IR ;) (type $i) (result i32)
(get_global $static-this/Foo.bar)
)
(func $start (; 2 ;) (type $v)
(func $start (; 2 ;) (; has Stack IR ;) (type $v)
(if
(i32.ne
(call $static-this/Foo.getBar)

View File

@ -15,7 +15,7 @@
(data (i32.const 8) "\16\00\00\00s\00t\00d\00/\00a\00l\00l\00o\00c\00a\00t\00o\00r\00_\00a\00r\00e\00n\00a\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $~lib/allocator/arena/__memory_allocate (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/allocator/arena/__memory_allocate (; 1 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -101,12 +101,7 @@
)
(i32.const 0)
)
(func $~lib/memory/memory.allocate (; 2 ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
(func $~lib/memory/memset (; 3 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memset (; 2 ;) (; has Stack IR ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i64)
(if
@ -436,14 +431,7 @@
)
)
)
(func $~lib/memory/memory.fill (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(call $~lib/memory/memset
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $~lib/memory/memcpy (; 5 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memcpy (; 3 ;) (; has Stack IR ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
@ -1829,7 +1817,7 @@
)
)
)
(func $~lib/memory/memmove (; 6 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memmove (; 4 ;) (; has Stack IR ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(if
@ -1864,7 +1852,7 @@
(if
(get_local $3)
(block
(call $~lib/memory/memcpy
(call $~lib/internal/memory/memcpy
(get_local $0)
(get_local $1)
(get_local $2)
@ -2121,14 +2109,7 @@
)
)
)
(func $~lib/memory/memory.copy (; 7 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(call $~lib/memory/memmove
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $~lib/memory/memcmp (; 8 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $~lib/internal/memory/memcmp (; 5 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(if
(i32.eq
@ -2198,30 +2179,15 @@
)
)
)
(func $~lib/memory/memory.compare (; 9 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(call $~lib/memory/memcmp
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $~lib/allocator/arena/__memory_free (; 10 ;) (type $iv) (param $0 i32)
(func $~lib/allocator/arena/__memory_free (; 6 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(nop)
)
(func $~lib/memory/memory.free (; 11 ;) (type $iv) (param $0 i32)
(call $~lib/allocator/arena/__memory_free
(get_local $0)
)
)
(func $~lib/allocator/arena/__memory_reset (; 12 ;) (type $v)
(func $~lib/allocator/arena/__memory_reset (; 7 ;) (; has Stack IR ;) (type $v)
(set_global $~lib/allocator/arena/offset
(get_global $~lib/allocator/arena/startOffset)
)
)
(func $~lib/memory/memory.reset (; 13 ;) (type $v)
(call $~lib/allocator/arena/__memory_reset)
)
(func $start (; 14 ;) (type $v)
(func $start (; 8 ;) (; has Stack IR ;) (type $v)
(set_global $~lib/allocator/arena/startOffset
(i32.const 56)
)
@ -2229,12 +2195,12 @@
(get_global $~lib/allocator/arena/startOffset)
)
(set_global $std/allocator_arena/ptr1
(call $~lib/memory/memory.allocate
(call $~lib/allocator/arena/__memory_allocate
(i32.const 42)
)
)
(set_global $std/allocator_arena/ptr2
(call $~lib/memory/memory.allocate
(call $~lib/allocator/arena/__memory_allocate
(i32.const 42)
)
)
@ -2253,7 +2219,7 @@
(unreachable)
)
)
(call $~lib/memory/memory.fill
(call $~lib/internal/memory/memset
(get_global $std/allocator_arena/ptr1)
(i32.const 18)
(i32.const 42)
@ -2300,7 +2266,7 @@
)
)
)
(call $~lib/memory/memory.copy
(call $~lib/internal/memory/memmove
(get_global $std/allocator_arena/ptr2)
(get_global $std/allocator_arena/ptr1)
(i32.const 42)
@ -2348,7 +2314,7 @@
)
)
(if
(call $~lib/memory/memory.compare
(call $~lib/internal/memory/memcmp
(get_global $std/allocator_arena/ptr1)
(get_global $std/allocator_arena/ptr2)
(i32.const 42)
@ -2363,15 +2329,15 @@
(unreachable)
)
)
(call $~lib/memory/memory.free
(call $~lib/allocator/arena/__memory_free
(get_global $std/allocator_arena/ptr1)
)
(call $~lib/memory/memory.free
(call $~lib/allocator/arena/__memory_free
(get_global $std/allocator_arena/ptr2)
)
(call $~lib/memory/memory.reset)
(call $~lib/allocator/arena/__memory_reset)
(set_global $std/allocator_arena/ptr1
(call $~lib/memory/memory.allocate
(call $~lib/allocator/arena/__memory_allocate
(i32.const 42)
)
)

View File

@ -129,14 +129,7 @@
)
(i32.const 0)
)
(func $~lib/memory/memory.allocate (; 2 ;) (type $ii) (param $0 i32) (result i32)
(return
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
)
(func $~lib/memory/memset (; 3 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memset (; 2 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i64)
@ -488,14 +481,7 @@
)
)
)
(func $~lib/memory/memory.fill (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(call $~lib/memory/memset
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $~lib/memory/memcpy (; 5 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memcpy (; 3 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
@ -2297,7 +2283,7 @@
)
)
)
(func $~lib/memory/memmove (; 6 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memmove (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(if
(i32.eq
@ -2327,7 +2313,7 @@
)
)
(block
(call $~lib/memory/memcpy
(call $~lib/internal/memory/memcpy
(get_local $0)
(get_local $1)
(get_local $2)
@ -2615,14 +2601,7 @@
)
)
)
(func $~lib/memory/memory.copy (; 7 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(call $~lib/memory/memmove
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $~lib/memory/memcmp (; 8 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $~lib/internal/memory/memcmp (; 5 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(if
(i32.eq
@ -2692,32 +2671,18 @@
(i32.const 0)
)
)
(func $~lib/memory/memory.compare (; 9 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(call $~lib/memory/memcmp
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $~lib/allocator/arena/__memory_free (; 10 ;) (type $iv) (param $0 i32)
(func $~lib/allocator/arena/__memory_free (; 6 ;) (type $iv) (param $0 i32)
(nop)
)
(func $~lib/memory/memory.free (; 11 ;) (type $iv) (param $0 i32)
(call $~lib/allocator/arena/__memory_free
(get_local $0)
)
(return)
)
(func $~lib/allocator/arena/__memory_reset (; 12 ;) (type $v)
(func $~lib/allocator/arena/__memory_reset (; 7 ;) (type $v)
(set_global $~lib/allocator/arena/offset
(get_global $~lib/allocator/arena/startOffset)
)
)
(func $~lib/memory/memory.reset (; 13 ;) (type $v)
(call $~lib/allocator/arena/__memory_reset)
(return)
)
(func $start (; 14 ;) (type $v)
(func $start (; 8 ;) (type $v)
(local $0 i32)
(local $1 i32)
(local $2 i32)
(set_global $~lib/allocator/arena/startOffset
(i32.and
(i32.add
@ -2734,13 +2699,27 @@
(get_global $~lib/allocator/arena/startOffset)
)
(set_global $std/allocator_arena/ptr1
(call $~lib/memory/memory.allocate
(get_global $std/allocator_arena/size)
(block $~lib/memory/memory.allocate|inlined.0 (result i32)
(set_local $0
(get_global $std/allocator_arena/size)
)
(br $~lib/memory/memory.allocate|inlined.0
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
)
)
(set_global $std/allocator_arena/ptr2
(call $~lib/memory/memory.allocate
(get_global $std/allocator_arena/size)
(block $~lib/memory/memory.allocate|inlined.1 (result i32)
(set_local $0
(get_global $std/allocator_arena/size)
)
(br $~lib/memory/memory.allocate|inlined.1
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
)
)
(if
@ -2760,10 +2739,21 @@
(unreachable)
)
)
(call $~lib/memory/memory.fill
(get_global $std/allocator_arena/ptr1)
(i32.const 18)
(get_global $std/allocator_arena/size)
(block $~lib/memory/memory.fill|inlined.0
(set_local $0
(get_global $std/allocator_arena/ptr1)
)
(set_local $1
(i32.const 18)
)
(set_local $2
(get_global $std/allocator_arena/size)
)
(call $~lib/internal/memory/memset
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(block $break|0
(set_global $std/allocator_arena/i
@ -2809,10 +2799,21 @@
(br $repeat|0)
)
)
(call $~lib/memory/memory.copy
(get_global $std/allocator_arena/ptr2)
(get_global $std/allocator_arena/ptr1)
(get_global $std/allocator_arena/size)
(block $~lib/memory/memory.copy|inlined.0
(set_local $2
(get_global $std/allocator_arena/ptr2)
)
(set_local $1
(get_global $std/allocator_arena/ptr1)
)
(set_local $0
(get_global $std/allocator_arena/size)
)
(call $~lib/internal/memory/memmove
(get_local $2)
(get_local $1)
(get_local $0)
)
)
(block $break|1
(set_global $std/allocator_arena/i
@ -2861,10 +2862,21 @@
(if
(i32.eqz
(i32.eq
(call $~lib/memory/memory.compare
(get_global $std/allocator_arena/ptr1)
(get_global $std/allocator_arena/ptr2)
(get_global $std/allocator_arena/size)
(block $~lib/memory/memory.compare|inlined.0 (result i32)
(set_local $0
(get_global $std/allocator_arena/ptr1)
)
(set_local $1
(get_global $std/allocator_arena/ptr2)
)
(set_local $2
(get_global $std/allocator_arena/size)
)
(call $~lib/internal/memory/memcmp
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(i32.const 0)
)
@ -2879,16 +2891,44 @@
(unreachable)
)
)
(call $~lib/memory/memory.free
(get_global $std/allocator_arena/ptr1)
(block $~lib/memory/memory.free|inlined.0
(set_local $2
(get_global $std/allocator_arena/ptr1)
)
(block
(call $~lib/allocator/arena/__memory_free
(get_local $2)
)
(br $~lib/memory/memory.free|inlined.0)
)
)
(call $~lib/memory/memory.free
(get_global $std/allocator_arena/ptr2)
(block $~lib/memory/memory.free|inlined.1
(set_local $2
(get_global $std/allocator_arena/ptr2)
)
(block
(call $~lib/allocator/arena/__memory_free
(get_local $2)
)
(br $~lib/memory/memory.free|inlined.1)
)
)
(block $~lib/memory/memory.reset|inlined.0
(block
(call $~lib/allocator/arena/__memory_reset)
(br $~lib/memory/memory.reset|inlined.0)
)
)
(call $~lib/memory/memory.reset)
(set_global $std/allocator_arena/ptr1
(call $~lib/memory/memory.allocate
(get_global $std/allocator_arena/size)
(block $~lib/memory/memory.allocate|inlined.2 (result i32)
(set_local $2
(get_global $std/allocator_arena/size)
)
(br $~lib/memory/memory.allocate|inlined.2
(call $~lib/allocator/arena/__memory_allocate
(get_local $2)
)
)
)
)
(if

View File

@ -14,7 +14,7 @@
(export "stringArrayMethodCall" (func $std/array-access/stringArrayMethodCall))
(export "stringArrayArrayPropertyAccess" (func $std/array-access/stringArrayArrayPropertyAccess))
(export "stringArrayArrayMethodCall" (func $std/array-access/stringArrayArrayMethodCall))
(func $~lib/array/Array<Array<i32>>#__get (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/array/Array<Array<i32>>#__get (; 1 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(tee_local $0
(if (result i32)
(i32.lt_u
@ -43,7 +43,7 @@
)
)
)
(func $std/array-access/i32ArrayArrayElementAccess (; 2 ;) (type $ii) (param $0 i32) (result i32)
(func $std/array-access/i32ArrayArrayElementAccess (; 2 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/array/Array<Array<i32>>#__get
(call $~lib/array/Array<Array<i32>>#__get
(get_local $0)
@ -52,7 +52,7 @@
(i32.const 1)
)
)
(func $std/array-access/stringArrayPropertyAccess (; 3 ;) (type $ii) (param $0 i32) (result i32)
(func $std/array-access/stringArrayPropertyAccess (; 3 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(i32.load
(call $~lib/array/Array<Array<i32>>#__get
(get_local $0)
@ -60,7 +60,7 @@
)
)
)
(func $~lib/internal/string/compareUnsafe (; 4 ;) (type $iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32)
(func $~lib/internal/string/compareUnsafe (; 4 ;) (; has Stack IR ;) (type $iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32)
(local $5 i32)
(set_local $1
(i32.add
@ -125,7 +125,7 @@
)
(get_local $5)
)
(func $~lib/string/String#startsWith (; 5 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $~lib/string/String#startsWith (; 5 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(if
@ -136,7 +136,7 @@
(call $~lib/env/abort
(i32.const 0)
(i32.const 12)
(i32.const 245)
(i32.const 241)
(i32.const 4)
)
(unreachable)
@ -198,7 +198,7 @@
)
)
)
(func $std/array-access/stringArrayMethodCall (; 6 ;) (type $ii) (param $0 i32) (result i32)
(func $std/array-access/stringArrayMethodCall (; 6 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/string/String#startsWith
(call $~lib/array/Array<Array<i32>>#__get
(get_local $0)
@ -208,7 +208,7 @@
(i32.const 0)
)
)
(func $std/array-access/stringArrayArrayPropertyAccess (; 7 ;) (type $ii) (param $0 i32) (result i32)
(func $std/array-access/stringArrayArrayPropertyAccess (; 7 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(i32.load
(call $~lib/array/Array<Array<i32>>#__get
(call $~lib/array/Array<Array<i32>>#__get
@ -219,7 +219,7 @@
)
)
)
(func $std/array-access/stringArrayArrayMethodCall (; 8 ;) (type $ii) (param $0 i32) (result i32)
(func $std/array-access/stringArrayArrayMethodCall (; 8 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/string/String#startsWith
(call $~lib/array/Array<Array<i32>>#__get
(call $~lib/array/Array<Array<i32>>#__get

View File

@ -210,7 +210,6 @@
(local $6 i32)
(local $7 i32)
(local $8 i32)
(local $9 i32)
(if
(i32.eqz
(i32.ne
@ -222,7 +221,7 @@
(call $~lib/env/abort
(i32.const 0)
(i32.const 12)
(i32.const 245)
(i32.const 241)
(i32.const 4)
)
(unreachable)
@ -245,37 +244,32 @@
(get_local $0)
)
)
(set_local $8
(block $~lib/internal/string/clamp<isize>|inlined.0 (result i32)
(set_local $5
(i32.const 0)
)
(select
(tee_local $6
(select
(tee_local $6
(get_local $3)
)
(tee_local $7
(get_local $5)
)
(i32.gt_s
(get_local $6)
(get_local $7)
)
(set_local $7
(select
(tee_local $5
(select
(tee_local $5
(get_local $3)
)
(tee_local $6
(i32.const 0)
)
(i32.gt_s
(get_local $5)
(get_local $6)
)
)
(tee_local $7
(get_local $4)
)
(i32.lt_s
(get_local $6)
(get_local $7)
)
)
(tee_local $6
(get_local $4)
)
(i32.lt_s
(get_local $5)
(get_local $6)
)
)
)
(set_local $9
(set_local $8
(i32.load
(get_local $1)
)
@ -283,8 +277,8 @@
(if
(i32.gt_s
(i32.add
(get_local $9)
(get_local $8)
(get_local $7)
)
(get_local $4)
)
@ -295,10 +289,10 @@
(i32.eqz
(call $~lib/internal/string/compareUnsafe
(get_local $0)
(get_local $8)
(get_local $7)
(get_local $1)
(i32.const 0)
(get_local $9)
(get_local $8)
)
)
)

View File

@ -7,23 +7,50 @@
(import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32)))
(global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0))
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
(global $std/array-literal/emptyArray (mut i32) (i32.const 0))
(global $std/array-literal/emptyArrayI32 (mut i32) (i32.const 120))
(global $std/array-literal/i (mut i32) (i32.const 0))
(global $std/array-literal/dynamicArray (mut i32) (i32.const 0))
(global $std/array-literal/dynamicArrayI8 (mut i32) (i32.const 0))
(global $std/array-literal/dynamicArrayI32 (mut i32) (i32.const 0))
(memory $0 1)
(data (i32.const 8) "\10\00\00\00\03\00\00\00\0c")
(data (i32.const 28) "\01\00\00\00\02")
(data (i32.const 48) "\14\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00-\00l\00i\00t\00e\00r\00a\00l\00.\00t\00s")
(data (i32.const 92) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s")
(data (i32.const 124) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s")
(data (i32.const 8) "\10\00\00\00\03\00\00\00\03")
(data (i32.const 25) "\01\02")
(data (i32.const 32) "\14\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00-\00l\00i\00t\00e\00r\00a\00l\00.\00t\00s")
(data (i32.const 80) "X\00\00\00\03\00\00\00\0c")
(data (i32.const 100) "\01\00\00\00\02")
(data (i32.const 120) "\80")
(data (i32.const 136) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s")
(data (i32.const 168) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $~lib/array/Array<i32>#get:length (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/array/Array<i8>#get:length (; 1 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(i32.load offset=4
(get_local $0)
)
)
(func $~lib/array/Array<i32>#__get (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/array/Array<i8>#__get (; 2 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(tee_local $0
(if (result i32)
(i32.lt_u
(get_local $1)
(i32.load
(tee_local $0
(i32.load
(get_local $0)
)
)
)
)
(i32.load8_s offset=8
(i32.add
(get_local $0)
(get_local $1)
)
)
(unreachable)
)
)
)
(func $~lib/array/Array<i32>#__get (; 3 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(tee_local $0
(if (result i32)
(i32.lt_u
@ -52,7 +79,7 @@
)
)
)
(func $~lib/internal/arraybuffer/computeSize (; 3 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/internal/arraybuffer/computeSize (; 4 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(i32.shl
(i32.const 1)
(i32.sub
@ -66,7 +93,7 @@
)
)
)
(func $~lib/allocator/arena/__memory_allocate (; 4 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/allocator/arena/__memory_allocate (; 5 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -152,12 +179,7 @@
)
(i32.const 0)
)
(func $~lib/memory/memory.allocate (; 5 ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
(func $~lib/internal/arraybuffer/allocUnsafe (; 6 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/internal/arraybuffer/allocateUnsafe (; 6 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(if
(i32.gt_u
@ -167,8 +189,8 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 124)
(i32.const 22)
(i32.const 168)
(i32.const 23)
(i32.const 2)
)
(unreachable)
@ -176,7 +198,7 @@
)
(i32.store
(tee_local $1
(call $~lib/memory/memory.allocate
(call $~lib/allocator/arena/__memory_allocate
(call $~lib/internal/arraybuffer/computeSize
(get_local $0)
)
@ -186,7 +208,12 @@
)
(get_local $1)
)
(func $~lib/memory/memset (; 7 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/memory/memory.allocate (; 7 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
(func $~lib/internal/memory/memset (; 8 ;) (; has Stack IR ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i64)
(if
@ -516,14 +543,77 @@
)
)
)
(func $~lib/memory/memory.fill (; 8 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(call $~lib/memory/memset
(func $~lib/array/Array<i8>#constructor (; 9 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(if
(i32.gt_u
(get_local $1)
(i32.const 1073741816)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 136)
(i32.const 23)
(i32.const 39)
)
(unreachable)
)
)
(set_local $2
(call $~lib/internal/arraybuffer/allocateUnsafe
(get_local $1)
)
)
(if
(i32.eqz
(get_local $0)
)
(block
(i32.store
(tee_local $0
(call $~lib/memory/memory.allocate
(i32.const 8)
)
)
(i32.const 0)
)
(i32.store offset=4
(get_local $0)
(i32.const 0)
)
)
)
(i32.store
(get_local $0)
(get_local $2)
)
(i32.store offset=4
(get_local $0)
(get_local $1)
)
(call $~lib/internal/memory/memset
(i32.add
(get_local $2)
(i32.const 8)
)
(i32.const 0)
(get_local $1)
)
(get_local $0)
)
(func $~lib/array/Array<i8>#__unchecked_set (; 10 ;) (; has Stack IR ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(i32.store8 offset=8
(i32.add
(i32.load
(get_local $0)
)
(get_local $1)
)
(get_local $2)
)
)
(func $~lib/array/Array<i32>#constructor (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/array/Array<i32>#constructor (; 11 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(if
@ -534,7 +624,7 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 92)
(i32.const 136)
(i32.const 23)
(i32.const 39)
)
@ -542,7 +632,7 @@
)
)
(set_local $2
(call $~lib/internal/arraybuffer/allocUnsafe
(call $~lib/internal/arraybuffer/allocateUnsafe
(tee_local $3
(i32.shl
(get_local $1)
@ -578,7 +668,7 @@
(get_local $0)
(get_local $1)
)
(call $~lib/memory/memory.fill
(call $~lib/internal/memory/memset
(i32.add
(get_local $2)
(i32.const 8)
@ -588,7 +678,7 @@
)
(get_local $0)
)
(func $~lib/array/Array<i32>#__unchecked_set (; 10 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/array/Array<i32>#__unchecked_set (; 12 ;) (; has Stack IR ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(i32.store offset=8
(i32.add
(i32.load
@ -602,17 +692,17 @@
(get_local $2)
)
)
(func $start (; 11 ;) (type $v)
(func $start (; 13 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(set_global $~lib/allocator/arena/startOffset
(i32.const 184)
(i32.const 232)
)
(set_global $~lib/allocator/arena/offset
(get_global $~lib/allocator/arena/startOffset)
)
(if
(i32.ne
(call $~lib/array/Array<i32>#get:length
(call $~lib/array/Array<i8>#get:length
(i32.const 8)
)
(i32.const 3)
@ -620,7 +710,7 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 32)
(i32.const 4)
(i32.const 0)
)
@ -628,14 +718,17 @@
)
)
(if
(call $~lib/array/Array<i32>#__get
(i32.const 8)
(i32.const 0)
(i32.and
(call $~lib/array/Array<i8>#__get
(i32.const 8)
(i32.const 0)
)
(i32.const 255)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 32)
(i32.const 5)
(i32.const 0)
)
@ -644,26 +737,100 @@
)
(if
(i32.ne
(call $~lib/array/Array<i32>#__get
(i32.const 8)
(i32.const 1)
(i32.and
(call $~lib/array/Array<i8>#__get
(i32.const 8)
(i32.const 1)
)
(i32.const 255)
)
(i32.const 1)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 32)
(i32.const 6)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.and
(call $~lib/array/Array<i8>#__get
(i32.const 8)
(i32.const 2)
)
(i32.const 255)
)
(i32.const 2)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 7)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(call $~lib/array/Array<i8>#get:length
(i32.const 80)
)
(i32.const 3)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 10)
(i32.const 0)
)
(unreachable)
)
)
(if
(call $~lib/array/Array<i32>#__get
(i32.const 80)
(i32.const 0)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 11)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(call $~lib/array/Array<i32>#__get
(i32.const 8)
(i32.const 80)
(i32.const 1)
)
(i32.const 1)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 12)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(call $~lib/array/Array<i32>#__get
(i32.const 80)
(i32.const 2)
)
(i32.const 2)
@ -671,33 +838,142 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 7)
(i32.const 32)
(i32.const 13)
(i32.const 0)
)
(unreachable)
)
)
(set_global $std/array-literal/emptyArray
(call $~lib/array/Array<i32>#constructor
(i32.const 0)
(i32.const 0)
)
)
(if
(call $~lib/array/Array<i32>#get:length
(get_global $std/array-literal/emptyArray)
(call $~lib/array/Array<i8>#get:length
(get_global $std/array-literal/emptyArrayI32)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 10)
(i32.const 32)
(i32.const 16)
(i32.const 0)
)
(unreachable)
)
)
(call $~lib/array/Array<i8>#__unchecked_set
(tee_local $0
(call $~lib/array/Array<i8>#constructor
(i32.const 0)
(i32.const 3)
)
)
(i32.const 0)
(get_global $std/array-literal/i)
)
(set_global $std/array-literal/i
(i32.add
(get_global $std/array-literal/i)
(i32.const 1)
)
)
(call $~lib/array/Array<i8>#__unchecked_set
(get_local $0)
(i32.const 1)
(get_global $std/array-literal/i)
)
(set_global $std/array-literal/i
(i32.add
(get_global $std/array-literal/i)
(i32.const 1)
)
)
(call $~lib/array/Array<i8>#__unchecked_set
(get_local $0)
(i32.const 2)
(get_global $std/array-literal/i)
)
(set_global $std/array-literal/dynamicArrayI8
(get_local $0)
)
(if
(i32.ne
(call $~lib/array/Array<i8>#get:length
(get_global $std/array-literal/dynamicArrayI8)
)
(i32.const 3)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 21)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.and
(call $~lib/array/Array<i8>#__get
(get_global $std/array-literal/dynamicArrayI8)
(i32.const 0)
)
(i32.const 255)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 22)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.and
(call $~lib/array/Array<i8>#__get
(get_global $std/array-literal/dynamicArrayI8)
(i32.const 1)
)
(i32.const 255)
)
(i32.const 1)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 23)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.and
(call $~lib/array/Array<i8>#__get
(get_global $std/array-literal/dynamicArrayI8)
(i32.const 2)
)
(i32.const 255)
)
(i32.const 2)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 24)
(i32.const 0)
)
(unreachable)
)
)
(set_global $std/array-literal/i
(i32.const 0)
)
(call $~lib/array/Array<i32>#__unchecked_set
(tee_local $0
(call $~lib/array/Array<i32>#constructor
@ -730,21 +1006,21 @@
(i32.const 2)
(get_global $std/array-literal/i)
)
(set_global $std/array-literal/dynamicArray
(set_global $std/array-literal/dynamicArrayI32
(get_local $0)
)
(if
(i32.ne
(call $~lib/array/Array<i32>#get:length
(get_global $std/array-literal/dynamicArray)
(call $~lib/array/Array<i8>#get:length
(get_global $std/array-literal/dynamicArrayI32)
)
(i32.const 3)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 14)
(i32.const 32)
(i32.const 29)
(i32.const 0)
)
(unreachable)
@ -752,14 +1028,14 @@
)
(if
(call $~lib/array/Array<i32>#__get
(get_global $std/array-literal/dynamicArray)
(get_global $std/array-literal/dynamicArrayI32)
(i32.const 0)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 15)
(i32.const 32)
(i32.const 30)
(i32.const 0)
)
(unreachable)
@ -768,7 +1044,7 @@
(if
(i32.ne
(call $~lib/array/Array<i32>#__get
(get_global $std/array-literal/dynamicArray)
(get_global $std/array-literal/dynamicArrayI32)
(i32.const 1)
)
(i32.const 1)
@ -776,8 +1052,8 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 16)
(i32.const 32)
(i32.const 31)
(i32.const 0)
)
(unreachable)
@ -786,7 +1062,7 @@
(if
(i32.ne
(call $~lib/array/Array<i32>#__get
(get_global $std/array-literal/dynamicArray)
(get_global $std/array-literal/dynamicArrayI32)
(i32.const 2)
)
(i32.const 2)
@ -794,8 +1070,8 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 17)
(i32.const 32)
(i32.const 32)
(i32.const 0)
)
(unreachable)

View File

@ -1,17 +1,32 @@
import "allocator/arena";
const staticArray: i32[] = [0, 1, 2];
assert(staticArray.length == 3);
assert(staticArray[0] == 0);
assert(staticArray[1] == 1);
assert(staticArray[2] == 2);
const staticArrayI8: i8[] = [0, 1, 2];
assert(staticArrayI8.length == 3);
assert(staticArrayI8[0] == 0);
assert(staticArrayI8[1] == 1);
assert(staticArrayI8[2] == 2);
var emptyArray: i32[] = []; // not static atm
assert(emptyArray.length == 0);
const staticArrayI32: i32[] = [0, 1, 2];
assert(staticArrayI32.length == 3);
assert(staticArrayI32[0] == 0);
assert(staticArrayI32[1] == 1);
assert(staticArrayI32[2] == 2);
var emptyArrayI32: i32[] = []; // static
assert(emptyArrayI32.length == 0);
var i = 0;
var dynamicArray: i32[] = [i, ++i, ++i];
assert(dynamicArray.length == 3);
assert(dynamicArray[0] == 0);
assert(dynamicArray[1] == 1);
assert(dynamicArray[2] == 2);
var dynamicArrayI8: i8[] = [<i8>i, <i8>++i, <i8>++i];
assert(dynamicArrayI8.length == 3);
assert(dynamicArrayI8[0] == 0);
assert(dynamicArrayI8[1] == 1);
assert(dynamicArrayI8[2] == 2);
i = 0;
var dynamicArrayI32: i32[] = [i, ++i, ++i];
assert(dynamicArrayI32.length == 3);
assert(dynamicArrayI32[0] == 0);
assert(dynamicArrayI32[1] == 1);
assert(dynamicArrayI32[2] == 2);

View File

@ -11,26 +11,66 @@
(global $~lib/internal/allocator/MAX_SIZE_32 i32 (i32.const 1073741824))
(global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0))
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
(global $std/array-literal/staticArray i32 (i32.const 8))
(global $std/array-literal/staticArrayI8 i32 (i32.const 8))
(global $~lib/internal/arraybuffer/HEADER_SIZE i32 (i32.const 8))
(global $~lib/internal/arraybuffer/MAX_BLENGTH i32 (i32.const 1073741816))
(global $std/array-literal/emptyArray (mut i32) (i32.const 0))
(global $std/array-literal/staticArrayI32 i32 (i32.const 80))
(global $std/array-literal/emptyArrayI32 (mut i32) (i32.const 120))
(global $std/array-literal/i (mut i32) (i32.const 0))
(global $std/array-literal/dynamicArray (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 184))
(global $~lib/internal/arraybuffer/MAX_BLENGTH i32 (i32.const 1073741816))
(global $std/array-literal/dynamicArrayI8 (mut i32) (i32.const 0))
(global $std/array-literal/dynamicArrayI32 (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 228))
(memory $0 1)
(data (i32.const 8) "\10\00\00\00\03\00\00\00\0c\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data (i32.const 48) "\14\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00-\00l\00i\00t\00e\00r\00a\00l\00.\00t\00s\00")
(data (i32.const 92) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00")
(data (i32.const 124) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00")
(data (i32.const 8) "\10\00\00\00\03\00\00\00\03\00\00\00\00\00\00\00\00\01\02\00\00\00\00\00")
(data (i32.const 32) "\14\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00-\00l\00i\00t\00e\00r\00a\00l\00.\00t\00s\00")
(data (i32.const 80) "X\00\00\00\03\00\00\00\0c\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data (i32.const 120) "\80\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data (i32.const 136) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00")
(data (i32.const 168) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00")
(export "memory" (memory $0))
(start $start)
(func $~lib/array/Array<i32>#get:length (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/array/Array<i8>#get:length (; 1 ;) (type $ii) (param $0 i32) (result i32)
(i32.load offset=4
(get_local $0)
)
)
(func $~lib/array/Array<i32>#__get (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/array/Array<i8>#__get (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(set_local $2
(i32.load
(get_local $0)
)
)
(if (result i32)
(i32.lt_u
(get_local $1)
(i32.shr_u
(i32.load
(get_local $2)
)
(i32.const 0)
)
)
(block $~lib/internal/arraybuffer/loadUnsafe<i8,i8>|inlined.0 (result i32)
(i32.load8_s offset=8
(i32.add
(get_local $2)
(i32.shl
(get_local $1)
(i32.const 0)
)
)
)
)
(unreachable)
)
)
(func $~lib/array/Array<i32>#get:length (; 3 ;) (type $ii) (param $0 i32) (result i32)
(i32.load offset=4
(get_local $0)
)
)
(func $~lib/array/Array<i32>#__get (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(set_local $2
(i32.load
@ -61,7 +101,7 @@
(unreachable)
)
)
(func $~lib/internal/arraybuffer/computeSize (; 3 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/internal/arraybuffer/computeSize (; 5 ;) (type $ii) (param $0 i32) (result i32)
(i32.shl
(i32.const 1)
(i32.sub
@ -78,7 +118,7 @@
)
)
)
(func $~lib/allocator/arena/__memory_allocate (; 4 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/allocator/arena/__memory_allocate (; 6 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -186,15 +226,9 @@
)
(i32.const 0)
)
(func $~lib/memory/memory.allocate (; 5 ;) (type $ii) (param $0 i32) (result i32)
(return
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
)
(func $~lib/internal/arraybuffer/allocUnsafe (; 6 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/internal/arraybuffer/allocateUnsafe (; 7 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(if
(i32.eqz
(i32.le_u
@ -205,17 +239,24 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 124)
(i32.const 22)
(i32.const 168)
(i32.const 23)
(i32.const 2)
)
(unreachable)
)
)
(set_local $1
(call $~lib/memory/memory.allocate
(call $~lib/internal/arraybuffer/computeSize
(get_local $0)
(block $~lib/memory/memory.allocate|inlined.0 (result i32)
(set_local $2
(call $~lib/internal/arraybuffer/computeSize
(get_local $0)
)
)
(br $~lib/memory/memory.allocate|inlined.0
(call $~lib/allocator/arena/__memory_allocate
(get_local $2)
)
)
)
)
@ -225,7 +266,14 @@
)
(get_local $1)
)
(func $~lib/memory/memset (; 7 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/memory/memory.allocate (; 8 ;) (type $ii) (param $0 i32) (result i32)
(return
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
)
(func $~lib/internal/memory/memset (; 9 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i64)
@ -577,26 +625,20 @@
)
)
)
(func $~lib/memory/memory.fill (; 8 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(call $~lib/memory/memset
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $~lib/array/Array<i32>#constructor (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/array/Array<i8>#constructor (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(if
(i32.gt_u
(get_local $1)
(i32.const 268435454)
(i32.const 1073741816)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 92)
(i32.const 136)
(i32.const 23)
(i32.const 39)
)
@ -606,11 +648,11 @@
(set_local $2
(i32.shl
(get_local $1)
(i32.const 2)
(i32.const 0)
)
)
(set_local $3
(call $~lib/internal/arraybuffer/allocUnsafe
(call $~lib/internal/arraybuffer/allocateUnsafe
(get_local $2)
)
)
@ -645,17 +687,125 @@
(get_local $0)
(get_local $1)
)
(call $~lib/memory/memory.fill
(i32.add
(get_local $3)
(get_global $~lib/internal/arraybuffer/HEADER_SIZE)
(block $~lib/memory/memory.fill|inlined.0
(set_local $4
(i32.add
(get_local $3)
(get_global $~lib/internal/arraybuffer/HEADER_SIZE)
)
)
(set_local $5
(i32.const 0)
)
(call $~lib/internal/memory/memset
(get_local $4)
(get_local $5)
(get_local $2)
)
(i32.const 0)
(get_local $2)
)
(get_local $0)
)
(func $~lib/array/Array<i32>#__unchecked_set (; 10 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/array/Array<i8>#__unchecked_set (; 11 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(block $~lib/internal/arraybuffer/storeUnsafe<i8,i8>|inlined.0
(set_local $3
(i32.load
(get_local $0)
)
)
(i32.store8 offset=8
(i32.add
(get_local $3)
(i32.shl
(get_local $1)
(i32.const 0)
)
)
(get_local $2)
)
)
)
(func $~lib/array/Array<i32>#constructor (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(if
(i32.gt_u
(get_local $1)
(i32.const 268435454)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 136)
(i32.const 23)
(i32.const 39)
)
(unreachable)
)
)
(set_local $2
(i32.shl
(get_local $1)
(i32.const 2)
)
)
(set_local $3
(call $~lib/internal/arraybuffer/allocateUnsafe
(get_local $2)
)
)
(i32.store
(tee_local $0
(if (result i32)
(get_local $0)
(get_local $0)
(tee_local $0
(block (result i32)
(set_local $4
(call $~lib/memory/memory.allocate
(i32.const 8)
)
)
(i32.store
(get_local $4)
(i32.const 0)
)
(i32.store offset=4
(get_local $4)
(i32.const 0)
)
(get_local $4)
)
)
)
)
(get_local $3)
)
(i32.store offset=4
(get_local $0)
(get_local $1)
)
(block $~lib/memory/memory.fill|inlined.1
(set_local $4
(i32.add
(get_local $3)
(get_global $~lib/internal/arraybuffer/HEADER_SIZE)
)
)
(set_local $5
(i32.const 0)
)
(call $~lib/internal/memory/memset
(get_local $4)
(get_local $5)
(get_local $2)
)
)
(get_local $0)
)
(func $~lib/array/Array<i32>#__unchecked_set (; 13 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(block $~lib/internal/arraybuffer/storeUnsafe<i32,i32>|inlined.0
(set_local $3
@ -675,7 +825,7 @@
)
)
)
(func $start (; 11 ;) (type $v)
(func $start (; 14 ;) (type $v)
(local $0 i32)
(set_global $~lib/allocator/arena/startOffset
(i32.and
@ -695,8 +845,8 @@
(if
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#get:length
(get_global $std/array-literal/staticArray)
(call $~lib/array/Array<i8>#get:length
(get_global $std/array-literal/staticArrayI8)
)
(i32.const 3)
)
@ -704,7 +854,7 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 32)
(i32.const 4)
(i32.const 0)
)
@ -714,9 +864,15 @@
(if
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#__get
(get_global $std/array-literal/staticArray)
(i32.const 0)
(i32.shr_s
(i32.shl
(call $~lib/array/Array<i8>#__get
(get_global $std/array-literal/staticArrayI8)
(i32.const 0)
)
(i32.const 24)
)
(i32.const 24)
)
(i32.const 0)
)
@ -724,7 +880,7 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 32)
(i32.const 5)
(i32.const 0)
)
@ -734,9 +890,15 @@
(if
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#__get
(get_global $std/array-literal/staticArray)
(i32.const 1)
(i32.shr_s
(i32.shl
(call $~lib/array/Array<i8>#__get
(get_global $std/array-literal/staticArrayI8)
(i32.const 1)
)
(i32.const 24)
)
(i32.const 24)
)
(i32.const 1)
)
@ -744,18 +906,103 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 32)
(i32.const 6)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.shr_s
(i32.shl
(call $~lib/array/Array<i8>#__get
(get_global $std/array-literal/staticArrayI8)
(i32.const 2)
)
(i32.const 24)
)
(i32.const 24)
)
(i32.const 2)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 7)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#get:length
(get_global $std/array-literal/staticArrayI32)
)
(i32.const 3)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 10)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#__get
(get_global $std/array-literal/staticArray)
(get_global $std/array-literal/staticArrayI32)
(i32.const 0)
)
(i32.const 0)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 11)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#__get
(get_global $std/array-literal/staticArrayI32)
(i32.const 1)
)
(i32.const 1)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 12)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#__get
(get_global $std/array-literal/staticArrayI32)
(i32.const 2)
)
(i32.const 2)
@ -764,24 +1011,18 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 7)
(i32.const 32)
(i32.const 13)
(i32.const 0)
)
(unreachable)
)
)
(set_global $std/array-literal/emptyArray
(call $~lib/array/Array<i32>#constructor
(i32.const 0)
(i32.const 0)
)
)
(if
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#get:length
(get_global $std/array-literal/emptyArray)
(get_global $std/array-literal/emptyArrayI32)
)
(i32.const 0)
)
@ -789,14 +1030,156 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 10)
(i32.const 32)
(i32.const 16)
(i32.const 0)
)
(unreachable)
)
)
(set_global $std/array-literal/dynamicArray
(set_global $std/array-literal/dynamicArrayI8
(block (result i32)
(set_local $0
(call $~lib/array/Array<i8>#constructor
(i32.const 0)
(i32.const 3)
)
)
(call $~lib/array/Array<i8>#__unchecked_set
(get_local $0)
(i32.const 0)
(get_global $std/array-literal/i)
)
(call $~lib/array/Array<i8>#__unchecked_set
(get_local $0)
(i32.const 1)
(block (result i32)
(set_global $std/array-literal/i
(i32.add
(get_global $std/array-literal/i)
(i32.const 1)
)
)
(get_global $std/array-literal/i)
)
)
(call $~lib/array/Array<i8>#__unchecked_set
(get_local $0)
(i32.const 2)
(block (result i32)
(set_global $std/array-literal/i
(i32.add
(get_global $std/array-literal/i)
(i32.const 1)
)
)
(get_global $std/array-literal/i)
)
)
(get_local $0)
)
)
(if
(i32.eqz
(i32.eq
(call $~lib/array/Array<i8>#get:length
(get_global $std/array-literal/dynamicArrayI8)
)
(i32.const 3)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 21)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.shr_s
(i32.shl
(call $~lib/array/Array<i8>#__get
(get_global $std/array-literal/dynamicArrayI8)
(i32.const 0)
)
(i32.const 24)
)
(i32.const 24)
)
(i32.const 0)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 22)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.shr_s
(i32.shl
(call $~lib/array/Array<i8>#__get
(get_global $std/array-literal/dynamicArrayI8)
(i32.const 1)
)
(i32.const 24)
)
(i32.const 24)
)
(i32.const 1)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 23)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.shr_s
(i32.shl
(call $~lib/array/Array<i8>#__get
(get_global $std/array-literal/dynamicArrayI8)
(i32.const 2)
)
(i32.const 24)
)
(i32.const 24)
)
(i32.const 2)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 32)
(i32.const 24)
(i32.const 0)
)
(unreachable)
)
)
(set_global $std/array-literal/i
(i32.const 0)
)
(set_global $std/array-literal/dynamicArrayI32
(block (result i32)
(set_local $0
(call $~lib/array/Array<i32>#constructor
@ -842,7 +1225,7 @@
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#get:length
(get_global $std/array-literal/dynamicArray)
(get_global $std/array-literal/dynamicArrayI32)
)
(i32.const 3)
)
@ -850,8 +1233,8 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 14)
(i32.const 32)
(i32.const 29)
(i32.const 0)
)
(unreachable)
@ -861,7 +1244,7 @@
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#__get
(get_global $std/array-literal/dynamicArray)
(get_global $std/array-literal/dynamicArrayI32)
(i32.const 0)
)
(i32.const 0)
@ -870,8 +1253,8 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 15)
(i32.const 32)
(i32.const 30)
(i32.const 0)
)
(unreachable)
@ -881,7 +1264,7 @@
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#__get
(get_global $std/array-literal/dynamicArray)
(get_global $std/array-literal/dynamicArrayI32)
(i32.const 1)
)
(i32.const 1)
@ -890,8 +1273,8 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 16)
(i32.const 32)
(i32.const 31)
(i32.const 0)
)
(unreachable)
@ -901,7 +1284,7 @@
(i32.eqz
(i32.eq
(call $~lib/array/Array<i32>#__get
(get_global $std/array-literal/dynamicArray)
(get_global $std/array-literal/dynamicArrayI32)
(i32.const 2)
)
(i32.const 2)
@ -910,8 +1293,8 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 48)
(i32.const 17)
(i32.const 32)
(i32.const 32)
(i32.const 0)
)
(unreachable)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@
(data (i32.const 112) "\12\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/internal/arraybuffer/computeSize (; 1 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(i32.shl
(i32.const 1)
(i32.sub
@ -30,7 +30,7 @@
)
)
)
(func $~lib/allocator/arena/__memory_allocate (; 2 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/allocator/arena/__memory_allocate (; 2 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -116,12 +116,7 @@
)
(i32.const 0)
)
(func $~lib/memory/memory.allocate (; 3 ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
(func $~lib/internal/arraybuffer/allocUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/internal/arraybuffer/allocateUnsafe (; 3 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(if
(i32.gt_u
@ -132,7 +127,7 @@
(call $~lib/env/abort
(i32.const 0)
(i32.const 52)
(i32.const 22)
(i32.const 23)
(i32.const 2)
)
(unreachable)
@ -140,7 +135,7 @@
)
(i32.store
(tee_local $1
(call $~lib/memory/memory.allocate
(call $~lib/allocator/arena/__memory_allocate
(call $~lib/internal/arraybuffer/computeSize
(get_local $0)
)
@ -150,7 +145,7 @@
)
(get_local $1)
)
(func $~lib/memory/memset (; 5 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memset (; 4 ;) (; has Stack IR ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i64)
(if
@ -480,14 +475,7 @@
)
)
)
(func $~lib/memory/memory.fill (; 6 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(call $~lib/memory/memset
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $~lib/arraybuffer/ArrayBuffer#constructor (; 7 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $~lib/arraybuffer/ArrayBuffer#constructor (; 5 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(if
(i32.gt_u
@ -505,7 +493,7 @@
)
)
(set_local $3
(call $~lib/internal/arraybuffer/allocUnsafe
(call $~lib/internal/arraybuffer/allocateUnsafe
(get_local $1)
)
)
@ -516,7 +504,7 @@
(i32.const 1)
)
)
(call $~lib/memory/memory.fill
(call $~lib/internal/memory/memset
(i32.add
(get_local $3)
(i32.const 8)
@ -527,7 +515,7 @@
)
(get_local $3)
)
(func $~lib/memory/memcpy (; 8 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memcpy (; 6 ;) (; has Stack IR ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
@ -1913,7 +1901,7 @@
)
)
)
(func $~lib/memory/memmove (; 9 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memmove (; 7 ;) (; has Stack IR ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(if
@ -1948,7 +1936,7 @@
(if
(get_local $3)
(block
(call $~lib/memory/memcpy
(call $~lib/internal/memory/memcpy
(get_local $0)
(get_local $1)
(get_local $2)
@ -2205,17 +2193,10 @@
)
)
)
(func $~lib/memory/memory.copy (; 10 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(call $~lib/memory/memmove
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $~lib/arraybuffer/ArrayBuffer#slice (; 11 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $~lib/arraybuffer/ArrayBuffer#slice (; 8 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(set_local $4
(set_local $3
(i32.load
(get_local $0)
)
@ -2227,82 +2208,84 @@
(i32.const 0)
)
(select
(tee_local $3
(tee_local $4
(i32.add
(get_local $4)
(get_local $3)
(get_local $1)
)
)
(i32.const 0)
(i32.gt_s
(get_local $3)
(get_local $4)
(i32.const 0)
)
)
(select
(tee_local $3
(tee_local $4
(get_local $1)
)
(get_local $4)
(get_local $3)
(i32.lt_s
(get_local $1)
(get_local $3)
(get_local $4)
)
)
)
)
(call $~lib/memory/memory.copy
(i32.add
(tee_local $2
(call $~lib/internal/arraybuffer/allocUnsafe
(tee_local $3
(select
(tee_local $3
(i32.sub
(tee_local $2
(if (result i32)
(i32.lt_s
(get_local $2)
(i32.const 0)
)
(select
(tee_local $3
(i32.add
(get_local $4)
(get_local $2)
)
)
(i32.const 0)
(i32.gt_s
(get_local $3)
(call $~lib/internal/memory/memmove
(tee_local $4
(i32.add
(tee_local $3
(call $~lib/internal/arraybuffer/allocateUnsafe
(tee_local $2
(select
(tee_local $4
(i32.sub
(tee_local $2
(if (result i32)
(i32.lt_s
(get_local $2)
(i32.const 0)
)
)
(select
(tee_local $3
(get_local $2)
(select
(tee_local $4
(i32.add
(get_local $3)
(get_local $2)
)
)
(i32.const 0)
(i32.gt_s
(get_local $4)
(i32.const 0)
)
)
(get_local $4)
(i32.lt_s
(select
(tee_local $4
(get_local $2)
)
(get_local $3)
(get_local $4)
(i32.lt_s
(get_local $2)
(get_local $3)
)
)
)
)
(get_local $1)
)
(get_local $1)
)
)
(i32.const 0)
(i32.gt_s
(get_local $3)
(i32.const 0)
(i32.gt_s
(get_local $4)
(i32.const 0)
)
)
)
)
)
(i32.const 8)
)
(i32.const 8)
)
(i32.add
(i32.add
@ -2311,11 +2294,11 @@
)
(get_local $1)
)
(get_local $3)
(get_local $2)
)
(get_local $2)
(get_local $3)
)
(func $~lib/arraybuffer/ArrayBuffer#slice|trampoline (; 12 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $~lib/arraybuffer/ArrayBuffer#slice|trampoline (; 9 ;) (; has Stack IR ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(block $2of2
(block $1of2
(block $0of2
@ -2340,7 +2323,7 @@
(get_local $2)
)
)
(func $start (; 13 ;) (type $v)
(func $start (; 10 ;) (; has Stack IR ;) (type $v)
(set_global $~lib/allocator/arena/startOffset
(i32.const 152)
)

View File

@ -148,15 +148,9 @@
)
(i32.const 0)
)
(func $~lib/memory/memory.allocate (; 3 ;) (type $ii) (param $0 i32) (result i32)
(return
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
)
(func $~lib/internal/arraybuffer/allocUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/internal/arraybuffer/allocateUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(if
(i32.eqz
(i32.le_u
@ -168,16 +162,23 @@
(call $~lib/env/abort
(i32.const 0)
(i32.const 52)
(i32.const 22)
(i32.const 23)
(i32.const 2)
)
(unreachable)
)
)
(set_local $1
(call $~lib/memory/memory.allocate
(call $~lib/internal/arraybuffer/computeSize
(get_local $0)
(block $~lib/memory/memory.allocate|inlined.0 (result i32)
(set_local $2
(call $~lib/internal/arraybuffer/computeSize
(get_local $0)
)
)
(br $~lib/memory/memory.allocate|inlined.0
(call $~lib/allocator/arena/__memory_allocate
(get_local $2)
)
)
)
)
@ -187,7 +188,7 @@
)
(get_local $1)
)
(func $~lib/memory/memset (; 5 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memset (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i64)
@ -539,15 +540,10 @@
)
)
)
(func $~lib/memory/memory.fill (; 6 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(call $~lib/memory/memset
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $~lib/arraybuffer/ArrayBuffer#constructor (; 7 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $~lib/arraybuffer/ArrayBuffer#constructor (; 5 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(if
(i32.gt_u
(get_local $1)
@ -564,7 +560,7 @@
)
)
(set_local $3
(call $~lib/internal/arraybuffer/allocUnsafe
(call $~lib/internal/arraybuffer/allocateUnsafe
(get_local $1)
)
)
@ -575,18 +571,26 @@
(i32.const 1)
)
)
(call $~lib/memory/memory.fill
(i32.add
(get_local $3)
(get_global $~lib/internal/arraybuffer/HEADER_SIZE)
(block $~lib/memory/memory.fill|inlined.0
(set_local $4
(i32.add
(get_local $3)
(get_global $~lib/internal/arraybuffer/HEADER_SIZE)
)
)
(set_local $5
(i32.const 0)
)
(call $~lib/internal/memory/memset
(get_local $4)
(get_local $5)
(get_local $1)
)
(i32.const 0)
(get_local $1)
)
)
(get_local $3)
)
(func $~lib/memory/memcpy (; 8 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memcpy (; 6 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
@ -2388,7 +2392,7 @@
)
)
)
(func $~lib/memory/memmove (; 9 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $~lib/internal/memory/memmove (; 7 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(if
(i32.eq
@ -2418,7 +2422,7 @@
)
)
(block
(call $~lib/memory/memcpy
(call $~lib/internal/memory/memcpy
(get_local $0)
(get_local $1)
(get_local $2)
@ -2706,14 +2710,7 @@
)
)
)
(func $~lib/memory/memory.copy (; 10 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(call $~lib/memory/memmove
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $~lib/arraybuffer/ArrayBuffer#slice (; 11 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $~lib/arraybuffer/ArrayBuffer#slice (; 8 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
@ -2816,27 +2813,35 @@
)
)
(set_local $7
(call $~lib/internal/arraybuffer/allocUnsafe
(call $~lib/internal/arraybuffer/allocateUnsafe
(get_local $6)
)
)
(call $~lib/memory/memory.copy
(i32.add
(get_local $7)
(get_global $~lib/internal/arraybuffer/HEADER_SIZE)
)
(i32.add
(block $~lib/memory/memory.copy|inlined.0
(set_local $4
(i32.add
(get_local $0)
(get_local $7)
(get_global $~lib/internal/arraybuffer/HEADER_SIZE)
)
(get_local $1)
)
(get_local $6)
(set_local $5
(i32.add
(i32.add
(get_local $0)
(get_global $~lib/internal/arraybuffer/HEADER_SIZE)
)
(get_local $1)
)
)
(call $~lib/internal/memory/memmove
(get_local $4)
(get_local $5)
(get_local $6)
)
)
(get_local $7)
)
(func $~lib/arraybuffer/ArrayBuffer#slice|trampoline (; 12 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func $~lib/arraybuffer/ArrayBuffer#slice|trampoline (; 9 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(block $2of2
(block $1of2
(block $0of2
@ -2861,7 +2866,7 @@
(get_local $2)
)
)
(func $start (; 13 ;) (type $v)
(func $start (; 10 ;) (type $v)
(set_global $~lib/allocator/arena/startOffset
(i32.and
(i32.add

View File

@ -17,7 +17,7 @@
(memory $0 0)
(export "memory" (memory $0))
(start $start)
(func $~lib/allocator/arena/__memory_allocate (; 0 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/allocator/arena/__memory_allocate (; 0 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -103,12 +103,12 @@
)
(i32.const 0)
)
(func $~lib/memory/memory.allocate (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/memory/memory.allocate (; 1 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
(func $std/constructor/EmptyCtor#constructor (; 2 ;) (type $ii) (param $0 i32) (result i32)
(func $std/constructor/EmptyCtor#constructor (; 2 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(if (result i32)
(get_local $0)
(get_local $0)
@ -117,7 +117,7 @@
)
)
)
(func $std/constructor/EmptyCtorWithFieldInit#constructor (; 3 ;) (type $ii) (param $0 i32) (result i32)
(func $std/constructor/EmptyCtorWithFieldInit#constructor (; 3 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(if
(i32.eqz
(get_local $0)
@ -133,7 +133,7 @@
)
(get_local $0)
)
(func $std/constructor/EmptyCtorWithFieldNoInit#constructor (; 4 ;) (type $ii) (param $0 i32) (result i32)
(func $std/constructor/EmptyCtorWithFieldNoInit#constructor (; 4 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(if
(i32.eqz
(get_local $0)
@ -149,29 +149,35 @@
)
(get_local $0)
)
(func $std/constructor/CtorReturns#constructor (; 5 ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/memory/memory.allocate
(func $std/constructor/CtorReturns#constructor (; 5 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/allocator/arena/__memory_allocate
(i32.const 0)
)
)
(func $std/constructor/CtorConditionallyReturns#constructor (; 6 ;) (type $ii) (param $0 i32) (result i32)
(func $std/constructor/CtorConditionallyReturns#constructor (; 6 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(if
(get_global $std/constructor/b)
(return
(tee_local $0
(call $~lib/allocator/arena/__memory_allocate
(i32.const 0)
)
)
)
)
(if
(i32.eqz
(get_local $0)
)
(set_local $0
(call $~lib/memory/memory.allocate
(i32.const 0)
)
)
)
(if (result i32)
(get_local $0)
(get_local $0)
(call $~lib/memory/memory.allocate
(i32.const 0)
)
)
(get_local $0)
)
(func $std/constructor/CtorConditionallyAllocates#constructor (; 7 ;) (type $ii) (param $0 i32) (result i32)
(func $std/constructor/CtorConditionallyAllocates#constructor (; 7 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(if
(get_global $std/constructor/b)
(if
@ -197,7 +203,7 @@
)
(get_local $0)
)
(func $start (; 8 ;) (type $v)
(func $start (; 8 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(set_global $~lib/allocator/arena/startOffset
(i32.const 8)

View File

@ -203,8 +203,16 @@
)
)
(func $std/constructor/CtorReturns#constructor (; 5 ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/memory/memory.allocate
(i32.const 0)
(local $1 i32)
(block $~lib/memory/memory.allocate|inlined.0 (result i32)
(set_local $1
(i32.const 0)
)
(br $~lib/memory/memory.allocate|inlined.0
(call $~lib/allocator/arena/__memory_allocate
(get_local $1)
)
)
)
)
(func $std/constructor/CtorConditionallyReturns#constructor (; 6 ;) (type $ii) (param $0 i32) (result i32)
@ -212,8 +220,15 @@
(if
(get_global $std/constructor/b)
(return
(call $~lib/memory/memory.allocate
(i32.const 0)
(block $~lib/memory/memory.allocate|inlined.1 (result i32)
(set_local $1
(i32.const 0)
)
(br $~lib/memory/memory.allocate|inlined.1
(call $~lib/allocator/arena/__memory_allocate
(get_local $1)
)
)
)
)
)

View File

@ -11,24 +11,24 @@
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
(global $~lib/collector/itcm/state (mut i32) (i32.const 0))
(global $~lib/collector/itcm/white (mut i32) (i32.const 0))
(global $~lib/collector/itcm/from (mut i32) (i32.const 0))
(global $~lib/collector/itcm/to (mut i32) (i32.const 0))
(global $~lib/collector/itcm/fromSpace (mut i32) (i32.const 0))
(global $~lib/collector/itcm/toSpace (mut i32) (i32.const 0))
(global $~lib/collector/itcm/iter (mut i32) (i32.const 0))
(global $~argc (mut i32) (i32.const 0))
(global $std/gc/obj (mut i32) (i32.const 0))
(global $std/gc/obj2 (mut i32) (i32.const 0))
(global $std/gc-basics/obj (mut i32) (i32.const 0))
(global $std/gc-basics/obj2 (mut i32) (i32.const 0))
(global $~started (mut i32) (i32.const 0))
(table 2 2 anyfunc)
(elem (i32.const 0) $std/gc/MyObject_visit $~lib/collector/itcm/__gc_mark)
(elem (i32.const 0) $std/gc-basics/MyObject_visit $~lib/collector/itcm/__gc_mark)
(memory $0 1)
(data (i32.const 8) "\t\00\00\00s\00t\00d\00/\00g\00c\00.\00t\00s")
(data (i32.const 24) "\10\00\00\00s\00t\00d\00/\00g\00c\00-\00b\00a\00s\00i\00c\00s\00.\00t\00s")
(export "memory" (memory $0))
(export "table" (table $0))
(export "main" (func $std/gc/main))
(func $std/gc/MyObject_visit (; 1 ;) (type $iv) (param $0 i32)
(export "main" (func $std/gc-basics/main))
(func $std/gc-basics/MyObject_visit (; 1 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(nop)
)
(func $~lib/allocator/arena/__memory_allocate (; 2 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/allocator/arena/__memory_allocate (; 2 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -114,12 +114,7 @@
)
(i32.const 0)
)
(func $~lib/memory/memory.allocate (; 3 ;) (type $ii) (param $0 i32) (result i32)
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
(func $~lib/collector/itcm/ManagedObjectList#clear (; 4 ;) (type $iv) (param $0 i32)
(func $~lib/collector/itcm/ManagedObjectList#clear (; 3 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(i32.store
(get_local $0)
(get_local $0)
@ -129,7 +124,7 @@
(get_local $0)
)
)
(func $~lib/collector/itcm/ManagedObject#get:color (; 5 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/collector/itcm/ManagedObject#get:color (; 4 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(i32.and
(i32.load
(get_local $0)
@ -137,7 +132,7 @@
(i32.const 3)
)
)
(func $~lib/collector/itcm/ManagedObject#get:next (; 6 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/collector/itcm/ManagedObject#get:next (; 5 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
(i32.and
(i32.load
(get_local $0)
@ -145,7 +140,7 @@
(i32.const -4)
)
)
(func $~lib/collector/itcm/ManagedObject#set:next (; 7 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $~lib/collector/itcm/ManagedObject#set:next (; 6 ;) (; has Stack IR ;) (type $iiv) (param $0 i32) (param $1 i32)
(i32.store
(get_local $0)
(i32.or
@ -159,7 +154,7 @@
)
)
)
(func $~lib/collector/itcm/ManagedObject#unlink (; 8 ;) (type $iv) (param $0 i32)
(func $~lib/collector/itcm/ManagedObject#unlink (; 7 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(local $1 i32)
(i32.store offset=4
(tee_local $1
@ -178,7 +173,7 @@
(get_local $1)
)
)
(func $~lib/collector/itcm/ManagedObjectList#push (; 9 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $~lib/collector/itcm/ManagedObjectList#push (; 8 ;) (; has Stack IR ;) (type $iiv) (param $0 i32) (param $1 i32)
(local $2 i32)
(set_local $2
(i32.load offset=4
@ -202,7 +197,7 @@
(get_local $1)
)
)
(func $~lib/collector/itcm/ManagedObject#makeGray (; 10 ;) (type $iv) (param $0 i32)
(func $~lib/collector/itcm/ManagedObject#makeGray (; 9 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(if
(i32.eq
(get_local $0)
@ -218,7 +213,7 @@
(get_local $0)
)
(call $~lib/collector/itcm/ManagedObjectList#push
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
(get_local $0)
)
(i32.store
@ -234,7 +229,7 @@
)
)
)
(func $~lib/collector/itcm/__gc_mark (; 11 ;) (type $iv) (param $0 i32)
(func $~lib/collector/itcm/__gc_mark (; 10 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(local $1 i32)
(if
(get_local $0)
@ -256,7 +251,7 @@
)
)
)
(func $~lib/collector/itcm/ManagedObject#set:color (; 12 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $~lib/collector/itcm/ManagedObject#set:color (; 11 ;) (; has Stack IR ;) (type $iiv) (param $0 i32) (param $1 i32)
(i32.store
(get_local $0)
(i32.or
@ -270,12 +265,7 @@
)
)
)
(func $~lib/memory/memory.free (; 13 ;) (type $iv) (param $0 i32)
(call $std/gc/MyObject_visit
(get_local $0)
)
)
(func $~lib/collector/itcm/step (; 14 ;) (type $v)
(func $~lib/collector/itcm/step (; 12 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(block $break|0
(block $case3|0
@ -297,32 +287,36 @@
(br $break|0)
)
)
(set_global $~lib/collector/itcm/from
(call $~lib/memory/memory.allocate
(i32.const 16)
(set_global $~lib/collector/itcm/fromSpace
(tee_local $0
(call $~lib/allocator/arena/__memory_allocate
(i32.const 16)
)
)
)
(i32.store offset=8
(get_global $~lib/collector/itcm/from)
(get_global $~lib/collector/itcm/fromSpace)
(i32.const -1)
)
(call $~lib/collector/itcm/ManagedObjectList#clear
(get_global $~lib/collector/itcm/from)
(get_global $~lib/collector/itcm/fromSpace)
)
(set_global $~lib/collector/itcm/to
(call $~lib/memory/memory.allocate
(i32.const 16)
(set_global $~lib/collector/itcm/toSpace
(tee_local $0
(call $~lib/allocator/arena/__memory_allocate
(i32.const 16)
)
)
)
(i32.store offset=8
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
(i32.const -1)
)
(call $~lib/collector/itcm/ManagedObjectList#clear
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(set_global $~lib/collector/itcm/iter
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(set_global $~lib/collector/itcm/state
(i32.const 1)
@ -343,7 +337,7 @@
(get_global $~lib/collector/itcm/iter)
)
)
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(block
(set_global $~lib/collector/itcm/iter
@ -377,16 +371,16 @@
(call $~lib/collector/itcm/ManagedObject#get:next
(get_global $~lib/collector/itcm/iter)
)
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(block
(set_local $0
(get_global $~lib/collector/itcm/from)
(get_global $~lib/collector/itcm/fromSpace)
)
(set_global $~lib/collector/itcm/from
(get_global $~lib/collector/itcm/to)
(set_global $~lib/collector/itcm/fromSpace
(get_global $~lib/collector/itcm/toSpace)
)
(set_global $~lib/collector/itcm/to
(set_global $~lib/collector/itcm/toSpace
(get_local $0)
)
(set_global $~lib/collector/itcm/white
@ -413,7 +407,7 @@
(tee_local $0
(get_global $~lib/collector/itcm/iter)
)
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(block
(set_global $~lib/collector/itcm/iter
@ -421,13 +415,19 @@
(get_local $0)
)
)
(call $~lib/memory/memory.free
(get_local $0)
(if
(i32.ge_u
(get_local $0)
(i32.const 60)
)
(call $std/gc-basics/MyObject_visit
(get_local $0)
)
)
)
(block
(call $~lib/collector/itcm/ManagedObjectList#clear
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(set_global $~lib/collector/itcm/state
(i32.const 1)
@ -436,8 +436,7 @@
)
)
)
(func $~lib/collector/itcm/__gc_allocate (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(func $~lib/collector/itcm/__gc_allocate (; 13 ;) (; has Stack IR ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(if
(i32.gt_u
(get_local $0)
@ -447,8 +446,8 @@
)
(call $~lib/collector/itcm/step)
(i32.store offset=8
(tee_local $2
(call $~lib/memory/memory.allocate
(tee_local $0
(call $~lib/allocator/arena/__memory_allocate
(i32.add
(get_local $0)
(i32.const 16)
@ -458,25 +457,19 @@
(get_local $1)
)
(call $~lib/collector/itcm/ManagedObject#set:color
(get_local $2)
(get_local $0)
(get_global $~lib/collector/itcm/white)
)
(call $~lib/collector/itcm/ManagedObjectList#push
(get_global $~lib/collector/itcm/from)
(get_local $2)
(get_global $~lib/collector/itcm/fromSpace)
(get_local $0)
)
(i32.add
(get_local $2)
(get_local $0)
(i32.const 16)
)
)
(func $~lib/gc/gc.allocate (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(call $~lib/collector/itcm/__gc_allocate
(get_local $0)
(get_local $1)
)
)
(func $~lib/collector/itcm/__gc_collect (; 17 ;) (type $v)
(func $~lib/collector/itcm/__gc_collect (; 14 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(block $break|0
(block $case1|0
@ -510,10 +503,10 @@
)
)
)
(func $~lib/gc/gc.collect (; 18 ;) (type $v)
(func $~lib/gc/gc.collect (; 15 ;) (; has Stack IR ;) (type $v)
(call $~lib/collector/itcm/__gc_collect)
)
(func $std/gc/main (; 19 ;) (type $i) (result i32)
(func $std/gc-basics/main (; 16 ;) (; has Stack IR ;) (type $i) (result i32)
(if
(i32.eqz
(get_global $~started)
@ -527,13 +520,13 @@
)
(i32.const 0)
)
(func $start (; 20 ;) (type $v)
(func $start (; 17 ;) (; has Stack IR ;) (type $v)
(local $0 i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(set_global $~lib/allocator/arena/startOffset
(i32.const 32)
(i32.const 64)
)
(set_global $~lib/allocator/arena/offset
(get_global $~lib/allocator/arena/startOffset)
@ -541,21 +534,21 @@
(set_global $~lib/collector/itcm/state
(i32.const 0)
)
(set_global $std/gc/obj
(call $~lib/gc/gc.allocate
(set_global $std/gc-basics/obj
(call $~lib/collector/itcm/__gc_allocate
(i32.const 4)
(i32.const 0)
)
)
(i32.store
(get_global $std/gc/obj)
(get_global $std/gc-basics/obj)
(i32.const 123)
)
(set_local $2
(i32.load offset=4
(tee_local $0
(i32.sub
(get_global $std/gc/obj)
(get_global $std/gc-basics/obj)
(i32.const 16)
)
)
@ -598,7 +591,7 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 8)
(i32.const 24)
(i32.const 19)
(i32.const 2)
)
@ -651,18 +644,18 @@
)
)
(call $~lib/gc/gc.collect)
(set_global $std/gc/obj
(set_global $std/gc-basics/obj
(i32.const 0)
)
(call $~lib/gc/gc.collect)
)
(func $~iterateRoots (; 21 ;) (type $iv) (param $0 i32)
(func $~iterateRoots (; 18 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(call_indirect (type $iv)
(get_global $std/gc/obj)
(get_global $std/gc-basics/obj)
(get_local $0)
)
(call_indirect (type $iv)
(get_global $std/gc/obj2)
(get_global $std/gc-basics/obj2)
(get_local $0)
)
)

View File

@ -8,7 +8,7 @@ class MyObject {
function MyObject_visit(ref: usize): void {} // function table index == classId ?
// allocate a managed instance
var obj: MyObject | null = changetype<MyObject>(gc.allocate(offsetof<MyObject>(), MyObject_visit));
var obj: MyObject | null = changetype<MyObject>(__gc_allocate(offsetof<MyObject>(), MyObject_visit));
obj.a = 123;
// check header
@ -32,6 +32,3 @@ gc.collect(); // should free 'obj' because it isn't referenced anymore (see trac
var obj2: MyObject; // should also iterate globals defined late
export function main(): i32 { return 0; }
// BEWARE: The compiler does not emit any integrations except gc.iterateRoots yet, hence trying to
// use the GC with a 'normally' allocated object will break it, as it has no managed header!

View File

@ -14,29 +14,29 @@
(global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0))
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
(global $~lib/collector/itcm/TRACE i32 (i32.const 0))
(global $~lib/collector/itcm/HEADER_SIZE i32 (i32.const 16))
(global $~lib/collector/itcm/State.INIT i32 (i32.const 0))
(global $~lib/collector/itcm/State.IDLE i32 (i32.const 1))
(global $~lib/collector/itcm/State.MARK i32 (i32.const 2))
(global $~lib/collector/itcm/State.SWEEP i32 (i32.const 3))
(global $~lib/collector/itcm/state (mut i32) (i32.const 0))
(global $~lib/collector/itcm/white (mut i32) (i32.const 0))
(global $~lib/collector/itcm/from (mut i32) (i32.const 0))
(global $~lib/collector/itcm/to (mut i32) (i32.const 0))
(global $~lib/collector/itcm/fromSpace (mut i32) (i32.const 0))
(global $~lib/collector/itcm/toSpace (mut i32) (i32.const 0))
(global $~lib/collector/itcm/iter (mut i32) (i32.const 0))
(global $~lib/collector/itcm/ManagedObject.SIZE i32 (i32.const 16))
(global $~argc (mut i32) (i32.const 0))
(global $std/gc/obj (mut i32) (i32.const 0))
(global $std/gc/obj2 (mut i32) (i32.const 0))
(global $std/gc-basics/obj (mut i32) (i32.const 0))
(global $std/gc-basics/obj2 (mut i32) (i32.const 0))
(global $~started (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 32))
(global $HEAP_BASE i32 (i32.const 60))
(table 2 2 anyfunc)
(elem (i32.const 0) $std/gc/MyObject_visit $~lib/collector/itcm/__gc_mark)
(elem (i32.const 0) $std/gc-basics/MyObject_visit $~lib/collector/itcm/__gc_mark)
(memory $0 1)
(data (i32.const 8) "\t\00\00\00s\00t\00d\00/\00g\00c\00.\00t\00s\00")
(data (i32.const 8) "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\10\00\00\00s\00t\00d\00/\00g\00c\00-\00b\00a\00s\00i\00c\00s\00.\00t\00s\00")
(export "memory" (memory $0))
(export "table" (table $0))
(export "main" (func $std/gc/main))
(func $std/gc/MyObject_visit (; 1 ;) (type $iv) (param $0 i32)
(export "main" (func $std/gc-basics/main))
(func $std/gc-basics/MyObject_visit (; 1 ;) (type $iv) (param $0 i32)
(nop)
)
(func $~lib/allocator/arena/__memory_allocate (; 2 ;) (type $ii) (param $0 i32) (result i32)
@ -147,14 +147,7 @@
)
(i32.const 0)
)
(func $~lib/memory/memory.allocate (; 3 ;) (type $ii) (param $0 i32) (result i32)
(return
(call $~lib/allocator/arena/__memory_allocate
(get_local $0)
)
)
)
(func $~lib/collector/itcm/ManagedObjectList#clear (; 4 ;) (type $iv) (param $0 i32)
(func $~lib/collector/itcm/ManagedObjectList#clear (; 3 ;) (type $iv) (param $0 i32)
(i32.store
(get_local $0)
(get_local $0)
@ -164,7 +157,7 @@
(get_local $0)
)
)
(func $~lib/collector/itcm/ManagedObject#get:color (; 5 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/collector/itcm/ManagedObject#get:color (; 4 ;) (type $ii) (param $0 i32) (result i32)
(i32.and
(i32.load
(get_local $0)
@ -172,7 +165,7 @@
(i32.const 3)
)
)
(func $~lib/collector/itcm/ManagedObject#get:next (; 6 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/collector/itcm/ManagedObject#get:next (; 5 ;) (type $ii) (param $0 i32) (result i32)
(i32.and
(i32.load
(get_local $0)
@ -183,7 +176,7 @@
)
)
)
(func $~lib/collector/itcm/ManagedObject#set:next (; 7 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $~lib/collector/itcm/ManagedObject#set:next (; 6 ;) (type $iiv) (param $0 i32) (param $1 i32)
(i32.store
(get_local $0)
(i32.or
@ -197,7 +190,7 @@
)
)
)
(func $~lib/collector/itcm/ManagedObject#unlink (; 8 ;) (type $iv) (param $0 i32)
(func $~lib/collector/itcm/ManagedObject#unlink (; 7 ;) (type $iv) (param $0 i32)
(local $1 i32)
(local $2 i32)
(set_local $1
@ -219,7 +212,7 @@
(get_local $1)
)
)
(func $~lib/collector/itcm/ManagedObjectList#push (; 9 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $~lib/collector/itcm/ManagedObjectList#push (; 8 ;) (type $iiv) (param $0 i32) (param $1 i32)
(local $2 i32)
(set_local $2
(i32.load offset=4
@ -243,7 +236,7 @@
(get_local $1)
)
)
(func $~lib/collector/itcm/ManagedObject#makeGray (; 10 ;) (type $iv) (param $0 i32)
(func $~lib/collector/itcm/ManagedObject#makeGray (; 9 ;) (type $iv) (param $0 i32)
(if
(i32.eq
(get_local $0)
@ -259,7 +252,7 @@
(get_local $0)
)
(call $~lib/collector/itcm/ManagedObjectList#push
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
(get_local $0)
)
(i32.store
@ -278,7 +271,7 @@
)
)
)
(func $~lib/collector/itcm/__gc_mark (; 11 ;) (type $iv) (param $0 i32)
(func $~lib/collector/itcm/__gc_mark (; 10 ;) (type $iv) (param $0 i32)
(local $1 i32)
(if
(get_local $0)
@ -287,7 +280,7 @@
(block $~lib/collector/itcm/refToObj|inlined.0 (result i32)
(i32.sub
(get_local $0)
(get_global $~lib/collector/itcm/ManagedObject.SIZE)
(get_global $~lib/collector/itcm/HEADER_SIZE)
)
)
)
@ -305,7 +298,7 @@
)
)
)
(func $~lib/collector/itcm/ManagedObject#set:color (; 12 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $~lib/collector/itcm/ManagedObject#set:color (; 11 ;) (type $iiv) (param $0 i32) (param $1 i32)
(i32.store
(get_local $0)
(i32.or
@ -322,16 +315,10 @@
)
)
)
(func $~lib/allocator/arena/__memory_free (; 13 ;) (type $iv) (param $0 i32)
(func $~lib/allocator/arena/__memory_free (; 12 ;) (type $iv) (param $0 i32)
(nop)
)
(func $~lib/memory/memory.free (; 14 ;) (type $iv) (param $0 i32)
(call $~lib/allocator/arena/__memory_free
(get_local $0)
)
(return)
)
(func $~lib/collector/itcm/step (; 15 ;) (type $v)
(func $~lib/collector/itcm/step (; 13 ;) (type $v)
(local $0 i32)
(local $1 i32)
(block $break|0
@ -369,32 +356,46 @@
(br $break|0)
)
(block
(set_global $~lib/collector/itcm/from
(call $~lib/memory/memory.allocate
(get_global $~lib/collector/itcm/ManagedObject.SIZE)
(set_global $~lib/collector/itcm/fromSpace
(block $~lib/memory/memory.allocate|inlined.0 (result i32)
(set_local $1
(get_global $~lib/collector/itcm/HEADER_SIZE)
)
(br $~lib/memory/memory.allocate|inlined.0
(call $~lib/allocator/arena/__memory_allocate
(get_local $1)
)
)
)
)
(i32.store offset=8
(get_global $~lib/collector/itcm/from)
(get_global $~lib/collector/itcm/fromSpace)
(i32.const -1)
)
(call $~lib/collector/itcm/ManagedObjectList#clear
(get_global $~lib/collector/itcm/from)
(get_global $~lib/collector/itcm/fromSpace)
)
(set_global $~lib/collector/itcm/to
(call $~lib/memory/memory.allocate
(get_global $~lib/collector/itcm/ManagedObject.SIZE)
(set_global $~lib/collector/itcm/toSpace
(block $~lib/memory/memory.allocate|inlined.1 (result i32)
(set_local $1
(get_global $~lib/collector/itcm/HEADER_SIZE)
)
(br $~lib/memory/memory.allocate|inlined.1
(call $~lib/allocator/arena/__memory_allocate
(get_local $1)
)
)
)
)
(i32.store offset=8
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
(i32.const -1)
)
(call $~lib/collector/itcm/ManagedObjectList#clear
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(set_global $~lib/collector/itcm/iter
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(set_global $~lib/collector/itcm/state
(get_global $~lib/collector/itcm/State.IDLE)
@ -420,7 +421,7 @@
(if
(i32.ne
(get_local $0)
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(block
(set_global $~lib/collector/itcm/iter
@ -439,7 +440,7 @@
(block $~lib/collector/itcm/objToRef|inlined.0 (result i32)
(i32.add
(get_local $0)
(get_global $~lib/collector/itcm/ManagedObject.SIZE)
(get_global $~lib/collector/itcm/HEADER_SIZE)
)
)
(i32.load offset=8
@ -459,16 +460,16 @@
(if
(i32.eq
(get_local $0)
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(block
(set_local $1
(get_global $~lib/collector/itcm/from)
(get_global $~lib/collector/itcm/fromSpace)
)
(set_global $~lib/collector/itcm/from
(get_global $~lib/collector/itcm/to)
(set_global $~lib/collector/itcm/fromSpace
(get_global $~lib/collector/itcm/toSpace)
)
(set_global $~lib/collector/itcm/to
(set_global $~lib/collector/itcm/toSpace
(get_local $1)
)
(set_global $~lib/collector/itcm/white
@ -498,7 +499,7 @@
(if
(i32.ne
(get_local $0)
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(block
(set_global $~lib/collector/itcm/iter
@ -506,13 +507,24 @@
(get_local $0)
)
)
(call $~lib/memory/memory.free
(get_local $0)
(if
(i32.ge_u
(get_local $0)
(get_global $HEAP_BASE)
)
(block $~lib/memory/memory.free|inlined.0
(block
(call $~lib/allocator/arena/__memory_free
(get_local $0)
)
(br $~lib/memory/memory.free|inlined.0)
)
)
)
)
(block
(call $~lib/collector/itcm/ManagedObjectList#clear
(get_global $~lib/collector/itcm/to)
(get_global $~lib/collector/itcm/toSpace)
)
(set_global $~lib/collector/itcm/state
(get_global $~lib/collector/itcm/State.IDLE)
@ -523,55 +535,55 @@
)
)
)
(func $~lib/collector/itcm/__gc_allocate (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/collector/itcm/__gc_allocate (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(if
(i32.gt_u
(get_local $0)
(i32.sub
(get_global $~lib/internal/allocator/MAX_SIZE_32)
(get_global $~lib/collector/itcm/ManagedObject.SIZE)
(get_global $~lib/collector/itcm/HEADER_SIZE)
)
)
(unreachable)
)
(call $~lib/collector/itcm/step)
(set_local $2
(call $~lib/memory/memory.allocate
(i32.add
(get_global $~lib/collector/itcm/ManagedObject.SIZE)
(get_local $0)
(set_local $3
(block $~lib/memory/memory.allocate|inlined.2 (result i32)
(set_local $2
(i32.add
(get_global $~lib/collector/itcm/HEADER_SIZE)
(get_local $0)
)
)
(br $~lib/memory/memory.allocate|inlined.2
(call $~lib/allocator/arena/__memory_allocate
(get_local $2)
)
)
)
)
(i32.store offset=8
(get_local $2)
(get_local $3)
(get_local $1)
)
(call $~lib/collector/itcm/ManagedObject#set:color
(get_local $2)
(get_local $3)
(get_global $~lib/collector/itcm/white)
)
(call $~lib/collector/itcm/ManagedObjectList#push
(get_global $~lib/collector/itcm/from)
(get_local $2)
(get_global $~lib/collector/itcm/fromSpace)
(get_local $3)
)
(block $~lib/collector/itcm/objToRef|inlined.1 (result i32)
(i32.add
(get_local $2)
(get_global $~lib/collector/itcm/ManagedObject.SIZE)
(get_local $3)
(get_global $~lib/collector/itcm/HEADER_SIZE)
)
)
)
(func $~lib/gc/gc.allocate (; 17 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(return
(call $~lib/collector/itcm/__gc_allocate
(get_local $0)
(get_local $1)
)
)
)
(func $~lib/collector/itcm/__gc_collect (; 18 ;) (type $v)
(func $~lib/collector/itcm/__gc_collect (; 15 ;) (type $v)
(local $0 i32)
(block $break|0
(block $case1|0
@ -611,11 +623,11 @@
)
)
)
(func $~lib/gc/gc.collect (; 19 ;) (type $v)
(func $~lib/gc/gc.collect (; 16 ;) (type $v)
(call $~lib/collector/itcm/__gc_collect)
(return)
)
(func $std/gc/main (; 20 ;) (type $i) (result i32)
(func $std/gc-basics/main (; 17 ;) (type $i) (result i32)
(if
(i32.eqz
(get_global $~started)
@ -629,7 +641,7 @@
)
(i32.const 0)
)
(func $start (; 21 ;) (type $v)
(func $start (; 18 ;) (type $v)
(local $0 i32)
(local $1 i32)
(local $2 i32)
@ -654,20 +666,20 @@
(set_global $~lib/collector/itcm/state
(get_global $~lib/collector/itcm/State.INIT)
)
(set_global $std/gc/obj
(call $~lib/gc/gc.allocate
(set_global $std/gc-basics/obj
(call $~lib/collector/itcm/__gc_allocate
(i32.const 4)
(i32.const 0)
)
)
(i32.store
(get_global $std/gc/obj)
(get_global $std/gc-basics/obj)
(i32.const 123)
)
(block
(set_local $0
(i32.sub
(get_global $std/gc/obj)
(get_global $std/gc-basics/obj)
(i32.const 16)
)
)
@ -715,7 +727,7 @@
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 8)
(i32.const 24)
(i32.const 19)
(i32.const 2)
)
@ -790,18 +802,18 @@
)
)
(call $~lib/gc/gc.collect)
(set_global $std/gc/obj
(set_global $std/gc-basics/obj
(i32.const 0)
)
(call $~lib/gc/gc.collect)
)
(func $~iterateRoots (; 22 ;) (type $iv) (param $0 i32)
(func $~iterateRoots (; 19 ;) (type $iv) (param $0 i32)
(call_indirect (type $iv)
(get_global $std/gc/obj)
(get_global $std/gc-basics/obj)
(get_local $0)
)
(call_indirect (type $iv)
(get_global $std/gc/obj2)
(get_global $std/gc-basics/obj2)
(get_local $0)
)
)

View File

@ -14,7 +14,7 @@
(export "memory" (memory $0))
(export "table" (table $0))
(start $start)
(func $start~anonymous|0 (; 1 ;) (type $iv) (param $0 i32)
(func $start~anonymous|0 (; 1 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(set_global $std/gc-integration/i
(i32.add
(get_global $std/gc-integration/i)
@ -33,14 +33,14 @@
(call $~lib/env/abort
(i32.const 0)
(i32.const 8)
(i32.const 14)
(i32.const 18)
(i32.const 37)
)
(unreachable)
)
)
)
(func $start (; 2 ;) (type $v)
(func $start (; 2 ;) (; has Stack IR ;) (type $v)
(call $~iterateRoots
(i32.const 0)
)
@ -53,14 +53,14 @@
(call $~lib/env/abort
(i32.const 0)
(i32.const 8)
(i32.const 15)
(i32.const 19)
(i32.const 0)
)
(unreachable)
)
)
)
(func $~iterateRoots (; 3 ;) (type $iv) (param $0 i32)
(func $~iterateRoots (; 3 ;) (; has Stack IR ;) (type $iv) (param $0 i32)
(call_indirect (type $iv)
(i32.const 8)
(get_local $0)

Some files were not shown because too many files have changed in this diff Show More