diff --git a/tests/latch/core/endianness_0.asserts.wast b/tests/latch/core/endianness_0.asserts.wast index ef787eea3..9acdf8b91 100644 --- a/tests/latch/core/endianness_0.asserts.wast +++ b/tests/latch/core/endianness_0.asserts.wast @@ -26,7 +26,6 @@ (assert_return (invoke "i64_load32_u" (i64.const 42424242)) (i64.const 42424242)) (assert_return (invoke "i64_load" (i64.const -1)) (i64.const -1)) (assert_return (invoke "i64_load" (i64.const -42424242)) (i64.const -42424242)) - (assert_return (invoke "i64_load" (i64.const 0xABAD1DEA)) (i64.const 0xABAD1DEA)) (assert_return (invoke "i32_store16" (i32.const -1)) (i32.const 0xFFFF)) (assert_return (invoke "i32_store16" (i32.const -4242)) (i32.const 61294)) (assert_return (invoke "i32_store16" (i32.const 42)) (i32.const 42)) @@ -43,4 +42,3 @@ (assert_return (invoke "i64_store32" (i64.const 42424242)) (i64.const 42424242)) (assert_return (invoke "i64_store" (i64.const -1)) (i64.const -1)) (assert_return (invoke "i64_store" (i64.const -42424242)) (i64.const -42424242)) - (assert_return (invoke "i64_store" (i64.const 0xABAD1DEA)) (i64.const 0xABAD1DEA)) diff --git a/tests/latch/core/i64_0.asserts.wast b/tests/latch/core/i64_0.asserts.wast index 6aef3586a..978865740 100644 --- a/tests/latch/core/i64_0.asserts.wast +++ b/tests/latch/core/i64_0.asserts.wast @@ -71,12 +71,10 @@ (assert_return (invoke "and" (i64.const 1) (i64.const 1)) (i64.const 1)) (assert_return (invoke "and" (i64.const 0) (i64.const 0)) (i64.const 0)) (assert_return (invoke "and" (i64.const 0x7fffffffffffffff) (i64.const 0x8000000000000000)) (i64.const 0)) - (assert_return (invoke "and" (i64.const 0xf0f0ffff) (i64.const 0xfffff0f0)) (i64.const 0xf0f0f0f0)) (assert_return (invoke "or" (i64.const 1) (i64.const 0)) (i64.const 1)) (assert_return (invoke "or" (i64.const 0) (i64.const 1)) (i64.const 1)) (assert_return (invoke "or" (i64.const 1) (i64.const 1)) (i64.const 1)) (assert_return (invoke "or" (i64.const 0) (i64.const 0)) (i64.const 0)) - (assert_return (invoke "or" (i64.const 0xf0f0ffff) (i64.const 0xfffff0f0)) (i64.const 0xffffffff)) (assert_return (invoke "xor" (i64.const 1) (i64.const 0)) (i64.const 1)) (assert_return (invoke "xor" (i64.const 0) (i64.const 1)) (i64.const 1)) (assert_return (invoke "xor" (i64.const 1) (i64.const 1)) (i64.const 0)) diff --git a/tests/latch/latch-0.5.1.tgz b/tests/latch/latch-0.5.1.tgz deleted file mode 100644 index 0415d34c7..000000000 Binary files a/tests/latch/latch-0.5.1.tgz and /dev/null differ diff --git a/tests/latch/latch-0.6.0.tgz b/tests/latch/latch-0.6.0.tgz new file mode 100644 index 000000000..836f7cea5 Binary files /dev/null and b/tests/latch/latch-0.6.0.tgz differ diff --git a/tests/latch/package.json b/tests/latch/package.json index fd5c16702..42c2a6db4 100644 --- a/tests/latch/package.json +++ b/tests/latch/package.json @@ -8,7 +8,7 @@ "comptest": "npx ts-node ./src/comp.test.ts" }, "devDependencies": { - "latch": "file:./latch-0.5.1.tgz", + "latch": "file:./latch-0.6.0.tgz", "mqtt": "^4.3.7", "serialport": "^10.4.0", "typescript": "^4.5.5" diff --git a/tests/latch/src/spec.test.ts b/tests/latch/src/spec.test.ts index 71cbdb81f..6f464822c 100644 --- a/tests/latch/src/spec.test.ts +++ b/tests/latch/src/spec.test.ts @@ -75,8 +75,8 @@ function createTest(module: string, asserts: string[]): TestScenario { for (const assert of asserts) { const cursor = {value: 0}; const func: string = find(/invoke "([^"]+)"/, assert); - const args: WASM.Value[] = parseArguments(assert.replace(`(invoke "${func} "`, ''), cursor); - const result: WASM.Value | undefined = parseResult(assert.slice(cursor.value)); + const args: WASM.Value[] = parseArguments(assert.replace(`(invoke "${func} "`, ''), cursor); + const result: WASM.Value | undefined = parseResult(assert.slice(cursor.value)); steps.push({ title: assert, diff --git a/tests/latch/src/util/spec.util.ts b/tests/latch/src/util/spec.util.ts index 94c5a63c9..c2553ebb7 100644 --- a/tests/latch/src/util/spec.util.ts +++ b/tests/latch/src/util/spec.util.ts @@ -1,11 +1,13 @@ import {WASM} from "latch"; import {readFileSync} from "fs"; +import Value = WASM.Value; +import WasmInt = WASM.WasmInt; interface Cursor { value: number; } -export function parseResult(input: string): WASM.Value | undefined { +export function parseResult(input: string): WASM.Value | undefined { let cursor = 0; let delta: number = consume(input, cursor, /\(/d); if (delta === 0) { @@ -14,27 +16,32 @@ export function parseResult(input: string): WASM.Value | undefined { cursor += delta; delta = consume(input, cursor, /^[^.)]*/d); - const type: WASM.Type = WASM.typing.get(input.slice(cursor, cursor + delta)) ?? WASM.Type.i64; + let type: WASM.Type = WASM.typing.get(input.slice(cursor, cursor + delta)) ?? WASM.Integer.i64; cursor += delta + consume(input, cursor + delta); - let value; delta = consume(input, cursor, /^[^)]*/d); - if (type === WASM.Type.f32 || type === WASM.Type.f64) { - value = parseHexFloat(input.slice(cursor, cursor + delta)); - } else { - value = parseInteger(input.slice(cursor, cursor + delta)); - } + return parseValue(input.slice(cursor, cursor + delta), type); +} - if (value === undefined) { - return value; +function parseValue(input: string, type: WASM.Type): Value | undefined { + let value: number | bigint; + switch (type) { + case WASM.Float.f32: + case WASM.Float.f64: + return {value: parseHexFloat(input), type}; + case WASM.Integer.u32: + case WASM.Integer.i32: + case WASM.Integer.u64: + case WASM.Integer.i64: + return {value: parseInteger(input, type), type}; + default: + return undefined; } - - return {type, value}; } -export function parseArguments(input: string, index: Cursor): WASM.Value[] { - const args: WASM.Value[] = []; +export function parseArguments(input: string, index: Cursor): WASM.Value[] { + const args: WASM.Value[] = []; let cursor: number = consume(input, 0, /invoke "[^"]+"/d); while (cursor < input.length) { @@ -45,19 +52,14 @@ export function parseArguments(input: string, index: Cursor): WASM.Value[] { cursor += delta; delta = consume(input, cursor, /^[^.)]*/d); - const type: WASM.Type = WASM.typing.get(input.slice(cursor + delta - 3, cursor + delta)) ?? WASM.Type.i64; + const type: WASM.Type = WASM.typing.get(input.slice(cursor + delta - 3, cursor + delta)) ?? WASM.Integer.i64; cursor += delta + consume(input, cursor + delta, /^[^)]*const /d); delta = consume(input, cursor, /^[^)]*/d); - let maybe: number | undefined; - if (type === WASM.Type.f32 || type === WASM.Type.f64) { - maybe = parseHexFloat(input.slice(cursor, cursor + delta)); - } else { - maybe = parseInteger(input.slice(cursor, cursor + delta)); - } + let maybe = parseValue(input.slice(cursor, cursor + delta), type); if (maybe !== undefined) { - args.push({type, value: maybe}); + args.push(maybe); } cursor += consume(input, cursor, /\)/d); @@ -131,16 +133,18 @@ function parseHexFloat(input: string): number { return mantissa * Math.pow(2, exponent); } -function parseInteger(hex: string, bytes: number = 4): number { +function parseInteger(hex: string, type: WASM.Integer): WasmInt { + const bytes = type === WASM.Integer.u32 || type === WASM.Integer.i32 ? 4 : 8; if (!hex.includes('0x')) { - return parseInt(hex); + const n: number = parseInt(hex); + return typeof n !== 'bigint' && isNaN(n) ? WasmInt.nan() : typeof n !== 'bigint' && n === Infinity ? WasmInt.infinity() : WasmInt.finite(BigInt(hex)); } - const mask = parseInt('0x80' + '00'.repeat(bytes - 1), 16); - let integer = parseInt(hex, 16); + const mask = BigInt(parseInt('0x80' + '00'.repeat(bytes - 1), 16)); + let integer = BigInt(parseInt(hex, 16)); if (integer >= mask) { - integer = integer - mask * 2; + integer = integer - mask * 2n; } - return integer; + return WasmInt.finite(integer); } export function find(regex: RegExp, input: string) {