mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-12 06:21:29 +00:00
Make memory allocators pluggable
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import "std:memory/arena";
|
||||
|
||||
var arr = changetype<i32[]>(allocate_memory(sizeof<usize>() + 2 * sizeof<i32>()));
|
||||
|
||||
assert(arr.length == 0);
|
||||
|
@ -7,10 +7,10 @@
|
||||
(type $iii (func (param i32 i32) (result i32)))
|
||||
(type $iiii (func (param i32 i32 i32) (result i32)))
|
||||
(type $v (func))
|
||||
(global $std:memory/arena/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||
(global $std:memory/arena/ALIGN_LOG2 i32 (i32.const 3))
|
||||
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
||||
(global $std:memory/arena/ALIGN_MASK i32 (i32.const 7))
|
||||
(global $std:memory/arena/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||
(global $std/array/arr (mut i32) (i32.const 0))
|
||||
(global $std/array/i (mut i32) (i32.const 0))
|
||||
(global $HEAP_BASE i32 (i32.const 4))
|
||||
|
@ -285,16 +285,6 @@
|
||||
FUNCTION_PROTOTYPE: std:string/parseFloat
|
||||
FUNCTION_PROTOTYPE: parseFloat
|
||||
GLOBAL: std/carray/arr
|
||||
GLOBAL: std:memory/arena/ALIGN_LOG2
|
||||
GLOBAL: std:memory/arena/ALIGN_SIZE
|
||||
GLOBAL: std:memory/arena/ALIGN_MASK
|
||||
GLOBAL: std:memory/arena/HEAP_OFFSET
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/allocate_memory
|
||||
FUNCTION_PROTOTYPE: allocate_memory
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/free_memory
|
||||
FUNCTION_PROTOTYPE: free_memory
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/clear_memory
|
||||
FUNCTION_PROTOTYPE: clear_memory
|
||||
[program.exports]
|
||||
CLASS_PROTOTYPE: std:array/Array
|
||||
CLASS_PROTOTYPE: Array
|
||||
@ -322,10 +312,4 @@
|
||||
FUNCTION_PROTOTYPE: std:string/parseInt
|
||||
FUNCTION_PROTOTYPE: parseFloat
|
||||
FUNCTION_PROTOTYPE: std:string/parseFloat
|
||||
FUNCTION_PROTOTYPE: allocate_memory
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/allocate_memory
|
||||
FUNCTION_PROTOTYPE: free_memory
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/free_memory
|
||||
FUNCTION_PROTOTYPE: clear_memory
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/clear_memory
|
||||
;)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import "std:memory/arena";
|
||||
|
||||
const size: usize = 42;
|
||||
let ptr1: usize = allocate_memory(size);
|
||||
let ptr2: usize = allocate_memory(size);
|
||||
@ -20,7 +22,6 @@ assert(compare_memory(ptr1, ptr2, size) == 0);
|
||||
free_memory(ptr1);
|
||||
free_memory(ptr2);
|
||||
|
||||
// arena
|
||||
clear_memory();
|
||||
ptr1 = allocate_memory(size);
|
||||
assert(ptr1 == HEAP_BASE);
|
||||
|
@ -5,11 +5,11 @@
|
||||
(type $iiii (func (param i32 i32 i32) (result i32)))
|
||||
(type $iv (func (param i32)))
|
||||
(type $v (func))
|
||||
(global $std/heap/size i32 (i32.const 42))
|
||||
(global $std:memory/arena/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||
(global $std:memory/arena/ALIGN_LOG2 i32 (i32.const 3))
|
||||
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
||||
(global $std:memory/arena/ALIGN_MASK i32 (i32.const 7))
|
||||
(global $std:memory/arena/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||
(global $std/heap/size i32 (i32.const 42))
|
||||
(global $std/heap/ptr1 (mut i32) (i32.const 0))
|
||||
(global $std/heap/ptr2 (mut i32) (i32.const 0))
|
||||
(global $std/heap/i (mut i32) (i32.const 0))
|
||||
|
@ -1,3 +1,5 @@
|
||||
import "std:memory/arena";
|
||||
|
||||
class AClass {
|
||||
static aStaticField: i32 = 0;
|
||||
aField: i32 = 1;
|
||||
|
@ -3,10 +3,10 @@
|
||||
(type $ii (func (param i32) (result i32)))
|
||||
(type $ifv (func (param i32 f32)))
|
||||
(type $v (func))
|
||||
(global $std:memory/arena/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||
(global $std:memory/arena/ALIGN_LOG2 i32 (i32.const 3))
|
||||
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
||||
(global $std:memory/arena/ALIGN_MASK i32 (i32.const 7))
|
||||
(global $std:memory/arena/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||
(global $std/new/aClass (mut i32) (i32.const 0))
|
||||
(global $HEAP_BASE i32 (i32.const 4))
|
||||
(memory $0 1)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import "std:memory/arena";
|
||||
|
||||
// note that this doesn't test a real set implementation yet, see std/assembly/set.ts
|
||||
|
||||
var set = changetype<Set<i32>>(allocate_memory(sizeof<usize>() + 2 * sizeof<i32>()));
|
||||
|
@ -5,10 +5,10 @@
|
||||
(type $iv (func (param i32)))
|
||||
(type $iii (func (param i32 i32) (result i32)))
|
||||
(type $v (func))
|
||||
(global $std:memory/arena/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||
(global $std:memory/arena/ALIGN_LOG2 i32 (i32.const 3))
|
||||
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
||||
(global $std:memory/arena/ALIGN_MASK i32 (i32.const 7))
|
||||
(global $std:memory/arena/HEAP_OFFSET (mut i32) (i32.const 0))
|
||||
(global $std/set/set (mut i32) (i32.const 0))
|
||||
(global $HEAP_BASE i32 (i32.const 4))
|
||||
(memory $0 1)
|
||||
|
@ -636,16 +636,6 @@
|
||||
FUNCTION_PROTOTYPE: parseFloat
|
||||
GLOBAL: std/string/str
|
||||
FUNCTION_PROTOTYPE: std/string/getString
|
||||
GLOBAL: std:memory/arena/ALIGN_LOG2
|
||||
GLOBAL: std:memory/arena/ALIGN_SIZE
|
||||
GLOBAL: std:memory/arena/ALIGN_MASK
|
||||
GLOBAL: std:memory/arena/HEAP_OFFSET
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/allocate_memory
|
||||
FUNCTION_PROTOTYPE: allocate_memory
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/free_memory
|
||||
FUNCTION_PROTOTYPE: free_memory
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/clear_memory
|
||||
FUNCTION_PROTOTYPE: clear_memory
|
||||
[program.exports]
|
||||
CLASS_PROTOTYPE: std:array/Array
|
||||
CLASS_PROTOTYPE: Array
|
||||
@ -674,10 +664,4 @@
|
||||
FUNCTION_PROTOTYPE: parseFloat
|
||||
FUNCTION_PROTOTYPE: std:string/parseFloat
|
||||
FUNCTION_PROTOTYPE: std/string/getString
|
||||
FUNCTION_PROTOTYPE: allocate_memory
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/allocate_memory
|
||||
FUNCTION_PROTOTYPE: free_memory
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/free_memory
|
||||
FUNCTION_PROTOTYPE: clear_memory
|
||||
FUNCTION_PROTOTYPE: std:memory/arena/clear_memory
|
||||
;)
|
||||
|
Reference in New Issue
Block a user