mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-18 01:11:32 +00:00
llvm-like naming of __heap_base, definition fixes, update examples
This commit is contained in:
@ -1,3 +1,3 @@
|
||||
// @ts-ignore: decorator
|
||||
@builtin
|
||||
export declare const HEAP_BASE: usize;
|
||||
export declare const __heap_base: usize;
|
||||
|
4
std/assembly/index.d.ts
vendored
4
std/assembly/index.d.ts
vendored
@ -105,7 +105,7 @@ declare const NaN: f32 | f64;
|
||||
/** Positive infinity as a 32-bit or 64-bit float depending on context. */
|
||||
declare const Infinity: f32 | f64;
|
||||
/** Heap base offset. */
|
||||
declare const HEAP_BASE: usize;
|
||||
declare const __heap_base: usize;
|
||||
/** Determines the byte size of the specified underlying core type. Compiles to a constant. */
|
||||
declare function sizeof<T>(): usize;
|
||||
/** Determines the alignment (log2) of the specified underlying core type. Compiles to a constant. */
|
||||
@ -539,7 +539,7 @@ declare namespace v128 {
|
||||
export function mul<T>(a: v128, b: v128): v128; // except i64
|
||||
/** Divides each lane of two 128-bit vectors. */
|
||||
export function div<T = f32 | f64>(a: v128, b: v128): v128;
|
||||
/** Negates each lane of a 128-bit vector */
|
||||
/** Negates each lane of a 128-bit vector. */
|
||||
export function neg<T>(a: v128): v128;
|
||||
/** Adds each lane of two 128-bit vectors using saturation. */
|
||||
export function add_saturate<T>(a: v128, b: v128): v128;
|
||||
|
@ -5,7 +5,7 @@ import { ArrayBufferView } from "./arraybuffer";
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@builtin
|
||||
export declare const RTTI_BASE: usize;
|
||||
export declare const __rtti_base: usize;
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@builtin @unsafe
|
||||
@ -18,7 +18,7 @@ export declare function __visit_members(ref: usize, cookie: u32): void;
|
||||
// @ts-ignore: decorator
|
||||
@unsafe
|
||||
export function __typeinfo(id: u32): TypeinfoFlags {
|
||||
var ptr = RTTI_BASE;
|
||||
var ptr = __rtti_base;
|
||||
if (id > load<u32>(ptr)) throw new Error(E_INDEXOUTOFRANGE);
|
||||
return changetype<Typeinfo>(ptr + sizeof<u32>() + id * offsetof<Typeinfo>()).flags;
|
||||
}
|
||||
@ -27,7 +27,7 @@ export function __typeinfo(id: u32): TypeinfoFlags {
|
||||
@unsafe
|
||||
export function __instanceof(ref: usize, superId: u32): bool { // keyword
|
||||
var id = changetype<BLOCK>(ref - BLOCK_OVERHEAD).rtId;
|
||||
var ptr = RTTI_BASE;
|
||||
var ptr = __rtti_base;
|
||||
if (id <= load<u32>(ptr)) {
|
||||
do if (id == superId) return true;
|
||||
while (id = changetype<Typeinfo>(ptr + sizeof<u32>() + id * offsetof<Typeinfo>()).base);
|
||||
|
@ -1,3 +1,3 @@
|
||||
export { __alloc } from "rt/tlsf";
|
||||
export { __retain, __release, __collect } from "rt/pure";
|
||||
export { RTTI_BASE as __rtti } from "rt";
|
||||
export { __rtti_base } from "rt";
|
||||
|
@ -1,2 +1,2 @@
|
||||
export { __alloc, __retain, __release, __collect } from "rt/stub";
|
||||
export { RTTI_BASE as __rtti } from "rt";
|
||||
export { __rtti_base } from "rt";
|
||||
|
@ -64,7 +64,7 @@ import { onincrement, ondecrement, onfree, onalloc } from "./rtrace";
|
||||
// @ts-ignore: decorator
|
||||
@global @unsafe
|
||||
function __visit(ref: usize, cookie: i32): void {
|
||||
if (ref < HEAP_BASE) return;
|
||||
if (ref < __heap_base) return;
|
||||
var s = changetype<Block>(ref - BLOCK_OVERHEAD);
|
||||
switch (cookie) {
|
||||
case VISIT_DECREMENT: {
|
||||
@ -251,12 +251,12 @@ function collectWhite(s: Block): void {
|
||||
// @ts-ignore: decorator
|
||||
@global @unsafe
|
||||
export function __retain(ref: usize): usize {
|
||||
if (ref > HEAP_BASE) increment(changetype<Block>(ref - BLOCK_OVERHEAD));
|
||||
if (ref > __heap_base) increment(changetype<Block>(ref - BLOCK_OVERHEAD));
|
||||
return ref;
|
||||
}
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@global @unsafe
|
||||
export function __release(ref: usize): void {
|
||||
if (ref > HEAP_BASE) decrement(changetype<Block>(ref - BLOCK_OVERHEAD));
|
||||
if (ref > __heap_base) decrement(changetype<Block>(ref - BLOCK_OVERHEAD));
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import { AL_MASK, BLOCK, BLOCK_OVERHEAD, BLOCK_MAXSIZE } from "rt/common";
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
var startOffset: usize = (HEAP_BASE + AL_MASK) & ~AL_MASK;
|
||||
var startOffset: usize = (__heap_base + AL_MASK) & ~AL_MASK;
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
|
@ -450,7 +450,7 @@ function prepareSize(size: usize): usize {
|
||||
|
||||
/** Initilizes the root structure. */
|
||||
export function initializeRoot(): void {
|
||||
var rootOffset = (HEAP_BASE + AL_MASK) & ~AL_MASK;
|
||||
var rootOffset = (__heap_base + AL_MASK) & ~AL_MASK;
|
||||
var pagesBefore = memory.size();
|
||||
var pagesNeeded = <i32>((((rootOffset + ROOT_SIZE) + 0xffff) & ~0xffff) >>> 16);
|
||||
if (pagesNeeded > pagesBefore && memory.grow(pagesNeeded - pagesBefore) < 0) unreachable();
|
||||
|
@ -3,7 +3,7 @@
|
||||
// ╒═══════════════════ Typeinfo interpretation ═══════════════════╕
|
||||
// 3 2 1
|
||||
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits
|
||||
// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ ◄─ RTTI_BASE
|
||||
// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ ◄─ __rtti_base
|
||||
// │ count │
|
||||
// ╞═══════════════════════════════════════════════════════════════╡ ┐
|
||||
// │ Typeinfo#flags [id=0] │ id < count
|
||||
|
Reference in New Issue
Block a user