Added a checkbox for enabling inline arguments transformation mode to the script editor toolbar.

This commit is contained in:
jtuu 2019-09-15 20:59:51 +03:00
parent 463685ffa1
commit 0618ca0b87
6 changed files with 86 additions and 7 deletions

View File

@ -1,12 +1,35 @@
import { ToolBar } from "../../core/gui/ToolBar"; import { ToolBar } from "../../core/gui/ToolBar";
import { Button } from "../../core/gui/Button"; import { CheckBox } from "../../core/gui/CheckBox";
import { asm_editor_store } from "../stores/AsmEditorStore";
export class AsmEditorToolBar extends ToolBar { export class AsmEditorToolBar extends ToolBar {
constructor() { constructor() {
const inline_args_mode_checkbox = new CheckBox(true, {
label: "Inline args mode",
tooltip: asm_editor_store.has_issues.map((has_issues) => {
let text = "Transform arg_push* opcodes to be inline with the opcode the arguments are given to.";
if (has_issues) {
text += "\nThis mode cannot be toggled because there are issues in the script.";
}
return text;
}),
});
super({ super({
children: [], children: [
inline_args_mode_checkbox
],
}); });
this.disposables(
asm_editor_store.inline_args_mode.bind_to(inline_args_mode_checkbox.checked),
inline_args_mode_checkbox.enabled.bind_to(asm_editor_store.has_issues.map(b => !b)),
);
this.finalize_construction(AsmEditorToolBar.prototype); this.finalize_construction(AsmEditorToolBar.prototype);
} }
} }

View File

@ -7,8 +7,9 @@ import {
NewAssemblyInput, NewAssemblyInput,
OutputMessageType, OutputMessageType,
SignatureHelpInput, SignatureHelpInput,
AssemblySettingsChangeInput,
} from "./assembly_worker_messages"; } from "./assembly_worker_messages";
import { AssemblyError, AssemblyWarning } from "./assembly"; import { AssemblyError, AssemblyWarning, AssemblySettings } from "./assembly";
import { disassemble } from "./disassembly"; import { disassemble } from "./disassembly";
import { QuestModel } from "../model/QuestModel"; import { QuestModel } from "../model/QuestModel";
import { Kind, OPCODES } from "./opcodes"; import { Kind, OPCODES } from "./opcodes";
@ -130,6 +131,14 @@ export class AssemblyAnalyser implements Disposable {
}); });
} }
update_settings(changed_settings: Partial<AssemblySettings>): void {
const message: AssemblySettingsChangeInput = {
type: InputMessageType.SettingsChange,
settings: changed_settings
};
this.worker.postMessage(message);
}
dispose(): void { dispose(): void {
this.worker.terminate(); this.worker.terminate();
} }

View File

