directize

This commit is contained in:
dcode
2019-04-02 10:12:57 +02:00
parent 1ada854830
commit 3bcd32f3ba
91 changed files with 4225 additions and 4615 deletions

View File

@ -1,4 +1,4 @@
import { runtime, classId } from "../runtime";
import { runtime, __runtime_id } from "../runtime";
import { ArrayBufferView } from "../arraybuffer";
import { CharCode } from "./string";
@ -266,7 +266,7 @@ export function utoa32(value: u32): String {
var out = runtime.allocate(decimals << 1);
utoa32_core(changetype<usize>(out), value, decimals);
return changetype<String>(runtime.register(out, classId<String>()));
return changetype<String>(runtime.register(out, __runtime_id<String>()));
}
export function itoa32(value: i32): String {
@ -281,7 +281,7 @@ export function itoa32(value: i32): String {
utoa32_core(changetype<usize>(out), value, decimals);
if (sign) store<u16>(changetype<usize>(out), CharCode.MINUS);
return changetype<String>(runtime.register(out, classId<String>()));
return changetype<String>(runtime.register(out, __runtime_id<String>()));
}
export function utoa64(value: u64): String {
@ -298,7 +298,7 @@ export function utoa64(value: u64): String {
out = runtime.allocate(decimals << 1);
utoa64_core(changetype<usize>(out), value, decimals);
}
return changetype<String>(runtime.register(out, classId<String>()));
return changetype<String>(runtime.register(out, __runtime_id<String>()));
}
export function itoa64(value: i64): String {
@ -320,7 +320,7 @@ export function itoa64(value: i64): String {
}
if (sign) store<u16>(changetype<usize>(out), CharCode.MINUS);
return changetype<String>(runtime.register(out, classId<String>()));
return changetype<String>(runtime.register(out, __runtime_id<String>()));
}
export function itoa<T extends number>(value: T): String {

View File

@ -0,0 +1,36 @@
import { AL_MASK, MAX_SIZE_32 } from "./allocator";
/**
* The common runtime object header prepended to all managed objects. Has a size of 16 bytes in
* WASM32 and contains a classId (e.g. for instanceof checks), the allocation size (e.g. for
* .byteLength and .length computation) and additional reserved fields to be used by GC. If no
* GC is present, the HEADER is cut into half excluding the reserved fields, as indicated by
* HEADER_SIZE.
*/
@unmanaged export class HEADER {
/** Unique id of the respective class or a magic value if not yet registered.*/
classId: u32;
/** Size of the allocated payload. */
payloadSize: u32;
/** Reserved field for use by GC. Only present if GC is. */
reserved1: usize; // itcm: tagged next
/** Reserved field for use by GC. Only present if GC is. */
reserved2: usize; // itcm: prev
}
/** Common runtime header size. */
// @ts-ignore: decorator
@lazy
export const HEADER_SIZE: usize = isDefined(__ref_collect)
? (offsetof<HEADER>( ) + AL_MASK) & ~AL_MASK // full header if GC is present
: (offsetof<HEADER>("reserved1") + AL_MASK) & ~AL_MASK; // half header if GC is absent
/** Common runtime header magic. Used to assert registered/unregistered status. */
// @ts-ignore: decorator
@lazy
export const HEADER_MAGIC: u32 = 0xA55E4B17;
/** Maximum byte length of any buffer-like object. */
// @ts-ignore
@lazy
export const MAX_BYTELENGTH: i32 = MAX_SIZE_32 - HEADER_SIZE;