From adf5034590c864b644b5bc8187927f9c70b7c4ad Mon Sep 17 00:00:00 2001 From: techforindustry Date: Tue, 15 Oct 2019 19:38:11 -0600 Subject: [PATCH 1/7] initial commit --- examples/asrt/app1/assembly/index.ts | 17 + examples/asrt/app1/assembly/tsconfig.json | 6 + examples/asrt/app1/build/.gitignore | 3 + examples/asrt/app1/build/untouched.wat | 160 ++ examples/asrt/app1/package.json | 7 + examples/asrt/app2/assembly/index.ts | 13 + examples/asrt/app2/assembly/tsconfig.json | 6 + examples/asrt/app2/build/.gitignore | 3 + examples/asrt/app2/build/untouched.wat | 1749 +++++++++++++++++++++ examples/asrt/app2/package.json | 7 + examples/asrt/dylinker.ts | 147 ++ examples/asrt/package.json | 7 + examples/asrt/start.ts | 13 + 13 files changed, 2138 insertions(+) create mode 100644 examples/asrt/app1/assembly/index.ts create mode 100644 examples/asrt/app1/assembly/tsconfig.json create mode 100644 examples/asrt/app1/build/.gitignore create mode 100644 examples/asrt/app1/build/untouched.wat create mode 100644 examples/asrt/app1/package.json create mode 100644 examples/asrt/app2/assembly/index.ts create mode 100644 examples/asrt/app2/assembly/tsconfig.json create mode 100644 examples/asrt/app2/build/.gitignore create mode 100644 examples/asrt/app2/build/untouched.wat create mode 100644 examples/asrt/app2/package.json create mode 100644 examples/asrt/dylinker.ts create mode 100644 examples/asrt/package.json create mode 100644 examples/asrt/start.ts diff --git a/examples/asrt/app1/assembly/index.ts b/examples/asrt/app1/assembly/index.ts new file mode 100644 index 0000000000..aad598c2aa --- /dev/null +++ b/examples/asrt/app1/assembly/index.ts @@ -0,0 +1,17 @@ +// The entry file of your WebAssembly module. + +@external("app2","sayHello") +declare function sayHello(msg:string):void + +@external("env","log") +declare function log(obj:T):void + + +export function main():void{ + let t=String.fromCharCode(13) + + log(t) + var t2="app1" + log(t2) + sayHello(t2) +} \ No newline at end of file diff --git a/examples/asrt/app1/assembly/tsconfig.json b/examples/asrt/app1/assembly/tsconfig.json new file mode 100644 index 0000000000..2686355684 --- /dev/null +++ b/examples/asrt/app1/assembly/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../../../std/assembly.json", + "include": [ + "./**/*.ts" + ] +} \ No newline at end of file diff --git a/examples/asrt/app1/build/.gitignore b/examples/asrt/app1/build/.gitignore new file mode 100644 index 0000000000..22b2ed20a7 --- /dev/null +++ b/examples/asrt/app1/build/.gitignore @@ -0,0 +1,3 @@ +*.wasm +*.wasm.map +*.asm.js diff --git a/examples/asrt/app1/build/untouched.wat b/examples/asrt/app1/build/untouched.wat new file mode 100644 index 0000000000..9ec7f3dec9 --- /dev/null +++ b/examples/asrt/app1/build/untouched.wat @@ -0,0 +1,160 @@ +(module + (type $FUNCSIG$v (func)) + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (import "env" "memory" (memory $0 1)) + (data (global.get $~lib/rt/__memory_base) "\00\00\00\00\00\00\00\00\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00a\00p\00p\001\00") + (import "env" "table" (table $0 2 funcref)) + (elem (global.get $~lib/rt/__table_base) $null $~lib/rt/shared/visit) + (import "env" "__memory_base" (global $~lib/rt/__memory_base i32)) + (import "env" "__table_base" (global $~lib/rt/__table_base i32)) + (import "asrt" "alloc" (func $~lib/bindings/asrt/alloc (param i32 i32 i32) (result i32))) + (import "asrt" "retain" (func $~lib/bindings/asrt/retain (param i32 i32) (result i32))) + (import "env" "log" (func $assembly/index/log<~lib/string/String> (param i32))) + (import "app2" "sayHello" (func $assembly/index/sayHello (param i32))) + (import "asrt" "release" (func $~lib/bindings/asrt/release (param i32 i32 i32) (result i32))) + (import "asrt" "visit" (func $~lib/bindings/asrt/visit (param i32 i32 i32 i32))) + (global $~lib/argc (mut i32) (i32.const 0)) + (export "memory" (memory $0)) + (export "main" (func $assembly/index/main)) + (func $~lib/rt/shared/__alloc (; 6 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + global.get $~lib/rt/__memory_base + local.get $0 + local.get $1 + call $~lib/bindings/asrt/alloc + ) + (func $~lib/rt/shared/__retain (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + global.get $~lib/rt/__memory_base + local.get $0 + call $~lib/bindings/asrt/retain + ) + (func $~lib/string/String.fromCharCode (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + local.get $1 + i32.const 0 + i32.gt_s + local.set $2 + i32.const 2 + local.get $2 + i32.shl + i32.const 1 + call $~lib/rt/shared/__alloc + local.set $3 + global.get $~lib/rt/__memory_base + local.get $3 + i32.add + local.get $0 + i32.store16 + local.get $2 + if + global.get $~lib/rt/__memory_base + local.get $3 + i32.add + local.get $1 + i32.store16 offset=2 + end + local.get $3 + call $~lib/rt/shared/__retain + ) + (func $~lib/string/String.fromCharCode|trampoline (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + block $1of1 + block $0of1 + block $outOfRange + global.get $~lib/argc + i32.const 1 + i32.sub + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const -1 + local.set $1 + end + local.get $0 + local.get $1 + call $~lib/string/String.fromCharCode + ) + (func $~lib/rt/shared/visit (; 10 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + local.get $1 + call $~lib/rt/__visit_members + ) + (func $~lib/rt/shared/__release (; 11 ;) (type $FUNCSIG$vi) (param $0 i32) + global.get $~lib/rt/__memory_base + local.get $0 + global.get $~lib/rt/__table_base + i32.const 1 + i32.add + call $~lib/bindings/asrt/release + drop + ) + (func $assembly/index/main (; 12 ;) (type $FUNCSIG$v) + (local $0 i32) + (local $1 i32) + i32.const 1 + global.set $~lib/argc + i32.const 13 + i32.const 0 + call $~lib/string/String.fromCharCode|trampoline + local.set $0 + local.get $0 + call $assembly/index/log<~lib/string/String> + i32.const 24 + call $~lib/rt/shared/__retain + local.set $1 + local.get $1 + call $assembly/index/log<~lib/string/String> + local.get $1 + call $assembly/index/sayHello + local.get $0 + call $~lib/rt/shared/__release + local.get $1 + call $~lib/rt/shared/__release + ) + (func $~lib/rt/shared/__visit (; 13 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + global.get $~lib/rt/__memory_base + local.get $0 + local.get $1 + global.get $~lib/rt/__table_base + i32.const 1 + i32.add + call $~lib/bindings/asrt/visit + ) + (func $~lib/rt/__visit_members (; 14 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + block $switch$1$default + block $switch$1$case$4 + block $switch$1$case$2 + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 8 + i32.sub + i32.add + i32.load + br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$default + end + return + end + global.get $~lib/rt/__memory_base + local.get $0 + i32.add + i32.load + local.tee $2 + if + local.get $2 + local.get $1 + call $~lib/rt/shared/__visit + end + return + end + unreachable + ) + (func $null (; 15 ;) (type $FUNCSIG$v) + ) + ;; custom section "dylink", size 5 +) diff --git a/examples/asrt/app1/package.json b/examples/asrt/app1/package.json new file mode 100644 index 0000000000..26618b2b06 --- /dev/null +++ b/examples/asrt/app1/package.json @@ -0,0 +1,7 @@ +{ + "scripts": { + "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --importMemory --importTable --relocatable --runtime shared --sourceMap --validate --debug", + "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat --importMemory --importTable --relocatable --runtime shared --sourceMap --validate --optimize", + "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized" + } +} \ No newline at end of file diff --git a/examples/asrt/app2/assembly/index.ts b/examples/asrt/app2/assembly/index.ts new file mode 100644 index 0000000000..5f6411d01e --- /dev/null +++ b/examples/asrt/app2/assembly/index.ts @@ -0,0 +1,13 @@ +// The entry file of your WebAssembly module. + +@external("env","log") +declare function log(obj:T):void + +export function sayHello(msg:string):void{ + log(msg) + let temp="app2" + log(temp) + let temp2=msg+temp + log(temp2) + // return "hello" +} \ No newline at end of file diff --git a/examples/asrt/app2/assembly/tsconfig.json b/examples/asrt/app2/assembly/tsconfig.json new file mode 100644 index 0000000000..2686355684 --- /dev/null +++ b/examples/asrt/app2/assembly/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../../../std/assembly.json", + "include": [ + "./**/*.ts" + ] +} \ No newline at end of file diff --git a/examples/asrt/app2/build/.gitignore b/examples/asrt/app2/build/.gitignore new file mode 100644 index 0000000000..22b2ed20a7 --- /dev/null +++ b/examples/asrt/app2/build/.gitignore @@ -0,0 +1,3 @@ +*.wasm +*.wasm.map +*.asm.js diff --git a/examples/asrt/app2/build/untouched.wat b/examples/asrt/app2/build/untouched.wat new file mode 100644 index 0000000000..f9a037599c --- /dev/null +++ b/examples/asrt/app2/build/untouched.wat @@ -0,0 +1,1749 @@ +(module + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$viii (func (param i32 i32 i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "memory" (memory $0 1)) + (data (global.get $~lib/rt/__memory_base) "\00\00\00\00\00\00\00\00\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00a\00p\00p\002\00\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00n\00u\00l\00l\00\00\00\00\00\01\00\00\00\01\00\00\00\00\00\00\00") + (import "env" "table" (table $0 2 funcref)) + (elem (global.get $~lib/rt/__table_base) $null $~lib/rt/shared/visit) + (import "env" "__memory_base" (global $~lib/rt/__memory_base i32)) + (import "env" "__table_base" (global $~lib/rt/__table_base i32)) + (import "asrt" "retain" (func $~lib/bindings/asrt/retain (param i32 i32) (result i32))) + (import "env" "log" (func $assembly/index/log<~lib/string/String> (param i32))) + (import "asrt" "release" (func $~lib/bindings/asrt/release (param i32 i32 i32) (result i32))) + (import "asrt" "alloc" (func $~lib/bindings/asrt/alloc (param i32 i32 i32) (result i32))) + (import "asrt" "visit" (func $~lib/bindings/asrt/visit (param i32 i32 i32 i32))) + (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) + (export "memory" (memory $0)) + (export "sayHello" (func $assembly/index/sayHello)) + (func $~lib/rt/shared/__retain (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + global.get $~lib/rt/__memory_base + local.get $0 + call $~lib/bindings/asrt/retain + ) + (func $~lib/rt/shared/visit (; 6 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + local.get $1 + call $~lib/rt/__visit_members + ) + (func $~lib/rt/shared/__release (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) + global.get $~lib/rt/__memory_base + local.get $0 + global.get $~lib/rt/__table_base + i32.const 1 + i32.add + call $~lib/bindings/asrt/release + drop + ) + (func $~lib/string/String#get:length (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 16 + i32.sub + i32.add + i32.load offset=12 + i32.const 1 + i32.shr_u + ) + (func $~lib/rt/shared/__alloc (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + global.get $~lib/rt/__memory_base + local.get $0 + local.get $1 + call $~lib/bindings/asrt/alloc + ) + (func $~lib/util/memory/memcpy (; 10 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $break|0 + loop $continue|0 + local.get $2 + if (result i32) + local.get $1 + i32.const 3 + i32.and + else + i32.const 0 + end + i32.eqz + br_if $break|0 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + local.get $2 + i32.const 1 + i32.sub + local.set $2 + br $continue|0 + end + unreachable + end + local.get $0 + i32.const 3 + i32.and + i32.const 0 + i32.eq + if + block $break|1 + loop $continue|1 + local.get $2 + i32.const 16 + i32.ge_u + i32.eqz + br_if $break|1 + global.get $~lib/rt/__memory_base + local.get $0 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + i32.add + i32.load + i32.store + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 4 + i32.add + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 4 + i32.add + i32.add + i32.load + i32.store + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 8 + i32.add + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 8 + i32.add + i32.add + i32.load + i32.store + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 12 + i32.add + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 12 + i32.add + i32.add + i32.load + i32.store + local.get $1 + i32.const 16 + i32.add + local.set $1 + local.get $0 + i32.const 16 + i32.add + local.set $0 + local.get $2 + i32.const 16 + i32.sub + local.set $2 + br $continue|1 + end + unreachable + end + local.get $2 + i32.const 8 + i32.and + if + global.get $~lib/rt/__memory_base + local.get $0 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + i32.add + i32.load + i32.store + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 4 + i32.add + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 4 + i32.add + i32.add + i32.load + i32.store + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + end + local.get $2 + i32.const 4 + i32.and + if + global.get $~lib/rt/__memory_base + local.get $0 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + i32.add + i32.load + i32.store + local.get $0 + i32.const 4 + i32.add + local.set $0 + local.get $1 + i32.const 4 + i32.add + local.set $1 + end + local.get $2 + i32.const 2 + i32.and + if + global.get $~lib/rt/__memory_base + local.get $0 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + i32.add + i32.load16_u + i32.store16 + local.get $0 + i32.const 2 + i32.add + local.set $0 + local.get $1 + i32.const 2 + i32.add + local.set $1 + end + local.get $2 + i32.const 1 + i32.and + if + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + end + return + end + local.get $2 + i32.const 32 + i32.ge_u + if + block $break|2 + block $case2|2 + block $case1|2 + block $case0|2 + local.get $0 + i32.const 3 + i32.and + local.set $5 + local.get $5 + i32.const 1 + i32.eq + br_if $case0|2 + local.get $5 + i32.const 2 + i32.eq + br_if $case1|2 + local.get $5 + i32.const 3 + i32.eq + br_if $case2|2 + br $break|2 + end + global.get $~lib/rt/__memory_base + local.get $1 + i32.add + i32.load + local.set $3 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + local.get $2 + i32.const 3 + i32.sub + local.set $2 + block $break|3 + loop $continue|3 + local.get $2 + i32.const 17 + i32.ge_u + i32.eqz + br_if $break|3 + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 1 + i32.add + i32.add + i32.load + local.set $4 + global.get $~lib/rt/__memory_base + local.get $0 + i32.add + local.get $3 + i32.const 24 + i32.shr_u + local.get $4 + i32.const 8 + i32.shl + i32.or + i32.store + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 5 + i32.add + i32.add + i32.load + local.set $3 + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 4 + i32.add + i32.add + local.get $4 + i32.const 24 + i32.shr_u + local.get $3 + i32.const 8 + i32.shl + i32.or + i32.store + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 9 + i32.add + i32.add + i32.load + local.set $4 + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 8 + i32.add + i32.add + local.get $3 + i32.const 24 + i32.shr_u + local.get $4 + i32.const 8 + i32.shl + i32.or + i32.store + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 13 + i32.add + i32.add + i32.load + local.set $3 + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 12 + i32.add + i32.add + local.get $4 + i32.const 24 + i32.shr_u + local.get $3 + i32.const 8 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 16 + i32.add + local.set $1 + local.get $0 + i32.const 16 + i32.add + local.set $0 + local.get $2 + i32.const 16 + i32.sub + local.set $2 + br $continue|3 + end + unreachable + end + br $break|2 + end + global.get $~lib/rt/__memory_base + local.get $1 + i32.add + i32.load + local.set $3 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + local.get $2 + i32.const 2 + i32.sub + local.set $2 + block $break|4 + loop $continue|4 + local.get $2 + i32.const 18 + i32.ge_u + i32.eqz + br_if $break|4 + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 2 + i32.add + i32.add + i32.load + local.set $4 + global.get $~lib/rt/__memory_base + local.get $0 + i32.add + local.get $3 + i32.const 16 + i32.shr_u + local.get $4 + i32.const 16 + i32.shl + i32.or + i32.store + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 6 + i32.add + i32.add + i32.load + local.set $3 + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 4 + i32.add + i32.add + local.get $4 + i32.const 16 + i32.shr_u + local.get $3 + i32.const 16 + i32.shl + i32.or + i32.store + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 10 + i32.add + i32.add + i32.load + local.set $4 + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 8 + i32.add + i32.add + local.get $3 + i32.const 16 + i32.shr_u + local.get $4 + i32.const 16 + i32.shl + i32.or + i32.store + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 14 + i32.add + i32.add + i32.load + local.set $3 + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 12 + i32.add + i32.add + local.get $4 + i32.const 16 + i32.shr_u + local.get $3 + i32.const 16 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 16 + i32.add + local.set $1 + local.get $0 + i32.const 16 + i32.add + local.set $0 + local.get $2 + i32.const 16 + i32.sub + local.set $2 + br $continue|4 + end + unreachable + end + br $break|2 + end + global.get $~lib/rt/__memory_base + local.get $1 + i32.add + i32.load + local.set $3 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + local.get $2 + i32.const 1 + i32.sub + local.set $2 + block $break|5 + loop $continue|5 + local.get $2 + i32.const 19 + i32.ge_u + i32.eqz + br_if $break|5 + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 3 + i32.add + i32.add + i32.load + local.set $4 + global.get $~lib/rt/__memory_base + local.get $0 + i32.add + local.get $3 + i32.const 8 + i32.shr_u + local.get $4 + i32.const 24 + i32.shl + i32.or + i32.store + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 7 + i32.add + i32.add + i32.load + local.set $3 + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 4 + i32.add + i32.add + local.get $4 + i32.const 8 + i32.shr_u + local.get $3 + i32.const 24 + i32.shl + i32.or + i32.store + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 11 + i32.add + i32.add + i32.load + local.set $4 + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 8 + i32.add + i32.add + local.get $3 + i32.const 8 + i32.shr_u + local.get $4 + i32.const 24 + i32.shl + i32.or + i32.store + global.get $~lib/rt/__memory_base + local.get $1 + i32.const 15 + i32.add + i32.add + i32.load + local.set $3 + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 12 + i32.add + i32.add + local.get $4 + i32.const 8 + i32.shr_u + local.get $3 + i32.const 24 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 16 + i32.add + local.set $1 + local.get $0 + i32.const 16 + i32.add + local.set $0 + local.get $2 + i32.const 16 + i32.sub + local.set $2 + br $continue|5 + end + unreachable + end + br $break|2 + end + end + local.get $2 + i32.const 16 + i32.and + if + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + end + local.get $2 + i32.const 8 + i32.and + if + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + end + local.get $2 + i32.const 4 + i32.and + if + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + end + local.get $2 + i32.const 2 + i32.and + if + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + end + local.get $2 + i32.const 1 + i32.and + if + global.get $~lib/rt/__memory_base + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.add + i32.load8_u + i32.store8 + end + ) + (func $~lib/memory/memory.copy (; 11 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + block $~lib/util/memory/memmove|inlined.0 + local.get $0 + local.set $5 + local.get $1 + local.set $4 + local.get $2 + local.set $3 + local.get $5 + local.get $4 + i32.eq + if + br $~lib/util/memory/memmove|inlined.0 + end + local.get $4 + local.get $3 + i32.add + local.get $5 + i32.le_u + if (result i32) + i32.const 1 + else + local.get $5 + local.get $3 + i32.add + local.get $4 + i32.le_u + end + if + local.get $5 + local.get $4 + local.get $3 + call $~lib/util/memory/memcpy + br $~lib/util/memory/memmove|inlined.0 + end + local.get $5 + local.get $4 + i32.lt_u + if + local.get $4 + i32.const 7 + i32.and + local.get $5 + i32.const 7 + i32.and + i32.eq + if + block $break|0 + loop $continue|0 + local.get $5 + i32.const 7 + i32.and + i32.eqz + br_if $break|0 + local.get $3 + i32.eqz + if + br $~lib/util/memory/memmove|inlined.0 + end + local.get $3 + i32.const 1 + i32.sub + local.set $3 + global.get $~lib/rt/__memory_base + local.get $5 + local.tee $6 + i32.const 1 + i32.add + local.set $5 + local.get $6 + i32.add + global.get $~lib/rt/__memory_base + local.get $4 + local.tee $6 + i32.const 1 + i32.add + local.set $4 + local.get $6 + i32.add + i32.load8_u + i32.store8 + br $continue|0 + end + unreachable + end + block $break|1 + loop $continue|1 + local.get $3 + i32.const 8 + i32.ge_u + i32.eqz + br_if $break|1 + global.get $~lib/rt/__memory_base + local.get $5 + i32.add + global.get $~lib/rt/__memory_base + local.get $4 + i32.add + i64.load + i64.store + local.get $3 + i32.const 8 + i32.sub + local.set $3 + local.get $5 + i32.const 8 + i32.add + local.set $5 + local.get $4 + i32.const 8 + i32.add + local.set $4 + br $continue|1 + end + unreachable + end + end + block $break|2 + loop $continue|2 + local.get $3 + i32.eqz + br_if $break|2 + global.get $~lib/rt/__memory_base + local.get $5 + local.tee $6 + i32.const 1 + i32.add + local.set $5 + local.get $6 + i32.add + global.get $~lib/rt/__memory_base + local.get $4 + local.tee $6 + i32.const 1 + i32.add + local.set $4 + local.get $6 + i32.add + i32.load8_u + i32.store8 + local.get $3 + i32.const 1 + i32.sub + local.set $3 + br $continue|2 + end + unreachable + end + else + local.get $4 + i32.const 7 + i32.and + local.get $5 + i32.const 7 + i32.and + i32.eq + if + block $break|3 + loop $continue|3 + local.get $5 + local.get $3 + i32.add + i32.const 7 + i32.and + i32.eqz + br_if $break|3 + local.get $3 + i32.eqz + if + br $~lib/util/memory/memmove|inlined.0 + end + global.get $~lib/rt/__memory_base + local.get $5 + local.get $3 + i32.const 1 + i32.sub + local.tee $3 + i32.add + i32.add + global.get $~lib/rt/__memory_base + local.get $4 + local.get $3 + i32.add + i32.add + i32.load8_u + i32.store8 + br $continue|3 + end + unreachable + end + block $break|4 + loop $continue|4 + local.get $3 + i32.const 8 + i32.ge_u + i32.eqz + br_if $break|4 + local.get $3 + i32.const 8 + i32.sub + local.set $3 + global.get $~lib/rt/__memory_base + local.get $5 + local.get $3 + i32.add + i32.add + global.get $~lib/rt/__memory_base + local.get $4 + local.get $3 + i32.add + i32.add + i64.load + i64.store + br $continue|4 + end + unreachable + end + end + block $break|5 + loop $continue|5 + local.get $3 + i32.eqz + br_if $break|5 + global.get $~lib/rt/__memory_base + local.get $5 + local.get $3 + i32.const 1 + i32.sub + local.tee $3 + i32.add + i32.add + global.get $~lib/rt/__memory_base + local.get $4 + local.get $3 + i32.add + i32.add + i32.load8_u + i32.store8 + br $continue|5 + end + unreachable + end + end + end + ) + (func $~lib/string/String#concat (; 12 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + local.get $1 + call $~lib/rt/shared/__retain + drop + local.get $1 + i32.const 0 + i32.eq + if + i32.const 48 + local.tee $2 + local.get $1 + local.tee $3 + i32.ne + if + local.get $2 + call $~lib/rt/shared/__retain + drop + local.get $3 + call $~lib/rt/shared/__release + end + local.get $2 + local.set $1 + end + local.get $0 + call $~lib/string/String#get:length + i32.const 1 + i32.shl + local.set $4 + local.get $1 + call $~lib/string/String#get:length + i32.const 1 + i32.shl + local.set $5 + local.get $4 + local.get $5 + i32.add + local.set $6 + local.get $6 + i32.const 0 + i32.eq + if + i32.const 72 + call $~lib/rt/shared/__retain + local.set $2 + local.get $1 + call $~lib/rt/shared/__release + local.get $2 + return + end + local.get $6 + i32.const 1 + call $~lib/rt/shared/__alloc + call $~lib/rt/shared/__retain + local.set $7 + local.get $7 + local.get $0 + local.get $4 + call $~lib/memory/memory.copy + local.get $7 + local.get $4 + i32.add + local.get $1 + local.get $5 + call $~lib/memory/memory.copy + local.get $7 + local.set $2 + local.get $1 + call $~lib/rt/shared/__release + local.get $2 + ) + (func $~lib/string/String.__concat (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $0 + call $~lib/rt/shared/__retain + drop + local.get $1 + call $~lib/rt/shared/__retain + drop + local.get $0 + i32.const 48 + local.get $0 + i32.const 0 + i32.ne + select + local.get $1 + call $~lib/string/String#concat + local.set $2 + local.get $0 + call $~lib/rt/shared/__release + local.get $1 + call $~lib/rt/shared/__release + local.get $2 + ) + (func $assembly/index/sayHello (; 14 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + local.get $0 + call $~lib/rt/shared/__retain + drop + local.get $0 + call $assembly/index/log<~lib/string/String> + i32.const 24 + call $~lib/rt/shared/__retain + local.set $1 + local.get $1 + call $assembly/index/log<~lib/string/String> + local.get $0 + local.get $1 + call $~lib/string/String.__concat + local.tee $2 + call $~lib/rt/shared/__retain + local.set $3 + local.get $3 + call $assembly/index/log<~lib/string/String> + local.get $1 + call $~lib/rt/shared/__release + local.get $2 + call $~lib/rt/shared/__release + local.get $3 + call $~lib/rt/shared/__release + local.get $0 + call $~lib/rt/shared/__release + ) + (func $~lib/rt/shared/__visit (; 15 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + global.get $~lib/rt/__memory_base + local.get $0 + local.get $1 + global.get $~lib/rt/__table_base + i32.const 1 + i32.add + call $~lib/bindings/asrt/visit + ) + (func $~lib/rt/__visit_members (; 16 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + block $switch$1$default + block $switch$1$case$4 + block $switch$1$case$2 + global.get $~lib/rt/__memory_base + local.get $0 + i32.const 8 + i32.sub + i32.add + i32.load + br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$default + end + return + end + global.get $~lib/rt/__memory_base + local.get $0 + i32.add + i32.load + local.tee $2 + if + local.get $2 + local.get $1 + call $~lib/rt/shared/__visit + end + return + end + unreachable + ) + (func $null (; 17 ;) (type $FUNCSIG$v) + ) + ;; custom section "dylink", size 5 +) diff --git a/examples/asrt/app2/package.json b/examples/asrt/app2/package.json new file mode 100644 index 0000000000..26618b2b06 --- /dev/null +++ b/examples/asrt/app2/package.json @@ -0,0 +1,7 @@ +{ + "scripts": { + "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --importMemory --importTable --relocatable --runtime shared --sourceMap --validate --debug", + "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat --importMemory --importTable --relocatable --runtime shared --sourceMap --validate --optimize", + "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized" + } +} \ No newline at end of file diff --git a/examples/asrt/dylinker.ts b/examples/asrt/dylinker.ts new file mode 100644 index 0000000000..ba15a09d06 --- /dev/null +++ b/examples/asrt/dylinker.ts @@ -0,0 +1,147 @@ +import * as loader from "../../lib/loader" +const fs = require("fs") +const nodePath = require("path") +export class DynamicLinker { + asrt: ModuleDefinition = new ModuleDefinition("asrt", "") + memory: WebAssembly.Memory = new WebAssembly.Memory({ initial: 1 }) + table: WebAssembly.Table = new WebAssembly.Table({ element: "anyfunc", initial: 10 }) + defaultImports: { env?: {} } = { + env: { + memory: this.memory, + table: this.table, + } + } + modules: Array = [] + run() { + let mem = 1000 + let table = 0 + this.asrt.build() + this.modules.forEach((m) => { + m.build() + mem += m.dylink.memory_size + table += m.dylink.table_size + }) + let mem_base = 1000 + let table_base = 0 + console.log("heap base", mem) + this.asrt.instantiate({ env: { "__heap_base": 2000 } }, this.defaultImports) + let rtImports = {} + this.modules.forEach(m => { + console.log(m.id,"mem base",mem_base) + m.instantiate(this.defaultImports, { env: { __memory_base: mem_base, __table_base: table_base }, asrt: this.asrt.exports }, rtImports) + mem_base += m.dylink.memory_size + table_base += m.dylink.table_size + rtImports[m.id] = m.exports + }) + console.log("final mem base",mem_base) + } +} + +export class ModuleDefinition { + module: WebAssembly.Module + exports: loader.ASUtil + dylink: DyLink + imports: { env: any } = { + env: { + log: (offset: number): void => { + console.log(this.id, offset) + }, + abort: (mesg, file, line, colm) => { + const memory = this.imports.env.memory // prefer exported, otherwise try imported + console.log(this.path,"abort: " + getString(memory, mesg) + " at " + getString(memory, file) + ":" + line + ":" + colm); + }, + } + } + + constructor(public id: string, public path: string) { + + } + build() { + this.module = new WebAssembly.Module(fs.readFileSync(nodePath.resolve(this.path))) + let custom = WebAssembly.Module.customSections(this.module, "dylink") + if (custom && custom.length > 0) { + this.dylink = readDylinkSection(custom[0]) + }else{ + this.dylink={memory_align:4,memory_size:1000,table_size:0, table_align:0} + } + } + + mergeImports(imports: {}[]) { + imports.forEach(i => { + for (let key in i) { + if (key in this.imports) { + this.imports[key] = { ...this.imports[key], ...i[key] } + } else { + this.imports[key] = i[key] + } + } + }) + } + instantiate(...imports: { [key: string]: any }[]) { + this.mergeImports(imports) + this.exports = loader.instantiate(this.module, this.imports) + } +} + +export interface DyLink { + memory_size: number + memory_align: number + table_size: number + table_align: number +} + +function readU32Leb128(buffer, offset) { + var value = 0; + var shift = 0; + var length = buffer.length; + while (offset < length) { + let b = buffer[offset++]; + value |= (b & 0x7f) << shift; + if (!(b & 0x80)) break; + shift += 7; + } + return { value, offset }; +} + +function readDylinkSection(buffer): DyLink { + var view = new Uint8Array(buffer); + var temp = readU32Leb128(view, 0); + var memory_size = temp.value; + temp = readU32Leb128(view, temp.offset); + var memory_align = temp.value; + temp = readU32Leb128(view, temp.offset); + var table_size = temp.value; + temp = readU32Leb128(view, temp.offset); + var table_align = temp.value; + // TODO: read required libraries + // temp = readU32Leb128(view, temp.offset); + // var lib_count = temp.value; + // ... + return { memory_size, memory_align, table_size, table_align }; +} + +const CHUNKSIZE = 1024; +const SIZE_OFFSET = -4; +/** Gets a string from an U32 and an U16 view on a memory. */ +function getStringImpl(buffer, ptr) { + const U32 = new Uint32Array(buffer); + const U16 = new Uint16Array(buffer); + var length = U32[(ptr + SIZE_OFFSET) >>> 2] >>> 1; + var offset = ptr >>> 1; + if (length <= CHUNKSIZE) return String.fromCharCode.apply(String, U16.subarray(offset, offset + length)); + const parts = []; + do { + const last = U16[offset + CHUNKSIZE - 1]; + const size = last >= 0xD800 && last < 0xDC00 ? CHUNKSIZE - 1 : CHUNKSIZE; + parts.push(String.fromCharCode.apply(String, U16.subarray(offset, offset += size))); + length -= size; + } while (length > CHUNKSIZE); + return parts.join("") + String.fromCharCode.apply(String, U16.subarray(offset, offset + length)); +} + + + +function getString(memory, ptr) { + if (!memory) return ""; + return getStringImpl(memory.buffer, ptr); +} \ No newline at end of file diff --git a/examples/asrt/package.json b/examples/asrt/package.json new file mode 100644 index 0000000000..f700d368cb --- /dev/null +++ b/examples/asrt/package.json @@ -0,0 +1,7 @@ +{ + "scripts": { + "app1":"cd ./app1 && npm run asbuild:untouched", + "app2":"cd ./app2 && npm run asbuild:untouched", + "asbuild":"npm run app1 && npm run app2" + } + } \ No newline at end of file diff --git a/examples/asrt/start.ts b/examples/asrt/start.ts new file mode 100644 index 0000000000..31da82396c --- /dev/null +++ b/examples/asrt/start.ts @@ -0,0 +1,13 @@ +import { DynamicLinker, ModuleDefinition } from "./dylinker"; + +let linker=new DynamicLinker() + +linker.asrt.path="../../lib/asrt/build/untouched.wasm" + +linker.modules.push(new ModuleDefinition("app2","./app2/build/untouched.wasm")) +linker.modules.push(new ModuleDefinition("app1","./app1/build/untouched.wasm")) + + +linker.run() +//@ts-ignore +linker.modules[1].exports.main() \ No newline at end of file From 0fc94790da269e3aa64c139e337842cffe2c0bf0 Mon Sep 17 00:00:00 2001 From: techforindustry Date: Wed, 16 Oct 2019 11:44:46 -0600 Subject: [PATCH 2/7] idof dont throw --- src/builtins.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/builtins.ts b/src/builtins.ts index b89493ab51..602ea4e971 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -3915,11 +3915,13 @@ export function compileCall( return module.i32(classReference.id); } } - compiler.error( - DiagnosticCode.Operation_0_cannot_be_applied_to_type_1, - reportNode.typeArgumentsRange, "idof", type.toString() - ); - return module.unreachable(); + //return 0 (i.e. non referenced type) rather than throwing an error + return module.i32(0) + // compiler.error( + // DiagnosticCode.Operation_0_cannot_be_applied_to_type_1, + // reportNode.typeArgumentsRange, "idof", type.toString() + // ); + // return module.unreachable(); } case BuiltinSymbols.visit_globals: { if ( From 0720a4d90223916d4e4a0657982b9bd79ed827b4 Mon Sep 17 00:00:00 2001 From: techforindustry Date: Wed, 16 Oct 2019 11:50:51 -0600 Subject: [PATCH 3/7] absoulte pointers --- lib/asrt/assembly/asrt.ts | 15 +++++++++------ src/compiler.ts | 2 +- src/module.ts | 6 +++--- std/assembly/bindings/asrt.ts | 8 ++++++++ std/assembly/rt/shared.ts | 8 ++++++-- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/asrt/assembly/asrt.ts b/lib/asrt/assembly/asrt.ts index ecdbf678c0..5f258b2196 100644 --- a/lib/asrt/assembly/asrt.ts +++ b/lib/asrt/assembly/asrt.ts @@ -1,6 +1,9 @@ import { __alloc, __realloc, __free } from "rt/tlsf"; import { __retain, __release, __visit, __collect } from "rt/pure"; +export {__alloc, __realloc, __free,__retain, __release, __visit, __collect } + + @external("env", "__heap_base") declare const __heap_base: usize; @@ -12,31 +15,31 @@ function __visit_members(ptr: usize, cookie: u32): void { } export function alloc(mbase: usize, size: usize, id: i32): usize { - return __alloc(size, id) - mbase; + return __alloc(size, id); } export function realloc(mbase: usize, ptr: usize, size: usize): usize { - return __realloc(mbase + ptr, size) - mbase; + return __realloc(ptr, size); } export function free(mbase: usize, ptr: usize): void { - __free(mbase + ptr); + __free(ptr); } export function retain(mbase: usize, ptr: usize): usize { - return __retain(mbase + ptr) - mbase; + return __retain(ptr); } export function release(mbase: usize, ptr: usize, visit: (ptr: usize, cookie: u32) => void): void { rel_mbase = mbase; rel_visit = visit; - __release(mbase + ptr); + __release(ptr); } export function visit(mbase: usize, ptr: usize, cookie: i32, visit: (ptr: usize, cookie: u32) => void): void { rel_mbase = mbase; rel_visit = visit; - __visit(mbase + ptr, cookie); + __visit(ptr, cookie); } export function collect(mbase: usize, visit: (ptr: usize, cookie: u32) => void): void { diff --git a/src/compiler.ts b/src/compiler.ts index b5677c73c1..824c0de085 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1505,7 +1505,7 @@ export class Compiler extends DiagnosticEmitter { return module.i64(i64_low(ref), i64_high(ref)); } else { assert(i64_is_u32(ref)); - return module.i32(i64_low(ref)); + return module.relocMem(module.i32(i64_low(ref))); } } diff --git a/src/module.ts b/src/module.ts index bb3e427ef1..c556694da7 100644 --- a/src/module.ts +++ b/src/module.ts @@ -472,7 +472,7 @@ export class Module { this.tbase = globalName ? this.allocStringCached(globalName) : 0; } - private relocMem(ptr: ExpressionRef): ExpressionRef { + relocMem(ptr: ExpressionRef): ExpressionRef { var mbase = this.mbase; if (!mbase) return ptr; var ref = this.ref; @@ -618,7 +618,7 @@ export class Module { offset: Index = 0, align: Index = bytes // naturally aligned by default ): ExpressionRef { - return _BinaryenLoad(this.ref, bytes, signed ? 1 : 0, offset, align, type, this.relocMem(ptr)); + return _BinaryenLoad(this.ref, bytes, signed ? 1 : 0, offset, align, type, ptr); } store( @@ -629,7 +629,7 @@ export class Module { offset: Index = 0, align: Index = bytes // naturally aligned by default ): ExpressionRef { - return _BinaryenStore(this.ref, bytes, offset, align, this.relocMem(ptr), value, type); + return _BinaryenStore(this.ref, bytes, offset, align, ptr, value, type); } atomic_load( diff --git a/std/assembly/bindings/asrt.ts b/std/assembly/bindings/asrt.ts index dbce01df6a..afff9f169d 100644 --- a/std/assembly/bindings/asrt.ts +++ b/std/assembly/bindings/asrt.ts @@ -5,3 +5,11 @@ export declare function retain(mbase: usize, ptr: usize): usize; export declare function release(mbase: usize, ptr: usize, local_visit_members: u32): usize; export declare function visit(mbase: usize, ptr: usize, cookie: u32, local_visit_members: u32): void; export declare function collect(mbase: usize, local_visit_members: u32): void; + +export declare function __alloc(size: usize, id: u32): usize; +export declare function __realloc(ref: usize, size: u32): usize; +export declare function __free( ptr: usize): usize; +export declare function __retain( ptr: usize): usize; +export declare function __release( ptr: usize): usize; +export declare function __visit(ptr: usize, cookie: u32): void; +export declare function __collect(): void; \ No newline at end of file diff --git a/std/assembly/rt/shared.ts b/std/assembly/rt/shared.ts index 12862bf630..365dcaa0f7 100644 --- a/std/assembly/rt/shared.ts +++ b/std/assembly/rt/shared.ts @@ -1,5 +1,7 @@ import * as asrt from "../bindings/asrt"; + + function visit(ptr: usize, cookie: u32): void { __visit_members(ptr, cookie); } @@ -7,13 +9,15 @@ function visit(ptr: usize, cookie: u32): void { // @ts-ignore: decorator @unsafe @global export function __alloc(size: usize, id: u32): usize { - return asrt.alloc(__memory_base, size, id); + let t=asrt.alloc(__memory_base, size, id); + return t; } // @ts-ignore: decorator @unsafe @global export function __realloc(ptr: usize, size: usize): usize { - return asrt.realloc(__memory_base, ptr, size); + let t= asrt.realloc(__memory_base, ptr, size); + return t } // @ts-ignore: decorator From 0d1b84ab98968cc9d7589d2b763ee600ba70ec6f Mon Sep 17 00:00:00 2001 From: techforindustry Date: Wed, 16 Oct 2019 12:07:19 -0600 Subject: [PATCH 4/7] add dynlink example (renamed from asrt) --- examples/asrt/app1/assembly/index.ts | 17 - examples/asrt/app2/assembly/index.ts | 13 - examples/asrt/package.json | 7 - examples/dylink/README.md | 9 + examples/dylink/app1/assembly/index.ts | 34 + .../app1/assembly/tsconfig.json | 0 .../{asrt => dylink}/app1/build/.gitignore | 0 .../{asrt => dylink}/app1/build/untouched.wat | 188 ++-- examples/{asrt => dylink}/app1/package.json | 0 examples/dylink/app2/assembly/index.ts | 34 + .../app2/assembly/tsconfig.json | 0 .../{asrt => dylink}/app2/build/.gitignore | 0 .../{asrt => dylink}/app2/build/untouched.wat | 957 ++++++++++++------ examples/{asrt => dylink}/app2/package.json | 0 examples/{asrt => dylink}/dylinker.ts | 43 +- examples/dylink/env/index.ts | 7 + examples/dylink/env/tsconfig.json | 6 + examples/dylink/package.json | 9 + examples/{asrt => dylink}/start.ts | 15 +- 19 files changed, 912 insertions(+), 427 deletions(-) delete mode 100644 examples/asrt/app1/assembly/index.ts delete mode 100644 examples/asrt/app2/assembly/index.ts delete mode 100644 examples/asrt/package.json create mode 100644 examples/dylink/README.md create mode 100644 examples/dylink/app1/assembly/index.ts rename examples/{asrt => dylink}/app1/assembly/tsconfig.json (100%) rename examples/{asrt => dylink}/app1/build/.gitignore (100%) rename examples/{asrt => dylink}/app1/build/untouched.wat (51%) rename examples/{asrt => dylink}/app1/package.json (100%) create mode 100644 examples/dylink/app2/assembly/index.ts rename examples/{asrt => dylink}/app2/assembly/tsconfig.json (100%) rename examples/{asrt => dylink}/app2/build/.gitignore (100%) rename examples/{asrt => dylink}/app2/build/untouched.wat (66%) rename examples/{asrt => dylink}/app2/package.json (100%) rename examples/{asrt => dylink}/dylinker.ts (71%) create mode 100644 examples/dylink/env/index.ts create mode 100644 examples/dylink/env/tsconfig.json create mode 100644 examples/dylink/package.json rename examples/{asrt => dylink}/start.ts (50%) diff --git a/examples/asrt/app1/assembly/index.ts b/examples/asrt/app1/assembly/index.ts deleted file mode 100644 index aad598c2aa..0000000000 --- a/examples/asrt/app1/assembly/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -// The entry file of your WebAssembly module. - -@external("app2","sayHello") -declare function sayHello(msg:string):void - -@external("env","log") -declare function log(obj:T):void - - -export function main():void{ - let t=String.fromCharCode(13) - - log(t) - var t2="app1" - log(t2) - sayHello(t2) -} \ No newline at end of file diff --git a/examples/asrt/app2/assembly/index.ts b/examples/asrt/app2/assembly/index.ts deleted file mode 100644 index 5f6411d01e..0000000000 --- a/examples/asrt/app2/assembly/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -// The entry file of your WebAssembly module. - -@external("env","log") -declare function log(obj:T):void - -export function sayHello(msg:string):void{ - log(msg) - let temp="app2" - log(temp) - let temp2=msg+temp - log(temp2) - // return "hello" -} \ No newline at end of file diff --git a/examples/asrt/package.json b/examples/asrt/package.json deleted file mode 100644 index f700d368cb..0000000000 --- a/examples/asrt/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "scripts": { - "app1":"cd ./app1 && npm run asbuild:untouched", - "app2":"cd ./app2 && npm run asbuild:untouched", - "asbuild":"npm run app1 && npm run app2" - } - } \ No newline at end of file diff --git a/examples/dylink/README.md b/examples/dylink/README.md new file mode 100644 index 0000000000..6c39ca212a --- /dev/null +++ b/examples/dylink/README.md @@ -0,0 +1,9 @@ +# Dynamic Link Example + +This example combines the shared runtime asrt with relocatable modules + +```console +npm run build +... +npm run start +``` diff --git a/examples/dylink/app1/assembly/index.ts b/examples/dylink/app1/assembly/index.ts new file mode 100644 index 0000000000..bc21c7c654 --- /dev/null +++ b/examples/dylink/app1/assembly/index.ts @@ -0,0 +1,34 @@ +// The entry file of your WebAssembly module. + +import {log} from "../../env" + +@external("app2","sayHello") +declare function sayHello(name:string):string + +@external("app2","sayHello2") +declare function sayHello2(msg:Person):string + +@external("app2","caps") +declare function caps(name:Person):void + +@external("app2","increaseAge") +declare function increaseAge(p:Person):void + +class Person{ + name:string + age:i32 +} + +const name="app1" +export function main():void{ + let p=new Person() + p.name="tom" + p.age=22 + caps(p) + let resp=sayHello(name) + log(resp) + let resp2=sayHello2(p) + log(resp2) + increaseAge(p) + log(p.age) +} \ No newline at end of file diff --git a/examples/asrt/app1/assembly/tsconfig.json b/examples/dylink/app1/assembly/tsconfig.json similarity index 100% rename from examples/asrt/app1/assembly/tsconfig.json rename to examples/dylink/app1/assembly/tsconfig.json diff --git a/examples/asrt/app1/build/.gitignore b/examples/dylink/app1/build/.gitignore similarity index 100% rename from examples/asrt/app1/build/.gitignore rename to examples/dylink/app1/build/.gitignore diff --git a/examples/asrt/app1/build/untouched.wat b/examples/dylink/app1/build/untouched.wat similarity index 51% rename from examples/asrt/app1/build/untouched.wat rename to examples/dylink/app1/build/untouched.wat index 9ec7f3dec9..891ef2f90c 100644 --- a/examples/asrt/app1/build/untouched.wat +++ b/examples/dylink/app1/build/untouched.wat @@ -1,90 +1,76 @@ (module - (type $FUNCSIG$v (func)) + (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$v (func)) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) - (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$vdd (func (param f64 f64))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (import "env" "memory" (memory $0 1)) - (data (global.get $~lib/rt/__memory_base) "\00\00\00\00\00\00\00\00\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00a\00p\00p\001\00") + (data (global.get $~lib/rt/__memory_base) "\00\00\00\00\00\00\00\00\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00a\00p\00p\001\00\06\00\00\00\01\00\00\00\01\00\00\00\06\00\00\00t\00o\00m\00") (import "env" "table" (table $0 2 funcref)) (elem (global.get $~lib/rt/__table_base) $null $~lib/rt/shared/visit) (import "env" "__memory_base" (global $~lib/rt/__memory_base i32)) (import "env" "__table_base" (global $~lib/rt/__table_base i32)) - (import "asrt" "alloc" (func $~lib/bindings/asrt/alloc (param i32 i32 i32) (result i32))) (import "asrt" "retain" (func $~lib/bindings/asrt/retain (param i32 i32) (result i32))) - (import "env" "log" (func $assembly/index/log<~lib/string/String> (param i32))) - (import "app2" "sayHello" (func $assembly/index/sayHello (param i32))) + (import "asrt" "alloc" (func $~lib/bindings/asrt/alloc (param i32 i32 i32) (result i32))) (import "asrt" "release" (func $~lib/bindings/asrt/release (param i32 i32 i32) (result i32))) + (import "app2" "caps" (func $assembly/index/caps (param i32))) + (import "app2" "sayHello" (func $assembly/index/sayHello (param i32) (result i32))) + (import "env" "_log" (func $../env/index/_log (param f64 f64))) + (import "app2" "sayHello2" (func $assembly/index/sayHello2 (param i32) (result i32))) + (import "app2" "increaseAge" (func $assembly/index/increaseAge (param i32))) (import "asrt" "visit" (func $~lib/bindings/asrt/visit (param i32 i32 i32 i32))) - (global $~lib/argc (mut i32) (i32.const 0)) + (global $assembly/index/name (mut i32) (i32.const 0)) (export "memory" (memory $0)) (export "main" (func $assembly/index/main)) - (func $~lib/rt/shared/__alloc (; 6 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (start $start) + (func $~lib/rt/shared/__retain (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) global.get $~lib/rt/__memory_base local.get $0 - local.get $1 - call $~lib/bindings/asrt/alloc + call $~lib/bindings/asrt/retain ) - (func $~lib/rt/shared/__retain (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $start:assembly/index (; 10 ;) (type $FUNCSIG$v) global.get $~lib/rt/__memory_base - local.get $0 - call $~lib/bindings/asrt/retain + i32.const 24 + i32.add + call $~lib/rt/shared/__retain + global.set $assembly/index/name ) - (func $~lib/string/String.fromCharCode (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/rt/shared/__alloc (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) - (local $3 i32) + global.get $~lib/rt/__memory_base + local.get $0 local.get $1 - i32.const 0 - i32.gt_s + call $~lib/bindings/asrt/alloc local.set $2 - i32.const 2 local.get $2 - i32.shl - i32.const 1 - call $~lib/rt/shared/__alloc - local.set $3 - global.get $~lib/rt/__memory_base - local.get $3 - i32.add + ) + (func $assembly/index/Person#constructor (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - i32.store16 - local.get $2 + i32.eqz if - global.get $~lib/rt/__memory_base - local.get $3 - i32.add - local.get $1 - i32.store16 offset=2 - end - local.get $3 - call $~lib/rt/shared/__retain - ) - (func $~lib/string/String.fromCharCode|trampoline (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - block $1of1 - block $0of1 - block $outOfRange - global.get $~lib/argc - i32.const 1 - i32.sub - br_table $0of1 $1of1 $outOfRange - end - unreachable - end - i32.const -1 - local.set $1 + i32.const 8 + i32.const 3 + call $~lib/rt/shared/__alloc + call $~lib/rt/shared/__retain + local.set $0 end local.get $0 - local.get $1 - call $~lib/string/String.fromCharCode + i32.const 0 + i32.store + local.get $0 + i32.const 0 + i32.store offset=4 + local.get $0 ) - (func $~lib/rt/shared/visit (; 10 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/rt/shared/visit (; 13 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) local.get $0 local.get $1 call $~lib/rt/__visit_members ) - (func $~lib/rt/shared/__release (; 11 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/rt/shared/__release (; 14 ;) (type $FUNCSIG$vi) (param $0 i32) global.get $~lib/rt/__memory_base local.get $0 global.get $~lib/rt/__table_base @@ -93,30 +79,92 @@ call $~lib/bindings/asrt/release drop ) - (func $assembly/index/main (; 12 ;) (type $FUNCSIG$v) + (func $../env/index/log<~lib/string/String> (; 15 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + call $~lib/rt/shared/__retain + drop + i32.const 1 + if (result i32) + i32.const 1 + else + i32.const 0 + end + f64.convert_i32_u + local.get $0 + f64.convert_i32_u + call $../env/index/_log + local.get $0 + call $~lib/rt/shared/__release + ) + (func $../env/index/log (; 16 ;) (type $FUNCSIG$vi) (param $0 i32) + i32.const 0 + if (result i32) + i32.const 0 + else + i32.const 0 + end + f64.convert_i32_u + local.get $0 + f64.convert_i32_u + call $../env/index/_log + ) + (func $assembly/index/main (; 17 ;) (type $FUNCSIG$v) (local $0 i32) (local $1 i32) - i32.const 1 - global.set $~lib/argc - i32.const 13 + (local $2 i32) i32.const 0 - call $~lib/string/String.fromCharCode|trampoline + call $assembly/index/Person#constructor local.set $0 local.get $0 - call $assembly/index/log<~lib/string/String> - i32.const 24 - call $~lib/rt/shared/__retain - local.set $1 - local.get $1 - call $assembly/index/log<~lib/string/String> + local.tee $1 + global.get $~lib/rt/__memory_base + i32.const 48 + i32.add + local.tee $2 local.get $1 + i32.load + local.tee $1 + i32.ne + if + local.get $2 + call $~lib/rt/shared/__retain + drop + local.get $1 + call $~lib/rt/shared/__release + end + local.get $2 + i32.store + local.get $0 + i32.const 22 + i32.store offset=4 + local.get $0 + call $assembly/index/caps + global.get $assembly/index/name call $assembly/index/sayHello + local.set $2 + local.get $2 + call $../env/index/log<~lib/string/String> + local.get $0 + call $assembly/index/sayHello2 + local.set $1 + local.get $1 + call $../env/index/log<~lib/string/String> + local.get $0 + call $assembly/index/increaseAge local.get $0 + i32.load offset=4 + call $../env/index/log + local.get $0 + call $~lib/rt/shared/__release + local.get $2 call $~lib/rt/shared/__release local.get $1 call $~lib/rt/shared/__release ) - (func $~lib/rt/shared/__visit (; 13 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $start (; 18 ;) (type $FUNCSIG$v) + call $start:assembly/index + ) + (func $~lib/rt/shared/__visit (; 19 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) global.get $~lib/rt/__memory_base local.get $0 local.get $1 @@ -125,24 +173,20 @@ i32.add call $~lib/bindings/asrt/visit ) - (func $~lib/rt/__visit_members (; 14 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/rt/__visit_members (; 20 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) block $switch$1$default block $switch$1$case$4 block $switch$1$case$2 - global.get $~lib/rt/__memory_base local.get $0 i32.const 8 i32.sub - i32.add i32.load - br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$default + br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$case$4 $switch$1$default end return end - global.get $~lib/rt/__memory_base local.get $0 - i32.add i32.load local.tee $2 if @@ -154,7 +198,7 @@ end unreachable ) - (func $null (; 15 ;) (type $FUNCSIG$v) + (func $null (; 21 ;) (type $FUNCSIG$v) ) ;; custom section "dylink", size 5 ) diff --git a/examples/asrt/app1/package.json b/examples/dylink/app1/package.json similarity index 100% rename from examples/asrt/app1/package.json rename to examples/dylink/app1/package.json diff --git a/examples/dylink/app2/assembly/index.ts b/examples/dylink/app2/assembly/index.ts new file mode 100644 index 0000000000..1670f2dfb1 --- /dev/null +++ b/examples/dylink/app2/assembly/index.ts @@ -0,0 +1,34 @@ +// The entry file of your WebAssembly module. + +import {log} from "../../env" + +export function sayHello(name:string):string{ + return "hello "+name +} + +export function sayHello2(p:Person):string{ + let c=new SomeOther() + c.id=5 + return "hello "+p.name +} + +export function increaseAge(p:Person):void{ + p.age++ +} + +export function caps(p:Person):void{ + let initial=p.name.charCodeAt(0) + if(initial >90){ + initial-=32 + } + p.name=p.name.replace(p.name.charAt(0),String.fromCharCode(initial)) +} + +class SomeOther{ + id:i32 +} + +class Person{ + name:string + age:i32 +} \ No newline at end of file diff --git a/examples/asrt/app2/assembly/tsconfig.json b/examples/dylink/app2/assembly/tsconfig.json similarity index 100% rename from examples/asrt/app2/assembly/tsconfig.json rename to examples/dylink/app2/assembly/tsconfig.json diff --git a/examples/asrt/app2/build/.gitignore b/examples/dylink/app2/build/.gitignore similarity index 100% rename from examples/asrt/app2/build/.gitignore rename to examples/dylink/app2/build/.gitignore diff --git a/examples/asrt/app2/build/untouched.wat b/examples/dylink/app2/build/untouched.wat similarity index 66% rename from examples/asrt/app2/build/untouched.wat rename to examples/dylink/app2/build/untouched.wat index f9a037599c..117c1e7d01 100644 --- a/examples/asrt/app2/build/untouched.wat +++ b/examples/dylink/app2/build/untouched.wat @@ -1,37 +1,41 @@ (module - (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) + (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$v (func)) (import "env" "memory" (memory $0 1)) - (data (global.get $~lib/rt/__memory_base) "\00\00\00\00\00\00\00\00\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00a\00p\00p\002\00\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00n\00u\00l\00l\00\00\00\00\00\01\00\00\00\01\00\00\00\00\00\00\00") + (data (global.get $~lib/rt/__memory_base) "\00\00\00\00\00\00\00\00\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00h\00e\00l\00l\00o\00 \00\00\00\00\00\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00n\00u\00l\00l\00\00\00\00\00\01\00\00\00\01\00\00\00\00\00\00\00") (import "env" "table" (table $0 2 funcref)) (elem (global.get $~lib/rt/__table_base) $null $~lib/rt/shared/visit) (import "env" "__memory_base" (global $~lib/rt/__memory_base i32)) (import "env" "__table_base" (global $~lib/rt/__table_base i32)) (import "asrt" "retain" (func $~lib/bindings/asrt/retain (param i32 i32) (result i32))) - (import "env" "log" (func $assembly/index/log<~lib/string/String> (param i32))) (import "asrt" "release" (func $~lib/bindings/asrt/release (param i32 i32 i32) (result i32))) (import "asrt" "alloc" (func $~lib/bindings/asrt/alloc (param i32 i32 i32) (result i32))) (import "asrt" "visit" (func $~lib/bindings/asrt/visit (param i32 i32 i32 i32))) (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) + (global $~lib/argc (mut i32) (i32.const 0)) (export "memory" (memory $0)) (export "sayHello" (func $assembly/index/sayHello)) - (func $~lib/rt/shared/__retain (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (export "sayHello2" (func $assembly/index/sayHello2)) + (export "increaseAge" (func $assembly/index/increaseAge)) + (export "caps" (func $assembly/index/caps)) + (func $~lib/rt/shared/__retain (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) global.get $~lib/rt/__memory_base local.get $0 call $~lib/bindings/asrt/retain ) - (func $~lib/rt/shared/visit (; 6 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/rt/shared/visit (; 5 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) local.get $0 local.get $1 call $~lib/rt/__visit_members ) - (func $~lib/rt/shared/__release (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/rt/shared/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) global.get $~lib/rt/__memory_base local.get $0 global.get $~lib/rt/__table_base @@ -40,23 +44,24 @@ call $~lib/bindings/asrt/release drop ) - (func $~lib/string/String#get:length (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - global.get $~lib/rt/__memory_base + (func $~lib/string/String#get:length (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.const 16 i32.sub - i32.add i32.load offset=12 i32.const 1 i32.shr_u ) - (func $~lib/rt/shared/__alloc (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/rt/shared/__alloc (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) global.get $~lib/rt/__memory_base local.get $0 local.get $1 call $~lib/bindings/asrt/alloc + local.set $2 + local.get $2 ) - (func $~lib/util/memory/memcpy (; 10 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/util/memory/memcpy (; 9 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -72,22 +77,18 @@ end i32.eqz br_if $break|0 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 local.get $2 @@ -111,48 +112,32 @@ i32.ge_u i32.eqz br_if $break|1 - global.get $~lib/rt/__memory_base local.get $0 - i32.add - global.get $~lib/rt/__memory_base local.get $1 - i32.add i32.load i32.store - global.get $~lib/rt/__memory_base local.get $0 i32.const 4 i32.add - i32.add - global.get $~lib/rt/__memory_base local.get $1 i32.const 4 i32.add - i32.add i32.load i32.store - global.get $~lib/rt/__memory_base local.get $0 i32.const 8 i32.add - i32.add - global.get $~lib/rt/__memory_base local.get $1 i32.const 8 i32.add - i32.add i32.load i32.store - global.get $~lib/rt/__memory_base local.get $0 i32.const 12 i32.add - i32.add - global.get $~lib/rt/__memory_base local.get $1 i32.const 12 i32.add - i32.add i32.load i32.store local.get $1 @@ -175,24 +160,16 @@ i32.const 8 i32.and if - global.get $~lib/rt/__memory_base local.get $0 - i32.add - global.get $~lib/rt/__memory_base local.get $1 - i32.add i32.load i32.store - global.get $~lib/rt/__memory_base local.get $0 i32.const 4 i32.add - i32.add - global.get $~lib/rt/__memory_base local.get $1 i32.const 4 i32.add - i32.add i32.load i32.store local.get $0 @@ -208,12 +185,8 @@ i32.const 4 i32.and if - global.get $~lib/rt/__memory_base local.get $0 - i32.add - global.get $~lib/rt/__memory_base local.get $1 - i32.add i32.load i32.store local.get $0 @@ -229,12 +202,8 @@ i32.const 2 i32.and if - global.get $~lib/rt/__memory_base local.get $0 - i32.add - global.get $~lib/rt/__memory_base local.get $1 - i32.add i32.load16_u i32.store16 local.get $0 @@ -250,22 +219,18 @@ i32.const 1 i32.and if - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 end @@ -297,63 +262,49 @@ br_if $case2|2 br $break|2 end - global.get $~lib/rt/__memory_base local.get $1 - i32.add i32.load local.set $3 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 local.get $2 @@ -367,16 +318,12 @@ i32.ge_u i32.eqz br_if $break|3 - global.get $~lib/rt/__memory_base local.get $1 i32.const 1 i32.add - i32.add i32.load local.set $4 - global.get $~lib/rt/__memory_base local.get $0 - i32.add local.get $3 i32.const 24 i32.shr_u @@ -385,18 +332,14 @@ i32.shl i32.or i32.store - global.get $~lib/rt/__memory_base local.get $1 i32.const 5 i32.add - i32.add i32.load local.set $3 - global.get $~lib/rt/__memory_base local.get $0 i32.const 4 i32.add - i32.add local.get $4 i32.const 24 i32.shr_u @@ -405,18 +348,14 @@ i32.shl i32.or i32.store - global.get $~lib/rt/__memory_base local.get $1 i32.const 9 i32.add - i32.add i32.load local.set $4 - global.get $~lib/rt/__memory_base local.get $0 i32.const 8 i32.add - i32.add local.get $3 i32.const 24 i32.shr_u @@ -425,18 +364,14 @@ i32.shl i32.or i32.store - global.get $~lib/rt/__memory_base local.get $1 i32.const 13 i32.add - i32.add i32.load local.set $3 - global.get $~lib/rt/__memory_base local.get $0 i32.const 12 i32.add - i32.add local.get $4 i32.const 24 i32.shr_u @@ -463,45 +398,35 @@ end br $break|2 end - global.get $~lib/rt/__memory_base local.get $1 - i32.add i32.load local.set $3 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 local.get $2 @@ -515,16 +440,12 @@ i32.ge_u i32.eqz br_if $break|4 - global.get $~lib/rt/__memory_base local.get $1 i32.const 2 i32.add - i32.add i32.load local.set $4 - global.get $~lib/rt/__memory_base local.get $0 - i32.add local.get $3 i32.const 16 i32.shr_u @@ -533,18 +454,14 @@ i32.shl i32.or i32.store - global.get $~lib/rt/__memory_base local.get $1 i32.const 6 i32.add - i32.add i32.load local.set $3 - global.get $~lib/rt/__memory_base local.get $0 i32.const 4 i32.add - i32.add local.get $4 i32.const 16 i32.shr_u @@ -553,18 +470,14 @@ i32.shl i32.or i32.store - global.get $~lib/rt/__memory_base local.get $1 i32.const 10 i32.add - i32.add i32.load local.set $4 - global.get $~lib/rt/__memory_base local.get $0 i32.const 8 i32.add - i32.add local.get $3 i32.const 16 i32.shr_u @@ -573,18 +486,14 @@ i32.shl i32.or i32.store - global.get $~lib/rt/__memory_base local.get $1 i32.const 14 i32.add - i32.add i32.load local.set $3 - global.get $~lib/rt/__memory_base local.get $0 i32.const 12 i32.add - i32.add local.get $4 i32.const 16 i32.shr_u @@ -611,27 +520,21 @@ end br $break|2 end - global.get $~lib/rt/__memory_base local.get $1 - i32.add i32.load local.set $3 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 local.get $2 @@ -645,16 +548,12 @@ i32.ge_u i32.eqz br_if $break|5 - global.get $~lib/rt/__memory_base local.get $1 i32.const 3 i32.add - i32.add i32.load local.set $4 - global.get $~lib/rt/__memory_base local.get $0 - i32.add local.get $3 i32.const 8 i32.shr_u @@ -663,18 +562,14 @@ i32.shl i32.or i32.store - global.get $~lib/rt/__memory_base local.get $1 i32.const 7 i32.add - i32.add i32.load local.set $3 - global.get $~lib/rt/__memory_base local.get $0 i32.const 4 i32.add - i32.add local.get $4 i32.const 8 i32.shr_u @@ -683,18 +578,14 @@ i32.shl i32.or i32.store - global.get $~lib/rt/__memory_base local.get $1 i32.const 11 i32.add - i32.add i32.load local.set $4 - global.get $~lib/rt/__memory_base local.get $0 i32.const 8 i32.add - i32.add local.get $3 i32.const 8 i32.shr_u @@ -703,18 +594,14 @@ i32.shl i32.or i32.store - global.get $~lib/rt/__memory_base local.get $1 i32.const 15 i32.add - i32.add i32.load local.set $3 - global.get $~lib/rt/__memory_base local.get $0 i32.const 12 i32.add - i32.add local.get $4 i32.const 8 i32.shr_u @@ -746,292 +633,228 @@ i32.const 16 i32.and if - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 end @@ -1039,148 +862,116 @@ i32.const 8 i32.and if - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 end @@ -1188,76 +979,60 @@ i32.const 4 i32.and if - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 end @@ -1265,40 +1040,32 @@ i32.const 2 i32.and if - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 end @@ -1306,27 +1073,23 @@ i32.const 1 i32.and if - global.get $~lib/rt/__memory_base local.get $0 local.tee $5 i32.const 1 i32.add local.set $0 local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $1 local.tee $5 i32.const 1 i32.add local.set $1 local.get $5 - i32.add i32.load8_u i32.store8 end ) - (func $~lib/memory/memory.copy (; 11 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/memory/memory.copy (; 10 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1393,22 +1156,18 @@ i32.const 1 i32.sub local.set $3 - global.get $~lib/rt/__memory_base local.get $5 local.tee $6 i32.const 1 i32.add local.set $5 local.get $6 - i32.add - global.get $~lib/rt/__memory_base local.get $4 local.tee $6 i32.const 1 i32.add local.set $4 local.get $6 - i32.add i32.load8_u i32.store8 br $continue|0 @@ -1422,12 +1181,8 @@ i32.ge_u i32.eqz br_if $break|1 - global.get $~lib/rt/__memory_base local.get $5 - i32.add - global.get $~lib/rt/__memory_base local.get $4 - i32.add i64.load i64.store local.get $3 @@ -1452,22 +1207,18 @@ local.get $3 i32.eqz br_if $break|2 - global.get $~lib/rt/__memory_base local.get $5 local.tee $6 i32.const 1 i32.add local.set $5 local.get $6 - i32.add - global.get $~lib/rt/__memory_base local.get $4 local.tee $6 i32.const 1 i32.add local.set $4 local.get $6 - i32.add i32.load8_u i32.store8 local.get $3 @@ -1501,19 +1252,15 @@ if br $~lib/util/memory/memmove|inlined.0 end - global.get $~lib/rt/__memory_base local.get $5 local.get $3 i32.const 1 i32.sub local.tee $3 i32.add - i32.add - global.get $~lib/rt/__memory_base local.get $4 local.get $3 i32.add - i32.add i32.load8_u i32.store8 br $continue|3 @@ -1531,16 +1278,12 @@ i32.const 8 i32.sub local.set $3 - global.get $~lib/rt/__memory_base local.get $5 local.get $3 i32.add - i32.add - global.get $~lib/rt/__memory_base local.get $4 local.get $3 i32.add - i32.add i64.load i64.store br $continue|4 @@ -1553,19 +1296,15 @@ local.get $3 i32.eqz br_if $break|5 - global.get $~lib/rt/__memory_base local.get $5 local.get $3 i32.const 1 i32.sub local.tee $3 i32.add - i32.add - global.get $~lib/rt/__memory_base local.get $4 local.get $3 i32.add - i32.add i32.load8_u i32.store8 br $continue|5 @@ -1575,7 +1314,7 @@ end end ) - (func $~lib/string/String#concat (; 12 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#concat (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1589,7 +1328,9 @@ i32.const 0 i32.eq if - i32.const 48 + global.get $~lib/rt/__memory_base + i32.const 56 + i32.add local.tee $2 local.get $1 local.tee $3 @@ -1622,7 +1363,9 @@ i32.const 0 i32.eq if - i32.const 72 + global.get $~lib/rt/__memory_base + i32.const 80 + i32.add call $~lib/rt/shared/__retain local.set $2 local.get $1 @@ -1651,7 +1394,7 @@ call $~lib/rt/shared/__release local.get $2 ) - (func $~lib/string/String.__concat (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__concat (; 12 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $0 call $~lib/rt/shared/__retain @@ -1660,7 +1403,9 @@ call $~lib/rt/shared/__retain drop local.get $0 - i32.const 48 + global.get $~lib/rt/__memory_base + i32.const 56 + i32.add local.get $0 i32.const 0 i32.ne @@ -1674,64 +1419,664 @@ call $~lib/rt/shared/__release local.get $2 ) - (func $assembly/index/sayHello (; 14 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $assembly/index/sayHello (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) - (local $3 i32) local.get $0 call $~lib/rt/shared/__retain drop - local.get $0 - call $assembly/index/log<~lib/string/String> + global.get $~lib/rt/__memory_base i32.const 24 + i32.add + local.get $0 + call $~lib/string/String.__concat + local.tee $1 call $~lib/rt/shared/__retain - local.set $1 + local.set $2 local.get $1 - call $assembly/index/log<~lib/string/String> + call $~lib/rt/shared/__release + local.get $0 + call $~lib/rt/shared/__release + local.get $2 + ) + (func $assembly/index/SomeOther#constructor (; 14 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 4 + call $~lib/rt/shared/__alloc + call $~lib/rt/shared/__retain + local.set $0 + end + local.get $0 + i32.const 0 + i32.store + local.get $0 + ) + (func $assembly/index/sayHello2 (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) local.get $0 + call $~lib/rt/shared/__retain + drop + i32.const 0 + call $assembly/index/SomeOther#constructor + local.set $1 local.get $1 + i32.const 5 + i32.store + global.get $~lib/rt/__memory_base + i32.const 24 + i32.add + local.get $0 + i32.load call $~lib/string/String.__concat local.tee $2 call $~lib/rt/shared/__retain local.set $3 - local.get $3 - call $assembly/index/log<~lib/string/String> local.get $1 call $~lib/rt/shared/__release local.get $2 call $~lib/rt/shared/__release - local.get $3 - call $~lib/rt/shared/__release local.get $0 call $~lib/rt/shared/__release + local.get $3 ) - (func $~lib/rt/shared/__visit (; 15 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - global.get $~lib/rt/__memory_base + (func $assembly/index/increaseAge (; 16 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 - local.get $1 - global.get $~lib/rt/__table_base + call $~lib/rt/shared/__retain + drop + local.get $0 + local.get $0 + i32.load offset=4 i32.const 1 i32.add - call $~lib/bindings/asrt/visit - ) - (func $~lib/rt/__visit_members (; 16 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + i32.store offset=4 + local.get $0 + call $~lib/rt/shared/__release + ) + (func $~lib/string/String#charCodeAt (; 17 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $1 + local.get $0 + call $~lib/string/String#get:length + i32.ge_u + if + i32.const -1 + return + end + local.get $0 + local.get $1 + i32.const 1 + i32.shl + i32.add + i32.load16_u + ) + (func $~lib/string/String#charAt (; 18 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $1 + local.get $0 + call $~lib/string/String#get:length + i32.ge_u + if + global.get $~lib/rt/__memory_base + i32.const 80 + i32.add + call $~lib/rt/shared/__retain + return + end + i32.const 2 + i32.const 1 + call $~lib/rt/shared/__alloc + local.set $2 + local.get $2 + local.get $0 + local.get $1 + i32.const 1 + i32.shl + i32.add + i32.load16_u + i32.store16 + local.get $2 + call $~lib/rt/shared/__retain + ) + (func $~lib/string/String.fromCharCode (; 19 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + local.get $1 + i32.const 0 + i32.gt_s + local.set $2 + i32.const 2 + local.get $2 + i32.shl + i32.const 1 + call $~lib/rt/shared/__alloc + local.set $3 + local.get $3 + local.get $0 + i32.store16 + local.get $2 + if + local.get $3 + local.get $1 + i32.store16 offset=2 + end + local.get $3 + call $~lib/rt/shared/__retain + ) + (func $~lib/string/String.fromCharCode|trampoline (; 20 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + block $1of1 + block $0of1 + block $outOfRange + global.get $~lib/argc + i32.const 1 + i32.sub + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const -1 + local.set $1 + end + local.get $0 + local.get $1 + call $~lib/string/String.fromCharCode + ) + (func $~lib/util/string/compareImpl (; 21 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + local.get $0 + call $~lib/rt/shared/__retain + drop + local.get $2 + call $~lib/rt/shared/__retain + drop + local.get $0 + local.get $1 + i32.const 1 + i32.shl + i32.add + local.set $5 + local.get $2 + local.get $3 + i32.const 1 + i32.shl + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.ge_u + if (result i32) + local.get $5 + i32.const 7 + i32.and + local.get $6 + i32.const 7 + i32.and + i32.or + i32.eqz + else + i32.const 0 + end + if + block $break|0 + loop $continue|0 + local.get $5 + i64.load + local.get $6 + i64.load + i64.ne + if + br $break|0 + end + local.get $5 + i32.const 8 + i32.add + local.set $5 + local.get $6 + i32.const 8 + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.sub + local.set $4 + local.get $4 + i32.const 4 + i32.ge_u + br_if $continue|0 + end + end + end + block $break|1 + loop $continue|1 + local.get $4 + local.tee $7 + i32.const 1 + i32.sub + local.set $4 + local.get $7 + i32.eqz + br_if $break|1 + local.get $5 + i32.load16_u + local.set $7 + local.get $6 + i32.load16_u + local.set $8 + local.get $7 + local.get $8 + i32.ne + if + local.get $7 + local.get $8 + i32.sub + local.set $9 + local.get $0 + call $~lib/rt/shared/__release + local.get $2 + call $~lib/rt/shared/__release + local.get $9 + return + end + local.get $5 + i32.const 2 + i32.add + local.set $5 + local.get $6 + i32.const 2 + i32.add + local.set $6 + br $continue|1 + end + unreachable + end + i32.const 0 + local.set $8 + local.get $0 + call $~lib/rt/shared/__release + local.get $2 + call $~lib/rt/shared/__release + local.get $8 + ) + (func $~lib/string/String.__eq (; 22 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + local.get $0 + call $~lib/rt/shared/__retain + drop + local.get $1 + call $~lib/rt/shared/__retain + drop + local.get $0 + local.get $1 + i32.eq + if + i32.const 1 + local.set $2 + local.get $0 + call $~lib/rt/shared/__release + local.get $1 + call $~lib/rt/shared/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + i32.eq + if (result i32) + i32.const 1 + else + local.get $1 + i32.const 0 + i32.eq + end + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/shared/__release + local.get $1 + call $~lib/rt/shared/__release + local.get $2 + return + end + local.get $0 + call $~lib/string/String#get:length + local.set $3 + local.get $3 + local.get $1 + call $~lib/string/String#get:length + i32.ne + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/shared/__release + local.get $1 + call $~lib/rt/shared/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + local.get $1 + i32.const 0 + local.get $3 + call $~lib/util/string/compareImpl + i32.eqz + local.set $2 + local.get $0 + call $~lib/rt/shared/__release + local.get $1 + call $~lib/rt/shared/__release + local.get $2 + ) + (func $~lib/string/String#indexOf (; 23 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + local.get $1 + call $~lib/rt/shared/__retain + drop + local.get $1 + call $~lib/string/String#get:length + local.set $3 + local.get $3 + i32.eqz + if + i32.const 0 + local.set $4 + local.get $1 + call $~lib/rt/shared/__release + local.get $4 + return + end + local.get $0 + call $~lib/string/String#get:length + local.set $5 + local.get $5 + i32.eqz + if + i32.const -1 + local.set $4 + local.get $1 + call $~lib/rt/shared/__release + local.get $4 + return + end + local.get $2 + local.tee $4 + i32.const 0 + local.tee $6 + local.get $4 + local.get $6 + i32.gt_s + select + local.tee $4 + local.get $5 + local.tee $6 + local.get $4 + local.get $6 + i32.lt_s + select + local.set $7 + block $break|0 + local.get $5 + local.get $3 + i32.sub + local.set $5 + loop $loop|0 + local.get $7 + local.get $5 + i32.le_s + i32.eqz + br_if $break|0 + local.get $0 + local.get $7 + local.get $1 + i32.const 0 + local.get $3 + call $~lib/util/string/compareImpl + i32.eqz + if + local.get $7 + local.set $4 + local.get $1 + call $~lib/rt/shared/__release + local.get $4 + return + end + local.get $7 + i32.const 1 + i32.add + local.set $7 + br $loop|0 + end + unreachable + end + i32.const -1 + local.set $4 + local.get $1 + call $~lib/rt/shared/__release + local.get $4 + ) + (func $~lib/string/String#replace (; 24 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + local.get $1 + call $~lib/rt/shared/__retain + drop + local.get $2 + call $~lib/rt/shared/__retain + drop + local.get $0 + call $~lib/string/String#get:length + local.set $3 + local.get $1 + call $~lib/string/String#get:length + local.set $4 + local.get $3 + local.get $4 + i32.le_u + if + local.get $3 + local.get $4 + i32.lt_u + if (result i32) + local.get $0 + call $~lib/rt/shared/__retain + local.tee $5 + else + local.get $2 + local.get $0 + local.get $1 + local.get $0 + call $~lib/string/String.__eq + select + call $~lib/rt/shared/__retain + local.tee $6 + end + call $~lib/rt/shared/__retain + local.set $7 + local.get $1 + call $~lib/rt/shared/__release + local.get $2 + call $~lib/rt/shared/__release + local.get $7 + return + end + local.get $0 + local.get $1 + i32.const 0 + call $~lib/string/String#indexOf + local.set $8 + local.get $8 + i32.const -1 + i32.xor + if + local.get $2 + call $~lib/string/String#get:length + local.set $6 + local.get $3 + local.get $4 + i32.sub + local.set $3 + local.get $3 + local.get $6 + i32.add + local.set $5 + local.get $5 + if + local.get $5 + i32.const 1 + i32.shl + i32.const 1 + call $~lib/rt/shared/__alloc + local.set $7 + local.get $7 + local.get $0 + local.get $8 + i32.const 1 + i32.shl + call $~lib/memory/memory.copy + local.get $7 + local.get $8 + i32.const 1 + i32.shl + i32.add + local.get $2 + local.get $6 + i32.const 1 + i32.shl + call $~lib/memory/memory.copy + local.get $7 + local.get $8 + local.get $6 + i32.add + i32.const 1 + i32.shl + i32.add + local.get $0 + local.get $8 + local.get $4 + i32.add + i32.const 1 + i32.shl + i32.add + local.get $3 + local.get $8 + i32.sub + i32.const 1 + i32.shl + call $~lib/memory/memory.copy + local.get $7 + call $~lib/rt/shared/__retain + local.set $9 + local.get $1 + call $~lib/rt/shared/__release + local.get $2 + call $~lib/rt/shared/__release + local.get $9 + return + end + end + local.get $0 + call $~lib/rt/shared/__retain + local.set $5 + local.get $1 + call $~lib/rt/shared/__release + local.get $2 + call $~lib/rt/shared/__release + local.get $5 + ) + (func $assembly/index/caps (; 25 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + local.get $0 + call $~lib/rt/shared/__retain + drop + local.get $0 + i32.load + i32.const 0 + call $~lib/string/String#charCodeAt + local.set $1 + local.get $1 + i32.const 90 + i32.gt_s + if + local.get $1 + i32.const 32 + i32.sub + local.set $1 + end + local.get $0 + local.tee $4 + local.get $0 + i32.load + local.get $0 + i32.load + i32.const 0 + call $~lib/string/String#charAt + local.tee $2 + i32.const 1 + global.set $~lib/argc + local.get $1 + i32.const 0 + call $~lib/string/String.fromCharCode|trampoline + local.tee $3 + call $~lib/string/String#replace + local.set $5 + local.get $4 + i32.load + call $~lib/rt/shared/__release + local.get $5 + i32.store + local.get $2 + call $~lib/rt/shared/__release + local.get $3 + call $~lib/rt/shared/__release + local.get $0 + call $~lib/rt/shared/__release + ) + (func $~lib/rt/shared/__visit (; 26 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + global.get $~lib/rt/__memory_base + local.get $0 + local.get $1 + global.get $~lib/rt/__table_base + i32.const 1 + i32.add + call $~lib/bindings/asrt/visit + ) + (func $~lib/rt/__visit_members (; 27 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) block $switch$1$default block $switch$1$case$4 block $switch$1$case$2 - global.get $~lib/rt/__memory_base local.get $0 i32.const 8 i32.sub - i32.add i32.load - br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$default + br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$case$4 $switch$1$case$2 $switch$1$default end return end - global.get $~lib/rt/__memory_base local.get $0 - i32.add i32.load local.tee $2 if @@ -1743,7 +2088,7 @@ end unreachable ) - (func $null (; 17 ;) (type $FUNCSIG$v) + (func $null (; 28 ;) (type $FUNCSIG$v) ) ;; custom section "dylink", size 5 ) diff --git a/examples/asrt/app2/package.json b/examples/dylink/app2/package.json similarity index 100% rename from examples/asrt/app2/package.json rename to examples/dylink/app2/package.json diff --git a/examples/asrt/dylinker.ts b/examples/dylink/dylinker.ts similarity index 71% rename from examples/asrt/dylinker.ts rename to examples/dylink/dylinker.ts index ba15a09d06..0dc04e00ee 100644 --- a/examples/asrt/dylinker.ts +++ b/examples/dylink/dylinker.ts @@ -1,8 +1,14 @@ import * as loader from "../../lib/loader" +import * as rtrace from "../../lib/rtrace" const fs = require("fs") const nodePath = require("path") export class DynamicLinker { - asrt: ModuleDefinition = new ModuleDefinition("asrt", "") + asrt: ModuleDefinition = new ModuleDefinition("asrt", "./asrt.wasm") + rtrace = rtrace(e => { + console.log("trace error", e) + },i=>{ + console.log("trace info",i) + }) memory: WebAssembly.Memory = new WebAssembly.Memory({ initial: 1 }) table: WebAssembly.Table = new WebAssembly.Table({ element: "anyfunc", initial: 10 }) defaultImports: { env?: {} } = { @@ -24,16 +30,16 @@ export class DynamicLinker { let mem_base = 1000 let table_base = 0 console.log("heap base", mem) - this.asrt.instantiate({ env: { "__heap_base": 2000 } }, this.defaultImports) + this.asrt.instantiate({ env: { "__heap_base": mem } }, this.defaultImports, { rtrace: this.rtrace }) let rtImports = {} this.modules.forEach(m => { - console.log(m.id,"mem base",mem_base) + console.log(m.id, "mem base", mem_base) m.instantiate(this.defaultImports, { env: { __memory_base: mem_base, __table_base: table_base }, asrt: this.asrt.exports }, rtImports) mem_base += m.dylink.memory_size table_base += m.dylink.table_size rtImports[m.id] = m.exports }) - console.log("final mem base",mem_base) + // console.log("final mem base",mem_base) } } @@ -43,12 +49,31 @@ export class ModuleDefinition { dylink: DyLink imports: { env: any } = { env: { - log: (offset: number): void => { - console.log(this.id, offset) + _log: (type: number, offset: number): void => { + switch (type) { + case 0: + console.log(`Log [${this.id}] ${offset}`) + break; + case 1: + console.log(`Log [${this.id}][${offset}] str:${this.exports.__getString(offset)}`) + break; + case 99: + let view=new DataView(this.imports.env.memory.buffer,offset) + let mmInfo:number=view.getUint32(0,true) + let gcInfo:number=view.getUint32(4,true) + let rtId:number=view.getUint32(8,true) + let rtsize:number=view.getUint32(12,true) + //block + console.log(`Log [${this.id}][${offset}]${mmInfo} ${gcInfo} ${rtId} ${rtsize}`) + default: + console.log(`Log [${this.id}][${offset}] type:${type}`) + break; + } + }, abort: (mesg, file, line, colm) => { const memory = this.imports.env.memory // prefer exported, otherwise try imported - console.log(this.path,"abort: " + getString(memory, mesg) + " at " + getString(memory, file) + ":" + line + ":" + colm); + console.log(this.path, "abort: " + getString(memory, mesg) + " at " + getString(memory, file) + ":" + line + ":" + colm); }, } } @@ -61,8 +86,8 @@ export class ModuleDefinition { let custom = WebAssembly.Module.customSections(this.module, "dylink") if (custom && custom.length > 0) { this.dylink = readDylinkSection(custom[0]) - }else{ - this.dylink={memory_align:4,memory_size:1000,table_size:0, table_align:0} + } else { + this.dylink = { memory_align: 4, memory_size: 1000, table_size: 0, table_align: 0 } } } diff --git a/examples/dylink/env/index.ts b/examples/dylink/env/index.ts new file mode 100644 index 0000000000..d093d99b36 --- /dev/null +++ b/examples/dylink/env/index.ts @@ -0,0 +1,7 @@ +@external("env","_log") +declare function _log(t:number,offset:number):void + + +export function log(obj:T):void{ + _log(idof()||0,changetype(obj)) +} \ No newline at end of file diff --git a/examples/dylink/env/tsconfig.json b/examples/dylink/env/tsconfig.json new file mode 100644 index 0000000000..449ca07c76 --- /dev/null +++ b/examples/dylink/env/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../../std/assembly.json", + "include": [ + "./**/*.ts" + ] +} \ No newline at end of file diff --git a/examples/dylink/package.json b/examples/dylink/package.json new file mode 100644 index 0000000000..8d3bf7d213 --- /dev/null +++ b/examples/dylink/package.json @@ -0,0 +1,9 @@ +{ + "scripts": { + "asrt": "asc ../../../lib/asrt/assembly/empty.ts --baseDir ../../lib/asrt/assembly -b ../../../examples/dylink/asrt.wasm --runtime asrt --use __visit_members=asrt/__visit_members --use __heap_base=asrt/__heap_base --importMemory --importTable --validate --debug", + "app1":"cd ./app1 && npm run asbuild:untouched", + "app2":"cd ./app2 && npm run asbuild:untouched", + "build":"npm run asrt && npm run app1 && npm run app2", + "start":"ts-node start.ts" + } + } \ No newline at end of file diff --git a/examples/asrt/start.ts b/examples/dylink/start.ts similarity index 50% rename from examples/asrt/start.ts rename to examples/dylink/start.ts index 31da82396c..f68795b390 100644 --- a/examples/asrt/start.ts +++ b/examples/dylink/start.ts @@ -2,12 +2,21 @@ import { DynamicLinker, ModuleDefinition } from "./dylinker"; let linker=new DynamicLinker() -linker.asrt.path="../../lib/asrt/build/untouched.wasm" - linker.modules.push(new ModuleDefinition("app2","./app2/build/untouched.wasm")) linker.modules.push(new ModuleDefinition("app1","./app1/build/untouched.wasm")) linker.run() //@ts-ignore -linker.modules[1].exports.main() \ No newline at end of file +linker.modules[1].exports.main() + +if(linker.rtrace.active){ + let leakCount=linker.rtrace.check() + if (leakCount){ + console.log("Found",leakCount,"memory leaks") + }else{ + console.log("No Memory Leaks found") + } +}else{ + console.log("rtrace not active") +} \ No newline at end of file From 72f6de1e3ea1cfbb07982860a25ce0a291fe7d3e Mon Sep 17 00:00:00 2001 From: techforindustry Date: Wed, 16 Oct 2019 12:09:32 -0600 Subject: [PATCH 5/7] add rtrace to asrt build --- examples/dylink/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/dylink/package.json b/examples/dylink/package.json index 8d3bf7d213..0334aa3cf4 100644 --- a/examples/dylink/package.json +++ b/examples/dylink/package.json @@ -1,6 +1,6 @@ { "scripts": { - "asrt": "asc ../../../lib/asrt/assembly/empty.ts --baseDir ../../lib/asrt/assembly -b ../../../examples/dylink/asrt.wasm --runtime asrt --use __visit_members=asrt/__visit_members --use __heap_base=asrt/__heap_base --importMemory --importTable --validate --debug", + "asrt": "asc ../../../lib/asrt/assembly/empty.ts --baseDir ../../lib/asrt/assembly -b ../../../examples/dylink/asrt.wasm --runtime asrt --use __visit_members=asrt/__visit_members --use __heap_base=asrt/__heap_base --use ASC_RTRACE=1 --importMemory --importTable --validate --debug", "app1":"cd ./app1 && npm run asbuild:untouched", "app2":"cd ./app2 && npm run asbuild:untouched", "build":"npm run asrt && npm run app1 && npm run app2", From 7065afbbc33291b2a9115ed4df0dc360b8d64c15 Mon Sep 17 00:00:00 2001 From: techforindustry Date: Wed, 16 Oct 2019 14:51:36 -0600 Subject: [PATCH 6/7] fix header log --- examples/dylink/dylinker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/dylink/dylinker.ts b/examples/dylink/dylinker.ts index 0dc04e00ee..a8aaac25e0 100644 --- a/examples/dylink/dylinker.ts +++ b/examples/dylink/dylinker.ts @@ -58,7 +58,7 @@ export class ModuleDefinition { console.log(`Log [${this.id}][${offset}] str:${this.exports.__getString(offset)}`) break; case 99: - let view=new DataView(this.imports.env.memory.buffer,offset) + let view=new DataView(this.imports.env.memory.buffer,offset-16) let mmInfo:number=view.getUint32(0,true) let gcInfo:number=view.getUint32(4,true) let rtId:number=view.getUint32(8,true) From 1b610c83137c49389fd8fa7a4ed97ef1031a8265 Mon Sep 17 00:00:00 2001 From: techforindustry Date: Wed, 16 Oct 2019 14:52:52 -0600 Subject: [PATCH 7/7] update tests (array not working) --- tests/compiler/relocatable.js | 35 ++- tests/compiler/relocatable.json | 4 +- tests/compiler/relocatable.optimized.wat | 287 +++++++++++------------ tests/compiler/relocatable.ts | 26 +- tests/compiler/relocatable.untouched.wat | 283 +++++----------------- 5 files changed, 240 insertions(+), 395 deletions(-) diff --git a/tests/compiler/relocatable.js b/tests/compiler/relocatable.js index 0478edd142..e7bf93235b 100644 --- a/tests/compiler/relocatable.js +++ b/tests/compiler/relocatable.js @@ -28,20 +28,47 @@ function readDylinkSection(buffer) { return { memory_size, memory_align, table_size, table_align }; } -exports.preInstantiate = function(imports, exports, module) { +exports.preInstantiate = function (imports, exports, module) { // compiler generates initial = 1 because it doesn't know the imported value // of env.memory_base yet, hence we need to import a suitable memory as well: imports["env"]["memory"] = new WebAssembly.Memory({ initial: 2 }); imports["env"]["__memory_base"] = 65536; imports["env"]["table"] = new WebAssembly.Table({ element: "anyfunc", initial: 20 }); imports["env"]["__table_base"] = 10; + imports["env"]["_log"] = (type, offset) => { + switch (type) { + case 0: + console.log(`Log ${offset}`) + break; + case 99: + let view = new DataView(imports.env.memory.buffer, offset-16) + let mmInfo = view.getUint32(0, true) + let gcInfo = view.getUint32(4, true) + let rtId = view.getUint32(8, true) + let rtsize = view.getUint32(12, true) + //block + console.log(`Log [${offset}]${mmInfo} ${gcInfo} ${rtId} ${rtsize}`) + break; + case 98: + console.log(`Log [${offset}]`,new Int32Array(imports.env.memory.buffer,offset,60)) + break + default: + console.log(`Log [${offset}] type:${type}`) + break; + } + + } imports["asrt"] = { - retain: function() {}, - release: function() {}, - visit: function() {} + retain: function () { }, + release: function () { }, + visit: function () { } }; var dylink = WebAssembly.Module.customSections(module, "dylink"); if (dylink && dylink.length) console.log(readDylinkSection(dylink[0])); else throw Error("missing dylink section"); }; + +exports.postInstantiate = function (instance) { + instance.exports.main() +} \ No newline at end of file diff --git a/tests/compiler/relocatable.json b/tests/compiler/relocatable.json index e5cb095878..a1c1856fa6 100644 --- a/tests/compiler/relocatable.json +++ b/tests/compiler/relocatable.json @@ -1,10 +1,8 @@ { "asc_flags": [ - "--runtime none", - "--explicitStart", "--importMemory", "--importTable", "--relocatable", - "--runtime shared" + "--runtime none" ] } \ No newline at end of file diff --git a/tests/compiler/relocatable.optimized.wat b/tests/compiler/relocatable.optimized.wat index 79d3471bc8..0be2226d37 100644 --- a/tests/compiler/relocatable.optimized.wat +++ b/tests/compiler/relocatable.optimized.wat @@ -1,123 +1,159 @@ (module + (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$i (func (result i32))) - (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$v (func)) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (type $FUNCSIG$vi (func (param i32))) - (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) - (type $FUNCSIG$v (func)) - (type $FUNCSIG$ii (func (param i32) (result i32))) (import "env" "memory" (memory $0 1)) - (data (global.get $~lib/rt/__memory_base) "\00\00\00\00\00\00\00\00\04\00\00\00\01\00\00\00\01\00\00\00\04\00\00\004\002\00\00\00\00\00\04\00\00\00\01\00\00\00\00\00\00\00\04\00\00\00*\00\00\00\00\00\00\00\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\000\00\00\000\00\00\00\04\00\00\00\01\00\00\00\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00r\00e\00l\00o\00c\00a\00t\00a\00b\00l\00e\00.\00t\00s\00\00\00\00\00$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e\00\00\00\00\00\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00\00\00\00\00\00\00\04\00\00\00\01\00\00\00\00\00\00\00\04\00\00\00+\00\00\00\00\00\00\00\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\00\00\01\00\00\00\01\00\00\04\00\00\00\01\00\00\00") - (import "env" "table" (table $0 3 funcref)) - (elem (global.get $~lib/rt/__table_base) $null $start:relocatable~anonymous|0 $~lib/rt/shared/visit) + (data (global.get $~lib/rt/__memory_base) "\00\00\00\00\00\00\00\00\04\00\00\00\01\00\00\00\01\00\00\00\04\00\00\004\002\00\00\00\00\00\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00r\00e\00l\00o\00c\00a\00t\00a\00b\00l\00e\00.\00t\00s\00") + (import "env" "table" (table $0 2 funcref)) + (elem (global.get $~lib/rt/__table_base) $null $start:relocatable~anonymous|0) (import "env" "__memory_base" (global $~lib/rt/__memory_base i32)) (import "env" "__table_base" (global $~lib/rt/__table_base i32)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) - (import "asrt" "retain" (func $~lib/bindings/asrt/retain (param i32 i32) (result i32))) - (import "asrt" "release" (func $~lib/bindings/asrt/release (param i32 i32 i32) (result i32))) - (import "asrt" "visit" (func $~lib/bindings/asrt/visit (param i32 i32 i32 i32))) + (global $relocatable/staticString (mut i32) (i32.const 0)) (global $~lib/argc (mut i32) (i32.const 0)) - (global $~lib/started (mut i32) (i32.const 0)) - (export "__start" (func $start)) (export "memory" (memory $0)) - (func $start:relocatable~anonymous|0 (; 4 ;) (type $FUNCSIG$i) (result i32) + (export "main" (func $relocatable/main)) + (start $start) + (func $start:relocatable~anonymous|0 (; 1 ;) (type $FUNCSIG$i) (result i32) i32.const 42 ) - (func $~lib/rt/shared/__retain (; 5 ;) (type $FUNCSIG$vi) (param $0 i32) - global.get $~lib/rt/__memory_base + (func $~lib/string/String#get:length (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - call $~lib/bindings/asrt/retain - drop + i32.const 16 + i32.sub + i32.load offset=12 + i32.const 1 + i32.shr_u ) - (func $~lib/rt/shared/visit (; 6 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/util/string/compareImpl (; 3 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) local.get $0 + i32.const 7 + i32.and local.get $1 - call $~lib/rt/__visit_members - ) - (func $~lib/rt/shared/__release (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) - global.get $~lib/rt/__memory_base - local.get $0 - global.get $~lib/rt/__table_base - i32.const 2 - i32.add - call $~lib/bindings/asrt/release - drop - ) - (func $~lib/array/Array#__get (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 7 + i32.and + i32.or + i32.eqz i32.const 0 - global.get $~lib/rt/__memory_base - local.get $0 - i32.add - i32.load offset=12 + local.get $2 + i32.const 4 i32.ge_u + select if - i32.const 152 - i32.const 208 - i32.const 92 - i32.const 41 - call $~lib/builtins/abort - unreachable + loop $continue|0 + local.get $0 + i64.load + local.get $1 + i64.load + i64.eq + if + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + local.get $2 + i32.const 4 + i32.sub + local.tee $2 + i32.const 4 + i32.ge_u + br_if $continue|0 + end + end end - global.get $~lib/rt/__memory_base - global.get $~lib/rt/__memory_base - local.get $0 - i32.add - i32.load offset=4 - i32.add - i32.load - ) - (func $start:relocatable (; 9 ;) (type $FUNCSIG$v) - i32.const 24 - global.get $~lib/rt/__memory_base - i32.ge_u - if - i32.const 0 - i32.const 104 - i32.const 6 - i32.const 0 - call $~lib/builtins/abort - unreachable + loop $continue|1 + block $break|1 + local.get $2 + local.tee $3 + i32.const 1 + i32.sub + local.set $2 + local.get $3 + i32.eqz + br_if $break|1 + local.get $0 + i32.load16_u + local.tee $3 + local.get $1 + i32.load16_u + local.tee $4 + i32.ne + if + local.get $3 + local.get $4 + i32.sub + return + else + local.get $0 + i32.const 2 + i32.add + local.set $0 + local.get $1 + i32.const 2 + i32.add + local.set $1 + br $continue|1 + end + unreachable + end end - i32.const 72 - global.get $~lib/rt/__memory_base - i32.ge_u + i32.const 0 + ) + (func $~lib/string/String.__eq (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $0 + local.get $1 + i32.eq if - i32.const 0 - i32.const 104 - i32.const 7 - i32.const 0 - call $~lib/builtins/abort - unreachable + i32.const 1 + return end - i32.const 1 - global.get $~lib/rt/__table_base - i32.ge_u - if - i32.const 0 - i32.const 104 - i32.const 8 - i32.const 0 - call $~lib/builtins/abort - unreachable + block $folding-inner0 + local.get $1 + i32.eqz + i32.const 1 + local.get $0 + select + br_if $folding-inner0 + local.get $0 + call $~lib/string/String#get:length + local.tee $2 + local.get $1 + call $~lib/string/String#get:length + i32.ne + br_if $folding-inner0 + local.get $0 + local.get $1 + local.get $2 + call $~lib/util/string/compareImpl + i32.eqz + return end + i32.const 0 + ) + (func $relocatable/main (; 5 ;) (type $FUNCSIG$v) + global.get $relocatable/staticString + global.get $~lib/rt/__memory_base i32.const 24 - call $~lib/rt/shared/__retain - i32.const 24 - call $~lib/rt/shared/__retain - i32.const 24 - call $~lib/rt/shared/__release - i32.const 24 - call $~lib/rt/shared/__release - i32.const 72 - call $~lib/array/Array#__get - i32.const 42 - i32.ne + i32.add + call $~lib/string/String.__eq + i32.eqz if i32.const 0 - i32.const 104 - i32.const 11 - i32.const 0 + global.get $~lib/rt/__memory_base + i32.const 48 + i32.add + i32.const 12 + i32.const 4 call $~lib/builtins/abort unreachable end @@ -131,68 +167,23 @@ i32.ne if i32.const 0 - i32.const 104 - i32.const 12 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 280 - call $~lib/array/Array#__get - i32.const 43 - i32.ne - if - i32.const 0 - i32.const 104 - i32.const 15 - i32.const 0 + global.get $~lib/rt/__memory_base + i32.const 48 + i32.add + i32.const 14 + i32.const 4 call $~lib/builtins/abort unreachable end ) - (func $start (; 10 ;) (type $FUNCSIG$v) - global.get $~lib/started - if - return - else - i32.const 1 - global.set $~lib/started - end - call $start:relocatable - ) - (func $~lib/rt/__visit_members (; 11 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - block $block$4$break - block $switch$1$default - block $switch$1$case$2 - global.get $~lib/rt/__memory_base - local.get $0 - i32.const 8 - i32.sub - i32.add - i32.load - br_table $switch$1$case$2 $switch$1$case$2 $block$4$break $block$4$break $switch$1$default - end - return - end - unreachable - end + (func $start (; 6 ;) (type $FUNCSIG$v) global.get $~lib/rt/__memory_base - local.get $0 + i32.const 24 i32.add - i32.load - local.tee $0 - if - global.get $~lib/rt/__memory_base - local.get $0 - local.get $1 - global.get $~lib/rt/__table_base - i32.const 2 - i32.add - call $~lib/bindings/asrt/visit - end + global.set $relocatable/staticString ) - (func $null (; 12 ;) (type $FUNCSIG$v) + (func $null (; 7 ;) (type $FUNCSIG$v) nop ) - ;; custom section "dylink", size 6 + ;; custom section "dylink", size 5 ) diff --git a/tests/compiler/relocatable.ts b/tests/compiler/relocatable.ts index 0f83b09683..2b8dd2585d 100644 --- a/tests/compiler/relocatable.ts +++ b/tests/compiler/relocatable.ts @@ -1,15 +1,19 @@ +@external("env","_log") +declare function _log(t:number,obj:T):void + +export function log(obj:T):void{ + _log(idof()||0,obj) +} const staticString = "42"; -const staticArray: i32[] = [ 42 ]; +// const staticArray: i32[] = [ 42 ]; const staticFunction = (): i32 => { return 42; }; -// stored internal pointers are zero-based -assert(changetype(staticString) < __memory_base); -assert(changetype(staticArray) < __memory_base); -assert(changetype(staticFunction) < __table_base); - -assert(staticString == "42"); -assert(staticArray[0] == 42); -assert(staticFunction() == 42); +export function main():void{ + assert(staticString == "42"); + // assert(staticArray[0] == 42); + assert(staticFunction() == 42); + + // var normalArray: i32[] = [ 43 ]; + // assert(normalArray[0] == 43); +} -var normalArray: i32[] = [ 43 ]; -assert(normalArray[0] == 43); diff --git a/tests/compiler/relocatable.untouched.wat b/tests/compiler/relocatable.untouched.wat index 6d98e783d8..2ceab1062b 100644 --- a/tests/compiler/relocatable.untouched.wat +++ b/tests/compiler/relocatable.untouched.wat @@ -1,75 +1,60 @@ (module + (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$i (func (result i32))) - (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$v (func)) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) - (type $FUNCSIG$vii (func (param i32 i32))) - (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) - (type $FUNCSIG$v (func)) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (import "env" "memory" (memory $0 1)) - (data (global.get $~lib/rt/__memory_base) "\00\00\00\00\00\00\00\00\04\00\00\00\01\00\00\00\01\00\00\00\04\00\00\004\002\00\00\00\00\00\04\00\00\00\01\00\00\00\00\00\00\00\04\00\00\00*\00\00\00\00\00\00\00\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\000\00\00\000\00\00\00\04\00\00\00\01\00\00\00\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00r\00e\00l\00o\00c\00a\00t\00a\00b\00l\00e\00.\00t\00s\00\00\00\00\00$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e\00\00\00\00\00\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00\00\00\00\00\00\00\04\00\00\00\01\00\00\00\00\00\00\00\04\00\00\00+\00\00\00\00\00\00\00\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\00\00\01\00\00\00\01\00\00\04\00\00\00\01\00\00\00") - (import "env" "table" (table $0 3 funcref)) - (elem (global.get $~lib/rt/__table_base) $null $start:relocatable~anonymous|0 $~lib/rt/shared/visit) + (data (global.get $~lib/rt/__memory_base) "\00\00\00\00\00\00\00\00\04\00\00\00\01\00\00\00\01\00\00\00\04\00\00\004\002\00\00\00\00\00\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00r\00e\00l\00o\00c\00a\00t\00a\00b\00l\00e\00.\00t\00s\00") + (import "env" "table" (table $0 2 funcref)) + (elem (global.get $~lib/rt/__table_base) $null $start:relocatable~anonymous|0) (import "env" "__memory_base" (global $~lib/rt/__memory_base i32)) (import "env" "__table_base" (global $~lib/rt/__table_base i32)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) - (import "asrt" "retain" (func $~lib/bindings/asrt/retain (param i32 i32) (result i32))) - (import "asrt" "release" (func $~lib/bindings/asrt/release (param i32 i32 i32) (result i32))) - (import "asrt" "visit" (func $~lib/bindings/asrt/visit (param i32 i32 i32 i32))) - (global $relocatable/staticString i32 (i32.const 24)) - (global $relocatable/staticArray i32 (i32.const 72)) + (global $relocatable/staticString (mut i32) (i32.const 0)) (global $relocatable/staticFunction i32 (i32.const 1)) (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) (global $~lib/argc (mut i32) (i32.const 0)) - (global $relocatable/normalArray (mut i32) (i32.const 280)) - (global $~lib/started (mut i32) (i32.const 0)) - (export "__start" (func $start)) (export "memory" (memory $0)) - (func $start:relocatable~anonymous|0 (; 4 ;) (type $FUNCSIG$i) (result i32) - i32.const 42 - ) - (func $~lib/rt/shared/__retain (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - global.get $~lib/rt/__memory_base + (export "main" (func $relocatable/main)) + (start $start) + (func $~lib/rt/stub/__retain (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - call $~lib/bindings/asrt/retain ) - (func $~lib/rt/shared/visit (; 6 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - local.get $0 - local.get $1 - call $~lib/rt/__visit_members + (func $start:relocatable~anonymous|0 (; 2 ;) (type $FUNCSIG$i) (result i32) + i32.const 42 ) - (func $~lib/rt/shared/__release (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $start:relocatable (; 3 ;) (type $FUNCSIG$v) global.get $~lib/rt/__memory_base - local.get $0 - global.get $~lib/rt/__table_base - i32.const 2 + i32.const 24 i32.add - call $~lib/bindings/asrt/release - drop + call $~lib/rt/stub/__retain + global.set $relocatable/staticString ) - (func $~lib/string/String#get:length (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - global.get $~lib/rt/__memory_base + (func $~lib/rt/stub/__release (; 4 ;) (type $FUNCSIG$vi) (param $0 i32) + nop + ) + (func $~lib/string/String#get:length (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.const 16 i32.sub - i32.add i32.load offset=12 i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 9 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) + (func $~lib/util/string/compareImpl (; 6 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) (local $5 i32) (local $6 i32) (local $7 i32) (local $8 i32) (local $9 i32) local.get $0 - call $~lib/rt/shared/__retain + call $~lib/rt/stub/__retain drop local.get $2 - call $~lib/rt/shared/__retain + call $~lib/rt/stub/__retain drop local.get $0 local.get $1 @@ -101,13 +86,9 @@ if block $break|0 loop $continue|0 - global.get $~lib/rt/__memory_base local.get $5 - i32.add i64.load - global.get $~lib/rt/__memory_base local.get $6 - i32.add i64.load i64.ne if @@ -142,14 +123,10 @@ local.get $7 i32.eqz br_if $break|1 - global.get $~lib/rt/__memory_base local.get $5 - i32.add i32.load16_u local.set $7 - global.get $~lib/rt/__memory_base local.get $6 - i32.add i32.load16_u local.set $8 local.get $7 @@ -161,9 +138,9 @@ i32.sub local.set $9 local.get $0 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $2 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $9 return end @@ -182,19 +159,19 @@ i32.const 0 local.set $8 local.get $0 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $2 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $8 ) - (func $~lib/string/String.__eq (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__eq (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) local.get $0 - call $~lib/rt/shared/__retain + call $~lib/rt/stub/__retain drop local.get $1 - call $~lib/rt/shared/__retain + call $~lib/rt/stub/__retain drop local.get $0 local.get $1 @@ -203,9 +180,9 @@ i32.const 1 local.set $2 local.get $0 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $1 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $2 return end @@ -223,9 +200,9 @@ i32.const 0 local.set $2 local.get $0 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $1 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $2 return end @@ -240,9 +217,9 @@ i32.const 0 local.set $2 local.get $0 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $1 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $2 return end @@ -255,108 +232,25 @@ i32.eqz local.set $2 local.get $0 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $1 - call $~lib/rt/shared/__release + call $~lib/rt/stub/__release local.get $2 ) - (func $~lib/array/Array#__unchecked_get (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - global.get $~lib/rt/__memory_base - global.get $~lib/rt/__memory_base - local.get $0 - i32.add - i32.load offset=4 - local.get $1 - i32.const 2 - i32.shl - i32.add - i32.add - i32.load - ) - (func $~lib/array/Array#__get (; 12 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - local.get $1 + (func $relocatable/main (; 8 ;) (type $FUNCSIG$v) + global.get $relocatable/staticString global.get $~lib/rt/__memory_base - local.get $0 - i32.add - i32.load offset=12 - i32.ge_u - if - i32.const 152 - i32.const 208 - i32.const 92 - i32.const 41 - call $~lib/builtins/abort - unreachable - end - local.get $0 - local.get $1 - call $~lib/array/Array#__unchecked_get - local.set $2 - local.get $2 - ) - (func $start:relocatable (; 13 ;) (type $FUNCSIG$v) - (local $0 i32) - (local $1 i32) - i32.const 24 - global.get $~lib/rt/__memory_base - i32.lt_u - i32.eqz - if - i32.const 0 - i32.const 104 - i32.const 6 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 72 - global.get $~lib/rt/__memory_base - i32.lt_u - i32.eqz - if - i32.const 0 - i32.const 104 - i32.const 7 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 1 - global.get $~lib/rt/__table_base - i32.lt_u - i32.eqz - if - i32.const 0 - i32.const 104 - i32.const 8 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 24 i32.const 24 + i32.add call $~lib/string/String.__eq i32.eqz if i32.const 0 - i32.const 104 - i32.const 10 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 72 - i32.const 0 - call $~lib/array/Array#__get - i32.const 42 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 104 - i32.const 11 - i32.const 0 + global.get $~lib/rt/__memory_base + i32.const 48 + i32.add + i32.const 12 + i32.const 4 call $~lib/builtins/abort unreachable end @@ -371,88 +265,19 @@ i32.eqz if i32.const 0 - i32.const 104 - i32.const 12 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - global.get $relocatable/normalArray - i32.const 0 - call $~lib/array/Array#__get - i32.const 43 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 104 - i32.const 15 - i32.const 0 + global.get $~lib/rt/__memory_base + i32.const 48 + i32.add + i32.const 14 + i32.const 4 call $~lib/builtins/abort unreachable end ) - (func $start (; 14 ;) (type $FUNCSIG$v) - global.get $~lib/started - if - return - else - i32.const 1 - global.set $~lib/started - end + (func $start (; 9 ;) (type $FUNCSIG$v) call $start:relocatable ) - (func $~lib/array/Array#__visit_impl (; 15 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - nop - ) - (func $~lib/rt/shared/__visit (; 16 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - global.get $~lib/rt/__memory_base - local.get $0 - local.get $1 - global.get $~lib/rt/__table_base - i32.const 2 - i32.add - call $~lib/bindings/asrt/visit - ) - (func $~lib/rt/__visit_members (; 17 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - (local $2 i32) - block $block$4$break - block $switch$1$default - block $switch$1$case$5 - block $switch$1$case$4 - block $switch$1$case$2 - global.get $~lib/rt/__memory_base - local.get $0 - i32.const 8 - i32.sub - i32.add - i32.load - br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$case$5 $switch$1$default - end - return - end - br $block$4$break - end - local.get $0 - local.get $1 - call $~lib/array/Array#__visit_impl - br $block$4$break - end - unreachable - end - global.get $~lib/rt/__memory_base - local.get $0 - i32.add - i32.load - local.tee $2 - if - local.get $2 - local.get $1 - call $~lib/rt/shared/__visit - end - return - ) - (func $null (; 18 ;) (type $FUNCSIG$v) + (func $null (; 10 ;) (type $FUNCSIG$v) ) - ;; custom section "dylink", size 6 + ;; custom section "dylink", size 5 )