Skip to content

Commit

Permalink
ignore labels and comments when resolving line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanJPNM committed Mar 16, 2024
1 parent 1d25199 commit 6d8762f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
4 changes: 4 additions & 0 deletions compiler/src/instructions/InstructionBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ export class InstructionBase implements IInstruction {
alwaysRuns = true;

protected _hidden = false;

public get hidden() {
return this._hidden;
}
public set hidden(value) {
this._hidden = value;
}

ignoredByParser = false;

args: (string | IValue | null)[];

source?: SourceLocation;
Expand Down
8 changes: 0 additions & 8 deletions compiler/src/instructions/ZeroSpaceInstruction.ts

This file was deleted.

1 change: 0 additions & 1 deletion compiler/src/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export * from "./EndInstruction";
export * from "./AddressResolver";
export * from "./JumpInstruction";
export * from "./SetCounterInstruction";
export * from "./ZeroSpaceInstruction";
export * from "./ControlInstructions";
25 changes: 20 additions & 5 deletions compiler/src/macros/Asm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CompilerError } from "../CompilerError";
import { ZeroSpaceInstruction } from "../instructions";
import { InstructionBase } from "../instructions";
import { IInstruction, IValue } from "../types";
import { isTemplateObjectArray } from "../utils";
import { formatInstructionArgs, isTemplateObjectArray } from "../utils";
import { LiteralValue } from "../values";
import { MacroFunction } from "./Function";

Expand Down Expand Up @@ -55,7 +55,7 @@ function formatInstructions(args: (string | IValue)[]) {
const params = [...buffer, segments[0]];

if (validateInstructionArgs(params)) {
instructions.push(new ZeroSpaceInstruction(...params));
instructions.push(new AsmInstruction(...params));
buffer = [];
}

Expand All @@ -67,7 +67,7 @@ function formatInstructions(args: (string | IValue)[]) {
for (let i = 1; i < segments.length - 1; i++) {
const trimmed = segments[i].trim();
if (trimmed.length == 0) continue;
instructions.push(new ZeroSpaceInstruction(trimmed));
instructions.push(new AsmInstruction(trimmed));
}

if (segments.length > 1) {
Expand All @@ -76,7 +76,7 @@ function formatInstructions(args: (string | IValue)[]) {
}

if (buffer.length > 0 && validateInstructionArgs(buffer)) {
instructions.push(new ZeroSpaceInstruction(...buffer));
instructions.push(new AsmInstruction(...buffer));
}

return instructions;
Expand All @@ -101,3 +101,18 @@ function validateInstructionArgs(args: (string | IValue)[]) {
if (typeof last === "string") args[args.length - 1] = last.trimEnd();
return true;
}

class AsmInstruction extends InstructionBase {
constructor(...args: (string | IValue)[]) {
super(...args);

const [first] = args;
if (typeof first === "string") {
this.ignoredByParser = /^(\s*#|\S+:)/.test(first);
}
}

toString() {
return formatInstructionArgs(this.args).join("");
}
}

0 comments on commit 6d8762f

Please sign in to comment.