Skip to content

Commit

Permalink
release: v1.0.0-alpha.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed Jan 21, 2025
1 parent fc4e0f1 commit eb42dca
Show file tree
Hide file tree
Showing 34 changed files with 995 additions and 965 deletions.
2 changes: 1 addition & 1 deletion assembly/__benches__/misc.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bench } from "as-bench/assembly/bench";
import { bs } from "as-bs";
import { bs } from "../../modules/bs";
import { deserializeString_SIMD } from "../deserialize/simd/string";
import { deserializeString } from "../deserialize/simple/string";
import { bytes } from "../util/bytes";
Expand Down
1 change: 0 additions & 1 deletion assembly/custom/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { isSpace } from "util/string";
import { BACK_SLASH, QUOTE } from "./chars";
import { Sink } from "./sink";


/** Scientific Notation Integer Parsing - SNIP
* This is absolutely the fastest algorithm I could think of while adding full support for Scientific Notation
* Loads 32 bits and retrieves the high/low bits.
Expand Down
2 changes: 1 addition & 1 deletion assembly/deserialize/simple/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ export function deserializeArray<T extends unknown[]>(srcStart: usize, srcEnd: u
function isMap<T>(): boolean {
let type: T = changetype<T>(0);
return type instanceof Map;
}
}
204 changes: 102 additions & 102 deletions assembly/deserialize/simple/array/arbitrary.ts
Original file line number Diff line number Diff line change
@@ -1,113 +1,113 @@
import { BACK_SLASH, BRACE_LEFT, BRACE_RIGHT, BRACKET_LEFT, BRACKET_RIGHT, CHAR_F, CHAR_N, CHAR_T, COMMA, QUOTE } from "../../../custom/chars";
import { JSON } from "../../../";
import { isSpace } from "util/string";
import { ptrToStr } from "../../../util/ptrToStr";

export function deserializeArbitraryArray<T extends JSON.Value>(srcStart: usize, srcEnd: usize, dst: usize): JSON.Value[] {
const out = dst ? changetype<T>(dst) : instantiate<T>();
let lastIndex: usize = 0;
let depth: u32 = 0;
while (srcStart < srcEnd) {
const out = dst ? changetype<T>(dst) : instantiate<T>();
let lastIndex: usize = 0;
let depth: u32 = 0;
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
if (code == QUOTE) {
lastIndex = srcStart;
srcStart += 2;
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
if (code == QUOTE) {
lastIndex = srcStart;
srcStart += 2;
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
if (code == QUOTE && load<u16>(srcStart - 2) !== BACK_SLASH) {
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
console.log("Value (string): " + ptrToStr(lastIndex, srcStart));
// @ts-ignore: exists
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart));
break;
}
srcStart += 2;
}
} else if (code - 48 <= 9 || code == 45) {
lastIndex = srcStart;
srcStart += 2;
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
if (code == COMMA || code == BRACE_RIGHT || isSpace(code)) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart));
console.log("Value (number): " + ptrToStr(lastIndex, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
break;
}
srcStart += 2;
}
} else if (code == BRACE_LEFT) {
lastIndex = srcStart;
depth++;
srcStart += 2;
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
if (code == BRACE_RIGHT) {
if (--depth == 0) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart));
console.log("Value (object): " + ptrToStr(lastIndex, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
break;
}
} else if (code == BRACE_LEFT) depth++;
srcStart += 2;
}
} else if (code == BRACKET_LEFT) {
lastIndex = srcStart;
depth++;
srcStart += 2;
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
if (code == BRACKET_RIGHT) {
if (--depth == 0) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart));
console.log("Value (array): " + ptrToStr(lastIndex, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
break;
}
} else if (code == BRACKET_LEFT) depth++;
srcStart += 2;
}
} else if (code == CHAR_T) {
if (load<u64>(srcStart) == 28429475166421108) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart += 8));
console.log("Value (bool): " + ptrToStr(srcStart - 8, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
}
} else if (code == CHAR_F) {
if (load<u64>(srcStart, 2) == 28429466576093281) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart += 10));
console.log("Value (bool): " + ptrToStr(srcStart - 10, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
if (code == QUOTE && load<u16>(srcStart - 2) !== BACK_SLASH) {
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
// console.log("Value (string): " + ptrToStr(lastIndex, srcStart));
// @ts-ignore: exists
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart));
break;
}
srcStart += 2;
}
} else if (code - 48 <= 9 || code == 45) {
lastIndex = srcStart;
srcStart += 2;
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
if (code == COMMA || code == BRACE_RIGHT || isSpace(code)) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart));
// console.log("Value (number): " + ptrToStr(lastIndex, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
break;
}
srcStart += 2;
}
} else if (code == BRACE_LEFT) {
lastIndex = srcStart;
depth++;
srcStart += 2;
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
if (code == BRACE_RIGHT) {
if (--depth == 0) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart));
// console.log("Value (object): " + ptrToStr(lastIndex, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
} else if (code == CHAR_N) {
if (load<u64>(srcStart) == 30399761348886638) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart += 8));
console.log("Value (null): " + ptrToStr(srcStart - 8, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
break;
}
} else if (code == BRACE_LEFT) depth++;
srcStart += 2;
}
} else if (code == BRACKET_LEFT) {
lastIndex = srcStart;
depth++;
srcStart += 2;
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
if (code == BRACKET_RIGHT) {
if (--depth == 0) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart));
// console.log("Value (array): " + ptrToStr(lastIndex, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
}
break;
}
} else if (code == BRACKET_LEFT) depth++;
srcStart += 2;
}
} else if (code == CHAR_T) {
if (load<u64>(srcStart) == 28429475166421108) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, (srcStart += 8)));
// console.log("Value (bool): " + ptrToStr(srcStart - 8, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
}
} else if (code == CHAR_F) {
if (load<u64>(srcStart, 2) == 28429466576093281) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, (srcStart += 10)));
// console.log("Value (bool): " + ptrToStr(srcStart - 10, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
}
} else if (code == CHAR_N) {
if (load<u64>(srcStart) == 30399761348886638) {
// @ts-ignore: type
out.push(JSON.__deserialize<valueof<T>>(lastIndex, (srcStart += 8)));
// console.log("Value (null): " + ptrToStr(srcStart - 8, srcStart));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
}
}
return out;
srcStart += 2;
}
// @ts-ignore: type
return out;
}
9 changes: 3 additions & 6 deletions assembly/deserialize/simple/array/integer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { atoi, isSpace } from "../../../util";
import { COMMA, BRACE_RIGHT, BRACKET_RIGHT } from "../../../custom/chars";
import { JSON } from "../../..";
import { ptrToStr } from "../../../util/ptrToStr";
import { COMMA, BRACKET_RIGHT } from "../../../custom/chars";

export function deserializeIntegerArray<T extends number[]>(srcStart: usize, srcEnd: usize, dst: usize): T {
const out = dst ? changetype<T>(dst) : instantiate<T>();
const out: T = dst ? changetype<T>(dst) : instantiate<T>();
let lastIndex: usize = 0;
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
Expand All @@ -14,8 +12,7 @@ export function deserializeIntegerArray<T extends number[]>(srcStart: usize, src
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
if (code == COMMA || code == BRACKET_RIGHT || isSpace(code)) {
console.log("element: " + ptrToStr(lastIndex, srcStart))
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart));
out.push(atoi<valueof<T>>(lastIndex, srcStart));
// while (isSpace(load<u16>((srcStart += 2)))) {
// /* empty */
// }
Expand Down
2 changes: 1 addition & 1 deletion assembly/deserialize/simple/bool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export function deserializeBoolean(srcStart: usize, srcEnd: usize): boolean {
if (firstChar == CHAR_T && load<u64>(srcStart) == 28429475166421108) return true;
else if (firstChar == CHAR_F && load<u64>(srcSize, 2) == 28429466576093281) return false;
return false; //ERROR(`Expected to find boolean, but found "${data.slice(0, 100)}" instead!`);
}
}
2 changes: 1 addition & 1 deletion assembly/deserialize/simple/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export function deserializeDate(srcStart: usize, srcEnd: usize): Date {
// This may seem redundant, but addreses the issue when Date
// is globally aliased to wasi_Date (or some other superclass).
return new Date(d.getTime());
}
}
14 changes: 7 additions & 7 deletions assembly/deserialize/simple/float.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ptrToStr } from "../../util/ptrToStr";

