implement __runtime_flags

This commit is contained in:
dcode
2019-04-05 01:59:01 +02:00
parent ed32a4c8ba
commit a9e4813798
90 changed files with 14549 additions and 7499 deletions

View File

@ -1,6 +1,7 @@
import { runtime, __runtime_id } from "../runtime";
import { ArrayBufferView } from "../arraybuffer";
import { allocate, register, discard } from "./runtime";
import { CharCode } from "./string";
import { __runtime_id } from "../runtime";
import { ArrayBufferView } from "../arraybuffer";
// @ts-ignore: decorator
@inline
@ -263,10 +264,10 @@ export function utoa32(value: u32): String {
if (!value) return "0";
var decimals = decimalCount32(value);
var out = runtime.allocate(decimals << 1);
var out = allocate(decimals << 1);
utoa32_core(changetype<usize>(out), value, decimals);
return changetype<String>(runtime.register(out, __runtime_id<String>()));
return changetype<String>(register(out, __runtime_id<String>()));
}
export function itoa32(value: i32): String {
@ -276,12 +277,12 @@ export function itoa32(value: i32): String {
if (sign) value = -value;
var decimals = decimalCount32(value) + u32(sign);
var out = runtime.allocate(decimals << 1);
var out = allocate(decimals << 1);
utoa32_core(changetype<usize>(out), value, decimals);
if (sign) store<u16>(changetype<usize>(out), CharCode.MINUS);
return changetype<String>(runtime.register(out, __runtime_id<String>()));
return changetype<String>(register(out, __runtime_id<String>()));
}
export function utoa64(value: u64): String {
@ -291,14 +292,14 @@ export function utoa64(value: u64): String {
if (value <= u32.MAX_VALUE) {
let val32 = <u32>value;
let decimals = decimalCount32(val32);
out = runtime.allocate(decimals << 1);
out = allocate(decimals << 1);
utoa32_core(out, val32, decimals);
} else {
let decimals = decimalCount64(value);
out = runtime.allocate(decimals << 1);
out = allocate(decimals << 1);
utoa64_core(changetype<usize>(out), value, decimals);
}
return changetype<String>(runtime.register(out, __runtime_id<String>()));
return changetype<String>(register(out, __runtime_id<String>()));
}
export function itoa64(value: i64): String {
@ -311,16 +312,16 @@ export function itoa64(value: i64): String {
if (<u64>value <= <u64>u32.MAX_VALUE) {
let val32 = <u32>value;
let decimals = decimalCount32(val32) + u32(sign);
out = runtime.allocate(decimals << 1);
out = allocate(decimals << 1);
utoa32_core(changetype<usize>(out), val32, decimals);
} else {
let decimals = decimalCount64(value) + u32(sign);
out = runtime.allocate(decimals << 1);
out = allocate(decimals << 1);
utoa64_core(changetype<usize>(out), value, decimals);
}
if (sign) store<u16>(changetype<usize>(out), CharCode.MINUS);
return changetype<String>(runtime.register(out, __runtime_id<String>()));
return changetype<String>(register(out, __runtime_id<String>()));
}
export function itoa<T extends number>(value: T): String {
@ -625,10 +626,10 @@ export function dtoa(value: f64): String {
if (isNaN<f64>(value)) return "NaN";
return select<String>("-Infinity", "Infinity", value < 0);
}
var temp = runtime.allocate(MAX_DOUBLE_LENGTH << 1);
var temp = allocate(MAX_DOUBLE_LENGTH << 1);
var length = dtoa_core(temp, value);
var result = changetype<String>(temp).substring(0, length); // registers
runtime.discard(temp);
discard(temp);
return result;
}