mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-26 15:32:16 +00:00
Make memory allocators pluggable
This commit is contained in:
parent
78debee847
commit
896810859e
@ -156,7 +156,7 @@ args._.forEach(filename => {
|
|||||||
while ((nextPath = parser.nextFile()) != null) {
|
while ((nextPath = parser.nextFile()) != null) {
|
||||||
try {
|
try {
|
||||||
readTime += measure(() => {
|
readTime += measure(() => {
|
||||||
if (nextPath.starsWith("std:"))
|
if (nextPath.startsWith("std:"))
|
||||||
nextText = fs.readFileSync(stdlibDir + "/" + nextPath.substring(4) + ".ts", { encoding: "utf8" });
|
nextText = fs.readFileSync(stdlibDir + "/" + nextPath.substring(4) + ".ts", { encoding: "utf8" });
|
||||||
else
|
else
|
||||||
nextText = fs.readFileSync(nextPath + ".ts", { encoding: "utf8" });
|
nextText = fs.readFileSync(nextPath + ".ts", { encoding: "utf8" });
|
||||||
|
@ -82,6 +82,8 @@ export function normalize(path: string, trimExtension: bool = false, separator:
|
|||||||
|
|
||||||
/** Resolves the specified path to a normalized path relative to the specified origin. */
|
/** Resolves the specified path to a normalized path relative to the specified origin. */
|
||||||
export function resolve(normalizedPath: string, normalizedOrigin: string, separator: CharCode = CharCode.SLASH): string {
|
export function resolve(normalizedPath: string, normalizedOrigin: string, separator: CharCode = CharCode.SLASH): string {
|
||||||
|
if (normalizedPath.startsWith("std:"))
|
||||||
|
return normalizedPath;
|
||||||
return normalize(dirname(normalizedOrigin, separator) + String.fromCharCode(separator) + normalizedPath);
|
return normalize(dirname(normalizedOrigin, separator) + String.fromCharCode(separator) + normalizedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import "std:memory/arena";
|
|
||||||
|
|
||||||
function copy_memory(dest: usize, src: usize, n: usize): void {
|
function copy_memory(dest: usize, src: usize, n: usize): void {
|
||||||
// based on musl's implementation of memcpy
|
// based on musl's implementation of memcpy
|
||||||
// not a future instruction and sufficiently covered by the upcoming move_memory intrinsic
|
// not a future instruction and sufficiently covered by the upcoming move_memory intrinsic
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import "std:memory/arena";
|
||||||
|
|
||||||
var arr = changetype<i32[]>(allocate_memory(sizeof<usize>() + 2 * sizeof<i32>()));
|
var arr = changetype<i32[]>(allocate_memory(sizeof<usize>() + 2 * sizeof<i32>()));
|
||||||
|
|
||||||
assert(arr.length == 0);
|
assert(arr.length == 0);
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
(type $iii (func (param i32 i32) (result i32)))
|
(type $iii (func (param i32 i32) (result i32)))
|
||||||
(type $iiii (func (param i32 i32 i32) (result i32)))
|
(type $iiii (func (param i32 i32 i32) (result i32)))
|
||||||
(type $v (func))
|
(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_LOG2 i32 (i32.const 3))
|
||||||
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
||||||
(global $std:memory/arena/ALIGN_MASK i32 (i32.const 7))
|
(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/arr (mut i32) (i32.const 0))
|
||||||
(global $std/array/i (mut i32) (i32.const 0))
|
(global $std/array/i (mut i32) (i32.const 0))
|
||||||
(global $HEAP_BASE i32 (i32.const 4))
|
(global $HEAP_BASE i32 (i32.const 4))
|
||||||
|
@ -285,16 +285,6 @@
|
|||||||
FUNCTION_PROTOTYPE: std:string/parseFloat
|
FUNCTION_PROTOTYPE: std:string/parseFloat
|
||||||
FUNCTION_PROTOTYPE: parseFloat
|
FUNCTION_PROTOTYPE: parseFloat
|
||||||
GLOBAL: std/carray/arr
|
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]
|
[program.exports]
|
||||||
CLASS_PROTOTYPE: std:array/Array
|
CLASS_PROTOTYPE: std:array/Array
|
||||||
CLASS_PROTOTYPE: Array
|
CLASS_PROTOTYPE: Array
|
||||||
@ -322,10 +312,4 @@
|
|||||||
FUNCTION_PROTOTYPE: std:string/parseInt
|
FUNCTION_PROTOTYPE: std:string/parseInt
|
||||||
FUNCTION_PROTOTYPE: parseFloat
|
FUNCTION_PROTOTYPE: parseFloat
|
||||||
FUNCTION_PROTOTYPE: std:string/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;
|
const size: usize = 42;
|
||||||
let ptr1: usize = allocate_memory(size);
|
let ptr1: usize = allocate_memory(size);
|
||||||
let ptr2: 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(ptr1);
|
||||||
free_memory(ptr2);
|
free_memory(ptr2);
|
||||||
|
|
||||||
// arena
|
|
||||||
clear_memory();
|
clear_memory();
|
||||||
ptr1 = allocate_memory(size);
|
ptr1 = allocate_memory(size);
|
||||||
assert(ptr1 == HEAP_BASE);
|
assert(ptr1 == HEAP_BASE);
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
(type $iiii (func (param i32 i32 i32) (result i32)))
|
(type $iiii (func (param i32 i32 i32) (result i32)))
|
||||||
(type $iv (func (param i32)))
|
(type $iv (func (param i32)))
|
||||||
(type $v (func))
|
(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_LOG2 i32 (i32.const 3))
|
||||||
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
||||||
(global $std:memory/arena/ALIGN_MASK i32 (i32.const 7))
|
(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/ptr1 (mut i32) (i32.const 0))
|
||||||
(global $std/heap/ptr2 (mut i32) (i32.const 0))
|
(global $std/heap/ptr2 (mut i32) (i32.const 0))
|
||||||
(global $std/heap/i (mut i32) (i32.const 0))
|
(global $std/heap/i (mut i32) (i32.const 0))
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import "std:memory/arena";
|
||||||
|
|
||||||
class AClass {
|
class AClass {
|
||||||
static aStaticField: i32 = 0;
|
static aStaticField: i32 = 0;
|
||||||
aField: i32 = 1;
|
aField: i32 = 1;
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
(type $ii (func (param i32) (result i32)))
|
(type $ii (func (param i32) (result i32)))
|
||||||
(type $ifv (func (param i32 f32)))
|
(type $ifv (func (param i32 f32)))
|
||||||
(type $v (func))
|
(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_LOG2 i32 (i32.const 3))
|
||||||
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
||||||
(global $std:memory/arena/ALIGN_MASK i32 (i32.const 7))
|
(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 $std/new/aClass (mut i32) (i32.const 0))
|
||||||
(global $HEAP_BASE i32 (i32.const 4))
|
(global $HEAP_BASE i32 (i32.const 4))
|
||||||
(memory $0 1)
|
(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
|
// 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>()));
|
var set = changetype<Set<i32>>(allocate_memory(sizeof<usize>() + 2 * sizeof<i32>()));
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
(type $iv (func (param i32)))
|
(type $iv (func (param i32)))
|
||||||
(type $iii (func (param i32 i32) (result i32)))
|
(type $iii (func (param i32 i32) (result i32)))
|
||||||
(type $v (func))
|
(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_LOG2 i32 (i32.const 3))
|
||||||
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
(global $std:memory/arena/ALIGN_SIZE i32 (i32.const 8))
|
||||||
(global $std:memory/arena/ALIGN_MASK i32 (i32.const 7))
|
(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 $std/set/set (mut i32) (i32.const 0))
|
||||||
(global $HEAP_BASE i32 (i32.const 4))
|
(global $HEAP_BASE i32 (i32.const 4))
|
||||||
(memory $0 1)
|
(memory $0 1)
|
||||||
|
@ -636,16 +636,6 @@
|
|||||||
FUNCTION_PROTOTYPE: parseFloat
|
FUNCTION_PROTOTYPE: parseFloat
|
||||||
GLOBAL: std/string/str
|
GLOBAL: std/string/str
|
||||||
FUNCTION_PROTOTYPE: std/string/getString
|
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]
|
[program.exports]
|
||||||
CLASS_PROTOTYPE: std:array/Array
|
CLASS_PROTOTYPE: std:array/Array
|
||||||
CLASS_PROTOTYPE: Array
|
CLASS_PROTOTYPE: Array
|
||||||
@ -674,10 +664,4 @@
|
|||||||
FUNCTION_PROTOTYPE: parseFloat
|
FUNCTION_PROTOTYPE: parseFloat
|
||||||
FUNCTION_PROTOTYPE: std:string/parseFloat
|
FUNCTION_PROTOTYPE: std:string/parseFloat
|
||||||
FUNCTION_PROTOTYPE: std/string/getString
|
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
|
|
||||||
;)
|
;)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user