Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/messaging/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Interrupt = WARDuino.Interrupt;
import State = WARDuino.State;
import Value = WASM.Value;
import Type = WASM.Type;
import Special = WASM.Special;

// An acknowledgement returned by the debugger
export interface Ack {
Expand All @@ -28,7 +29,6 @@ export interface Request<R> {

export namespace Message {
import Inspect = WARDuino.Inspect;
import Integer = WASM.Integer;
import Float = WASM.Float;
export const run: Request<Ack> = {
type: Interrupt.run,
Expand Down Expand Up @@ -176,7 +176,7 @@ export namespace Message {
function convert(args: Value<Type>[]) {
let payload: string = '';
args.forEach((arg: Value<Type>) => {
if (arg.type === Float.f32 || arg.type === Float.f64) {
if (arg.type === Float.f32 || arg.type === Float.f64 || arg.type === Special.nan || arg.type === Special.infinity) {
const buff = Buffer.alloc(arg.type === Float.f32 ? 4 : 8);
write(buff, Number(arg.value), 0, true, arg.type === Float.f32 ? 23 : 52, buff.length); // todo fix precision loss
payload += buff.toString('hex');
Expand Down
23 changes: 17 additions & 6 deletions src/sourcemap/Wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
['i64', Integer.i64]
]);

export interface Value<T extends Type> {
export interface Value<T extends Type> {
type: T;
value: T extends Integer ? bigint : number;
}
Expand All @@ -49,12 +49,21 @@
}
}

export interface Nothing extends Value<Special> {}
export interface Nothing extends Value<Special> {

Check failure

Code scanning / ESLint

Disallow accidentally using the "empty object" type Error

An interface declaring no members is equivalent to its supertype.
Comment thread
tolauwae marked this conversation as resolved.
Dismissed
}

export const nothing: Nothing = {
type: Special.nothing, value: 0
}

export const nan: WASM.Value<Special> = {value: NaN, type: Special.nan};

export const negnan: WASM.Value<Special> = {value: -NaN, type: Special.nan};

export const infinity: WASM.Value<Special> = {value: Infinity, type: Special.infinity};

export const neginfinity: WASM.Value<Special> = {value: -Infinity, type: Special.infinity};

export function u32(n: bigint): WASM.Value<Integer> {
return {value: n, type: Integer.u32};
}
Expand All @@ -63,12 +72,14 @@
return {value: n, type: Integer.i32};
}

export function f32(n: number): WASM.Value<Float> {
return {value: n, type: Float.f32};
const determineType: (n: number) => WASM.Type = (n: number) => n === Infinity || n === -Infinity ? Special.infinity : (isNaN(n) ? Special.nan : Float.f64);

export function f32(n: number): WASM.Value<Type> {
return {value: n, type: determineType(n)};
}

export function f64(n: number): WASM.Value<Float> {
return {value: n, type: Float.f64};
export function f64(n: number): WASM.Value<Type> {
return {value: n, type: determineType(n)};
}

export function u64(n: bigint): WASM.Value<Integer> {
Expand Down
Loading