mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-22 11:11:43 +00:00
Heap fill/compare; Std string experiments
This commit is contained in:
31
tests/compiler/recursive.optimized.wast
Normal file
31
tests/compiler/recursive.optimized.wast
Normal file
@ -0,0 +1,31 @@
|
||||
(module
|
||||
(type $ii (func (param i32) (result i32)))
|
||||
(memory $0 1)
|
||||
(export "fib" (func $recursive/fib))
|
||||
(export "memory" (memory $0))
|
||||
(func $recursive/fib (; 0 ;) (type $ii) (param $0 i32) (result i32)
|
||||
(if
|
||||
(i32.le_s
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
(return
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.add
|
||||
(call $recursive/fib
|
||||
(i32.sub
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(call $recursive/fib
|
||||
(i32.sub
|
||||
(get_local $0)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
4
tests/compiler/recursive.ts
Normal file
4
tests/compiler/recursive.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export function fib(n: i32): i32 {
|
||||
if (n <= 1) return 1;
|
||||
return fib(n - 1) + fib(n - 2);
|
||||
}
|
84
tests/compiler/recursive.wast
Normal file
84
tests/compiler/recursive.wast
Normal file
@ -0,0 +1,84 @@
|
||||
(module
|
||||
(type $ii (func (param i32) (result i32)))
|
||||
(global $HEAP_BASE i32 (i32.const 4))
|
||||
(memory $0 1)
|
||||
(export "fib" (func $recursive/fib))
|
||||
(export "memory" (memory $0))
|
||||
(func $recursive/fib (; 0 ;) (type $ii) (param $0 i32) (result i32)
|
||||
(if
|
||||
(i32.le_s
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
(return
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(return
|
||||
(i32.add
|
||||
(call $recursive/fib
|
||||
(i32.sub
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(call $recursive/fib
|
||||
(i32.sub
|
||||
(get_local $0)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(;
|
||||
[program.elements]
|
||||
NaN
|
||||
Infinity
|
||||
isNaN
|
||||
isFinite
|
||||
clz
|
||||
ctz
|
||||
popcnt
|
||||
rotl
|
||||
rotr
|
||||
abs
|
||||
max
|
||||
min
|
||||
ceil
|
||||
floor
|
||||
copysign
|
||||
nearest
|
||||
reinterpret
|
||||
sqrt
|
||||
trunc
|
||||
load
|
||||
store
|
||||
sizeof
|
||||
select
|
||||
unreachable
|
||||
current_memory
|
||||
grow_memory
|
||||
parseInt
|
||||
parseFloat
|
||||
changetype
|
||||
assert
|
||||
i8
|
||||
i16
|
||||
i32
|
||||
i64
|
||||
u8
|
||||
u16
|
||||
u32
|
||||
u64
|
||||
bool
|
||||
f32
|
||||
f64
|
||||
isize
|
||||
usize
|
||||
HEAP_BASE
|
||||
recursive/fib
|
||||
[program.exports]
|
||||
recursive/fib
|
||||
;)
|
@ -49,36 +49,38 @@
|
||||
isize
|
||||
usize
|
||||
HEAP_BASE
|
||||
array/Array
|
||||
std:array/Array
|
||||
Array
|
||||
error/Error
|
||||
std:error/Error
|
||||
Error
|
||||
error/RangeError
|
||||
std:error/RangeError
|
||||
RangeError
|
||||
heap/ALIGN_LOG2
|
||||
heap/ALIGN_SIZE
|
||||
heap/ALIGN_MASK
|
||||
heap/HEAP_OFFSET
|
||||
heap/Heap
|
||||
std:heap/ALIGN_LOG2
|
||||
std:heap/ALIGN_SIZE
|
||||
std:heap/ALIGN_MASK
|
||||
std:heap/HEAP_OFFSET
|
||||
std:heap/Heap
|
||||
Heap
|
||||
heap/Heap.used
|
||||
heap/Heap.free
|
||||
heap/Heap.size
|
||||
heap/Heap.allocate
|
||||
heap/Heap.dispose
|
||||
heap/Heap.copy
|
||||
map/Map
|
||||
std:heap/Heap.used
|
||||
std:heap/Heap.free
|
||||
std:heap/Heap.size
|
||||
std:heap/Heap.allocate
|
||||
std:heap/Heap.dispose
|
||||
std:heap/Heap.copy
|
||||
std:heap/Heap.fill
|
||||
std:heap/Heap.compare
|
||||
std:map/Map
|
||||
Map
|
||||
set/Set
|
||||
std:set/Set
|
||||
Set
|
||||
string/String
|
||||
std:string/String
|
||||
String
|
||||
[program.exports]
|
||||
array/Array
|
||||
error/Error
|
||||
error/RangeError
|
||||
heap/Heap
|
||||
map/Map
|
||||
set/Set
|
||||
string/String
|
||||
std:array/Array
|
||||
std:error/Error
|
||||
std:error/RangeError
|
||||
std:heap/Heap
|
||||
std:map/Map
|
||||
std:set/Set
|
||||
std:string/String
|
||||
;)
|
||||
|
@ -1,119 +0,0 @@
|
||||
(module
|
||||
(type $ii (func (param i32) (result i32)))
|
||||
(type $iv (func (param i32)))
|
||||
(type $v (func))
|
||||
(global $heap/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||
(global $std/heap/ptr (mut i32) (i32.const 0))
|
||||
(global $HEAP_BASE i32 (i32.const 4))
|
||||
(memory $0 1)
|
||||
(export "memory" (memory $0))
|
||||
(start $start)
|
||||
(func $heap/Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32)
|
||||
(local $1 i32)
|
||||
(local $2 i32)
|
||||
(if
|
||||
(i32.eqz
|
||||
(get_local $0)
|
||||
)
|
||||
(return
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
(set_local $1
|
||||
(current_memory)
|
||||
)
|
||||
(if
|
||||
(i32.gt_u
|
||||
(i32.add
|
||||
(get_global $heap/HEAP_OFFSET)
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.shl
|
||||
(get_local $1)
|
||||
(i32.const 16)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.lt_s
|
||||
(grow_memory
|
||||
(select
|
||||
(tee_local $2
|
||||
(i32.trunc_s/f64
|
||||
(f64.ceil
|
||||
(f64.div
|
||||
(f64.convert_u/i32
|
||||
(get_local $0)
|
||||
)
|
||||
(f64.const 65536)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(tee_local $1
|
||||
(i32.sub
|
||||
(i32.mul
|
||||
(get_local $1)
|
||||
(i32.const 2)
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
(i32.gt_s
|
||||
(get_local $2)
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(set_local $1
|
||||
(get_global $heap/HEAP_OFFSET)
|
||||
)
|
||||
(if
|
||||
(block (result i32)
|
||||
(set_global $heap/HEAP_OFFSET
|
||||
(i32.add
|
||||
(get_global $heap/HEAP_OFFSET)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(get_global $heap/HEAP_OFFSET)
|
||||
(i32.const 7)
|
||||
)
|
||||
)
|
||||
(set_global $heap/HEAP_OFFSET
|
||||
(i32.add
|
||||
(i32.or
|
||||
(get_global $heap/HEAP_OFFSET)
|
||||
(i32.const 7)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
(func $start (; 1 ;) (type $v)
|
||||
(local $0 i32)
|
||||
(set_global $heap/HEAP_OFFSET
|
||||
(get_global $HEAP_BASE)
|
||||
)
|
||||
(set_global $std/heap/ptr
|
||||
(call $heap/Heap.allocate
|
||||
(i32.const 10)
|
||||
)
|
||||
)
|
||||
(block
|
||||
(block $__inlined_func$heap/Heap.dispose
|
||||
(set_local $0
|
||||
(get_global $std/heap/ptr)
|
||||
)
|
||||
(nop)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
File diff suppressed because it is too large
Load Diff
@ -1,2 +1,21 @@
|
||||
let ptr: usize = Heap.allocate(10);
|
||||
Heap.dispose(ptr);
|
||||
const size: usize = 42;
|
||||
let ptr1: usize = Heap.allocate(size);
|
||||
let ptr2: usize = Heap.allocate(size);
|
||||
|
||||
assert(ptr1 != ptr2);
|
||||
|
||||
Heap.fill(ptr1, 0x12, size);
|
||||
|
||||
let i: usize;
|
||||
for (i = 0; i < size; ++i)
|
||||
assert(load<u8>(ptr1 + i) == 0x12);
|
||||
|
||||
Heap.copy(ptr2, ptr1, size);
|
||||
|
||||
for (i = 0; i < size; ++i)
|
||||
assert(load<u8>(ptr2 + i) == 0x12);
|
||||
|
||||
assert(Heap.compare(ptr1, ptr2, size) == 0);
|
||||
|
||||
Heap.dispose(ptr1);
|
||||
Heap.dispose(ptr2);
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user