Skip to content

Commit

Permalink
Add a few new flags
Browse files Browse the repository at this point in the history
  • Loading branch information
gingershaped committed Dec 23, 2023
1 parent bcec1d2 commit 66e042b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/latest/js/dialogs/FlagsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export const FlagsDialog = memo(function({ flags, setFlags, show, setShow }: Fla
<BooleanSwitch parameter="fullTrace" flags={flags} setFlags={setFlags}>
Full traceback information
</BooleanSwitch>
<BooleanSwitch parameter="limitPrint" flags={flags} setFlags={setFlags}>
Limit printing
</BooleanSwitch>
<BooleanSwitch parameter="dontEvalInputs" flags={flags} setFlags={setFlags}>
Don't evaluate inputs
</BooleanSwitch>
<hr className="mt-1" />
<div>
<label htmlFor="end-print-mode">End print mode:</label>
Expand Down
34 changes: 24 additions & 10 deletions src/latest/js/flagsReducer.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
export enum EndPrintMode {
Default, TopJoinNewlines, TopJoinSpaces, TopSquish,
Sum, DeepSum,
LogicalNot,
MaximumTop, MinimumTop, LengthTop,
StackLength, StackSum, StackJoinSpaces,
Force, None
}

export interface InterpreterFlagSettings {
flags: string[],
presetStack: boolean,
startRangeAtZero: boolean,
offsetRangeByOne: boolean,
literate: boolean,
rangify: boolean,
fullTrace: boolean,
endPrintMode: EndPrintMode,
}

export interface ChangeFlagValue {
type: "setting",
Expand All @@ -37,6 +28,7 @@ export const END_PRINT_MODES = new Map([
["j", EndPrintMode.TopJoinNewlines],
["s", EndPrintMode.Sum],
["d", EndPrintMode.DeepSum],
["¬", EndPrintMode.LogicalNot],
["O", EndPrintMode.None],
["o", EndPrintMode.Force],
["!", EndPrintMode.StackLength],
Expand All @@ -52,6 +44,7 @@ export const END_PRINT_NAMES = new Map([
["j", "Join top of stack with newlines"],
["s", "Sum top of stack"],
["d", "Flatten and sum top of stack"],
["¬", "Apply logical NOT to the top of the stack"],
["O", "Do nothing"],
["o", `"Force"`],
["!", "Length of stack"],
Expand All @@ -64,6 +57,19 @@ export const END_PRINT_NAMES = new Map([
]);
export const END_PRINT_FLAGS = new Map(Array.from(END_PRINT_MODES, a => [a[1], a[0]]));

export interface InterpreterFlagSettings {
flags: string[],
presetStack: boolean,
startRangeAtZero: boolean,
offsetRangeByOne: boolean,
literate: boolean,
rangify: boolean,
fullTrace: boolean,
limitPrint: boolean,
dontEvalInputs: boolean,
endPrintMode: EndPrintMode,
}

export const INITIAL_FLAGS: InterpreterFlagSettings = {
flags: [],
presetStack: false,
Expand All @@ -72,6 +78,8 @@ export const INITIAL_FLAGS: InterpreterFlagSettings = {
literate: false,
rangify: false,
fullTrace: false,
limitPrint: false,
dontEvalInputs: false,
endPrintMode: EndPrintMode.Default
};

Expand Down Expand Up @@ -104,6 +112,12 @@ export function settingsFromFlags(flags: string[]) {
case "X":
settings.fullTrace = true;
break;
case "…":
settings.limitPrint = true;
break;
case "Ṡ":
settings.dontEvalInputs = true;
break;
default:
settings.endPrintMode = END_PRINT_MODES.get(flag) ?? EndPrintMode.Default;
}
Expand Down

0 comments on commit 66e042b

Please sign in to comment.