forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.ts
More file actions
56 lines (41 loc) · 1.78 KB
/
memory.ts
File metadata and controls
56 lines (41 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { memcmp, memmove, memset } from "./internal/memory";
@builtin export declare const HEAP_BASE: usize; // tslint:disable-line
/* tslint:disable */
export namespace memory {
@builtin export declare function size(): i32;
@builtin export declare function grow(pages: i32): i32;
@inline export function fill(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset
if (isDefined(__memory_fill)) { __memory_fill(dest, c, n); return; }
memset(dest, c, n);
}
@inline export function copy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c
if (isDefined(__memory_copy)) { __memory_copy(dest, src, n); return; }
memmove(dest, src, n);
}
@inline export function compare(vl: usize, vr: usize, n: usize): i32 { // see: musl/src/string/memcmp.c
if (isDefined(__memory_compare)) return __memory_compare(vl, vr, n);
return memcmp(vl, vr, n);
}
// Passive segments
// export function init(segmentIndex: u32, srcOffset: usize, dstOffset: usize, n: usize): void {
// __memory_init(segmentIndex, srcOffset, dstOffset);
// }
// export function drop(segmentIndex: u32): void {
// __memory_drop(segmentIndex);
// }
// Allocator
@inline export function allocate(size: usize): usize {
if (isDefined(__memory_allocate)) return __memory_allocate(size);
WARNING("Calling 'memory.allocate' requires a memory manager to be present.");
return <usize>unreachable();
}
@inline export function free(ptr: usize): void {
if (isDefined(__memory_free)) { __memory_free(ptr); return; }
WARNING("Calling 'memory.free' requires a memory manager to be present.");
unreachable();
}
@inline export function reset(): void {
if (isDefined(__memory_reset)) { __memory_reset(); return; }
unreachable();
}
}