Skip to content

Commit

Permalink
chore: Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Quramy committed Mar 4, 2024
1 parent 7cf7217 commit dae724f
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 69 deletions.
5 changes: 4 additions & 1 deletion packages/core/src/cli/error-reporter.ts
Expand Up @@ -19,7 +19,10 @@ export type ErrorContent = {
};

export class ErrorReporter {
constructor(private readonly _currentDirectory: string, private readonly _output: (msg: string) => void = () => {}) {}
constructor(
private readonly _currentDirectory: string,
private readonly _output: (msg: string) => void = () => {},
) {}

outputError(error: ErrorContent) {
if (!error.occurence?.loc) {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/cli/parser.ts
Expand Up @@ -50,12 +50,12 @@ type ParseOptions = {
type Dispatch<T extends CommandLineOptionEntry> = T extends BooleanOptionEntry
? boolean
: T extends StringOptionEntry
? string
: T extends OptionalStringOptionEntry
? string | undefined
: T extends IntegerOptionEntry
? number
: never;
? string
: T extends OptionalStringOptionEntry
? string | undefined
: T extends IntegerOptionEntry
? number
: never;

type OptionsResult<T extends OptionsHolder> = {
[P in keyof T["options"]]: Dispatch<T["options"][P]>;
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/compiler/assets/modules/float.ts
Expand Up @@ -55,9 +55,12 @@ export const getFloatValueInstr = wat.instructions`
`;

export const reduceInstructions = (instructions: readonly InstructionNode[]) =>
instructions.reduce((acc, node) => {
if (!isCalling(node, "__float_get__")) return [...acc, node];
const last = acc.slice(-1);
if (!last.length || !isCalling(last[0], "__float_new__")) return [...acc, node];
return acc.slice(0, acc.length - 1);
}, [] as readonly InstructionNode[]);
instructions.reduce(
(acc, node) => {
if (!isCalling(node, "__float_get__")) return [...acc, node];
const last = acc.slice(-1);
if (!last.length || !isCalling(last[0], "__float_new__")) return [...acc, node];
return acc.slice(0, acc.length - 1);
},
[] as readonly InstructionNode[],
);
Expand Up @@ -3,7 +3,7 @@ import { isMatch } from "./pattern-match";
import { EvaluationValue } from "../types";
import { createRootEnvironment } from "../environment";

const id = (name: string) => ({ kind: "Identifier", name } as const);
const id = (name: string) => ({ kind: "Identifier", name }) as const;

describe(isMatch, () => {
const getEnv = (input: string, value: EvaluationValue) =>
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/syntax/parser.test.ts
Expand Up @@ -33,13 +33,13 @@ const num = (value: number) =>
({
kind: "IntLiteral",
value,
} as IntLiteralNode);
}) as IntLiteralNode;

const float = (value: number) =>
({
kind: "FloatLiteral",
value,
} as FloatLiteralNode);
}) as FloatLiteralNode;

const minus: MinusOperation = {
kind: "Minus",
Expand Down Expand Up @@ -203,15 +203,15 @@ const pne: PNEOperation = {
const empty = () =>
({
kind: "EmptyList",
} as EmptyListNode);
}) as EmptyListNode;

const bool = (value: boolean) =>
({
kind: "BoolLiteral",
value,
} as BoolLiteralNode);
}) as BoolLiteralNode;

const id = (name: string) => ({ kind: "Identifier", name } as IdentifierNode);
const id = (name: string) => ({ kind: "Identifier", name }) as IdentifierNode;

const expr = <T extends ExpressionNode = ExpressionNode>(node: T) => node;

Expand Down
52 changes: 26 additions & 26 deletions packages/core/src/syntax/parser.ts
Expand Up @@ -298,20 +298,20 @@ const comp: Parser<ExpressionNode> = leftAssociate(use(() => cons))(
token.symbol === "<"
? "LessThan"
: token.symbol === ">"
? "GreaterThan"
: token.symbol === "<="
? "LessEqualThan"
: token.symbol === ">="
? "GreaterEqualThan"
: token.symbol === "="
? "Equal"
: token.symbol === "<>"
? "NotEqual"
: token.symbol === "=="
? "PEqual"
: token.symbol === "!="
? "PNotEqual"
: (undefined as never),
? "GreaterThan"
: token.symbol === "<="
? "LessEqualThan"
: token.symbol === ">="
? "GreaterEqualThan"
: token.symbol === "="
? "Equal"
: token.symbol === "<>"
? "NotEqual"
: token.symbol === "=="
? "PEqual"
: token.symbol === "!="
? "PNotEqual"
: (undefined as never),
token,
},
left,
Expand Down Expand Up @@ -350,12 +350,12 @@ const add: Parser<ExpressionNode> = leftAssociate(use(() => mul))(
token.symbol === "+"
? { kind: "Add", token }
: token.symbol === "+."
? { kind: "FAdd", token }
: token.symbol === "-"
? { kind: "Sub", token }
: token.symbol === "-."
? { kind: "FSub", token }
: (null as never),
? { kind: "FAdd", token }
: token.symbol === "-"
? { kind: "Sub", token }
: token.symbol === "-."
? { kind: "FSub", token }
: (null as never),
left,
right,
...loc(left, token, right),
Expand All @@ -377,12 +377,12 @@ const mul: Parser<ExpressionNode> = leftAssociate(use(() => prfx))(
token.symbol === "*"
? "Multiply"
: token.symbol === "*."
? "FMultiply"
: token.symbol === "/"
? "Div"
: token.symbol === "/."
? "FDiv"
: (null as never),
? "FMultiply"
: token.symbol === "/"
? "Div"
: token.symbol === "/."
? "FDiv"
: (null as never),
token,
},
left,
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/type-checker/unparse.ts
Expand Up @@ -84,10 +84,13 @@ export function createTypePrinter(opts: TypePrinterOptions = {}) {
const solvedVariables = opts.remapWithSubstitutions && getResolvedTypeVariables(opts.remapWithSubstitutions);
const solvedIds =
solvedVariables &&
solvedVariables.reduce((acc, v) => {
acc[v.id] = true;
return acc;
}, [] as (boolean | undefined)[]);
solvedVariables.reduce(
(acc, v) => {
acc[v.id] = true;
return acc;
},
[] as (boolean | undefined)[],
);
const ctx: Context = {
idMap(id) {
if (!solvedIds) return id - this.baseId;
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/wasm/converter/convert-node/func.ts
Expand Up @@ -62,7 +62,7 @@ const controlInstruction: ConvertInstrFn<"ControlInstruction"> = (node, { refCtx
kind: "ControlInstruction",
instructionKind: node.instructionKind,
parameters,
} as Instruction),
}) as Instruction,
);
};

Expand All @@ -79,7 +79,7 @@ const variableInstruction: ConvertInstrFn<"VariableInstruction"> = (node, { refC
kind: "VariableInstruction",
instructionKind: node.instructionKind,
parameters,
} as Instruction),
}) as Instruction,
);
};