export function deserializeFloat<T>(srcStart: usize, srcEnd: usize): T {
// @ts-ignore
const type: T = 0;
// @ts-ignore
if (type instanceof f64) return f64.parse(ptrToStr(srcStart, srcEnd));
// @ts-ignore
return f32.parse(ptrToStr(srcStart, srcEnd));
}
// @ts-ignore
const type: T = 0;
// @ts-ignore
if (type instanceof f64) return f64.parse(ptrToStr(srcStart, srcEnd));
// @ts-ignore
return f32.parse(ptrToStr(srcStart, srcEnd));
}
2 changes: 1 addition & 1 deletion assembly/deserialize/simple/integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { atoi } from "../../util/atoi";

export function deserializeInteger<T>(srcStart: usize, srcEnd: usize): T {
return atoi<T>(srcStart, srcEnd);
}
}
12 changes: 6 additions & 6 deletions assembly/deserialize/simple/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
srcStart += 2;
}
// @ts-ignore: type
} else if (!isBoolean<valueof<T>>() && isInteger<valueof<T>>() && code - 48 <= 9 || code == 45) {
} else if ((!isBoolean<valueof<T>>() && isInteger<valueof<T>>() && code - 48 <= 9) || code == 45) {
lastIndex = srcStart;
srcStart += 2;
while (srcStart < srcEnd) {
Expand Down Expand Up @@ -113,7 +113,7 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
} else if (isBoolean<valueof<T>>() && code == CHAR_T) {
if (load<u64>(srcStart) == 28429475166421108) {
// @ts-ignore: type
out.set(key, JSON.__deserialize<valueof<T>>(srcStart, srcStart += 8));
out.set(key, JSON.__deserialize<valueof<T>>(srcStart, (srcStart += 8)));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
Expand All @@ -123,7 +123,7 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
} else if (isBoolean<valueof<T>>() && code == CHAR_F) {
if (load<u64>(srcStart, 2) == 28429466576093281) {
// @ts-ignore: type
out.set(key, JSON.__deserialize<valueof<T>>(srcStart, srcStart += 10));
out.set(key, JSON.__deserialize<valueof<T>>(srcStart, (srcStart += 10)));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
Expand All @@ -132,14 +132,14 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
} else if ((isNullable<T>() || nameof<T>() == "usize") && code == CHAR_N) {
if (load<u64>(srcStart) == 30399761348886638) {
// @ts-ignore: type
out.set(key, JSON.__deserialize<valueof<T>>(srcStart, srcStart += 8));
out.set(key, JSON.__deserialize<valueof<T>>(srcStart, (srcStart += 8)));
while (isSpace(load<u16>((srcStart += 2)))) {
/* empty */
}
}
} else {
// @ts-ignore: type
throw new Error("Unexpected character " + String.fromCharCode(code) + " or type " + nameof<valueof<T>>() + " does not match found type!")
throw new Error("Unexpected character " + String.fromCharCode(code) + " or type " + nameof<valueof<T>>() + " does not match found type!");
}
}
}
Expand All @@ -151,4 +151,4 @@ function sliceTo(srcStart: usize, srcEnd: usize): string {
const dst = __new(dstSize, idof<string>());
memory.copy(dst, srcStart, dstSize);
return changetype<string>(dst);
}
}
Loading

0 comments on commit eb42dca

Please sign in to comment.