@ -35,6 +35,10 @@ export type AssemblyWarning = {
export type AssemblyError = AssemblyWarning; export type AssemblyError = AssemblyWarning;
export type AssemblySettings = {
manual_stack: boolean
};
export function assemble( export function assemble(
assembly: string[], assembly: string[],
manual_stack: boolean = false, manual_stack: boolean = false,

View File

@ -6,8 +6,9 @@ import {
OutputMessageType, OutputMessageType,
SignatureHelpInput, SignatureHelpInput,
SignatureHelpOutput, SignatureHelpOutput,
AssemblySettingsChangeInput,
} from "./assembly_worker_messages"; } from "./assembly_worker_messages";
import { assemble } from "./assembly"; import { assemble, AssemblySettings } from "./assembly";
import Logger from "js-logger"; import Logger from "js-logger";
import { SegmentType } from "./instructions"; import { SegmentType } from "./instructions";
import { Opcode, OPCODES_BY_MNEMONIC } from "./opcodes"; import { Opcode, OPCODES_BY_MNEMONIC } from "./opcodes";
@ -24,6 +25,10 @@ let lines: string[] = [];
const messages: AssemblyWorkerInput[] = []; const messages: AssemblyWorkerInput[] = [];
let timeout: any; let timeout: any;
const assembly_settings: AssemblySettings = {
manual_stack: false
};
ctx.onmessage = (e: MessageEvent) => { ctx.onmessage = (e: MessageEvent) => {
messages.push(e.data); messages.push(e.data);
@ -52,6 +57,9 @@ function process_messages(): void {
case InputMessageType.SignatureHelp: case InputMessageType.SignatureHelp:
signature_help(message); signature_help(message);
break; break;
case InputMessageType.SettingsChange:
settings_change(message);
break;
} }
} }
} }
@ -130,8 +138,17 @@ function signature_help(message: SignatureHelpInput): void {
ctx.postMessage(response); ctx.postMessage(response);
} }
/**
* Apply changes to settings.
*/
function settings_change(message: AssemblySettingsChangeInput): void {
if (message.settings.hasOwnProperty("manual_stack")) {
assembly_settings.manual_stack = Boolean(message.settings.manual_stack);
}
}
function assemble_and_send(): void { function assemble_and_send(): void {
const assembler_result = assemble(lines); const assembler_result = assemble(lines, assembly_settings.manual_stack);
const map_designations = new Map<number, number>(); const map_designations = new Map<number, number>();
for (const segment of assembler_result.object_code) { for (const segment of assembler_result.object_code) {

View File

@ -1,4 +1,4 @@
import { AssemblyError, AssemblyWarning } from "./assembly"; import { AssemblyError, AssemblyWarning, AssemblySettings } from "./assembly";
import { Segment } from "./instructions"; import { Segment } from "./instructions";
import { Opcode } from "./opcodes"; import { Opcode } from "./opcodes";
@ -6,9 +6,10 @@ export enum InputMessageType {
NewAssembly, NewAssembly,
AssemblyChange, AssemblyChange,
SignatureHelp, SignatureHelp,
SettingsChange,
} }
export type AssemblyWorkerInput = NewAssemblyInput | AssemblyChangeInput | SignatureHelpInput; export type AssemblyWorkerInput = NewAssemblyInput | AssemblyChangeInput | SignatureHelpInput | AssemblySettingsChangeInput;
export type NewAssemblyInput = { export type NewAssemblyInput = {
readonly type: InputMessageType.NewAssembly; readonly type: InputMessageType.NewAssembly;
@ -33,6 +34,11 @@ export type SignatureHelpInput = {
readonly col: number; readonly col: number;
}; };
export type AssemblySettingsChangeInput = {
readonly type: InputMessageType.SettingsChange;
readonly settings: Partial<AssemblySettings>;
};
export enum OutputMessageType { export enum OutputMessageType {
NewObjectCode, NewObjectCode,
SignatureHelp, SignatureHelp,

View File

@ -69,6 +69,9 @@ export class AsmEditorStore implements Disposable {
() => this._did_redo.emit({ value: "asm undo" }), () => this._did_redo.emit({ value: "asm undo" }),
); );
readonly inline_args_mode: WritableProperty<boolean> = property(true);
readonly has_issues: WritableProperty<boolean> = property(false);
private readonly disposer = new Disposer(); private readonly disposer = new Disposer();
private readonly model_disposer = this.disposer.add(new Disposer()); private readonly model_disposer = this.disposer.add(new Disposer());
private readonly _model: WritableProperty<ITextModel | undefined> = property(undefined); private readonly _model: WritableProperty<ITextModel | undefined> = property(undefined);
@ -88,6 +91,17 @@ export class AsmEditorStore implements Disposable {
assembly_analyser.issues.observe(({ value }) => this.update_model_markers(value), { assembly_analyser.issues.observe(({ value }) => this.update_model_markers(value), {
call_now: true, call_now: true,
}), }),
this.inline_args_mode.observe(() => {
// don't allow changing inline args mode if there are issues
if (!this.has_issues.val) {
this.update_assembly_settings();
}
}),
assembly_analyser.issues.observe(({ value }) => {
this.has_issues.val = Boolean(value.warnings.length) || Boolean(value.errors.length);
})
); );
} }
@ -188,6 +202,12 @@ export class AsmEditorStore implements Disposable {
), ),
); );
} }
private update_assembly_settings(): void {
assembly_analyser.update_settings({
manual_stack: !this.inline_args_mode.val
});
}
} }
export const asm_editor_store = new AsmEditorStore(); export const asm_editor_store = new AsmEditorStore();