Rework resolver (#489)

* Rework IR and resolver to use nested lookup tables
* Integrate types into IR
* Make components prefer IR, slimmed down AST
* Implement `export *`
* Add `@lazy` annotation and remove `--noTreeShaking`
* Add `@start` annotation and remove magic `main`
* Related refactoring, cleanup and docs
This commit is contained in:
Daniel Wirtz
2019-02-21 00:11:22 +01:00
committed by GitHub
parent e623786b42
commit 0c64f21250
234 changed files with 16949 additions and 37871 deletions

View File

@ -8,6 +8,12 @@ declare module ASModule {
type f32 = number;
type f64 = number;
type bool = any;
namespace JSMath {
function log(x: f64): f64;
function log2(x: f64): f64;
}
var NUM_COLORS: i32;
function computeLine(y: u32, width: u32, height: u32, limit: u32): void;
function clamp<f64>(value: f64, minValue: f64, maxValue: f64): f64;
}
export default ASModule;

View File

@ -1,16 +1,16 @@
(module
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iiii_ (func (param i32 i32 i32 i32)))
(type $FF (func (param f64) (result f64)))
(type $v (func))
(type $_ (func))
(import "env" "memory" (memory $0 0))
(import "Math" "log" (func $~lib/bindings/Math/log (param f64) (result f64)))
(import "Math" "log2" (func $~lib/bindings/Math/log2 (param f64) (result f64)))
(table $0 1 anyfunc)
(table $0 1 funcref)
(elem (i32.const 0) $null)
(export "memory" (memory $0))
(export "table" (table $0))
(export "computeLine" (func $assembly/index/computeLine))
(func $assembly/index/computeLine (; 2 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $assembly/index/computeLine (; 2 ;) (type $iiii_) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 f64)
(local $5 f64)
(local $6 f64)
@ -24,188 +24,188 @@
(local $14 f64)
f64.const 10
f64.const 3
get_local $1
f64.convert_u/i32
tee_local $8
local.get $1
f64.convert_i32_u
local.tee $8
f64.mul
f64.const 4
get_local $2
f64.convert_u/i32
tee_local $4
local.get $2
f64.convert_i32_u
local.tee $4
f64.mul
f64.min
f64.div
set_local $9
get_local $0
f64.convert_u/i32
get_local $4
local.set $9
local.get $0
f64.convert_i32_u
local.get $4
f64.const 0.5
f64.mul
f64.sub
get_local $9
local.get $9
f64.mul
set_local $10
get_local $8
local.set $10
local.get $8
f64.const 0.625
f64.mul
get_local $9
local.get $9
f64.mul
set_local $12
get_local $0
get_local $1
local.set $12
local.get $0
local.get $1
i32.mul
i32.const 1
i32.shl
set_local $0
local.set $0
f64.const 1
get_local $3
f64.convert_u/i32
tee_local $6
local.get $3
f64.convert_i32_u
local.tee $6
f64.div
set_local $13
local.set $13
f64.const 8
get_local $6
local.get $6
f64.min
set_local $8
local.set $8
loop $repeat|0
get_local $7
get_local $1
local.get $7
local.get $1
i32.lt_u
if
get_local $7
f64.convert_u/i32
get_local $9
local.get $7
f64.convert_i32_u
local.get $9
f64.mul
get_local $12
local.get $12
f64.sub
set_local $11
local.set $11
f64.const 0
set_local $4
local.set $4
f64.const 0
set_local $5
local.set $5
i32.const 0
set_local $2
local.set $2
loop $continue|1
get_local $4
get_local $4
local.get $4
local.get $4
f64.mul
tee_local $14
get_local $5
get_local $5
local.tee $14
local.get $5
local.get $5
f64.mul
tee_local $6
local.tee $6
f64.add
f64.const 4
f64.le
if
block $break|1
f64.const 2
get_local $4
local.get $4
f64.mul
get_local $5
local.get $5
f64.mul
get_local $10
local.get $10
f64.add
set_local $5
get_local $14
get_local $6
local.set $5
local.get $14
local.get $6
f64.sub
get_local $11
local.get $11
f64.add
set_local $4
get_local $2
get_local $3
local.set $4
local.get $2
local.get $3
i32.ge_u
br_if $break|1
get_local $2
local.get $2
i32.const 1
i32.add
set_local $2
local.set $2
br $continue|1
end
end
end
loop $continue|2
get_local $2
f64.convert_u/i32
get_local $8
local.get $2
f64.convert_i32_u
local.get $8
f64.lt
if
get_local $4
get_local $4
local.get $4
local.get $4
f64.mul
get_local $5
get_local $5
local.get $5
local.get $5
f64.mul
f64.sub
get_local $11
local.get $11
f64.add
set_local $6
local.set $6
f64.const 2
get_local $4
local.get $4
f64.mul
get_local $5
local.get $5
f64.mul
get_local $10
local.get $10
f64.add
set_local $5
get_local $6
set_local $4
get_local $2
local.set $5
local.get $6
local.set $4
local.get $2
i32.const 1
i32.add
set_local $2
local.set $2
br $continue|2
end
end
get_local $7
local.get $7
i32.const 1
i32.shl
get_local $0
local.get $0
i32.add
get_local $4
get_local $4
local.get $4
local.get $4
f64.mul
get_local $5
get_local $5
local.get $5
local.get $5
f64.mul
f64.add
tee_local $6
local.tee $6
f64.const 1
f64.gt
if (result i32)
f64.const 2047
get_local $2
local.get $2
i32.const 1
i32.add
f64.convert_u/i32
f64.convert_i32_u
f64.const 0.5
get_local $6
local.get $6
call $~lib/bindings/Math/log
f64.mul
call $~lib/bindings/Math/log2
f64.sub
get_local $13
local.get $13
f64.mul
f64.const 0
f64.max
f64.const 1
f64.min
f64.mul
i32.trunc_u/f64
i32.trunc_f64_u
else
i32.const 2047
end
i32.store16
get_local $7
local.get $7
i32.const 1
i32.add
set_local $7
local.set $7
br $repeat|0
end
end
)
(func $null (; 3 ;) (type $v)
(func $null (; 3 ;) (type $_)
nop
)
)

View File

@ -1,26 +1,26 @@
(module
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iiii_ (func (param i32 i32 i32 i32)))
(type $FF (func (param f64) (result f64)))
(type $FFFF (func (param f64 f64 f64) (result f64)))
(type $v (func))
(type $_ (func))
(import "env" "memory" (memory $0 0))
(import "Math" "log" (func $~lib/bindings/Math/log (param f64) (result f64)))
(import "Math" "log2" (func $~lib/bindings/Math/log2 (param f64) (result f64)))
(table $0 1 anyfunc)
(table $0 1 funcref)
(elem (i32.const 0) $null)
(global $assembly/index/NUM_COLORS i32 (i32.const 2048))
(global $HEAP_BASE i32 (i32.const 8))
(global $~lib/memory/HEAP_BASE i32 (i32.const 8))
(export "memory" (memory $0))
(export "table" (table $0))
(export "computeLine" (func $assembly/index/computeLine))
(func $assembly/index/clamp<f64> (; 2 ;) (type $FFFF) (param $0 f64) (param $1 f64) (param $2 f64) (result f64)
get_local $0
get_local $1
local.get $0
local.get $1
f64.max
get_local $2
local.get $2
f64.min
)
(func $assembly/index/computeLine (; 3 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $assembly/index/computeLine (; 3 ;) (type $iiii_) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 f64)
(local $5 f64)
(local $6 f64)
@ -39,121 +39,121 @@
(local $19 f64)
(local $20 i32)
(local $21 f64)
get_local $1
f64.convert_u/i32
local.get $1
f64.convert_i32_u
f64.const 1
f64.const 1.6
f64.div
f64.mul
set_local $4
get_local $2
f64.convert_u/i32
local.set $4
local.get $2
f64.convert_i32_u
f64.const 1
f64.const 2
f64.div
f64.mul
set_local $5
local.set $5
f64.const 10
f64.const 3
get_local $1
f64.convert_u/i32
local.get $1
f64.convert_i32_u
f64.mul
f64.const 4
get_local $2
f64.convert_u/i32
local.get $2
f64.convert_i32_u
f64.mul
f64.min
f64.div
set_local $6
get_local $0
f64.convert_u/i32
get_local $5
local.set $6
local.get $0
f64.convert_i32_u
local.get $5
f64.sub
get_local $6
local.get $6
f64.mul
set_local $7
get_local $4
get_local $6
local.set $7
local.get $4
local.get $6
f64.mul
set_local $8
get_local $0
get_local $1
local.set $8
local.get $0
local.get $1
i32.mul
i32.const 1
i32.shl
set_local $9
local.set $9
f64.const 1
get_local $3
f64.convert_u/i32
local.get $3
f64.convert_i32_u
f64.div
set_local $10
local.set $10
f64.const 8
get_local $3
f64.convert_u/i32
local.get $3
f64.convert_i32_u
f64.min
set_local $11
local.set $11
block $break|0
i32.const 0
set_local $12
local.set $12
loop $repeat|0
get_local $12
get_local $1
local.get $12
local.get $1
i32.lt_u
i32.eqz
br_if $break|0
block
get_local $12
f64.convert_u/i32
get_local $6
local.get $12
f64.convert_i32_u
local.get $6
f64.mul
get_local $8
local.get $8
f64.sub
set_local $13
local.set $13
f64.const 0
set_local $14
local.set $14
f64.const 0
set_local $15
local.set $15
i32.const 0
set_local $18
local.set $18
block $break|1
loop $continue|1
get_local $14
get_local $14
local.get $14
local.get $14
f64.mul
tee_local $16
get_local $15
get_local $15
local.tee $16
local.get $15
local.get $15
f64.mul
tee_local $17
local.tee $17
f64.add
f64.const 4
f64.le
if
block
f64.const 2
get_local $14
local.get $14
f64.mul
get_local $15
local.get $15
f64.mul
get_local $7
local.get $7
f64.add
set_local $15
get_local $16
get_local $17
local.set $15
local.get $16
local.get $17
f64.sub
get_local $13
local.get $13
f64.add
set_local $14
get_local $18
get_local $3
local.set $14
local.get $18
local.get $3
i32.ge_u
if
br $break|1
end
get_local $18
local.get $18
i32.const 1
i32.add
set_local $18
local.set $18
end
br $continue|1
end
@ -161,100 +161,100 @@
end
block $break|2
loop $continue|2
get_local $18
f64.convert_u/i32
get_local $11
local.get $18
f64.convert_i32_u
local.get $11
f64.lt
if
block
get_local $14
get_local $14
local.get $14
local.get $14
f64.mul
get_local $15
get_local $15
local.get $15
local.get $15
f64.mul
f64.sub
get_local $13
local.get $13
f64.add
set_local $19
local.set $19
f64.const 2
get_local $14
local.get $14
f64.mul
get_local $15
local.get $15
f64.mul
get_local $7
local.get $7
f64.add
set_local $15
get_local $19
set_local $14
get_local $18
local.set $15
local.get $19
local.set $14
local.get $18
i32.const 1
i32.add
set_local $18
local.set $18
end
br $continue|2
end
end
end
get_global $assembly/index/NUM_COLORS
global.get $assembly/index/NUM_COLORS
i32.const 1
i32.sub
set_local $20
get_local $14
get_local $14
local.set $20
local.get $14
local.get $14
f64.mul
get_local $15
get_local $15
local.get $15
local.get $15
f64.mul
f64.add
set_local $19
get_local $19
local.set $19
local.get $19
f64.const 1
f64.gt
if
f64.const 0.5
get_local $19
local.get $19
call $~lib/bindings/Math/log
f64.mul
call $~lib/bindings/Math/log2
set_local $21
get_global $assembly/index/NUM_COLORS
local.set $21
global.get $assembly/index/NUM_COLORS
i32.const 1
i32.sub
f64.convert_s/i32
get_local $18
f64.convert_i32_s
local.get $18
i32.const 1
i32.add
f64.convert_u/i32
get_local $21
f64.convert_i32_u
local.get $21
f64.sub
get_local $10
local.get $10
f64.mul
f64.const 0
f64.const 1
call $assembly/index/clamp<f64>
f64.mul
i32.trunc_u/f64
set_local $20
i32.trunc_f64_u
local.set $20
end
get_local $9
get_local $12
local.get $9
local.get $12
i32.const 1
i32.shl
i32.add
get_local $20
local.get $20
i32.store16
end
get_local $12
local.get $12
i32.const 1
i32.add
set_local $12
local.set $12
br $repeat|0
unreachable
end
unreachable
end
)
(func $null (; 4 ;) (type $v)
(func $null (; 4 ;) (type $_)
)
)