Skip to content

Commit

Permalink
SOURCELINE
Browse files Browse the repository at this point in the history
  • Loading branch information
mungre committed Aug 25, 2024
1 parent 1309506 commit b0a343e
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ Seed the random number generator used by the RND() function. If this is not use

Assemble the supplied assembly language string. For example `ASM "LDA #&41"`.

`SOURCELINE <line number> [,<filename>]`

For error reporting act as if the following lines started at `<line number>` in `<filename>`. This is a similar to `#line` in C/C++.

## 7. TIPS AND TRICKS

BeebAsm's approach of treating memory as a canvas which can be written to, saved, and rewritten if desired makes it very easy to create certain types of applications.
Expand Down
1 change: 1 addition & 0 deletions src/asmexception.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ DEFINE_SYNTAX_EXCEPTION( NoAnonSave, "Cannot specify SAVE without a filename if
DEFINE_SYNTAX_EXCEPTION( OnlyOneAnonSave, "Can only use SAVE without a filename once per project." );
DEFINE_SYNTAX_EXCEPTION( TypeMismatch, "Type mismatch." );
DEFINE_SYNTAX_EXCEPTION( OutOfIntegerRange, "Number out of range for a 32-bit integer." );
DEFINE_SYNTAX_EXCEPTION( SourceLineNotLast, "SOURCELINE must be the final statement on a line." );



Expand Down
28 changes: 27 additions & 1 deletion src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ const LineParser::Token LineParser::m_gaTokenTable[] =
{ N("ERROR"), &LineParser::HandleError, 0 },
{ N("COPYBLOCK"), &LineParser::HandleCopyBlock, 0 },
{ N("RANDOMIZE"), &LineParser::HandleRandomize, 0 },
{ N("ASM"), &LineParser::HandleAsm, 0 }
{ N("ASM"), &LineParser::HandleAsm, 0 },
{ N("SOURCELINE"), &LineParser::HandleSourceLine, 0 }
};

#undef N
Expand Down Expand Up @@ -1877,3 +1878,28 @@ void LineParser::HandleAsm()

parser.HandleAssembler(instruction);
}

/*************************************************************************************************/
/**
LineParser::HandleSourceLine()
*/
/*************************************************************************************************/
void LineParser::HandleSourceLine()
{
ArgListParser args(*this);
int line = args.ParseInt().Range(0, INT_MAX);
StringArg fileParam = args.ParseString();
args.CheckComplete();

if (m_column != m_line.length())
{
// This must be the last thing on the line
throw AsmException_SyntaxError_SourceLineNotLast( m_line, m_column );
}

m_sourceCode->SetLineNumber(line - 1);
if (fileParam.Found())
{
m_sourceCode->SetFileName(static_cast<string>(fileParam));
}
}
1 change: 1 addition & 0 deletions src/lineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class LineParser
void HandleCopyBlock();
void HandleRandomize();
void HandleAsm();
void HandleSourceLine();

// expression evaluating methods

Expand Down
3 changes: 3 additions & 0 deletions src/sourcecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class SourceCode
void StartMacro( const std::string& line, int column );
void EndMacro( const std::string& line, int column );
bool IsRealForLevel( int level ) const;
// For SOURCELINE
void SetLineNumber(int line) { m_lineNumber = line; }
void SetFileName(const std::string& name) { m_filename = name; }


protected:
Expand Down
1 change: 1 addition & 0 deletions test/3-directives/sourceline/last.fail.6502
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SOURCELINE 1,"first.6502":PRINT"HELLO"
2 changes: 2 additions & 0 deletions test/3-directives/sourceline/linefile.fail.6502
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SOURCELINE 5, "other.asm"
LDZ #2
1 change: 1 addition & 0 deletions test/3-directives/sourceline/linefile.fail.gold.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
other.asm:5: error: Unrecognised token.
2 changes: 2 additions & 0 deletions test/3-directives/sourceline/lineonly.fail.6502
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SOURCELINE 5
LDZ #2
1 change: 1 addition & 0 deletions test/3-directives/sourceline/lineonly.fail.gold.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lineonly.fail.6502:5: error: Unrecognised token.
9 changes: 9 additions & 0 deletions test/3-directives/sourceline/macro.fail.6502
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MACRO SL pass
IF pass=2
LDZ #1
ENDIF
SOURCELINE 1,"random.asm"
ENDMACRO

SL 1
SL 2
1 change: 1 addition & 0 deletions test/3-directives/sourceline/macro.fail.gold.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
macro.fail.6502:3: error: Unrecognised token.
9 changes: 9 additions & 0 deletions test/3-directives/sourceline/macro2.fail.6502
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MACRO SL pass
SOURCELINE 20,"random.asm"
IF pass=2
LDZ #1
ENDIF
ENDMACRO

SL 1
SL 2
1 change: 1 addition & 0 deletions test/3-directives/sourceline/macro2.fail.gold.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
random.asm:21: error: Unrecognised token.

0 comments on commit b0a343e

Please sign in to comment.