Heap fill/compare; Std string experiments

This commit is contained in:
dcodeIO
2017-12-21 10:14:53 +01:00
parent dd5c3e7a4e
commit 666ba54e42
17 changed files with 5108 additions and 222 deletions

View 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)
)
)
)
)
)

View File

@ -0,0 +1,4 @@
export function fib(n: i32): i32 {
if (n <= 1) return 1;
return fib(n - 1) + fib(n - 2);
}

View 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
;)

View File

@ -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
;)

View File

@ -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

View File

@ -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