fixes for nested DO/IF/ELSE/FIN

This commit is contained in:
marketideas 2019-11-21 19:20:59 -08:00
parent d86bd06e8e
commit b154efff36
5 changed files with 120 additions and 68 deletions

45
asm.cpp
View File

@ -2030,13 +2030,38 @@ restart:
return (res);
}
bool CLASS::doOFF(void)
{
bool res=curDO.doskip;
std::stack<TDOstruct> tmpstack;
TDOstruct doitem;
uint32_t ct=DOstack.size();
if (ct>0)
{
tmpstack=DOstack;
}
while(ct>0)
{
doitem=tmpstack.top();
tmpstack.pop();
if (doitem.doskip)
{
res=true;
}
ct--;
}
return(res);
}
// this function determines if code generation is turned off (IF,DO,LUP,MAC, etc
bool CLASS::codeSkipped(void)
{
bool res = false;
res = (curLUP.lupskip) ? true : res;
res = (curDO.doskip) ? true : res;
res = doOFF() ? true : res;
res = currentmacro.running ? true : res;
//printf("codeskip: %d\n",res);
@ -2062,7 +2087,7 @@ void CLASS::process(void)
char c;
char buff[256];
MerlinLine errLine;
std::string op, operand, ls;
std::string op, realop, operand, ls;
pass = 0;
while (pass < 2)
@ -2116,6 +2141,7 @@ void CLASS::process(void)
//printf("lineno: %d %d |%s|\n",lineno,l,line.operand.c_str());
op = Poco::toLower(line.opcode);
realop = line.opcode;
operand = Poco::toLower(line.operand);
line.startpc = PC.currentpc;
line.linemx = mx;
@ -2193,10 +2219,21 @@ void CLASS::process(void)
x = 0;
if (op.length() > 0)
{
bool skipop = false;
if (doOFF())
{
skipop = true;
if ((op == "fin") || (op == "else") || (op == "do") || (op == "if"))
{
skipop = false;
}
}
if (!skipop)
{
TMacro *mac = NULL;
bool inoperand = false;
mac = findMacro(op);
mac = findMacro(realop);
if (mac == NULL)
{
if (op == ">>>") // specal merlin way of calling a macro
@ -2261,7 +2298,7 @@ void CLASS::process(void)
x = 0;
expand_macro.currentline = 0;
}
//}
}
}
if ((x > 0) && (codeSkipped())) // has a psuedo-op turned off code generation? (LUP, IF, etc)

2
asm.h
View File

@ -473,6 +473,8 @@ public:
int substituteVariables(MerlinLine & line, std::string &outop);
bool codeSkipped(void);
bool doOFF(void);
int parseOperand(MerlinLine &line);
int getAddrMode(MerlinLine &line);

View File

@ -15,6 +15,7 @@ std::ostream& operator<<(std::ostream& os, const Token& token)
CLASS::CLASS(T65816Asm &_asm) : assembler(_asm)
{
allowMX = false;
}
CLASS::~CLASS()
@ -231,6 +232,15 @@ std::deque<Token> CLASS::shuntingYard(const std::deque<Token>& tokens)
token.str = buff;
}
else
{
std::string tok = Poco::toUpper(token.str);
if ((tok == "MX") && (allowMX))
{
//printf("MX EVAL\n");
sprintf(buff,"$%02X",assembler.mx&0x03);
token.str=buff;;
}
else
{
sym = assembler.findSymbol(token.str);
//printf("symbol find |%s| %p\n",token.str.c_str(),sym);
@ -248,6 +258,7 @@ std::deque<Token> CLASS::shuntingYard(const std::deque<Token>& tokens)
token.str = "0";
}
}
}
queue.push_back(token);
break;
case Token::Type::Ascii:

1
eval.h
View File

@ -68,6 +68,7 @@ protected:
public:
CLASS(T65816Asm &_asm);
~CLASS();
bool allowMX;
std::string badsymbol;
std::deque<Token> shuntingYard(const std::deque<Token>& tokens);
std::deque<Token> exprToTokens(const std::string& expr);

View File

@ -36,6 +36,7 @@ int CLASS::doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
UNUSED(opinfo);
TEvaluator eval(a);
eval.allowMX=true; // allow the built in MX symbol
int64_t eval_value = 0;
uint8_t shift;