From 279de5caa5d62e8af9d0ca4cb354f4822a2a63ce Mon Sep 17 00:00:00 2001 From: marketideas Date: Thu, 21 Nov 2019 21:00:26 -0800 Subject: [PATCH] macro on last line bug fixed, nested macro defs --- asm.cpp | 42 ++++++++++++++++++++++++++---------------- psuedo.cpp | 10 +++++++--- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/asm.cpp b/asm.cpp index 1eb5ac7..3bbec9f 100644 --- a/asm.cpp +++ b/asm.cpp @@ -1371,12 +1371,13 @@ int CLASS::callOpCode(std::string op, MerlinLine &line) char c; std::string s; + // 'op' is always lowercase here + // during MACRO definition no opcodes are called (except for MAC, EOM, <<) if (macrostack.size() > 0) { // if something on the macro stack, then a macro is being defined - std::string upop = Poco::toUpper(op); - if (!((upop == "MAC") || (upop == "EOM") || (upop == "<<<"))) + if (!((op == "mac") || (op == "eom") || (op == "<<<"))) { return 0; } @@ -1728,7 +1729,7 @@ void CLASS::complete(void) showSymbolTable(true); showSymbolTable(false); showVariables(variables); - showMacros(false); + showMacros(true); } } @@ -2032,27 +2033,27 @@ restart: bool CLASS::doOFF(void) { - bool res=curDO.doskip; + bool res = curDO.doskip; std::stack tmpstack; TDOstruct doitem; - uint32_t ct=DOstack.size(); - if (ct>0) + uint32_t ct = DOstack.size(); + if (ct > 0) { - tmpstack=DOstack; + tmpstack = DOstack; } - while(ct>0) + while (ct > 0) { - doitem=tmpstack.top(); + doitem = tmpstack.top(); tmpstack.pop(); if (doitem.doskip) { - res=true; + res = true; } ct--; } - - return(res); + //printf("DOOFF: %d\n",res); + return (res); } // this function determines if code generation is turned off (IF,DO,LUP,MAC, etc @@ -2095,7 +2096,8 @@ void CLASS::process(void) initpass(); l = lines.size(); - while ((lineno < l) && (!passcomplete)) + bool passdone = false; + while ((!passdone) && (!passcomplete)) { MerlinLine *ml = NULL; @@ -2127,7 +2129,15 @@ void CLASS::process(void) } if (srcline) { - ml = &lines[lineno]; + if (lineno >= l) + { + passdone = true; + goto passout; + } + else + { + ml = &lines[lineno]; + } } MerlinLine &line = *ml; @@ -2150,7 +2160,7 @@ void CLASS::process(void) line.syntax = syntax; line.merlinerrors = merlinerrors; - if ((line.lable != "")) + if ((line.lable != "") && (op != "mac")) { std::string lable = Poco::trim(line.lable); TSymbol *sym = NULL; @@ -2365,7 +2375,7 @@ void CLASS::process(void) } lineno++; } - +passout: // end of file reached here, do some final checks #if 0 diff --git a/psuedo.cpp b/psuedo.cpp index ba90566..51c34d4 100644 --- a/psuedo.cpp +++ b/psuedo.cpp @@ -141,9 +141,8 @@ int CLASS::doMAC(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) std::string op = Poco::toUpper(line.opcode); if (op == "MAC") { - if (a.currentmacro.running) + if (a.expand_macrostack.size()>0) { - err = errUnexpectedOp; goto out; } if (line.lable.length() == 0) @@ -165,6 +164,7 @@ int CLASS::doMAC(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) { // don't need to do anything on pass > 0 } + //printf("macro stack size=%zu\n",a.macrostack.size()); } else if (op == ">>>") { @@ -172,27 +172,31 @@ int CLASS::doMAC(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) } else // it is EOM or <<< { - if (a.macrostack.size() > 0) + while (a.macrostack.size() > 0) { a.currentmacro.end = line.lineno - 1; a.currentmacro.len = 0; if (a.currentmacro.end >= a.currentmacro.start) { a.currentmacro.len = a.currentmacro.end - a.currentmacro.start; + //printf("macro len=%d\n",a.currentmacro.len); } a.currentmacro.running = false; std::pair p(a.currentmacro.name, a.currentmacro); + //printf("macro insert %s\n",a.currentmacro.name.c_str()); a.macros.insert(p); a.currentmacro = a.macrostack.top(); a.macrostack.pop(); } +#if 0 else { err = errUnexpectedOp; goto out; } +#endif } out: if (err)