Expand All @@ -98,7 +98,7 @@ const numericInstruction: ConvertInstrFn<
kind: "NumericInstruction",
instructionKind: node.instructionKind,
parameters,
} as Instruction),
}) as Instruction,
);
};

Expand Down Expand Up @@ -196,13 +196,13 @@ export function convertFunc(node: FuncNode, idx: number, prev: State, refCtx: Re
type: typeidx,
locals: mapToValTypeListFrom(node.locals),
body,
} as Func),
}) as Func,
)
.map(
func =>
({
types: mutTypes,
funcs: [...prev.funcs, func],
} as State),
}) as State,
);
}
2 changes: 1 addition & 1 deletion packages/core/src/wasm/converter/convert-node/mod.ts
Expand Up @@ -91,7 +91,7 @@ function names(refCtx: RefereneceContext): Names {
kind: "NameAssociation",
idx,
name,
} as const),
}) as const,
);
return {
kind: "Names",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/wasm/wat/parser.ts
Expand Up @@ -580,10 +580,10 @@ const exportSec: Parser<ExportedSecNode> = tryWith(
tKeyword.keyword === "func"
? "ExportedFunc"
: tKeyword.keyword === "memory"
? "ExportedMemory"
: tKeyword.keyword === "table"
? "ExportedTable"
: "ExportedGlobal",
? "ExportedMemory"
: tKeyword.keyword === "table"
? "ExportedTable"
: "ExportedGlobal",
index,
...loc(tLp, tKeyword, index, tRp),
}),
Expand Down
20 changes: 10 additions & 10 deletions packages/playground/src/hooks/use-program-stream.ts
Expand Up @@ -52,15 +52,15 @@ export function useProgramStream<
error: null,
}
: state.ok
? {
ready: true,
data: state.value,
error: null,
}
: {
ready: true,
data: null,
error: state.value,
};
? {
ready: true,
data: state.value,
error: null,
}
: {
ready: true,
data: null,
error: state.value,
};
return ret;
}

0 comments on commit dae724f

Please sign in to comment.