Skip to content

Commit 3ccedf5

Browse files
committed
SOURCELINE
1 parent d7e3860 commit 3ccedf5

14 files changed

+64
-1
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ Seed the random number generator used by the RND() function. If this is not use
647647

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

650+
`SOURCELINE <line number> [,<filename>]`
651+
652+
For error reporting act as if the following lines started at `<line number>` in `<filename>`. This is similar to `#line` in C/C++.
653+
650654
## 7. TIPS AND TRICKS
651655

652656
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.

src/asmexception.h

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ DEFINE_SYNTAX_EXCEPTION( NoAnonSave, "Cannot specify SAVE without a filename if
252252
DEFINE_SYNTAX_EXCEPTION( OnlyOneAnonSave, "Can only use SAVE without a filename once per project." );
253253
DEFINE_SYNTAX_EXCEPTION( TypeMismatch, "Type mismatch." );
254254
DEFINE_SYNTAX_EXCEPTION( OutOfIntegerRange, "Number out of range for a 32-bit integer." );
255+
DEFINE_SYNTAX_EXCEPTION( SourceLineNotLast, "SOURCELINE must be the final statement on a line." );
255256

256257

257258

src/commands.cpp

+28-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <cstring>
3030
#include <ctime>
3131
#include <sstream>
32+
#include <climits>
3233

3334
#include "lineparser.h"
3435
#include "globaldata.h"
@@ -86,7 +87,8 @@ const LineParser::Token LineParser::m_gaTokenTable[] =
8687
{ N("ERROR"), &LineParser::HandleError, 0 },
8788
{ N("COPYBLOCK"), &LineParser::HandleCopyBlock, 0 },
8889
{ N("RANDOMIZE"), &LineParser::HandleRandomize, 0 },
89-
{ N("ASM"), &LineParser::HandleAsm, 0 }
90+
{ N("ASM"), &LineParser::HandleAsm, 0 },
91+
{ N("SOURCELINE"), &LineParser::HandleSourceLine, 0 }
9092
};
9193

9294
#undef N
@@ -1887,3 +1889,28 @@ void LineParser::HandleAsm()
18871889

18881890
parser.HandleAssembler(instruction);
18891891
}
1892+
1893+
/*************************************************************************************************/
1894+
/**
1895+
LineParser::HandleSourceLine()
1896+
*/
1897+
/*************************************************************************************************/
1898+
void LineParser::HandleSourceLine()
1899+
{
1900+
ArgListParser args(*this);
1901+
int line = args.ParseInt().Range(0, INT_MAX);
1902+
StringArg fileParam = args.ParseString();
1903+
args.CheckComplete();
1904+
1905+
if (m_column != m_line.length())
1906+
{
1907+
// This must be the last thing on the line
1908+
throw AsmException_SyntaxError_SourceLineNotLast( m_line, m_column );
1909+
}
1910+
1911+
m_sourceCode->SetLineNumber(line - 1);
1912+
if (fileParam.Found())
1913+
{
1914+
m_sourceCode->SetFileName(static_cast<string>(fileParam));
1915+
}
1916+
}

src/lineparser.h

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class LineParser
168168
void HandleCopyBlock();
169169
void HandleRandomize();
170170
void HandleAsm();
171+
void HandleSourceLine();
171172

172173
// expression evaluating methods
173174

src/sourcecode.h

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ class SourceCode
137137
void StartMacro( const std::string& line, int column );
138138
void EndMacro( const std::string& line, int column );
139139
bool IsRealForLevel( int level ) const;
140+
// For SOURCELINE
141+
void SetLineNumber(int line) { m_lineNumber = line; }
142+
void SetFileName(const std::string& name) { m_filename = name; }
140143

141144

142145
protected:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SOURCELINE 1,"first.6502":PRINT"HELLO"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SOURCELINE 5, "other.asm"
2+
LDZ #2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
other.asm:5: error: Unrecognised token.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SOURCELINE 5
2+
LDZ #2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lineonly.fail.6502:5: error: Unrecognised token.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MACRO SL pass
2+
IF pass=2
3+
LDZ #1
4+
ENDIF
5+
SOURCELINE 1,"random.asm"
6+
ENDMACRO
7+
8+
SL 1
9+
SL 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
macro.fail.6502:3: error: Unrecognised token.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MACRO SL pass
2+
SOURCELINE 20,"random.asm"
3+
IF pass=2
4+
LDZ #1
5+
ENDIF
6+
ENDMACRO
7+
8+
SL 1
9+
SL 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
random.asm:21: error: Unrecognised token.

0 commit comments

Comments
 (0)