Skip to content

Commit 39b489b

Browse files
authored
Rename memory instructions; Rework constant handling (AssemblyScript#177)
* Rename memory instructions as proposed by the bulk-memory-operations spec. * Rename memory manager functions to memory.* as well * Remove automatic inlining of constant globals (Binaryen does this now) * Improve 'const' enum compatibility * Improve module-level export generation * Enable the inline decorator for constant variables * Add ERROR, WARNING and INFO macros that emit a user-defined diagnostic * Reintroduce builtin decorator so these can appear anywhere in stdlib again * Inline isNaN and isFinite by default * Make an interface around gc.* similar to memory.* * Emit an error when trying to inline a mutable variable * Slim down CI stages * Add a more convenient tracing utility for debugging * Implement some prequesites for an eventual bundled GC
1 parent 34e8fac commit 39b489b

File tree

196 files changed

+28564
-6524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+28564
-6524
lines changed

.travis.yml

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,24 @@
11
language: node_js
22
notifications:
33
email: false
4-
before_install: npm i -g npm@latest --no-audit
5-
install: npm config set progress=false && npm i --no-audit
4+
before_install: npm config set progress=false && npm i -g npm@latest --no-audit
5+
install: npm i --no-audit
66
cache:
77
directories:
88
- node_modules
9-
stages:
10-
- name: check-pr
11-
if: type = pull_request
129
jobs:
1310
include:
14-
15-
- stage: check-pr
16-
node_js: lts/*
17-
script: ./scripts/check-pr.sh
18-
env: Checks contributing guidelines before testing pull requests
19-
20-
- stage: lint
21-
node_js: node
22-
script: npm run lint
23-
env: Checks the sources with TSLint
24-
25-
- stage: test
26-
node_js: lts/*
27-
script: npm run clean && node bin/asc -v && npm test
28-
env: Tests the sources on latest node.js LTS
29-
- node_js: node
30-
script: npm run clean && node bin/asc -v && npm test
31-
env: Tests the sources on latest stable node.js
3211
- node_js: lts/*
3312
script:
34-
- npm run clean
35-
- cd $TRAVIS_BUILD_DIR/tests/allocators/arena && npm run build && cd .. && npm test arena
36-
- cd $TRAVIS_BUILD_DIR/tests/allocators/buddy && npm run build && cd .. && npm test buddy
37-
- cd $TRAVIS_BUILD_DIR/tests/allocators/tlsf && npm run build && cd .. && npm test tlsf
38-
env: Tests the allocators on latest node.js LTS
39-
40-
- stage: build
41-
node_js: lts/*
42-
script: npm run build && node bin/asc -v && npm test
43-
env: Builds and tests the bundle on latest node.js LTS
13+
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then ./scripts/check-pr.sh; fi
14+
- npm run all
15+
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
16+
cd $TRAVIS_BUILD_DIR/tests/allocators/arena && npm run build && cd .. && npm test arena &&
17+
cd $TRAVIS_BUILD_DIR/tests/allocators/buddy && npm run build && cd .. && npm test buddy &&
18+
cd $TRAVIS_BUILD_DIR/tests/allocators/tlsf && npm run build && cd .. && npm test tlsf;
19+
fi
20+
env: Runs the tests on node.js LTS
4421
- node_js: node
45-
script: npm run build && node bin/asc -v && npm test
46-
env: Builds and tests the bundle on latest stable node.js
22+
script:
23+
- npm run all
24+
env: Runs the tests on node.js stable

cli/asc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ exports.main = function main(argv, options, callback) {
414414
// Initialize default aliases
415415
assemblyscript.setGlobalAlias(compilerOptions, "Math", "NativeMath");
416416
assemblyscript.setGlobalAlias(compilerOptions, "Mathf", "NativeMathf");
417-
assemblyscript.setGlobalAlias(compilerOptions, "abort", "~lib/env/abort"); // to disable: --use abort=
417+
assemblyscript.setGlobalAlias(compilerOptions, "abort", "~lib/env/abort");
418+
assemblyscript.setGlobalAlias(compilerOptions, "trace", "~lib/env/trace");
418419

419420
// Add or override aliases if specified
420421
if (args.use) {
0 Bytes
Binary file not shown.

examples/game-of-life/build/optimized.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
(global $assembly/index/w (mut i32) (i32.const 0))
1212
(global $assembly/index/h (mut i32) (i32.const 0))
1313
(global $assembly/index/s (mut i32) (i32.const 0))
14+
(export "memory" (memory $0))
1415
(export "init" (func $assembly/index/init))
1516
(export "step" (func $assembly/index/step))
1617
(export "fill" (func $assembly/index/fill))
17-
(export "memory" (memory $0))
1818
(func $assembly/index/init (; 1 ;) (type $iiv) (param $0 i32) (param $1 i32)
1919
(local $2 i32)
2020
;;@ assembly/index.ts:29:2

examples/game-of-life/build/untouched.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
(global $assembly/index/h (mut i32) (i32.const 0))
1313
(global $assembly/index/s (mut i32) (i32.const 0))
1414
(global $HEAP_BASE i32 (i32.const 8))
15+
(export "memory" (memory $0))
1516
(export "init" (func $assembly/index/init))
1617
(export "step" (func $assembly/index/step))
1718
(export "fill" (func $assembly/index/fill))
18-
(export "memory" (memory $0))
1919
(func $assembly/index/init (; 1 ;) (type $iiv) (param $0 i32) (param $1 i32)
2020
(local $2 i32)
2121
(local $3 i32)

examples/i64-polyfill/build/optimized.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
(type $iiiiv (func (param i32 i32 i32 i32)))
55
(global $assembly/i64/lo (mut i32) (i32.const 0))
66
(global $assembly/i64/hi (mut i32) (i32.const 0))
7-
(memory $0 1)
7+
(memory $0 0)
8+
(export "memory" (memory $0))
89
(export "getLo" (func $assembly/i64/getLo))
910
(export "getHi" (func $assembly/i64/getHi))
1011
(export "clz" (func $assembly/i64/clz))
@@ -36,7 +37,6 @@
3637
(export "gt_u" (func $assembly/i64/gt_u))
3738
(export "ge_s" (func $assembly/i64/ge_s))
3839
(export "ge_u" (func $assembly/i64/ge_u))
39-
(export "memory" (memory $0))
4040
(func $assembly/i64/getLo (; 0 ;) (type $i) (result i32)
4141
;;@ assembly/i64.ts:4:9
4242
(get_global $assembly/i64/lo)

examples/i64-polyfill/build/untouched.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
(global $NaN f64 (f64.const nan:0x8000000000000))
88
(global $Infinity f64 (f64.const inf))
99
(global $HEAP_BASE i32 (i32.const 8))
10-
(memory $0 1)
10+
(memory $0 0)
11+
(export "memory" (memory $0))
1112
(export "getLo" (func $assembly/i64/getLo))
1213
(export "getHi" (func $assembly/i64/getHi))
1314
(export "clz" (func $assembly/i64/clz))
@@ -39,7 +40,6 @@
3940
(export "gt_u" (func $assembly/i64/gt_u))
4041
(export "ge_s" (func $assembly/i64/ge_s))
4142
(export "ge_u" (func $assembly/i64/ge_u))
42-
(export "memory" (memory $0))
4343
(func $assembly/i64/getLo (; 0 ;) (type $i) (result i32)
4444
;;@ assembly/i64.ts:4:9
4545
(get_global $assembly/i64/lo)
0 Bytes
Binary file not shown.

examples/mandelbrot/build/optimized.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
(import "JSMath" "log" (func $~lib/math/JSMath.log (param f64) (result f64)))
66
(import "JSMath" "LN2" (global $~lib/math/JSMath.LN2 f64))
77
(import "env" "memory" (memory $0 0))
8-
(export "computeLine" (func $assembly/index/computeLine))
98
(export "memory" (memory $0))
9+
(export "computeLine" (func $assembly/index/computeLine))
1010
(func $assembly/index/computeLine (; 2 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
1111
(local $4 f64)
1212
(local $5 f64)

examples/mandelbrot/build/untouched.wat

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
(import "env" "memory" (memory $0 0))
1010
(global $assembly/index/NUM_COLORS i32 (i32.const 2048))
1111
(global $HEAP_BASE i32 (i32.const 8))
12-
(export "computeLine" (func $assembly/index/computeLine))
1312
(export "memory" (memory $0))
14-
(func $isFinite<f64> (; 2 ;) (type $Fi) (param $0 f64) (result i32)
15-
;;@ ~lib/builtins.ts:22:26
13+
(export "computeLine" (func $assembly/index/computeLine))
14+
(func $~lib/builtins/isFinite<f64> (; 2 ;) (type $Fi) (param $0 f64) (result i32)
15+
;;@ ~lib/builtins.ts:16:70
1616
(f64.eq
17-
;;@ ~lib/builtins.ts:22:9
17+
;;@ ~lib/builtins.ts:16:53
1818
(f64.sub
1919
(get_local $0)
20-
;;@ ~lib/builtins.ts:22:17
20+
;;@ ~lib/builtins.ts:16:61
2121
(get_local $0)
2222
)
23-
;;@ ~lib/builtins.ts:22:26
23+
;;@ ~lib/builtins.ts:16:70
2424
(f64.const 0)
2525
)
2626
)
@@ -375,7 +375,7 @@
375375
(set_local $17
376376
;;@ assembly/index.ts:37:15
377377
(if (result i32)
378-
(call $isFinite<f64>
378+
(call $~lib/builtins/isFinite<f64>
379379
;;@ assembly/index.ts:37:24
380380
(get_local $15)
381381
)
@@ -386,7 +386,7 @@
386386
(f64.convert_s/i32
387387
(i32.sub
388388
;;@ assembly/index.ts:38:15
389-
(i32.const 2048)
389+
(get_global $assembly/index/NUM_COLORS)
390390
;;@ assembly/index.ts:38:28
391391
(i32.const 1)
392392
)
@@ -421,7 +421,7 @@
421421
)
422422
;;@ assembly/index.ts:39:8
423423
(i32.sub
424-
(i32.const 2048)
424+
(get_global $assembly/index/NUM_COLORS)
425425
;;@ assembly/index.ts:39:21
426426
(i32.const 1)
427427
)

examples/n-body/build/index.asm.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ function asmFunc(global, env, buffer) {
2424
var $lib_allocator_arena_startOffset = 0;
2525
var $lib_allocator_arena_offset = 0;
2626
var assembly_index_system = 0;
27-
var HEAP_BASE = 40;
2827
var i64toi32_i32$HIGH_BITS = 0;
29-
function $lib_allocator_arena_allocate_memory($0) {
28+
function $lib_allocator_arena___memory_allocate($0) {
3029
$0 = $0 | 0;
3130
var $1 = 0, $2 = 0, $3 = 0, wasm2asm_i32$0 = 0, wasm2asm_i32$1 = 0, wasm2asm_i32$2 = 0;
3231
if ($0) {
@@ -55,7 +54,7 @@ function asmFunc(global, env, buffer) {
5554
$7 = +$7;
5655
var wasm2asm_i32$0 = 0, wasm2asm_f64$0 = 0.0;
5756
if (($0 | 0) == (0 | 0)) {
58-
$0 = $lib_allocator_arena_allocate_memory(56 | 0) | 0;
57+
$0 = $lib_allocator_arena___memory_allocate(56 | 0) | 0;
5958
wasm2asm_i32$0 = $0;
6059
wasm2asm_f64$0 = $1;
6160
HEAPF64[wasm2asm_i32$0 >> 3] = wasm2asm_f64$0;
@@ -81,7 +80,7 @@ function asmFunc(global, env, buffer) {
8180
return $0 | 0;
8281
}
8382

84-
function $lib_memory_set_memory($0, $1, $2) {
83+
function $lib_memory_memset($0, $1, $2) {
8584
$0 = $0 | 0;
8685
$1 = $1 | 0;
8786
$2 = $2 | 0;
@@ -253,12 +252,12 @@ function asmFunc(global, env, buffer) {
253252
abort();
254253
}
255254
$2 = $1 << 2 | 0;
256-
$3 = $lib_allocator_arena_allocate_memory(1 << (32 - Math_clz32($2 + 7 | 0) | 0) | 0 | 0) | 0;
255+
$3 = $lib_allocator_arena___memory_allocate(1 << (32 - Math_clz32($2 + 7 | 0) | 0) | 0 | 0) | 0;
257256
wasm2asm_i32$0 = $3;
258257
wasm2asm_i32$1 = $2;
259258
HEAP32[wasm2asm_i32$0 >> 2] = wasm2asm_i32$1;
260259
if (($0 | 0) == (0 | 0)) {
261-
$0 = $lib_allocator_arena_allocate_memory(8 | 0) | 0;
260+
$0 = $lib_allocator_arena___memory_allocate(8 | 0) | 0;
262261
wasm2asm_i32$0 = $0;
263262
wasm2asm_i32$1 = 0;
264263
HEAP32[wasm2asm_i32$0 >> 2] = wasm2asm_i32$1;
@@ -272,7 +271,7 @@ function asmFunc(global, env, buffer) {
272271
wasm2asm_i32$0 = $0;
273272
wasm2asm_i32$1 = $1;
274273
HEAP32[(wasm2asm_i32$0 + 4 | 0) >> 2] = wasm2asm_i32$1;
275-
$lib_memory_set_memory($3 + 8 | 0 | 0, 0 | 0, $2 | 0);
274+
$lib_memory_memset($3 + 8 | 0 | 0, 0 | 0, $2 | 0);
276275
return $0 | 0;
277276
}
278277

@@ -307,7 +306,7 @@ function asmFunc(global, env, buffer) {
307306
wasm2asm_f64$0 = -$7 / 39.47841760435743;
308307
HEAPF64[(wasm2asm_i32$0 + 40 | 0) >> 3] = wasm2asm_f64$0;
309308
if (($0 | 0) == (0 | 0)) {
310-
$2 = $lib_allocator_arena_allocate_memory(4 | 0) | 0;
309+
$2 = $lib_allocator_arena___memory_allocate(4 | 0) | 0;
311310
wasm2asm_i32$0 = $2;
312311
wasm2asm_i32$1 = $1;
313312
HEAP32[wasm2asm_i32$0 >> 2] = wasm2asm_i32$1;
@@ -492,7 +491,7 @@ function asmFunc(global, env, buffer) {
492491
}
493492

494493
function start() {
495-
$lib_allocator_arena_startOffset = (HEAP_BASE + 7 | 0) & 4294967288 | 0;
494+
$lib_allocator_arena_startOffset = 40;
496495
$lib_allocator_arena_offset = $lib_allocator_arena_startOffset;
497496
}
498497

@@ -522,10 +521,6 @@ function asmFunc(global, env, buffer) {
522521
}
523522

524523
return {
525-
init: assembly_index_init,
526-
getBody: assembly_index_getBody,
527-
step: assembly_index_step,
528-
bench: assembly_index_bench,
529524
memory: Object.create(Object.prototype, {
530525
grow: {
531526
value: __wasm_grow_memory
@@ -536,6 +531,10 @@ function asmFunc(global, env, buffer) {
536531
}
537532

538533
}
539-
})
534+
}),
535+
init: assembly_index_init,
536+
getBody: assembly_index_getBody,
537+
step: assembly_index_step,
538+
bench: assembly_index_bench
540539
};
541540
}

examples/n-body/build/optimized.wasm

-11 Bytes
Binary file not shown.

examples/n-body/build/optimized.wat

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
(global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0))
1414
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
1515
(global $assembly/index/system (mut i32) (i32.const 0))
16-
(global $HEAP_BASE i32 (i32.const 40))
1716
(memory $0 1)
1817
(data (i32.const 8) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s")
18+
(export "memory" (memory $0))
1919
(export "init" (func $assembly/index/init))
2020
(export "getBody" (func $assembly/index/getBody))
2121
(export "step" (func $assembly/index/step))
2222
(export "bench" (func $assembly/index/bench))
23-
(export "memory" (memory $0))
2423
(start $start)
25-
(func $~lib/allocator/arena/allocate_memory (; 1 ;) (type $ii) (param $0 i32) (result i32)
24+
(func $~lib/allocator/arena/__memory_allocate (; 1 ;) (type $ii) (param $0 i32) (result i32)
2625
(local $1 i32)
2726
(local $2 i32)
2827
(local $3 i32)
@@ -116,7 +115,7 @@
116115
(block
117116
(f64.store
118117
(tee_local $0
119-
(call $~lib/allocator/arena/allocate_memory
118+
(call $~lib/allocator/arena/__memory_allocate
120119
(i32.const 56)
121120
)
122121
)
@@ -150,7 +149,7 @@
150149
)
151150
(get_local $0)
152151
)
153-
(func $~lib/memory/set_memory (; 3 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
152+
(func $~lib/memory/memset (; 3 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
154153
(local $3 i32)
155154
(local $4 i64)
156155
(if
@@ -500,7 +499,7 @@
500499
)
501500
(i32.store
502501
(tee_local $3
503-
(call $~lib/allocator/arena/allocate_memory
502+
(call $~lib/allocator/arena/__memory_allocate
504503
(i32.shl
505504
(i32.const 1)
506505
(i32.sub
@@ -529,7 +528,7 @@
529528
(block
530529
(i32.store
531530
(tee_local $0
532-
(call $~lib/allocator/arena/allocate_memory
531+
(call $~lib/allocator/arena/__memory_allocate
533532
(i32.const 8)
534533
)
535534
)
@@ -549,7 +548,7 @@
549548
(get_local $0)
550549
(get_local $1)
551550
)
552-
(call $~lib/memory/set_memory
551+
(call $~lib/memory/memset
553552
(i32.add
554553
(get_local $3)
555554
(i32.const 8)
@@ -693,7 +692,7 @@
693692
(block
694693
(i32.store
695694
(tee_local $2
696-
(call $~lib/allocator/arena/allocate_memory
695+
(call $~lib/allocator/arena/__memory_allocate
697696
(i32.const 4)
698697
)
699698
)
@@ -1403,13 +1402,7 @@
14031402
)
14041403
(func $start (; 12 ;) (type $v)
14051404
(set_global $~lib/allocator/arena/startOffset
1406-
(i32.and
1407-
(i32.add
1408-
(get_global $HEAP_BASE)
1409-
(i32.const 7)
1410-
)
1411-
(i32.const -8)
1412-
)
1405+
(i32.const 40)
14131406
)
14141407
(set_global $~lib/allocator/arena/offset
14151408
(get_global $~lib/allocator/arena/startOffset)

0 commit comments

Comments
 (0)