feat: allow 128-bit types

This commit is contained in:
Jonas Kruckenberg
2023-05-31 15:38:29 +02:00
parent 7671fa709c
commit 9fc8395899
63 changed files with 1631 additions and 722 deletions

View File

@@ -205,10 +205,12 @@ fn type_ident(typedefs: &TypeDefArena, ty: &Type) -> String {
Type::U16 => "U16".to_string(),
Type::U32 => "U32".to_string(),
Type::U64 => "U64".to_string(),
Type::U128 => "U128".to_string(),
Type::S8 => "I8".to_string(),
Type::S16 => "I16".to_string(),
Type::S32 => "S32".to_string(),
Type::S64 => "S64".to_string(),
Type::S128 => "S128".to_string(),
Type::Float32 => "F32".to_string(),
Type::Float64 => "F64".to_string(),
Type::Char => "Char".to_string(),

View File

@@ -177,7 +177,7 @@ async {ident} ({params}) {{
| Type::S32
| Type::Float32
| Type::Float64 => "number".to_string(),
Type::U64 | Type::S64 => "bigint".to_string(),
Type::U64 | Type::S64 | Type::U128 | Type::S128 => "bigint".to_string(),
Type::Char | Type::String => "string".to_string(),
Type::Tuple(types) => {
let types = types
@@ -223,7 +223,9 @@ async {ident} ({params}) {{
TypeDefKind::Alias(t) => self.array_ty(t),
_ => None,
},
Type::Bool
Type::U128
| Type::S128
| Type::Bool
| Type::Tuple(_)
| Type::List(_)
| Type::Option(_)

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -83,10 +88,10 @@ function deserializeChar(de) {
return __text_decoder.decode(bytes);
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -101,10 +106,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);

View File

@@ -17,20 +17,25 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -45,10 +50,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -83,10 +88,10 @@ function deserializeU32(de) {
function deserializeU64(de) {
return de_varint_big(de, 64)
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -101,10 +106,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -83,6 +88,9 @@ function deserializeU32(de) {
function deserializeU64(de) {
return de_varint_big(de, 64)
}
function deserializeU128(de) {
return de_varint_big(de, 128)
}
function deserializeS8(de) {
const buf = new ArrayBuffer(1);
const view = new DataView(buf);
@@ -106,10 +114,15 @@ function deserializeS64(de) {
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFn))
}
function ser_varint(out, type, val) {
function deserializeS128(de) {
const n = de_varint_big(de, 128)
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn))
}
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -124,10 +137,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -153,6 +166,9 @@ function serializeU32(out, val) {
function serializeU64(out, val) {
return ser_varint_big(out, 64, BigInt(val))
}
function serializeU128(out, val) {
return ser_varint_big(out, 128, BigInt(val))
}
function serializeS8(out, val) {
out.push(val)
}
@@ -166,6 +182,10 @@ function serializeS64(out, val) {
val = BigInt(val)
ser_varint_big(out, 64, (val << 1n) ^ (val >> 63n))
}
function serializeS128(out, val) {
val = BigInt(val)
ser_varint_big(out, 128, (val << 1n) ^ (val >> 127n))
}
/**
@@ -248,6 +268,26 @@ export async function a8 (x) {
return fetch('ipc://localhost/integers/a8', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
}
/**
* @param {bigint} x
*/
export async function a9 (x) {
const out = []
serializeU128(out, x)
return fetch('ipc://localhost/integers/a9', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
}
/**
* @param {bigint} x
*/
export async function a10 (x) {
const out = []
serializeS128(out, x)
return fetch('ipc://localhost/integers/a10', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
}
/**
* @param {number} p1
* @param {number} p2
@@ -257,8 +297,10 @@ export async function a8 (x) {
* @param {number} p6
* @param {bigint} p7
* @param {bigint} p8
* @param {bigint} p9
* @param {bigint} p10
*/
export async function a9 (p1, p2, p3, p4, p5, p6, p7, p8) {
export async function a11 (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) {
const out = []
serializeU8(out, p1);
serializeS8(out, p2);
@@ -267,9 +309,11 @@ serializeS16(out, p4);
serializeU32(out, p5);
serializeS32(out, p6);
serializeU64(out, p7);
serializeS64(out, p8)
serializeS64(out, p8);
serializeU128(out, p9);
serializeS128(out, p10)
return fetch('ipc://localhost/integers/a9', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
return fetch('ipc://localhost/integers/a11', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
}
/**
@@ -400,6 +444,38 @@ export async function r8 () {
})
}
/**
* @returns {Promise<bigint>}
*/
export async function r9 () {
const out = []
return fetch('ipc://localhost/integers/r9', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeU128(de)
})
}
/**
* @returns {Promise<bigint>}
*/
export async function r10 () {
const out = []
return fetch('ipc://localhost/integers/r10', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeS128(de)
})
}
/**
* @returns {Promise<[bigint, number]>}
*/

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -83,6 +88,9 @@ function deserializeU32(de) {
function deserializeU64(de) {
return de_varint_big(de, 64)
}
function deserializeU128(de) {
return de_varint_big(de, 128)
}
function deserializeS8(de) {
const buf = new ArrayBuffer(1);
const view = new DataView(buf);
@@ -106,6 +114,11 @@ function deserializeS64(de) {
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFn))
}
function deserializeS128(de) {
const n = de_varint_big(de, 128)
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn))
}
function deserializeF32(de) {
const bytes = de.try_take_n(4);
@@ -160,10 +173,10 @@ function deserializeList(de, inner) {
return out;
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -178,10 +191,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -207,6 +220,9 @@ function serializeU32(out, val) {
function serializeU64(out, val) {
return ser_varint_big(out, 64, BigInt(val))
}
function serializeU128(out, val) {
return ser_varint_big(out, 128, BigInt(val))
}
function serializeS8(out, val) {
out.push(val)
}
@@ -220,6 +236,10 @@ function serializeS64(out, val) {
val = BigInt(val)
ser_varint_big(out, 64, (val << 1n) ^ (val >> 63n))
}
function serializeS128(out, val) {
val = BigInt(val)
ser_varint_big(out, 128, (val << 1n) ^ (val >> 127n))
}
function serializeF32(out, val) {
const buf = new ArrayBuffer(4);
const view = new DataView(buf);
@@ -392,6 +412,16 @@ export async function listU64Param (x) {
return fetch('ipc://localhost/lists/list_u64_param', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
}
/**
* @param {bigint[]} x
*/
export async function listU128Param (x) {
const out = []
serializeList(out, (out, v) => serializeU128(out, v), x)
return fetch('ipc://localhost/lists/list_u128_param', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
}
/**
* @param {Int8Array[]} x
*/
@@ -432,6 +462,16 @@ export async function listS64Param (x) {
return fetch('ipc://localhost/lists/list_s64_param', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
}
/**
* @param {bigint[]} x
*/
export async function listS128Param (x) {
const out = []
serializeList(out, (out, v) => serializeS128(out, v), x)
return fetch('ipc://localhost/lists/list_s128_param', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
}
/**
* @param {Float32Array[]} x
*/
@@ -516,6 +556,22 @@ export async function listU64Ret () {
})
}
/**
* @returns {Promise<bigint[]>}
*/
export async function listU128Ret () {
const out = []
return fetch('ipc://localhost/lists/list_u128_ret', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeList(de, (de) => deserializeU128(de))
})
}
/**
* @returns {Promise<Int8Array[]>}
*/
@@ -580,6 +636,22 @@ export async function listS64Ret () {
})
}
/**
* @returns {Promise<bigint[]>}
*/
export async function listS128Ret () {
const out = []
return fetch('ipc://localhost/lists/list_s128_ret', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeList(de, (de) => deserializeS128(de))
})
}
/**
* @returns {Promise<Float32Array[]>}
*/

View File

@@ -17,20 +17,25 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -45,10 +50,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -87,6 +92,11 @@ function deserializeS32(de) {
return Number(((n >> 1) & 0xFFFFFFFF) ^ (-((n & 0b1) & 0xFFFFFFFF)))
}
function deserializeS64(de) {
const n = de_varint_big(de, 64)
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFn))
}
function deserializeChar(de) {
const sz = deserializeU64(de);
if (sz > 4) {
@@ -103,10 +113,10 @@ function deserializeString(de) {
return __text_decoder.decode(bytes);
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -121,10 +131,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -150,6 +160,10 @@ function serializeU64(out, val) {
function serializeS32(out, val) {
ser_varint(out, 32, (val << 1) ^ (val >> 31))
}
function serializeS64(out, val) {
val = BigInt(val)
ser_varint_big(out, 64, (val << 1n) ^ (val >> 63n))
}
function serializeChar(out, val) {
if (val.len > 1) {
throw new Error("Serialize bad char");

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -74,10 +79,10 @@ function de_varint_big(de, type) {
function deserializeU32(de) {
return de_varint(de, 32)
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -92,10 +97,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -88,10 +93,10 @@ function deserializeList(de, inner) {
return out;
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -106,10 +111,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -81,10 +86,10 @@ function deserializeString(de) {
return __text_decoder.decode(bytes);
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -99,10 +104,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -147,10 +152,10 @@ function deserializeString(de) {
return __text_decoder.decode(bytes);
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -165,10 +170,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -85,6 +90,14 @@ function deserializeU32(de) {
function deserializeU64(de) {
return de_varint_big(de, 64)
}
function deserializeS8(de) {
const buf = new ArrayBuffer(1);
const view = new DataView(buf);
buf[0] = view.setUint8(0, de.pop());
return view.getInt8(0);
}
function deserializeS32(de) {
const n = de_varint(de, 32)
@@ -153,10 +166,10 @@ function deserializeResult(de, ok, err) {
throw new Error(`Deserialize bad result ${tag}`)
}
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -171,10 +184,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -200,6 +213,9 @@ function serializeU32(out, val) {
function serializeU64(out, val) {
return ser_varint_big(out, 64, BigInt(val))
}
function serializeS8(out, val) {
out.push(val)
}
function serializeS32(out, val) {
ser_varint(out, 32, (val << 1) ^ (val >> 31))
}

View File

@@ -27,7 +27,13 @@ pub mod integers {
pub async fn a8(x: i64) {
::tauri_bindgen_guest_rust::invoke("integers", "a8", &(x)).await.unwrap()
}
pub async fn a9(
pub async fn a9(x: u128) {
::tauri_bindgen_guest_rust::invoke("integers", "a9", &(x)).await.unwrap()
}
pub async fn a10(x: i128) {
::tauri_bindgen_guest_rust::invoke("integers", "a10", &(x)).await.unwrap()
}
pub async fn a11(
p1: u8,
p2: i8,
p3: u16,
@@ -36,11 +42,13 @@ pub mod integers {
p6: i32,
p7: u64,
p8: i64,
p9: u128,
p10: i128,
) {
::tauri_bindgen_guest_rust::invoke(
"integers",
"a9",
&(p1, p2, p3, p4, p5, p6, p7, p8),
"a11",
&(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10),
)
.await
.unwrap()
@@ -69,6 +77,12 @@ pub mod integers {
pub async fn r8() -> i64 {
::tauri_bindgen_guest_rust::invoke("integers", "r8", &()).await.unwrap()
}
pub async fn r9() -> u128 {
::tauri_bindgen_guest_rust::invoke("integers", "r9", &()).await.unwrap()
}
pub async fn r10() -> i128 {
::tauri_bindgen_guest_rust::invoke("integers", "r10", &()).await.unwrap()
}
pub async fn pair_ret() -> (i64, u8) {
::tauri_bindgen_guest_rust::invoke("integers", "pair_ret", &()).await.unwrap()
}

View File

@@ -104,6 +104,11 @@ pub mod lists {
.await
.unwrap()
}
pub async fn list_u128_param(x: &'_ [u128]) {
::tauri_bindgen_guest_rust::invoke("lists", "list_u128_param", &(x))
.await
.unwrap()
}
pub async fn list_s8_param(x: &'_ [i8]) {
::tauri_bindgen_guest_rust::invoke("lists", "list_s8_param", &(x)).await.unwrap()
}
@@ -122,6 +127,11 @@ pub mod lists {
.await
.unwrap()
}
pub async fn list_s128_param(x: &'_ [i128]) {
::tauri_bindgen_guest_rust::invoke("lists", "list_s128_param", &(x))
.await
.unwrap()
}
pub async fn list_float32_param(x: &'_ [f32]) {
::tauri_bindgen_guest_rust::invoke("lists", "list_float32_param", &(x))
.await
@@ -144,6 +154,9 @@ pub mod lists {
pub async fn list_u64_ret() -> Vec<u64> {
::tauri_bindgen_guest_rust::invoke("lists", "list_u64_ret", &()).await.unwrap()
}
pub async fn list_u128_ret() -> Vec<u128> {
::tauri_bindgen_guest_rust::invoke("lists", "list_u128_ret", &()).await.unwrap()
}
pub async fn list_s8_ret() -> Vec<i8> {
::tauri_bindgen_guest_rust::invoke("lists", "list_s8_ret", &()).await.unwrap()
}
@@ -156,6 +169,9 @@ pub mod lists {
pub async fn list_s64_ret() -> Vec<i64> {
::tauri_bindgen_guest_rust::invoke("lists", "list_s64_ret", &()).await.unwrap()
}
pub async fn list_s128_ret() -> Vec<i128> {
::tauri_bindgen_guest_rust::invoke("lists", "list_s128_ret", &()).await.unwrap()
}
pub async fn list_float32_ret() -> Vec<f32> {
::tauri_bindgen_guest_rust::invoke("lists", "list_float32_ret", &())
.await

View File

@@ -94,7 +94,7 @@ impl TypeScript {
export async function {ident} ({params}) : {result} {{
const out = []
{serialize_params}
{ret} fetch('ipc://localhost/{intf_name}/{name}', {{ method: "POST", body: Uint8Array.from(out) }}){deserialize_result} {as_ret}
}}
"#
@@ -143,7 +143,7 @@ export async function {ident} ({params}) : {result} {{
| Type::S32
| Type::Float32
| Type::Float64 => "number".to_string(),
Type::U64 | Type::S64 => "bigint".to_string(),
Type::U64 | Type::S64 | Type::U128 | Type::S128 => "bigint".to_string(),
Type::Char | Type::String => "string".to_string(),
Type::Tuple(types) => {
let types = types
@@ -343,7 +343,9 @@ async {ident} ({params}) {result} {{
TypeDefKind::Alias(t) => self.array_ty(t),
_ => None,
},
Type::Bool
Type::U128
| Type::S128
| Type::Bool
| Type::Tuple(_)
| Type::List(_)
| Type::Option(_)

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -83,10 +88,10 @@ function deserializeChar(de) {
return __text_decoder.decode(bytes);
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -101,10 +106,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -141,7 +146,7 @@ const __text_encoder = new TextEncoder();
export async function takeChar (x: string) : Promise<void> {
const out = []
serializeChar(out, x)
fetch('ipc://localhost/chars/take_char', { method: "POST", body: Uint8Array.from(out) })
}
@@ -151,7 +156,7 @@ export async function takeChar (x: string) : Promise<void> {
export async function returnChar () : Promise<string> {
const out = []
return fetch('ipc://localhost/chars/return_char', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -17,20 +17,25 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -45,10 +50,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -84,7 +89,7 @@ iAmGoingExtremelySlow: bigint,
export async function kebabCase () : Promise<void> {
const out = []
fetch('ipc://localhost/conventions/kebab_case', { method: "POST", body: Uint8Array.from(out) })
}
@@ -92,7 +97,7 @@ export async function kebabCase () : Promise<void> {
export async function foo (x: LudicrousSpeed) : Promise<void> {
const out = []
serializeLudicrousSpeed(out, x)
fetch('ipc://localhost/conventions/foo', { method: "POST", body: Uint8Array.from(out) })
}
@@ -100,7 +105,7 @@ export async function foo (x: LudicrousSpeed) : Promise<void> {
export async function functionWithUnderscores () : Promise<void> {
const out = []
fetch('ipc://localhost/conventions/function_with_underscores', { method: "POST", body: Uint8Array.from(out) })
}
@@ -108,7 +113,7 @@ export async function functionWithUnderscores () : Promise<void> {
export async function functionWithNoWeirdCharacters () : Promise<void> {
const out = []
fetch('ipc://localhost/conventions/function_with_no_weird_characters', { method: "POST", body: Uint8Array.from(out) })
}
@@ -116,7 +121,7 @@ export async function functionWithNoWeirdCharacters () : Promise<void> {
export async function apple () : Promise<void> {
const out = []
fetch('ipc://localhost/conventions/apple', { method: "POST", body: Uint8Array.from(out) })
}
@@ -124,7 +129,7 @@ export async function apple () : Promise<void> {
export async function applePear () : Promise<void> {
const out = []
fetch('ipc://localhost/conventions/apple_pear', { method: "POST", body: Uint8Array.from(out) })
}
@@ -132,7 +137,7 @@ export async function applePear () : Promise<void> {
export async function applePearGrape () : Promise<void> {
const out = []
fetch('ipc://localhost/conventions/apple_pear_grape', { method: "POST", body: Uint8Array.from(out) })
}
@@ -140,7 +145,7 @@ export async function applePearGrape () : Promise<void> {
export async function a0 () : Promise<void> {
const out = []
fetch('ipc://localhost/conventions/a0', { method: "POST", body: Uint8Array.from(out) })
}
@@ -148,7 +153,7 @@ export async function a0 () : Promise<void> {
export async function isXml () : Promise<void> {
const out = []
fetch('ipc://localhost/conventions/is_xml', { method: "POST", body: Uint8Array.from(out) })
}
@@ -156,7 +161,7 @@ export async function isXml () : Promise<void> {
export async function explicit () : Promise<void> {
const out = []
fetch('ipc://localhost/conventions/explicit', { method: "POST", body: Uint8Array.from(out) })
}
@@ -164,7 +169,7 @@ export async function explicit () : Promise<void> {
export async function explicitSnake () : Promise<void> {
const out = []
fetch('ipc://localhost/conventions/explicit_snake', { method: "POST", body: Uint8Array.from(out) })
}
@@ -172,7 +177,7 @@ export async function explicitSnake () : Promise<void> {
export async function bool () : Promise<void> {
const out = []
fetch('ipc://localhost/conventions/bool', { method: "POST", body: Uint8Array.from(out) })
}

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -83,10 +88,10 @@ function deserializeU32(de) {
function deserializeU64(de) {
return de_varint_big(de, 64)
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -101,10 +106,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -433,7 +438,7 @@ B63 = 0,
export async function roundtripFlag1 (x: Flag1) : Promise<Flag1> {
const out = []
serializeFlag1(out, x)
return fetch('ipc://localhost/flegs/roundtrip_flag1', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -447,7 +452,7 @@ export async function roundtripFlag1 (x: Flag1) : Promise<Flag1> {
export async function roundtripFlag2 (x: Flag2) : Promise<Flag2> {
const out = []
serializeFlag2(out, x)
return fetch('ipc://localhost/flegs/roundtrip_flag2', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -461,7 +466,7 @@ export async function roundtripFlag2 (x: Flag2) : Promise<Flag2> {
export async function roundtripFlag4 (x: Flag4) : Promise<Flag4> {
const out = []
serializeFlag4(out, x)
return fetch('ipc://localhost/flegs/roundtrip_flag4', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -475,7 +480,7 @@ export async function roundtripFlag4 (x: Flag4) : Promise<Flag4> {
export async function roundtripFlag8 (x: Flag8) : Promise<Flag8> {
const out = []
serializeFlag8(out, x)
return fetch('ipc://localhost/flegs/roundtrip_flag8', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -489,7 +494,7 @@ export async function roundtripFlag8 (x: Flag8) : Promise<Flag8> {
export async function roundtripFlag16 (x: Flag16) : Promise<Flag16> {
const out = []
serializeFlag16(out, x)
return fetch('ipc://localhost/flegs/roundtrip_flag16', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -503,7 +508,7 @@ export async function roundtripFlag16 (x: Flag16) : Promise<Flag16> {
export async function roundtripFlag32 (x: Flag32) : Promise<Flag32> {
const out = []
serializeFlag32(out, x)
return fetch('ipc://localhost/flegs/roundtrip_flag32', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -517,7 +522,7 @@ export async function roundtripFlag32 (x: Flag32) : Promise<Flag32> {
export async function roundtripFlag64 (x: Flag64) : Promise<Flag64> {
const out = []
serializeFlag64(out, x)
return fetch('ipc://localhost/flegs/roundtrip_flag64', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -60,7 +60,7 @@ function serializeF64(out, val) {
export async function float32Param (x: number) : Promise<void> {
const out = []
serializeF32(out, x)
fetch('ipc://localhost/floats/float32_param', { method: "POST", body: Uint8Array.from(out) })
}
@@ -68,7 +68,7 @@ export async function float32Param (x: number) : Promise<void> {
export async function float64Param (x: number) : Promise<void> {
const out = []
serializeF64(out, x)
fetch('ipc://localhost/floats/float64_param', { method: "POST", body: Uint8Array.from(out) })
}
@@ -76,7 +76,7 @@ export async function float64Param (x: number) : Promise<void> {
export async function float32Result () : Promise<number> {
const out = []
return fetch('ipc://localhost/floats/float32_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -90,7 +90,7 @@ export async function float32Result () : Promise<number> {
export async function float64Result () : Promise<number> {
const out = []
return fetch('ipc://localhost/floats/float64_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -83,6 +88,9 @@ function deserializeU32(de) {
function deserializeU64(de) {
return de_varint_big(de, 64)
}
function deserializeU128(de) {
return de_varint_big(de, 128)
}
function deserializeS8(de) {
const buf = new ArrayBuffer(1);
const view = new DataView(buf);
@@ -106,10 +114,15 @@ function deserializeS64(de) {
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFn))
}
function ser_varint(out, type, val) {
function deserializeS128(de) {
const n = de_varint_big(de, 128)
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn))
}
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -124,10 +137,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -153,6 +166,9 @@ function serializeU32(out, val) {
function serializeU64(out, val) {
return ser_varint_big(out, 64, BigInt(val))
}
function serializeU128(out, val) {
return ser_varint_big(out, 128, BigInt(val))
}
function serializeS8(out, val) {
out.push(val)
}
@@ -166,6 +182,10 @@ function serializeS64(out, val) {
val = BigInt(val)
ser_varint_big(out, 64, (val << 1n) ^ (val >> 63n))
}
function serializeS128(out, val) {
val = BigInt(val)
ser_varint_big(out, 128, (val << 1n) ^ (val >> 127n))
}
@@ -173,7 +193,7 @@ function serializeS64(out, val) {
export async function a1 (x: number) : Promise<void> {
const out = []
serializeU8(out, x)
fetch('ipc://localhost/integers/a1', { method: "POST", body: Uint8Array.from(out) })
}
@@ -181,7 +201,7 @@ export async function a1 (x: number) : Promise<void> {
export async function a2 (x: number) : Promise<void> {
const out = []
serializeS8(out, x)
fetch('ipc://localhost/integers/a2', { method: "POST", body: Uint8Array.from(out) })
}
@@ -189,7 +209,7 @@ export async function a2 (x: number) : Promise<void> {
export async function a3 (x: number) : Promise<void> {
const out = []
serializeU16(out, x)
fetch('ipc://localhost/integers/a3', { method: "POST", body: Uint8Array.from(out) })
}
@@ -197,7 +217,7 @@ export async function a3 (x: number) : Promise<void> {
export async function a4 (x: number) : Promise<void> {
const out = []
serializeS16(out, x)
fetch('ipc://localhost/integers/a4', { method: "POST", body: Uint8Array.from(out) })
}
@@ -205,7 +225,7 @@ export async function a4 (x: number) : Promise<void> {
export async function a5 (x: number) : Promise<void> {
const out = []
serializeU32(out, x)
fetch('ipc://localhost/integers/a5', { method: "POST", body: Uint8Array.from(out) })
}
@@ -213,7 +233,7 @@ export async function a5 (x: number) : Promise<void> {
export async function a6 (x: number) : Promise<void> {
const out = []
serializeS32(out, x)
fetch('ipc://localhost/integers/a6', { method: "POST", body: Uint8Array.from(out) })
}
@@ -221,7 +241,7 @@ export async function a6 (x: number) : Promise<void> {
export async function a7 (x: bigint) : Promise<void> {
const out = []
serializeU64(out, x)
fetch('ipc://localhost/integers/a7', { method: "POST", body: Uint8Array.from(out) })
}
@@ -229,12 +249,28 @@ export async function a7 (x: bigint) : Promise<void> {
export async function a8 (x: bigint) : Promise<void> {
const out = []
serializeS64(out, x)
fetch('ipc://localhost/integers/a8', { method: "POST", body: Uint8Array.from(out) })
}
export async function a9 (p1: number, p2: number, p3: number, p4: number, p5: number, p6: number, p7: bigint, p8: bigint) : Promise<void> {
export async function a9 (x: bigint) : Promise<void> {
const out = []
serializeU128(out, x)
fetch('ipc://localhost/integers/a9', { method: "POST", body: Uint8Array.from(out) })
}
export async function a10 (x: bigint) : Promise<void> {
const out = []
serializeS128(out, x)
fetch('ipc://localhost/integers/a10', { method: "POST", body: Uint8Array.from(out) })
}
export async function a11 (p1: number, p2: number, p3: number, p4: number, p5: number, p6: number, p7: bigint, p8: bigint, p9: bigint, p10: bigint) : Promise<void> {
const out = []
serializeU8(out, p1);
serializeS8(out, p2);
@@ -243,16 +279,18 @@ serializeS16(out, p4);
serializeU32(out, p5);
serializeS32(out, p6);
serializeU64(out, p7);
serializeS64(out, p8)
fetch('ipc://localhost/integers/a9', { method: "POST", body: Uint8Array.from(out) })
serializeS64(out, p8);
serializeU128(out, p9);
serializeS128(out, p10)
fetch('ipc://localhost/integers/a11', { method: "POST", body: Uint8Array.from(out) })
}
export async function r1 () : Promise<number> {
const out = []
return fetch('ipc://localhost/integers/r1', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -266,7 +304,7 @@ export async function r1 () : Promise<number> {
export async function r2 () : Promise<number> {
const out = []
return fetch('ipc://localhost/integers/r2', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -280,7 +318,7 @@ export async function r2 () : Promise<number> {
export async function r3 () : Promise<number> {
const out = []
return fetch('ipc://localhost/integers/r3', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -294,7 +332,7 @@ export async function r3 () : Promise<number> {
export async function r4 () : Promise<number> {
const out = []
return fetch('ipc://localhost/integers/r4', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -308,7 +346,7 @@ export async function r4 () : Promise<number> {
export async function r5 () : Promise<number> {
const out = []
return fetch('ipc://localhost/integers/r5', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -322,7 +360,7 @@ export async function r5 () : Promise<number> {
export async function r6 () : Promise<number> {
const out = []
return fetch('ipc://localhost/integers/r6', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -336,7 +374,7 @@ export async function r6 () : Promise<number> {
export async function r7 () : Promise<bigint> {
const out = []
return fetch('ipc://localhost/integers/r7', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -350,7 +388,7 @@ export async function r7 () : Promise<bigint> {
export async function r8 () : Promise<bigint> {
const out = []
return fetch('ipc://localhost/integers/r8', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -361,10 +399,38 @@ export async function r8 () : Promise<bigint> {
}
export async function r9 () : Promise<bigint> {
const out = []
return fetch('ipc://localhost/integers/r9', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeU128(de)
}) as Promise<bigint>
}
export async function r10 () : Promise<bigint> {
const out = []
return fetch('ipc://localhost/integers/r10', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeS128(de)
}) as Promise<bigint>
}
export async function pairRet () : Promise<[bigint, number]> {
const out = []
return fetch('ipc://localhost/integers/pair_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -83,6 +88,9 @@ function deserializeU32(de) {
function deserializeU64(de) {
return de_varint_big(de, 64)
}
function deserializeU128(de) {
return de_varint_big(de, 128)
}
function deserializeS8(de) {
const buf = new ArrayBuffer(1);
const view = new DataView(buf);
@@ -106,6 +114,11 @@ function deserializeS64(de) {
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFn))
}
function deserializeS128(de) {
const n = de_varint_big(de, 128)
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn))
}
function deserializeF32(de) {
const bytes = de.try_take_n(4);
@@ -160,10 +173,10 @@ function deserializeList(de, inner) {
return out;
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -178,10 +191,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -207,6 +220,9 @@ function serializeU32(out, val) {
function serializeU64(out, val) {
return ser_varint_big(out, 64, BigInt(val))
}
function serializeU128(out, val) {
return ser_varint_big(out, 128, BigInt(val))
}
function serializeS8(out, val) {
out.push(val)
}
@@ -220,6 +236,10 @@ function serializeS64(out, val) {
val = BigInt(val)
ser_varint_big(out, 64, (val << 1n) ^ (val >> 63n))
}
function serializeS128(out, val) {
val = BigInt(val)
ser_varint_big(out, 128, (val << 1n) ^ (val >> 127n))
}
function serializeF32(out, val) {
const buf = new ArrayBuffer(4);
const view = new DataView(buf);
@@ -416,7 +436,7 @@ export type LoadStoreAllSizes = [string, number, number, number, number, number,
export async function listU8Param (x: Uint8Array[]) : Promise<void> {
const out = []
serializeBytes(out, x)
fetch('ipc://localhost/lists/list_u8_param', { method: "POST", body: Uint8Array.from(out) })
}
@@ -424,7 +444,7 @@ export async function listU8Param (x: Uint8Array[]) : Promise<void> {
export async function listU16Param (x: Uint16Array[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeU16(out, v), x)
fetch('ipc://localhost/lists/list_u16_param', { method: "POST", body: Uint8Array.from(out) })
}
@@ -432,7 +452,7 @@ export async function listU16Param (x: Uint16Array[]) : Promise<void> {
export async function listU32Param (x: Uint32Array[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeU32(out, v), x)
fetch('ipc://localhost/lists/list_u32_param', { method: "POST", body: Uint8Array.from(out) })
}
@@ -440,15 +460,23 @@ export async function listU32Param (x: Uint32Array[]) : Promise<void> {
export async function listU64Param (x: BigUint64Array[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeU64(out, v), x)
fetch('ipc://localhost/lists/list_u64_param', { method: "POST", body: Uint8Array.from(out) })
}
export async function listU128Param (x: bigint[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeU128(out, v), x)
fetch('ipc://localhost/lists/list_u128_param', { method: "POST", body: Uint8Array.from(out) })
}
export async function listS8Param (x: Int8Array[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeS8(out, v), x)
fetch('ipc://localhost/lists/list_s8_param', { method: "POST", body: Uint8Array.from(out) })
}
@@ -456,7 +484,7 @@ export async function listS8Param (x: Int8Array[]) : Promise<void> {
export async function listS16Param (x: Int16Array[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeS16(out, v), x)
fetch('ipc://localhost/lists/list_s16_param', { method: "POST", body: Uint8Array.from(out) })
}
@@ -464,7 +492,7 @@ export async function listS16Param (x: Int16Array[]) : Promise<void> {
export async function listS32Param (x: Int32Array[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeS32(out, v), x)
fetch('ipc://localhost/lists/list_s32_param', { method: "POST", body: Uint8Array.from(out) })
}
@@ -472,15 +500,23 @@ export async function listS32Param (x: Int32Array[]) : Promise<void> {
export async function listS64Param (x: BigInt64Array[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeS64(out, v), x)
fetch('ipc://localhost/lists/list_s64_param', { method: "POST", body: Uint8Array.from(out) })
}
export async function listS128Param (x: bigint[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeS128(out, v), x)
fetch('ipc://localhost/lists/list_s128_param', { method: "POST", body: Uint8Array.from(out) })
}
export async function listFloat32Param (x: Float32Array[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeF32(out, v), x)
fetch('ipc://localhost/lists/list_float32_param', { method: "POST", body: Uint8Array.from(out) })
}
@@ -488,7 +524,7 @@ export async function listFloat32Param (x: Float32Array[]) : Promise<void> {
export async function listFloat64Param (x: Float64Array[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeF64(out, v), x)
fetch('ipc://localhost/lists/list_float64_param', { method: "POST", body: Uint8Array.from(out) })
}
@@ -496,7 +532,7 @@ export async function listFloat64Param (x: Float64Array[]) : Promise<void> {
export async function listU8Ret () : Promise<Uint8Array[]> {
const out = []
return fetch('ipc://localhost/lists/list_u8_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -510,7 +546,7 @@ export async function listU8Ret () : Promise<Uint8Array[]> {
export async function listU16Ret () : Promise<Uint16Array[]> {
const out = []
return fetch('ipc://localhost/lists/list_u16_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -524,7 +560,7 @@ export async function listU16Ret () : Promise<Uint16Array[]> {
export async function listU32Ret () : Promise<Uint32Array[]> {
const out = []
return fetch('ipc://localhost/lists/list_u32_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -538,7 +574,7 @@ export async function listU32Ret () : Promise<Uint32Array[]> {
export async function listU64Ret () : Promise<BigUint64Array[]> {
const out = []
return fetch('ipc://localhost/lists/list_u64_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -549,10 +585,24 @@ export async function listU64Ret () : Promise<BigUint64Array[]> {
}
export async function listU128Ret () : Promise<bigint[]> {
const out = []
return fetch('ipc://localhost/lists/list_u128_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeList(de, (de) => deserializeU128(de))
}) as Promise<bigint[]>
}
export async function listS8Ret () : Promise<Int8Array[]> {
const out = []
return fetch('ipc://localhost/lists/list_s8_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -566,7 +616,7 @@ export async function listS8Ret () : Promise<Int8Array[]> {
export async function listS16Ret () : Promise<Int16Array[]> {
const out = []
return fetch('ipc://localhost/lists/list_s16_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -580,7 +630,7 @@ export async function listS16Ret () : Promise<Int16Array[]> {
export async function listS32Ret () : Promise<Int32Array[]> {
const out = []
return fetch('ipc://localhost/lists/list_s32_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -594,7 +644,7 @@ export async function listS32Ret () : Promise<Int32Array[]> {
export async function listS64Ret () : Promise<BigInt64Array[]> {
const out = []
return fetch('ipc://localhost/lists/list_s64_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -605,10 +655,24 @@ export async function listS64Ret () : Promise<BigInt64Array[]> {
}
export async function listS128Ret () : Promise<bigint[]> {
const out = []
return fetch('ipc://localhost/lists/list_s128_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeList(de, (de) => deserializeS128(de))
}) as Promise<bigint[]>
}
export async function listFloat32Ret () : Promise<Float32Array[]> {
const out = []
return fetch('ipc://localhost/lists/list_float32_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -622,7 +686,7 @@ export async function listFloat32Ret () : Promise<Float32Array[]> {
export async function listFloat64Ret () : Promise<Float64Array[]> {
const out = []
return fetch('ipc://localhost/lists/list_float64_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -636,7 +700,7 @@ export async function listFloat64Ret () : Promise<Float64Array[]> {
export async function tupleList (x: [number, number][]) : Promise<[bigint, number][]> {
const out = []
serializeList(out, (out, v) => {serializeU8(out, v[0]);serializeS8(out, v[1])}, x)
return fetch('ipc://localhost/lists/tuple_list', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -650,7 +714,7 @@ export async function tupleList (x: [number, number][]) : Promise<[bigint, numbe
export async function stringListArg (a: string[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeString(out, v), a)
fetch('ipc://localhost/lists/string_list_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -658,7 +722,7 @@ export async function stringListArg (a: string[]) : Promise<void> {
export async function stringListRet () : Promise<string[]> {
const out = []
return fetch('ipc://localhost/lists/string_list_ret', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -672,7 +736,7 @@ export async function stringListRet () : Promise<string[]> {
export async function tupleStringList (x: [number, string][]) : Promise<[string, number][]> {
const out = []
serializeList(out, (out, v) => {serializeU8(out, v[0]);serializeString(out, v[1])}, x)
return fetch('ipc://localhost/lists/tuple_string_list', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -686,7 +750,7 @@ export async function tupleStringList (x: [number, string][]) : Promise<[string,
export async function stringList (x: string[]) : Promise<string[]> {
const out = []
serializeList(out, (out, v) => serializeString(out, v), x)
return fetch('ipc://localhost/lists/string_list', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -700,7 +764,7 @@ export async function stringList (x: string[]) : Promise<string[]> {
export async function recordList (x: SomeRecord[]) : Promise<OtherRecord[]> {
const out = []
serializeList(out, (out, v) => serializeSomeRecord(out, v), x)
return fetch('ipc://localhost/lists/record_list', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -714,7 +778,7 @@ export async function recordList (x: SomeRecord[]) : Promise<OtherRecord[]> {
export async function recordListReverse (x: OtherRecord[]) : Promise<SomeRecord[]> {
const out = []
serializeList(out, (out, v) => serializeOtherRecord(out, v), x)
return fetch('ipc://localhost/lists/record_list_reverse', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -728,7 +792,7 @@ export async function recordListReverse (x: OtherRecord[]) : Promise<SomeRecord[
export async function variantList (x: SomeVariant[]) : Promise<OtherVariant[]> {
const out = []
serializeList(out, (out, v) => serializeSomeVariant(out, v), x)
return fetch('ipc://localhost/lists/variant_list', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -742,7 +806,7 @@ export async function variantList (x: SomeVariant[]) : Promise<OtherVariant[]> {
export async function loadStoreEverything (a: LoadStoreAllSizes) : Promise<LoadStoreAllSizes> {
const out = []
serializeLoadStoreAllSizes(out, a)
return fetch('ipc://localhost/lists/load_store_everything', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -17,20 +17,25 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -45,10 +50,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -156,7 +161,7 @@ serializeU64(out, a13);
serializeU64(out, a14);
serializeU64(out, a15);
serializeU64(out, a16)
fetch('ipc://localhost/many_arguments/many_args', { method: "POST", body: Uint8Array.from(out) })
}
@@ -164,7 +169,7 @@ serializeU64(out, a16)
export async function bigArgument (x: BigStruct) : Promise<void> {
const out = []
serializeBigStruct(out, x)
fetch('ipc://localhost/many_arguments/big_argument', { method: "POST", body: Uint8Array.from(out) })
}

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -91,7 +96,7 @@ function deserializeF32(de) {
export async function mra () : Promise<void> {
const out = []
fetch('ipc://localhost/multi_return/mra', { method: "POST", body: Uint8Array.from(out) })
}
@@ -99,7 +104,7 @@ export async function mra () : Promise<void> {
export async function mrb () : Promise<void> {
const out = []
return fetch('ipc://localhost/multi_return/mrb', { method: "POST", body: Uint8Array.from(out) }) as Promise<void>
}
@@ -107,7 +112,7 @@ export async function mrb () : Promise<void> {
export async function mrc () : Promise<number> {
const out = []
return fetch('ipc://localhost/multi_return/mrc', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -121,7 +126,7 @@ export async function mrc () : Promise<number> {
export async function mrd () : Promise<number> {
const out = []
return fetch('ipc://localhost/multi_return/mrd', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -135,7 +140,7 @@ export async function mrd () : Promise<number> {
export async function mre () : Promise<[number, number]> {
const out = []
return fetch('ipc://localhost/multi_return/mre', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -87,6 +92,11 @@ function deserializeS32(de) {
return Number(((n >> 1) & 0xFFFFFFFF) ^ (-((n & 0b1) & 0xFFFFFFFF)))
}
function deserializeS64(de) {
const n = de_varint_big(de, 64)
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFn))
}
function deserializeChar(de) {
const sz = deserializeU64(de);
if (sz > 4) {
@@ -103,10 +113,10 @@ function deserializeString(de) {
return __text_decoder.decode(bytes);
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -121,10 +131,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -150,6 +160,10 @@ function serializeU64(out, val) {
function serializeS32(out, val) {
ser_varint(out, 32, (val << 1) ^ (val >> 31))
}
function serializeS64(out, val) {
val = BigInt(val)
ser_varint_big(out, 64, (val << 1n) ^ (val >> 63n))
}
function serializeChar(out, val) {
if (val.len > 1) {
throw new Error("Serialize bad char");
@@ -281,7 +295,7 @@ export type TupleTypedef2 = [IntTypedef];
export async function tupleArg (x: [string, number]) : Promise<void> {
const out = []
{serializeChar(out, x[0]);serializeU32(out, x[1])}
fetch('ipc://localhost/records/tuple_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -289,7 +303,7 @@ export async function tupleArg (x: [string, number]) : Promise<void> {
export async function tupleResult () : Promise<[string, number]> {
const out = []
return fetch('ipc://localhost/records/tuple_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -303,7 +317,7 @@ export async function tupleResult () : Promise<[string, number]> {
export async function emptyArg (x: Empty) : Promise<void> {
const out = []
serializeEmpty(out, x)
fetch('ipc://localhost/records/empty_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -311,7 +325,7 @@ export async function emptyArg (x: Empty) : Promise<void> {
export async function emptyResult () : Promise<Empty> {
const out = []
return fetch('ipc://localhost/records/empty_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -325,7 +339,7 @@ export async function emptyResult () : Promise<Empty> {
export async function scalarArg (x: Scalars) : Promise<void> {
const out = []
serializeScalars(out, x)
fetch('ipc://localhost/records/scalar_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -333,7 +347,7 @@ export async function scalarArg (x: Scalars) : Promise<void> {
export async function scalarResult () : Promise<Scalars> {
const out = []
return fetch('ipc://localhost/records/scalar_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -347,7 +361,7 @@ export async function scalarResult () : Promise<Scalars> {
export async function flagsArg (x: ReallyFlags) : Promise<void> {
const out = []
serializeReallyFlags(out, x)
fetch('ipc://localhost/records/flags_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -355,7 +369,7 @@ export async function flagsArg (x: ReallyFlags) : Promise<void> {
export async function flagsResult () : Promise<ReallyFlags> {
const out = []
return fetch('ipc://localhost/records/flags_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -369,7 +383,7 @@ export async function flagsResult () : Promise<ReallyFlags> {
export async function aggregateArg (x: Aggregates) : Promise<void> {
const out = []
serializeAggregates(out, x)
fetch('ipc://localhost/records/aggregate_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -377,7 +391,7 @@ export async function aggregateArg (x: Aggregates) : Promise<void> {
export async function aggregateResult () : Promise<Aggregates> {
const out = []
return fetch('ipc://localhost/records/aggregate_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -391,7 +405,7 @@ export async function aggregateResult () : Promise<Aggregates> {
export async function typedefInout (e: TupleTypedef2) : Promise<number> {
const out = []
serializeTupleTypedef2(out, e)
return fetch('ipc://localhost/records/typedef_inout', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -58,7 +58,7 @@ async f3 (x: A[] | null) Promise<Result<A, null>> {
export async function constructorA () : Promise<A> {
const out = []
return fetch('ipc://localhost/resources/constructor_a', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -72,7 +72,7 @@ export async function constructorA () : Promise<A> {
export async function constructorB () : Promise<B> {
const out = []
return fetch('ipc://localhost/resources/constructor_b', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -74,10 +79,10 @@ function de_varint_big(de, type) {
function deserializeU32(de) {
return de_varint(de, 32)
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -92,10 +97,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -119,7 +124,7 @@ function serializeU32(out, val) {
export async function f1 () : Promise<void> {
const out = []
fetch('ipc://localhost/simple_functions/f1', { method: "POST", body: Uint8Array.from(out) })
}
@@ -127,7 +132,7 @@ export async function f1 () : Promise<void> {
export async function f2 (a: number) : Promise<void> {
const out = []
serializeU32(out, a)
fetch('ipc://localhost/simple_functions/f2', { method: "POST", body: Uint8Array.from(out) })
}
@@ -136,7 +141,7 @@ export async function f3 (a: number, b: number) : Promise<void> {
const out = []
serializeU32(out, a);
serializeU32(out, b)
fetch('ipc://localhost/simple_functions/f3', { method: "POST", body: Uint8Array.from(out) })
}
@@ -144,7 +149,7 @@ serializeU32(out, b)
export async function f4 () : Promise<number> {
const out = []
return fetch('ipc://localhost/simple_functions/f4', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -158,7 +163,7 @@ export async function f4 () : Promise<number> {
export async function f5 () : Promise<[number, number]> {
const out = []
return fetch('ipc://localhost/simple_functions/f5', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -174,7 +179,7 @@ export async function f6 (a: number, b: number, c: number) : Promise<[number, nu
serializeU32(out, a);
serializeU32(out, b);
serializeU32(out, c)
return fetch('ipc://localhost/simple_functions/f6', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -88,10 +93,10 @@ function deserializeList(de, inner) {
return out;
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -106,10 +111,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -142,7 +147,7 @@ function serializeList(out, inner, val) {
export async function simpleList1 (l: Uint32Array[]) : Promise<void> {
const out = []
serializeList(out, (out, v) => serializeU32(out, v), l)
fetch('ipc://localhost/simple_lists/simple_list1', { method: "POST", body: Uint8Array.from(out) })
}
@@ -150,7 +155,7 @@ export async function simpleList1 (l: Uint32Array[]) : Promise<void> {
export async function simpleList2 () : Promise<Uint32Array[]> {
const out = []
return fetch('ipc://localhost/simple_lists/simple_list2', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -165,7 +170,7 @@ export async function simpleList3 (a: Uint32Array[], b: Uint32Array[]) : Promise
const out = []
serializeList(out, (out, v) => serializeU32(out, v), a);
serializeList(out, (out, v) => serializeU32(out, v), b)
return fetch('ipc://localhost/simple_lists/simple_list3', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -179,7 +184,7 @@ serializeList(out, (out, v) => serializeU32(out, v), b)
export async function simpleList4 (l: Uint32Array[][]) : Promise<Uint32Array[][]> {
const out = []
serializeList(out, (out, v) => serializeList(out, (out, v) => serializeU32(out, v), v), l)
return fetch('ipc://localhost/simple_lists/simple_list4', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -18,31 +18,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -53,16 +58,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -135,7 +140,7 @@ Failure,
export async function optionTest () : Promise<Result<string | null, Error>> {
const out = []
return fetch('ipc://localhost/small_anonymous/option_test', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -81,10 +86,10 @@ function deserializeString(de) {
return __text_decoder.decode(bytes);
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -99,10 +104,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -133,7 +138,7 @@ const __text_encoder = new TextEncoder();
export async function a (x: string) : Promise<void> {
const out = []
serializeString(out, x)
fetch('ipc://localhost/strings/a', { method: "POST", body: Uint8Array.from(out) })
}
@@ -141,7 +146,7 @@ export async function a (x: string) : Promise<void> {
export async function b () : Promise<string> {
const out = []
return fetch('ipc://localhost/strings/b', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -156,7 +161,7 @@ export async function c (a: string, b: string) : Promise<string> {
const out = []
serializeString(out, a);
serializeString(out, b)
return fetch('ipc://localhost/strings/c', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -147,10 +152,10 @@ function deserializeString(de) {
return __text_decoder.decode(bytes);
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -165,10 +170,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -480,7 +485,7 @@ bigint
export async function addOneInteger (num: AllIntegers) : Promise<AllIntegers> {
const out = []
serializeAllIntegers(out, num)
return fetch('ipc://localhost/unions/add_one_integer', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -494,7 +499,7 @@ export async function addOneInteger (num: AllIntegers) : Promise<AllIntegers> {
export async function addOneFloat (num: AllFloats) : Promise<AllFloats> {
const out = []
serializeAllFloats(out, num)
return fetch('ipc://localhost/unions/add_one_float', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -509,7 +514,7 @@ export async function replaceFirstChar (text: AllText, letter: string) : Promise
const out = []
serializeAllText(out, text);
serializeChar(out, letter)
return fetch('ipc://localhost/unions/replace_first_char', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -523,7 +528,7 @@ serializeChar(out, letter)
export async function identifyInteger (num: AllIntegers) : Promise<number> {
const out = []
serializeAllIntegers(out, num)
return fetch('ipc://localhost/unions/identify_integer', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -537,7 +542,7 @@ export async function identifyInteger (num: AllIntegers) : Promise<number> {
export async function identifyFloat (num: AllFloats) : Promise<number> {
const out = []
serializeAllFloats(out, num)
return fetch('ipc://localhost/unions/identify_float', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -551,7 +556,7 @@ export async function identifyFloat (num: AllFloats) : Promise<number> {
export async function identifyText (text: AllText) : Promise<number> {
const out = []
serializeAllText(out, text)
return fetch('ipc://localhost/unions/identify_text', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -565,7 +570,7 @@ export async function identifyText (text: AllText) : Promise<number> {
export async function addOneDuplicated (num: DuplicatedS32) : Promise<DuplicatedS32> {
const out = []
serializeDuplicatedS32(out, num)
return fetch('ipc://localhost/unions/add_one_duplicated', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -579,7 +584,7 @@ export async function addOneDuplicated (num: DuplicatedS32) : Promise<Duplicated
export async function identifyDuplicated (num: DuplicatedS32) : Promise<number> {
const out = []
serializeDuplicatedS32(out, num)
return fetch('ipc://localhost/unions/identify_duplicated', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -593,7 +598,7 @@ export async function identifyDuplicated (num: DuplicatedS32) : Promise<number>
export async function addOneDistinguishableNum (num: DistinguishableNum) : Promise<DistinguishableNum> {
const out = []
serializeDistinguishableNum(out, num)
return fetch('ipc://localhost/unions/add_one_distinguishable_num', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -607,7 +612,7 @@ export async function addOneDistinguishableNum (num: DistinguishableNum) : Promi
export async function identifyDistinguishableNum (num: DistinguishableNum) : Promise<number> {
const out = []
serializeDistinguishableNum(out, num)
return fetch('ipc://localhost/unions/identify_distinguishable_num', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -18,31 +18,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -53,16 +58,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -86,6 +91,14 @@ function deserializeU32(de) {
function deserializeU64(de) {
return de_varint_big(de, 64)
}
function deserializeS8(de) {
const buf = new ArrayBuffer(1);
const view = new DataView(buf);
buf[0] = view.setUint8(0, de.pop());
return view.getInt8(0);
}
function deserializeS32(de) {
const n = de_varint(de, 32)
@@ -154,10 +167,10 @@ function deserializeResult(de, ok, err) {
throw new Error(`Deserialize bad result ${tag}`)
}
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -172,10 +185,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -201,6 +214,9 @@ function serializeU32(out, val) {
function serializeU64(out, val) {
return ser_varint_big(out, 64, BigInt(val))
}
function serializeS8(out, val) {
out.push(val)
}
function serializeS32(out, val) {
ser_varint(out, 32, (val << 1) ^ (val >> 31))
}
@@ -626,7 +642,7 @@ v1: V1,
export async function e1Arg (x: E1) : Promise<void> {
const out = []
serializeE1(out, x)
fetch('ipc://localhost/variants/e1_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -634,7 +650,7 @@ export async function e1Arg (x: E1) : Promise<void> {
export async function e1Result () : Promise<E1> {
const out = []
return fetch('ipc://localhost/variants/e1_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -648,7 +664,7 @@ export async function e1Result () : Promise<E1> {
export async function u1Arg (x: U1) : Promise<void> {
const out = []
serializeU1(out, x)
fetch('ipc://localhost/variants/u1_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -656,7 +672,7 @@ export async function u1Arg (x: U1) : Promise<void> {
export async function u1Result () : Promise<U1> {
const out = []
return fetch('ipc://localhost/variants/u1_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -670,7 +686,7 @@ export async function u1Result () : Promise<U1> {
export async function v1Arg (x: V1) : Promise<void> {
const out = []
serializeV1(out, x)
fetch('ipc://localhost/variants/v1_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -678,7 +694,7 @@ export async function v1Arg (x: V1) : Promise<void> {
export async function v1Result () : Promise<V1> {
const out = []
return fetch('ipc://localhost/variants/v1_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -692,7 +708,7 @@ export async function v1Result () : Promise<V1> {
export async function boolArg (x: boolean) : Promise<void> {
const out = []
serializeBool(out, x)
fetch('ipc://localhost/variants/bool_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -700,7 +716,7 @@ export async function boolArg (x: boolean) : Promise<void> {
export async function boolResult () : Promise<boolean> {
const out = []
return fetch('ipc://localhost/variants/bool_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -720,7 +736,7 @@ serializeOption(out, (out, v) => serializeE1(out, v), d);
serializeOption(out, (out, v) => serializeF32(out, v), e);
serializeOption(out, (out, v) => serializeU1(out, v), f);
serializeOption(out, (out, v) => serializeOption(out, (out, v) => serializeBool(out, v), v), g)
fetch('ipc://localhost/variants/option_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -728,7 +744,7 @@ serializeOption(out, (out, v) => serializeOption(out, (out, v) => serializeBool(
export async function optionResult () : Promise<[boolean | null, [] | null, number | null, E1 | null, number | null, U1 | null, boolean | null | null]> {
const out = []
return fetch('ipc://localhost/variants/option_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -747,7 +763,7 @@ serializeCasts3(out, c);
serializeCasts4(out, d);
serializeCasts5(out, e);
serializeCasts6(out, f)
return fetch('ipc://localhost/variants/casts', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -766,7 +782,7 @@ serializeResult(out, (out, v) => serializeE1(out, v), (out, v) => {}, c);
serializeResult(out, (out, v) => {}, (out, v) => {}, d);
serializeResult(out, (out, v) => serializeU32(out, v), (out, v) => serializeV1(out, v), e);
serializeResult(out, (out, v) => serializeString(out, v), (out, v) => serializeBytes(out, v), f)
fetch('ipc://localhost/variants/result_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -774,7 +790,7 @@ serializeResult(out, (out, v) => serializeString(out, v), (out, v) => serializeB
export async function resultResult () : Promise<[Result<null, null>, Result<null, E1>, Result<E1, null>, Result<[], []>, Result<number, V1>, Result<string, Uint8Array[]>]> {
const out = []
return fetch('ipc://localhost/variants/result_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -788,7 +804,7 @@ export async function resultResult () : Promise<[Result<null, null>, Result<null
export async function returnResultSugar () : Promise<Result<number, MyErrno>> {
const out = []
return fetch('ipc://localhost/variants/return_result_sugar', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -802,7 +818,7 @@ export async function returnResultSugar () : Promise<Result<number, MyErrno>> {
export async function returnResultSugar2 () : Promise<Result<null, MyErrno>> {
const out = []
return fetch('ipc://localhost/variants/return_result_sugar2', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -816,7 +832,7 @@ export async function returnResultSugar2 () : Promise<Result<null, MyErrno>> {
export async function returnResultSugar3 () : Promise<Result<MyErrno, MyErrno>> {
const out = []
return fetch('ipc://localhost/variants/return_result_sugar3', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -830,7 +846,7 @@ export async function returnResultSugar3 () : Promise<Result<MyErrno, MyErrno>>
export async function returnResultSugar4 () : Promise<Result<[number, number], MyErrno>> {
const out = []
return fetch('ipc://localhost/variants/return_result_sugar4', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -844,7 +860,7 @@ export async function returnResultSugar4 () : Promise<Result<[number, number], M
export async function returnOptionSugar () : Promise<number | null> {
const out = []
return fetch('ipc://localhost/variants/return_option_sugar', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -858,7 +874,7 @@ export async function returnOptionSugar () : Promise<number | null> {
export async function returnOptionSugar2 () : Promise<MyErrno | null> {
const out = []
return fetch('ipc://localhost/variants/return_option_sugar2', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -872,7 +888,7 @@ export async function returnOptionSugar2 () : Promise<MyErrno | null> {
export async function resultSimple () : Promise<Result<number, number>> {
const out = []
return fetch('ipc://localhost/variants/result_simple', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -886,7 +902,7 @@ export async function resultSimple () : Promise<Result<number, number>> {
export async function isCloneArg (a: IsClone) : Promise<void> {
const out = []
serializeIsClone(out, a)
fetch('ipc://localhost/variants/is_clone_arg', { method: "POST", body: Uint8Array.from(out) })
}
@@ -894,7 +910,7 @@ export async function isCloneArg (a: IsClone) : Promise<void> {
export async function isCloneReturn () : Promise<IsClone> {
const out = []
return fetch('ipc://localhost/variants/is_clone_return', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -908,7 +924,7 @@ export async function isCloneReturn () : Promise<IsClone> {
export async function returnNamedOption () : Promise<number | null> {
const out = []
return fetch('ipc://localhost/variants/return_named_option', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {
@@ -922,7 +938,7 @@ export async function returnNamedOption () : Promise<number | null> {
export async function returnNamedResult () : Promise<Result<number, MyErrno>> {
const out = []
return fetch('ipc://localhost/variants/return_named_result', { method: "POST", body: Uint8Array.from(out) })
.then(r => r.arrayBuffer())
.then(bytes => {

View File

@@ -126,10 +126,12 @@ impl RustGenerator for Host {
Type::U16 => quote! { u16 },
Type::U32 => quote! { u32 },
Type::U64 => quote! { u64 },
Type::U128 => quote! { u128 },
Type::S8 => quote! { i8 },
Type::S16 => quote! { i16 },
Type::S32 => quote! { i32 },
Type::S64 => quote! { i64 },
Type::S128 => quote! { i128 },
Type::Float32 => quote! { f32 },
Type::Float64 => quote! { f64 },
Type::Char => quote! { char },

View File

@@ -12,7 +12,9 @@ pub mod integers {
fn a6(&self, x: i32);
fn a7(&self, x: u64);
fn a8(&self, x: i64);
fn a9(
fn a9(&self, x: u128);
fn a10(&self, x: i128);
fn a11(
&self,
p1: u8,
p2: i8,
@@ -22,6 +24,8 @@ pub mod integers {
p6: i32,
p7: u64,
p8: i64,
p9: u128,
p10: i128,
);
fn r1(&self) -> u8;
fn r2(&self) -> i8;
@@ -31,6 +35,8 @@ pub mod integers {
fn r6(&self) -> i32;
fn r7(&self) -> u64;
fn r8(&self) -> i64;
fn r9(&self) -> u128;
fn r10(&self) -> i128;
fn pair_ret(&self) -> (i64, u8);
}
pub fn add_to_router<T, U>(
@@ -150,6 +156,32 @@ pub mod integers {
.func_wrap(
"integers",
"a9",
move |
ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>,
x: u128,
| -> ::tauri_bindgen_host::anyhow::Result<()> {
let ctx = get_cx(ctx.data());
Ok(ctx.a9(x))
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"integers",
"a10",
move |
ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>,
x: i128,
| -> ::tauri_bindgen_host::anyhow::Result<()> {
let ctx = get_cx(ctx.data());
Ok(ctx.a10(x))
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"integers",
"a11",
move |
ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>,
p1: u8,
@@ -160,9 +192,11 @@ pub mod integers {
p6: i32,
p7: u64,
p8: i64,
p9: u128,
p10: i128,
| -> ::tauri_bindgen_host::anyhow::Result<()> {
let ctx = get_cx(ctx.data());
Ok(ctx.a9(p1, p2, p3, p4, p5, p6, p7, p8))
Ok(ctx.a11(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10))
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
@@ -262,6 +296,30 @@ pub mod integers {
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"integers",
"r9",
move |
ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>,
| -> ::tauri_bindgen_host::anyhow::Result<u128> {
let ctx = get_cx(ctx.data());
Ok(ctx.r9())
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"integers",
"r10",
move |
ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>,
| -> ::tauri_bindgen_host::anyhow::Result<i128> {
let ctx = get_cx(ctx.data());
Ok(ctx.r10())
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"integers",

View File

@@ -47,20 +47,24 @@ pub mod lists {
fn list_u16_param(&self, x: Vec<u16>);
fn list_u32_param(&self, x: Vec<u32>);
fn list_u64_param(&self, x: Vec<u64>);
fn list_u128_param(&self, x: Vec<u128>);
fn list_s8_param(&self, x: Vec<i8>);
fn list_s16_param(&self, x: Vec<i16>);
fn list_s32_param(&self, x: Vec<i32>);
fn list_s64_param(&self, x: Vec<i64>);
fn list_s128_param(&self, x: Vec<i128>);
fn list_float32_param(&self, x: Vec<f32>);
fn list_float64_param(&self, x: Vec<f64>);
fn list_u8_ret(&self) -> Vec<u8>;
fn list_u16_ret(&self) -> Vec<u16>;
fn list_u32_ret(&self) -> Vec<u32>;
fn list_u64_ret(&self) -> Vec<u64>;
fn list_u128_ret(&self) -> Vec<u128>;
fn list_s8_ret(&self) -> Vec<i8>;
fn list_s16_ret(&self) -> Vec<i16>;
fn list_s32_ret(&self) -> Vec<i32>;
fn list_s64_ret(&self) -> Vec<i64>;
fn list_s128_ret(&self) -> Vec<i128>;
fn list_float32_ret(&self) -> Vec<f32>;
fn list_float64_ret(&self) -> Vec<f64>;
fn tuple_list(&self, x: Vec<(u8, i8)>) -> Vec<(i64, u32)>;
@@ -134,6 +138,19 @@ pub mod lists {
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"lists",
"list_u128_param",
move |
ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>,
x: Vec<u128>,
| -> ::tauri_bindgen_host::anyhow::Result<()> {
let ctx = get_cx(ctx.data());
Ok(ctx.list_u128_param(x))
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"lists",
@@ -186,6 +203,19 @@ pub mod lists {
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"lists",
"list_s128_param",
move |
ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>,
x: Vec<i128>,
| -> ::tauri_bindgen_host::anyhow::Result<()> {
let ctx = get_cx(ctx.data());
Ok(ctx.list_s128_param(x))
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"lists",
@@ -260,6 +290,18 @@ pub mod lists {
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"lists",
"list_u128_ret",
move |
ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>,
| -> ::tauri_bindgen_host::anyhow::Result<Vec<u128>> {
let ctx = get_cx(ctx.data());
Ok(ctx.list_u128_ret())
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"lists",
@@ -308,6 +350,18 @@ pub mod lists {
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"lists",
"list_s128_ret",
move |
ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>,
| -> ::tauri_bindgen_host::anyhow::Result<Vec<i128>> {
let ctx = get_cx(ctx.data());
Ok(ctx.list_s128_ret())
},
)?;
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
router
.func_wrap(
"lists",

View File

@@ -0,0 +1,5 @@
function deserializeS128(de) {
const n = de_varint_big(de, 128)
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn))
}

View File

@@ -0,0 +1,3 @@
function deserializeU128(de) {
return de_varint_big(de, 128)
}

View File

@@ -3,16 +3,16 @@ function max_of_last_byte(type) {
return (1 << extra_bits) - 1;
}
function de_varint(de, type) {
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -23,16 +23,16 @@ function de_varint(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint_big(de, type) {
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out

View File

@@ -0,0 +1,4 @@
function serializeS128(out, val) {
val = BigInt(val)
ser_varint_big(out, 128, (val << 1n) ^ (val >> 127n))
}

View File

@@ -0,0 +1,3 @@
function serializeU128(out, val) {
return ser_varint_big(out, 128, BigInt(val))
}

View File

@@ -1,7 +1,7 @@
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -16,10 +16,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);

View File

@@ -1,10 +1,15 @@
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}

View File

@@ -52,10 +52,12 @@ pub trait JavaScriptGenerator {
Type::U16 => "deserializeU16(de)".to_string(),
Type::U32 => "deserializeU32(de)".to_string(),
Type::U64 => "deserializeU64(de)".to_string(),
Type::U128 => "deserializeU128(de)".to_string(),
Type::S8 => "deserializeS8(de)".to_string(),
Type::S16 => "deserializeS16(de)".to_string(),
Type::S32 => "deserializeS32(de)".to_string(),
Type::S64 => "deserializeS64(de)".to_string(),
Type::S128 => "deserializeS128(de)".to_string(),
Type::Float32 => "deserializeF32(de)".to_string(),
Type::Float64 => "deserializeF64(de)".to_string(),
Type::Char => "deserializeChar(de)".to_string(),
@@ -155,6 +157,7 @@ pub trait JavaScriptGenerator {
wit_parser::Int::U16 => "U16",
wit_parser::Int::U32 => "U32",
wit_parser::Int::U64 => "U64",
wit_parser::Int::U128 => "U128",
};
format!(
@@ -260,10 +263,12 @@ pub trait JavaScriptGenerator {
Type::U16 => format!("serializeU16(out, {ident})"),
Type::U32 => format!("serializeU32(out, {ident})"),
Type::U64 => format!("serializeU64(out, {ident})"),
Type::U128 => format!("serializeU128(out, {ident})"),
Type::S8 => format!("serializeS8(out, {ident})"),
Type::S16 => format!("serializeS16(out, {ident})"),
Type::S32 => format!("serializeS32(out, {ident})"),
Type::S64 => format!("serializeS64(out, {ident})"),
Type::S128 => format!("serializeS128(out, {ident})"),
Type::Float32 => format!("serializeF32(out, {ident})"),
Type::Float64 => format!("serializeF64(out, {ident})"),
Type::Char => format!("serializeChar(out, {ident})"),
@@ -358,6 +363,7 @@ pub trait JavaScriptGenerator {
wit_parser::Int::U16 => "U16",
wit_parser::Int::U32 => "U32",
wit_parser::Int::U64 => "U64",
wit_parser::Int::U128 => "U128",
};
format!(
@@ -459,14 +465,14 @@ bitflags::bitflags! {
const _VARINT = 1 << 2;
const BOOl = 1 << 3;
const U8 = 1 << 4;
const _U16 = 1 << 5;
const _U32 = 1 << 6;
const _U64 = 1 << 7;
const S8 = 1 << 8;
const _S16 = 1 << 9;
const _S32 = 1 << 10;
const _S64 = 1 << 11;
const BITS8 = 1 << 4;
const BITS16 = 1 << 5;
const BITS32 = 1 << 6;
const BITS64 = 1 << 7;
const BITS128 = 1 << 8;
const SIGNED = 1 << 9;
const UNSIGNED = 1 << 10;
const F32 = 1 << 12;
const F64 = 1 << 13;
const _CHAR = 1 << 14;
@@ -480,12 +486,16 @@ bitflags::bitflags! {
const STR_UTIL = 1 << 22;
const VARINT = Self::_VARINT.bits() | Self::VARINT_MAX.bits();
const U16 = Self::_U16.bits() | Self::VARINT.bits();
const U32 = Self::_U32.bits() | Self::VARINT.bits();
const U64 = Self::_U64.bits() | Self::VARINT.bits();
const S16 = Self::_S16.bits() | Self::VARINT.bits();
const S32 = Self::_S32.bits() | Self::VARINT.bits();
const S64 = Self::_S64.bits() | Self::VARINT.bits();
const U8 = Self::BITS8.bits() | Self::VARINT.bits() | Self::UNSIGNED.bits();
const U16 = Self::BITS16.bits() | Self::VARINT.bits() | Self::UNSIGNED.bits();
const U32 = Self::BITS32.bits() | Self::VARINT.bits() | Self::UNSIGNED.bits();
const U64 = Self::BITS64.bits() | Self::VARINT.bits() | Self::UNSIGNED.bits();
const U128 = Self::BITS128.bits() | Self::VARINT.bits() | Self::UNSIGNED.bits();
const S8 = Self::BITS8.bits() | Self::VARINT.bits() | Self::SIGNED.bits();
const S16 = Self::BITS16.bits() | Self::VARINT.bits() | Self::SIGNED.bits();
const S32 = Self::BITS32.bits() | Self::VARINT.bits() | Self::SIGNED.bits();
const S64 = Self::BITS64.bits() | Self::VARINT.bits() | Self::SIGNED.bits();
const S128 = Self::BITS128.bits() | Self::VARINT.bits() | Self::SIGNED.bits();
const CHAR = Self::_CHAR.bits() | Self::U64.bits() | Self::STR_UTIL.bits();
const STRING = Self::_STRING.bits() | Self::U64.bits() | Self::STR_UTIL.bits();
const BYTES = Self::_BYTES.bits() | Self::U64.bits();
@@ -512,38 +522,46 @@ impl std::fmt::Display for SerdeUtils {
f.write_str(include_str!("./js/de_bool.js"))?;
}
if self.contains(SerdeUtils::U8 | SerdeUtils::DE) {
if self.contains(SerdeUtils::BITS8 | SerdeUtils::UNSIGNED | SerdeUtils::DE) {
f.write_str(include_str!("./js/de_u8.js"))?;
}
if self.contains(SerdeUtils::_U16 | SerdeUtils::DE) {
if self.contains(SerdeUtils::BITS16 | SerdeUtils::UNSIGNED | SerdeUtils::DE) {
f.write_str(include_str!("./js/de_u16.js"))?;
}
if self.contains(SerdeUtils::_U32 | SerdeUtils::DE) {
if self.contains(SerdeUtils::BITS32 | SerdeUtils::UNSIGNED | SerdeUtils::DE) {
f.write_str(include_str!("./js/de_u32.js"))?;
}
if self.contains(SerdeUtils::_U64 | SerdeUtils::DE) {
if self.contains(SerdeUtils::BITS64 | SerdeUtils::UNSIGNED | SerdeUtils::DE) {
f.write_str(include_str!("./js/de_u64.js"))?;
}
if self.contains(SerdeUtils::S8 | SerdeUtils::DE) {
if self.contains(SerdeUtils::BITS128 | SerdeUtils::UNSIGNED | SerdeUtils::DE) {
f.write_str(include_str!("./js/de_u128.js"))?;
}
if self.contains(SerdeUtils::BITS8 | SerdeUtils::SIGNED | SerdeUtils::DE) {
f.write_str(include_str!("./js/de_s8.js"))?;
}
if self.contains(SerdeUtils::_S16 | SerdeUtils::DE) {
if self.contains(SerdeUtils::BITS16 | SerdeUtils::SIGNED | SerdeUtils::DE) {
f.write_str(include_str!("./js/de_s16.js"))?;
}
if self.contains(SerdeUtils::_S32 | SerdeUtils::DE) {
if self.contains(SerdeUtils::BITS32 | SerdeUtils::SIGNED | SerdeUtils::DE) {
f.write_str(include_str!("./js/de_s32.js"))?;
}
if self.contains(SerdeUtils::_S64 | SerdeUtils::DE) {
if self.contains(SerdeUtils::BITS64 | SerdeUtils::SIGNED | SerdeUtils::DE) {
f.write_str(include_str!("./js/de_s64.js"))?;
}
if self.contains(SerdeUtils::BITS128 | SerdeUtils::SIGNED | SerdeUtils::DE) {
f.write_str(include_str!("./js/de_s128.js"))?;
}
if self.contains(SerdeUtils::F32 | SerdeUtils::DE) {
f.write_str(include_str!("./js/de_f32.js"))?;
}
@@ -584,38 +602,46 @@ impl std::fmt::Display for SerdeUtils {
f.write_str(include_str!("./js/ser_bool.js"))?;
}
if self.contains(SerdeUtils::U8 | SerdeUtils::SER) {
if self.contains(SerdeUtils::BITS8 | SerdeUtils::UNSIGNED | SerdeUtils::SER) {
f.write_str(include_str!("./js/ser_u8.js"))?;
}
if self.contains(SerdeUtils::_U16 | SerdeUtils::SER) {
if self.contains(SerdeUtils::BITS16 | SerdeUtils::UNSIGNED | SerdeUtils::SER) {
f.write_str(include_str!("./js/ser_u16.js"))?;
}
if self.contains(SerdeUtils::_U32 | SerdeUtils::SER) {
if self.contains(SerdeUtils::BITS32 | SerdeUtils::UNSIGNED | SerdeUtils::SER) {
f.write_str(include_str!("./js/ser_u32.js"))?;
}
if self.contains(SerdeUtils::_U64 | SerdeUtils::SER) {
if self.contains(SerdeUtils::BITS64 | SerdeUtils::UNSIGNED | SerdeUtils::SER) {
f.write_str(include_str!("./js/ser_u64.js"))?;
}
if self.contains(SerdeUtils::S8 | SerdeUtils::SER) {
if self.contains(SerdeUtils::BITS128 | SerdeUtils::UNSIGNED | SerdeUtils::SER) {
f.write_str(include_str!("./js/ser_u128.js"))?;
}
if self.contains(SerdeUtils::BITS8 | SerdeUtils::SIGNED | SerdeUtils::SER) {
f.write_str(include_str!("./js/ser_s8.js"))?;
}
if self.contains(SerdeUtils::_S16 | SerdeUtils::SER) {
if self.contains(SerdeUtils::BITS16 | SerdeUtils::SIGNED | SerdeUtils::SER) {
f.write_str(include_str!("./js/ser_s16.js"))?;
}
if self.contains(SerdeUtils::_S32 | SerdeUtils::SER) {
if self.contains(SerdeUtils::BITS32 | SerdeUtils::SIGNED | SerdeUtils::SER) {
f.write_str(include_str!("./js/ser_s32.js"))?;
}
if self.contains(SerdeUtils::_S64 | SerdeUtils::SER) {
if self.contains(SerdeUtils::BITS64 | SerdeUtils::SIGNED | SerdeUtils::SER) {
f.write_str(include_str!("./js/ser_s64.js"))?;
}
if self.contains(SerdeUtils::BITS128 | SerdeUtils::SIGNED | SerdeUtils::SER) {
f.write_str(include_str!("./js/ser_s128.js"))?;
}
if self.contains(SerdeUtils::F32 | SerdeUtils::SER) {
f.write_str(include_str!("./js/ser_f32.js"))?;
}
@@ -723,6 +749,7 @@ impl SerdeUtils {
wit_parser::Int::U16 => SerdeUtils::U16,
wit_parser::Int::U32 => SerdeUtils::U32,
wit_parser::Int::U64 => SerdeUtils::U64,
wit_parser::Int::U128 => SerdeUtils::U128,
};
}
TypeDefKind::Resource(_) => {}
@@ -740,10 +767,12 @@ impl SerdeUtils {
Type::U16 => SerdeUtils::U16,
Type::U32 => SerdeUtils::U32,
Type::U64 => SerdeUtils::U64,
Type::U128 => SerdeUtils::U128,
Type::S8 => SerdeUtils::S8,
Type::S16 => SerdeUtils::S16,
Type::S32 => SerdeUtils::S32,
Type::S64 => SerdeUtils::S64,
Type::S128 => SerdeUtils::S128,
Type::Float32 => SerdeUtils::F32,
Type::Float64 => SerdeUtils::F64,
Type::Char => SerdeUtils::CHAR,

View File

@@ -31,10 +31,12 @@ impl Markdown {
Type::U16 => "u16".to_string(),
Type::U32 => "u32".to_string(),
Type::U64 => "u64".to_string(),
Type::U128 => "u128".to_string(),
Type::S8 => "s8".to_string(),
Type::S16 => "s16".to_string(),
Type::S32 => "s32".to_string(),
Type::S64 => "s64".to_string(),
Type::S128 => "s128".to_string(),
Type::Float32 => "float32".to_string(),
Type::Float64 => "float64".to_string(),
Type::Char => "char".to_string(),

View File

@@ -50,7 +50,17 @@
### Function a9
`func a9 (p1: u8, p2: s8, p3: u16, p4: s16, p5: u32, p6: s32, p7: u64, p8: s64)`
`func a9 (x: u128)`
### Function a10
`func a10 (x: s128)`
### Function a11
`func a11 (p1: u8, p2: s8, p3: u16, p4: s16, p5: u32, p6: s32, p7: u64, p8: s64, p9: u128, p10: s128)`
### Function r1
@@ -93,6 +103,16 @@
`func r8 () -> s64`
### Function r9
`func r9 () -> u128`
### Function r10
`func r10 () -> s128`
### Function pair_ret
`func pair_ret () -> tuple<s64, u8>`

View File

@@ -100,6 +100,11 @@
`func list_u64_param (x: list<u64>)`
### Function list_u128_param
`func list_u128_param (x: list<u128>)`
### Function list_s8_param
`func list_s8_param (x: list<s8>)`
@@ -120,6 +125,11 @@
`func list_s64_param (x: list<s64>)`
### Function list_s128_param
`func list_s128_param (x: list<s128>)`
### Function list_float32_param
`func list_float32_param (x: list<float32>)`
@@ -150,6 +160,11 @@
`func list_u64_ret () -> list<u64>`
### Function list_u128_ret
`func list_u128_ret () -> list<u128>`
### Function list_s8_ret
`func list_s8_ret () -> list<s8>`
@@ -170,6 +185,11 @@
`func list_s64_ret () -> list<s64>`
### Function list_s128_ret
`func list_s128_ret () -> list<s128>`
### Function list_float32_ret
`func list_float32_ret () -> list<float32>`

View File

@@ -81,10 +81,12 @@ pub trait RustGenerator {
Type::U16 => quote! { u16 },
Type::U32 => quote! { u32 },
Type::U64 => quote! { u64 },
Type::U128 => quote! { u128 },
Type::S8 => quote! { i8 },
Type::S16 => quote! { i16 },
Type::S32 => quote! { i32 },
Type::S64 => quote! { i64 },
Type::S128 => quote! { i128 },
Type::Float32 => quote! { f32 },
Type::Float64 => quote! { f64 },
Type::Char => quote! { char },
@@ -449,6 +451,7 @@ pub trait RustGenerator {
Int::U16 => quote! { u16 },
Int::U32 => quote! { u32 },
Int::U64 => quote! { u64 },
Int::U128 => quote! { u128 },
}
}

View File

@@ -21,6 +21,10 @@ pub enum Error {
/// # Errors
///
/// Everything here is fallible (TODO improve this)
///
/// # Panics
///
/// Panics when the response returned by JavaScript is not a `ResponseObject`
pub async fn invoke<P, R>(module: &str, method: &str, val: &P) -> Result<R, Error>
where
P: Serialize,

View File

@@ -95,6 +95,8 @@ pub enum Token {
U32,
#[token("u64")]
U64,
#[token("u128")]
U128,
#[token("s8")]
S8,
#[token("s16")]
@@ -103,6 +105,8 @@ pub enum Token {
S32,
#[token("s64")]
S64,
#[token("s128")]
S128,
#[token("float32")]
Float32,
#[token("float64")]
@@ -156,15 +160,17 @@ impl Token {
Token::Variant,
Token::Resource,
];
pub const TYPE_KEYWORD: [Token; 18] = [
pub const TYPE_KEYWORD: [Token; 20] = [
Token::U8,
Token::U16,
Token::U32,
Token::U64,
Token::U128,
Token::S8,
Token::S16,
Token::S32,
Token::S64,
Token::S128,
Token::Float32,
Token::Float64,
Token::Char,
@@ -201,10 +207,12 @@ impl Token {
Token::U16 => "'u16'",
Token::U32 => "'u32'",
Token::U64 => "'u64'",
Token::U128 => "'u128'",
Token::S8 => "'s8'",
Token::S16 => "'s16'",
Token::S32 => "'s32'",
Token::S64 => "'s64'",
Token::S128 => "'s128'",
Token::Float32 => "'float32'",
Token::Float64 => "'float64'",
Token::Char => "'char'",

View File

@@ -71,6 +71,7 @@ pub enum Int {
U16,
U32,
U64,
U128,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -88,10 +89,12 @@ pub enum Type {
U16,
U32,
U64,
U128,
S8,
S16,
S32,
S64,
S128,
Float32,
Float64,
Char,

View File

@@ -126,10 +126,12 @@ pub enum Type {
U16,
U32,
U64,
U128,
S8,
S16,
S32,
S64,
S128,
Float32,
Float64,
Char,
@@ -397,10 +399,12 @@ impl<'a> FromTokens<'a> for Type {
Token::U16 => Ok(Self::U16),
Token::U32 => Ok(Self::U32),
Token::U64 => Ok(Self::U64),
Token::U128 => Ok(Self::U128),
Token::S8 => Ok(Self::S8),
Token::S16 => Ok(Self::S16),
Token::S32 => Ok(Self::S32),
Token::S64 => Ok(Self::S64),
Token::S128 => Ok(Self::S128),
Token::Float32 => Ok(Self::Float32),
Token::Float64 => Ok(Self::Float64),
Token::Char => Ok(Self::Char),

View File

@@ -187,10 +187,12 @@ impl<'a> Resolver<'a> {
parse::Type::U16 => Type::U16,
parse::Type::U32 => Type::U32,
parse::Type::U64 => Type::U64,
parse::Type::U128 => Type::U128,
parse::Type::S8 => Type::S8,
parse::Type::S16 => Type::S16,
parse::Type::S32 => Type::S32,
parse::Type::S64 => Type::S64,
parse::Type::S128 => Type::S128,
parse::Type::Float32 => Type::Float32,
parse::Type::Float64 => Type::Float64,
parse::Type::Char => Type::Char,

View File

@@ -93,6 +93,14 @@ impl roundtrip::Roundtrip for Ctx {
x
}
fn u128(&self, x: u128) -> u128 {
x
}
fn s128(&self, x: i128) -> i128 {
x
}
fn list_u8(&self, x: Vec<u8>) -> Vec<u8> {
x
}
@@ -109,6 +117,10 @@ impl roundtrip::Roundtrip for Ctx {
x
}
fn list_u128(&self, x: Vec<u128>) -> Vec<u128> {
x
}
fn list_s8(&self, x: Vec<i8>) -> Vec<i8> {
x
}
@@ -125,6 +137,10 @@ impl roundtrip::Roundtrip for Ctx {
x
}
fn list_s128(&self, x: Vec<i128>) -> Vec<i128> {
x
}
fn list_float32(&self, x: Vec<f32>) -> Vec<f32> {
x
}

View File

@@ -128,16 +128,20 @@ fn main() {
Test(name="s32",test=roundtrip::s32())
Test(name="u64",test=roundtrip::u64())
Test(name="s64",test=roundtrip::s64())
Test(name="u128",test=roundtrip::u128())
Test(name="s128",test=roundtrip::s128())
Test(name="list_u8",test=roundtrip::list_u8())
Test(name="list_u16",test=roundtrip::list_u16())
Test(name="list_u32",test=roundtrip::list_u32())
Test(name="list_u64",test=roundtrip::list_u64())
Test(name="list_u128",test=roundtrip::list_u128())
Test(name="list_s8",test=roundtrip::list_s8())
Test(name="list_s16",test=roundtrip::list_s16())
Test(name="list_s32",test=roundtrip::list_s32())
Test(name="list_s64",test=roundtrip::list_s64())
Test(name="list_s128",test=roundtrip::list_s128())
Test(name="list_float32",test=roundtrip::list_float32())
Test(name="list_float64",test=roundtrip::list_float64())
@@ -171,16 +175,20 @@ fn main() {
Test(name="s32",test=roundtrip_js::s32())
Test(name="u64",test=roundtrip_js::u64())
Test(name="s64",test=roundtrip_js::s64())
Test(name="u128",test=roundtrip_js::u128())
Test(name="s128",test=roundtrip_js::s128())
Test(name="list_u8",test=roundtrip_js::list_u8())
Test(name="list_u16",test=roundtrip_js::list_u16())
Test(name="list_u32",test=roundtrip_js::list_u32())
Test(name="list_u64",test=roundtrip_js::list_u64())
Test(name="list_u128",test=roundtrip_js::list_u128())
Test(name="list_s8",test=roundtrip_js::list_s8())
Test(name="list_s16",test=roundtrip_js::list_s16())
Test(name="list_s32",test=roundtrip_js::list_s32())
Test(name="list_s64",test=roundtrip_js::list_s64())
Test(name="list_s128",test=roundtrip_js::list_s128())
Test(name="list_float32",test=roundtrip_js::list_float32())
Test(name="list_float64",test=roundtrip_js::list_float64())

View File

@@ -17,31 +17,36 @@ class Deserializer {
return out
}
}
function varint_max(type) {
const BITS_PER_BYTE = 8;
const BITS_PER_VARINT_BYTE = 7;
// function varint_max(bits) {
// const BITS_PER_BYTE = 8;
// const BITS_PER_VARINT_BYTE = 7;
const bits = type * BITS_PER_BYTE;
// const roundup_bits = bits + (BITS_PER_BYTE - 1);
const roundup_bits = bits + (BITS_PER_BYTE - 1);
// return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
// }
return Math.floor(roundup_bits / BITS_PER_VARINT_BYTE);
const varint_max = {
16: 3,
32: 5,
64: 10,
128: 19
}
function max_of_last_byte(type) {
let extra_bits = type % 7;
return (1 << extra_bits) - 1;
}
function de_varint_big(de, type) {
let out = 0n;
function de_varint(de, bits) {
let out = 0;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
const carry = val & 0x7F;
out |= carry << (7 * i);
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -52,16 +57,16 @@ function de_varint_big(de, type) {
throw new Error('deserialize bad variant')
}
function de_varint(de, type) {
let out = 0;
function de_varint_big(de, bits) {
let out = 0n;
for (let i = 0; i < varint_max(type); i++) {
for (let i = 0; i < varint_max[bits]; i++) {
const val = de.pop();
const carry = val & 0x7F;
out |= carry << (7 * i);
const carry = BigInt(val) & 0x7Fn;
out |= carry << (7n * BigInt(i));
if ((val & 0x80) === 0) {
if (i === varint_max(type) - 1 && val > max_of_last_byte(type)) {
if (i === varint_max[bits] - 1 && val > max_of_last_byte(bits)) {
throw new Error('deserialize bad variant')
} else {
return out
@@ -88,6 +93,9 @@ function deserializeU32(de) {
function deserializeU64(de) {
return de_varint_big(de, 64)
}
function deserializeU128(de) {
return de_varint_big(de, 128)
}
function deserializeS8(de) {
const buf = new ArrayBuffer(1);
const view = new DataView(buf);
@@ -111,6 +119,11 @@ function deserializeS64(de) {
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFn))
}
function deserializeS128(de) {
const n = de_varint_big(de, 128)
return ((n >> 1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn) ^ (-((n & 0b1n) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn))
}
function deserializeF32(de) {
const bytes = de.try_take_n(4);
@@ -189,10 +202,10 @@ function deserializeList(de, inner) {
return out;
}
function ser_varint(out, type, val) {
function ser_varint(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, val, true);
buf[i] = view.getUint8(0);
@@ -207,10 +220,10 @@ function ser_varint(out, type, val) {
out.push(...buf)
}
function ser_varint_big(out, type, val) {
function ser_varint_big(out, bits, val) {
let buf = []
for (let i = 0; i < varint_max(type); i++) {
const buffer = new ArrayBuffer(type / 8);
for (let i = 0; i < varint_max[bits]; i++) {
const buffer = new ArrayBuffer(bits / 8);
const view = new DataView(buffer);
view.setInt16(0, Number(val), true);
buf[i] = view.getUint8(0);
@@ -239,6 +252,9 @@ function serializeU32(out, val) {
function serializeU64(out, val) {
return ser_varint_big(out, 64, BigInt(val))
}
function serializeU128(out, val) {
return ser_varint_big(out, 128, BigInt(val))
}
function serializeS8(out, val) {
out.push(val)
}
@@ -252,6 +268,10 @@ function serializeS64(out, val) {
val = BigInt(val)
ser_varint_big(out, 64, (val << 1n) ^ (val >> 63n))
}
function serializeS128(out, val) {
val = BigInt(val)
ser_varint_big(out, 128, (val << 1n) ^ (val >> 127n))
}
function serializeF32(out, val) {
const buf = new ArrayBuffer(4);
const view = new DataView(buf);
@@ -985,6 +1005,40 @@ export async function s64 (x) {
})
}
/**
* @param {bigint} x
* @returns {Promise<bigint>}
*/
export async function u128 (x) {
const out = []
serializeU128(out, x)
return fetch('ipc://localhost/roundtrip/u128', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeU128(de)
})
}
/**
* @param {bigint} x
* @returns {Promise<bigint>}
*/
export async function s128 (x) {
const out = []
serializeS128(out, x)
return fetch('ipc://localhost/roundtrip/s128', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeS128(de)
})
}
/**
* @param {Uint8Array[]} x
* @returns {Promise<Uint8Array[]>}
@@ -1053,6 +1107,23 @@ export async function listU64 (x) {
})
}
/**
* @param {bigint[]} x
* @returns {Promise<bigint[]>}
*/
export async function listU128 (x) {
const out = []
serializeList(out, (out, v) => serializeU128(out, v), x)
return fetch('ipc://localhost/roundtrip/list_u128', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeList(de, (de) => deserializeU128(de))
})
}
/**
* @param {Int8Array[]} x
* @returns {Promise<Int8Array[]>}
@@ -1121,6 +1192,23 @@ export async function listS64 (x) {
})
}
/**
* @param {bigint[]} x
* @returns {Promise<bigint[]>}
*/
export async function listS128 (x) {
const out = []
serializeList(out, (out, v) => serializeS128(out, v), x)
return fetch('ipc://localhost/roundtrip/list_s128', { method: "POST", body: Uint8Array.from(out), headers: { 'Content-Type': 'application/octet-stream' } })
.then(r => r.arrayBuffer())
.then(bytes => {
const de = new Deserializer(new Uint8Array(bytes))
return deserializeList(de, (de) => deserializeS128(de))
})
}
/**
* @param {Float32Array[]} x
* @returns {Promise<Float32Array[]>}

View File

@@ -196,6 +196,20 @@ pub async fn s64() -> anyhow::Result<()> {
Ok(())
}
pub async fn u128() -> anyhow::Result<()> {
let x = 1777777777267;
ensure!(roundtrip::u128(x).await == x);
Ok(())
}
pub async fn s128() -> anyhow::Result<()> {
let x = -1777777777267;
ensure!(roundtrip::s128(x).await == x);
Ok(())
}
pub async fn list_u8() -> anyhow::Result<()> {
let x = [16, 32, 42];
@@ -224,6 +238,13 @@ pub async fn list_u64() -> anyhow::Result<()> {
Ok(())
}
pub async fn list_u128() -> anyhow::Result<()> {
let x = [16, 32, 42, 17776276762];
ensure!(roundtrip::list_u128(&x).await == x);
Ok(())
}
pub async fn list_s8() -> anyhow::Result<()> {
let x = [16, 32, 42, -24, -26];
@@ -252,6 +273,13 @@ pub async fn list_s64() -> anyhow::Result<()> {
Ok(())
}
pub async fn list_s128() -> anyhow::Result<()> {
let x = [16, 32, 42, 187878787, -18787827];
ensure!(roundtrip::list_s128(&x).await == x);
Ok(())
}
pub async fn list_float32() -> anyhow::Result<()> {
let x = [16.0, 32.5, 42.187878787, -18787827.7];

View File

@@ -1,5 +1,5 @@
use anyhow::ensure;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
use serde_wasm_bindgen::{from_value, to_value};
use wasm_bindgen::JsValue;
@@ -24,14 +24,18 @@ mod roundtrip_js {
pub async fn s32(x: JsValue) -> JsValue;
pub async fn u64(x: JsValue) -> JsValue;
pub async fn s64(x: JsValue) -> JsValue;
pub async fn u128(x: JsValue) -> JsValue;
pub async fn s128(x: JsValue) -> JsValue;
pub async fn listU8(x: JsValue) -> JsValue;
pub async fn listU16(x: JsValue) -> JsValue;
pub async fn listU32(x: JsValue) -> JsValue;
pub async fn listU64(x: JsValue) -> JsValue;
pub async fn listU128(x: JsValue) -> JsValue;
pub async fn listS8(x: JsValue) -> JsValue;
pub async fn listS16(x: JsValue) -> JsValue;
pub async fn listS32(x: JsValue) -> JsValue;
pub async fn listS64(x: JsValue) -> JsValue;
pub async fn listS128(x: JsValue) -> JsValue;
pub async fn listFloat32(x: JsValue) -> JsValue;
pub async fn listFloat64(x: JsValue) -> JsValue;
pub async fn tupleList(x: JsValue) -> JsValue;
@@ -320,6 +324,30 @@ pub async fn s64() -> anyhow::Result<()> {
Ok(())
}
pub async fn u128() -> anyhow::Result<()> {
let x = 1777777777267;
let jsval = to_value(&x).unwrap();
let jsval = roundtrip_js::u128(jsval).await;
let other: u128 = from_value(jsval).unwrap();
ensure!(other == x);
Ok(())
}
pub async fn s128() -> anyhow::Result<()> {
let x = -1777777777267;
let jsval = to_value(&x).unwrap();
let jsval = roundtrip_js::s128(jsval).await;
let other: i128 = from_value(jsval).unwrap();
ensure!(other == x);
Ok(())
}
pub async fn list_u8() -> anyhow::Result<()> {
let x = [16, 32, 42];
@@ -368,6 +396,18 @@ pub async fn list_u64() -> anyhow::Result<()> {
Ok(())
}
pub async fn list_u128() -> anyhow::Result<()> {
let x = [16, 32, 42, 17776276762];
let jsval = to_value(&x).unwrap();
let jsval = roundtrip_js::listU64(jsval).await;
let other: [u128; 4] = from_value(jsval).unwrap();
ensure!(other == x);
Ok(())
}
pub async fn list_s8() -> anyhow::Result<()> {
let x = [16, 32, 42, -24, -26];
@@ -416,6 +456,18 @@ pub async fn list_s64() -> anyhow::Result<()> {
Ok(())
}
pub async fn list_s128() -> anyhow::Result<()> {
let x = [16, 32, 42, 187878787, -18787827];
let jsval = to_value(&x).unwrap();
let jsval = roundtrip_js::listS64(jsval).await;
let other: [i128; 5] = from_value(jsval).unwrap();
ensure!(other == x);
Ok(())
}
pub async fn list_float32() -> anyhow::Result<()> {
let x = [16.0, 32.5, 42.187878787, -18787827.7];
@@ -490,7 +542,7 @@ pub async fn all_integers() -> anyhow::Result<()> {
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct AllIntegers {
tag: u32,
val: AllIntegersInner
val: AllIntegersInner,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
@@ -504,7 +556,7 @@ pub async fn all_integers() -> anyhow::Result<()> {
S8(u8),
S16(u16),
S32(u32),
S64(u64)
S64(u64),
}
let x = roundtrip::AllIntegers::U8(7);
@@ -650,16 +702,16 @@ pub async fn results() -> anyhow::Result<()> {
#[cfg(test)]
mod test {
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
#[test]
fn feature() {
#[derive(Debug, Serialize, Deserialize)]
enum AllFloats {
F32,
F64
F64,
}
println!("{:?}", serde_json::to_string(&AllFloats::F64))
}
}
}

View File

@@ -1,8 +1,8 @@
interface roundtrip {
record empty {}
func empty(x: empty) -> empty
/// A record containing two scalar fields
/// that both have the same type
record scalars {
@@ -11,9 +11,9 @@ interface roundtrip {
/// The second field, named b
b: u32,
}
func record_scalars(val: scalars) -> scalars
/// A record that is really just flags
/// All of the fields are bool
record really_flags {
@@ -27,9 +27,9 @@ interface roundtrip {
h: bool,
i: bool,
}
func record_really_flags(val: really_flags) -> really_flags
record aggregates {
a: scalars,
b: u32,
@@ -37,37 +37,37 @@ interface roundtrip {
d: string,
e: really_flags,
}
func record_aggregates(val: aggregates) -> aggregates
flags flag1 {
b0,
}
flags flag2 {
b0, b1,
}
flags flag4 {
b0, b1, b2, b3,
}
flags flag8 {
b0, b1, b2, b3, b4, b5, b6, b7,
}
flags flag16 {
b0, b1, b2, b3, b4, b5, b6, b7,
b8, b9, b10, b11, b12, b13, b14, b15,
}
flags flag32 {
b0, b1, b2, b3, b4, b5, b6, b7,
b8, b9, b10, b11, b12, b13, b14, b15,
b16, b17, b18, b19, b20, b21, b22, b23,
b24, b25, b26, b27, b28, b29, b30, b31,
}
flags flag64 {
b0, b1, b2, b3, b4, b5, b6, b7,
b8, b9, b10, b11, b12, b13, b14, b15,
@@ -78,7 +78,7 @@ interface roundtrip {
b48, b49, b50, b51, b52, b53, b54, b55,
b56, b57, b58, b59, b60, b61, b62, b63,
}
func flag1(x: flag1) -> flag1
func flag2(x: flag2) -> flag2
func flag4(x: flag4) -> flag4
@@ -86,10 +86,10 @@ interface roundtrip {
func flag16(x: flag16) -> flag16
func flag32(x: flag32) -> flag32
func flag64(x: flag64) -> flag64
func %float32(x: float32) -> float32
func %float64(x: float64) -> float64
func %u8(x: u8) -> u8
func %s8(x: s8) -> s8
func %u16(x: u16) -> u16
@@ -98,22 +98,26 @@ interface roundtrip {
func %s32(x: s32) -> s32
func %u64(x: u64) -> u64
func %s64(x: s64) -> s64
func %u128(x: u128) -> u128
func %s128(x: s128) -> s128
func list_u8(x: list<u8>) -> list<u8>
func list_u16(x: list<u16>) -> list<u16>
func list_u32(x: list<u32>) -> list<u32>
func list_u64(x: list<u64>) -> list<u64>
func list_u128(x: list<u128>) -> list<u128>
func list_s8(x: list<s8>) -> list<s8>
func list_s16(x: list<s16>) -> list<s16>
func list_s32(x: list<s32>) -> list<s32>
func list_s64(x: list<s64>) -> list<s64>
func list_s128(x: list<s128>) -> list<s128>
func list_float32(x: list<float32>) -> list<float32>
func list_float64(x: list<float64>) -> list<float64>
func tuple_list(x: list<tuple<u8, s8>>) -> list<tuple<u8, s8>>
func string_list(a: list<string>) -> list<string>
func tuple_string_list(x: list<tuple<u8, string>>) -> list<tuple<u8, string>>
record some_record {
x: string,
y: other_record,
@@ -132,34 +136,34 @@ interface roundtrip {
c: list<u8>,
}
func record_list(x: list<some_record>) -> list<other_record>
union all_integers {
bool,
u8, u16, u32, u64,
s8, s16, s32, s64
}
func all_integers(x: all_integers) -> all_integers
union all_floats {
float32, float64
}
func all_floats(x: all_floats) -> all_floats
union all_text {
char, string
}
func all_text(x: all_text) -> all_text
enum e1 {
a,
}
func e1(x: e1) -> e1
union u1 {
u32,
float32,
}
variant v1 {
a,
b(u1),
@@ -170,7 +174,7 @@ interface roundtrip {
g(u32),
}
func v1(x: v1) -> v1
func options(
a: option<bool>,
b: option<tuple<>>,
@@ -188,7 +192,7 @@ interface roundtrip {
option<u1>,
option<option<bool>>,
>
func results(
a: result,
b: result<_, e1>,
@@ -204,4 +208,4 @@ interface roundtrip {
result<u32, v1>,
result<string, list<u8>>,
>
}
}

View File

@@ -7,8 +7,10 @@ interface integers {
func a6(x: s32)
func a7(x: u64)
func a8(x: s64)
func a9(x: u128)
func a10(x: s128)
func a9(
func a11(
p1: u8,
p2: s8,
p3: u16,
@@ -17,6 +19,8 @@ interface integers {
p6: s32,
p7: u64,
p8: s64,
p9: u128,
p10: s128,
)
@@ -28,6 +32,8 @@ interface integers {
func r6() -> s32
func r7() -> u64
func r8() -> s64
func r9() -> u128
func r10() -> s128
func pair_ret() -> tuple<s64, u8>
}

View File

@@ -3,10 +3,12 @@ interface lists {
func list_u16_param(x: list<u16>)
func list_u32_param(x: list<u32>)
func list_u64_param(x: list<u64>)
func list_u128_param(x: list<u128>)
func list_s8_param(x: list<s8>)
func list_s16_param(x: list<s16>)
func list_s32_param(x: list<s32>)
func list_s64_param(x: list<s64>)
func list_s128_param(x: list<s128>)
func list_float32_param(x: list<float32>)
func list_float64_param(x: list<float64>)
@@ -14,10 +16,12 @@ interface lists {
func list_u16_ret() -> list<u16>
func list_u32_ret() -> list<u32>
func list_u64_ret() -> list<u64>
func list_u128_ret() -> list<u128>
func list_s8_ret() -> list<s8>
func list_s16_ret() -> list<s16>
func list_s32_ret() -> list<s32>
func list_s64_ret() -> list<s64>
func list_s128_ret() -> list<s128>
func list_float32_ret() -> list<float32>
func list_float64_ret() -> list<float64>