Skip to content

Commit 48cbbbb

Browse files
committed
More cleanup
1 parent 3d7e8b2 commit 48cbbbb

File tree

18 files changed

+380
-387
lines changed

18 files changed

+380
-387
lines changed

dist/assemblyscript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
1212
},
1313
"dependencies": {
14-
"@types/long": "^3.0.32",
1514
"binaryen": "42.0.0-nightly.20180213",
1615
"glob": "^7.1.2",
1716
"long": "^4.0.0",
@@ -26,7 +25,7 @@
2625
"source-map-support": "^0.5.3",
2726
"ts-loader": "^3.5.0",
2827
"tslint": "^5.9.1",
29-
"typescript": "^2.7.1",
28+
"typescript": "^2.7.2",
3029
"webpack": "^3.11.0"
3130
},
3231
"main": "index.js",

src/ast.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
///////////////////////////// Abstract Syntax Tree /////////////////////////////
2-
31
import {
42
PATH_DELIMITER,
53
STATIC_DELIMITER,

src/builtins.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ import {
4141
} from "./program";
4242

4343
/** Compiles a get of a built-in global. */
44-
export function compileGetConstant(compiler: Compiler, global: Global, reportNode: Node): ExpressionRef {
44+
export function compileGetConstant(
45+
compiler: Compiler,
46+
global: Global,
47+
reportNode: Node
48+
): ExpressionRef {
4549
switch (global.internalName) {
4650

4751
case "NaN": // context-sensitive
@@ -58,14 +62,23 @@ export function compileGetConstant(compiler: Compiler, global: Global, reportNod
5862

5963
case "HEAP_BASE": // never inlined for linking purposes
6064
compiler.currentType = compiler.options.usizeType;
61-
return compiler.module.createGetGlobal("HEAP_BASE", compiler.options.nativeSizeType);
65+
return compiler.module.createGetGlobal(
66+
"HEAP_BASE", compiler.currentType.toNativeType()
67+
);
6268
}
6369
compiler.error(DiagnosticCode.Operation_not_supported, reportNode.range);
6470
return compiler.module.createUnreachable();
6571
}
6672

6773
/** Compiles a call to a built-in function. */
68-
export function compileCall(compiler: Compiler, prototype: FunctionPrototype, typeArguments: Type[] | null, operands: Expression[], contextualType: Type, reportNode: Node): ExpressionRef {
74+
export function compileCall(
75+
compiler: Compiler,
76+
prototype: FunctionPrototype,
77+
typeArguments: Type[] | null,
78+
operands: Expression[],
79+
contextualType: Type,
80+
reportNode: Node
81+
): ExpressionRef {
6982
var module = compiler.module;
7083

7184
var arg0: ExpressionRef,

src/extra/ast.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
///////////////////////// Abstract Syntax Tree Extras //////////////////////////
1+
// Abstract Syntax Tree extras that are not needed in a standalone compiler but
2+
// quite useful for testing the parser.
23

34
import {
45
Token,

src/glue/js/binaryen.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare function allocate_memory(size: usize): usize;
2+
declare function free_memory(ptr: usize): void;

src/glue/js/binaryen.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copy Binaryen exports to global scope
2+
3+
const binaryen = global.Binaryen || require("binaryen");
4+
5+
for (var key in binaryen)
6+
if (key.startsWith("_Binaryen") || key.startsWith("_Relooper"))
7+
global[key] = binaryen[key];
8+
9+
// Utilize Binaryen's heap
10+
11+
global.allocate_memory = function(size) {
12+
if (!size) return 0; // should be safe in our case
13+
return binaryen._malloc(size);
14+
};
15+
16+
global.free_memory = function(ptr) {
17+
if (ptr) binaryen._free(ptr);
18+
};
19+
20+
global.move_memory = function(dest, src, n) {
21+
return binaryen._memmove(dest, src, n);
22+
};
23+
24+
global.store = function(ptr, val) {
25+
binaryen.HEAPU8[ptr] = val;
26+
};
27+
28+
global.load = function(ptr) {
29+
return binaryen.HEAPU8[ptr];
30+
};
31+
32+
// Implement module stubs
33+
34+
const Module = require("../../module").Module;
35+
36+
Module.prototype.toText = function toText() {
37+
var previousPrint = binaryen.print;
38+
var ret = "";
39+
binaryen.print = function(x) { ret += x + "\n" };
40+
_BinaryenModulePrint(this.ref);
41+
binaryen.print = previousPrint;
42+
return ret;
43+
};
44+
45+
Module.prototype.toAsmjs = function toAsmjs() {
46+
var previousPrint = binaryen.print;
47+
var ret = "";
48+
binaryen.print = function(x) { ret += x + "\n" };
49+
_BinaryenModulePrintAsmjs(this.ref);
50+
binaryen.print = previousPrint;
51+
return ret;
52+
};

src/glue/js/i64.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare type I64 = Long;
1+
declare type I64 = { __Long__: true }; // opaque
22

33
declare function i64_new(lo: i32, hi?: i32): I64;
44
declare function i64_low(value: I64): i32;

0 commit comments

Comments
 (0)