So instead of DEFINED(), how about IFDEF ?
This is maybe not correct...
Code:
Only in beebasm-new: beebasm
diff -cr beebasm-c35bc523430d/src/commands.cpp beebasm-new/src/commands.cpp
*** beebasm-c35bc523430d/src/commands.cpp Mon Apr 8 21:04:15 2013
--- beebasm-new/src/commands.cpp Mon Apr 8 21:09:06 2013
***************
*** 56,61 ****
--- 56,63 ----
{ "SAVE", &LineParser::HandleSave, 0 },
{ "FOR", &LineParser::HandleFor, 0 },
{ "NEXT", &LineParser::HandleNext, 0 },
+ { "IFDEF", &LineParser::HandleIfDef, &SourceFile::AddIfLevel },
+ { "ELIFDEF", &LineParser::HandleIfDef, &SourceFile::StartElif },
{ "IF", &LineParser::HandleIf, &SourceFile::AddIfLevel },
{ "ELIF", &LineParser::HandleIf, &SourceFile::StartElif },
{ "ELSE", &LineParser::HandleDirective, &SourceFile::StartElse },
***************
*** 1296,1301 ****
--- 1298,1317 ----
}
}
+ void LineParser::HandleIfDef()
+ {
+ if (!LineParser::MoveToNextAtom())
+ {
+ throw AsmException_SyntaxError_EmptyExpression( m_line, m_column );
+ }
+ else
+ {
+ string symbolName = GetSymbolName();
+ bool condition = SymbolTable::Instance().IsSymbolDefined(symbolName);
+ m_sourceCode->SetCurrentIfCondition( condition );
+ }
+ }
+
/*************************************************************************************************/
diff -cr beebasm-c35bc523430d/src/lineparser.h beebasm-new/src/lineparser.h
*** beebasm-c35bc523430d/src/lineparser.h Mon Apr 8 21:04:15 2013
--- beebasm-new/src/lineparser.h Mon Apr 8 21:05:53 2013
***************
*** 143,148 ****
--- 143,149 ----
void HandleOpenBrace();
void HandleCloseBrace();
void HandleIf();
+ void HandleIfDef();
void HandleAlign();
void HandleSkip();
void HandleSkipTo();
diff -cr beebasm-c35bc523430d/src/main.cpp beebasm-new/src/main.cpp
*** beebasm-c35bc523430d/src/main.cpp Mon Apr 8 21:04:15 2013
--- beebasm-new/src/main.cpp Mon Apr 8 21:15:56 2013
***************
*** 67,72 ****
--- 67,73 ----
READY,
WAITING_FOR_INPUT_FILENAME,
WAITING_FOR_OUTPUT_FILENAME,
+ WAITING_FOR_DEFINE_NAME,
WAITING_FOR_DISC_INPUT_FILENAME,
WAITING_FOR_DISC_OUTPUT_FILENAME,
WAITING_FOR_BOOT_FILENAME,
***************
*** 77,82 ****
--- 78,84 ----
bool bDumpSymbols = false;
GlobalData::Create();
+ SymbolTable::Create();
// Parse command line parameters
***************
*** 94,99 ****
--- 96,105 ----
{
state = WAITING_FOR_OUTPUT_FILENAME;
}
+ else if ( strcmp( argv[i], "-D" ) == 0 )
+ {
+ state = WAITING_FOR_DEFINE_NAME;
+ }
else if ( strcmp( argv[i], "-do" ) == 0 )
{
state = WAITING_FOR_DISC_OUTPUT_FILENAME;
***************
*** 124,129 ****
--- 130,136 ----
cout << "Possible options:" << endl;
cout << " -i <file> Specify source filename" << endl;
cout << " -o <file> Specify output filename (when not specified by SAVE command)" << endl;
+ cout << " -D NAME Sets NAME = TRUE as a global variable" << endl;
cout << " -di <file> Specify a disc image file to be added to" << endl;
cout << " -do <file> Specify a disc image file to output" << endl;
cout << " -boot <file> Specify a filename to be run by !BOOT on a new disc image" << endl;
***************
*** 156,161 ****
--- 163,173 ----
state = READY;
break;
+ case WAITING_FOR_DEFINE_NAME:
+ SymbolTable::Instance().AddSymbol (argv[i],-1);
+ state = READY;
+ break;
+
case WAITING_FOR_DISC_OUTPUT_FILENAME:
***************
*** 213,219 ****
int exitCode = EXIT_SUCCESS;
- SymbolTable::Create();
ObjectCode::Create();
MacroTable::Create();
SetupBASICTables();
--- 225,230 ----
Only in beebasm-new/src: objects
Whadya think?
(Edited to fix no-parameter case)
(Edited for "-D FOO" functionality)