macros with vars now working

This commit is contained in:
marketideas 2019-11-21 18:14:30 -08:00
parent 21da3e7536
commit d86bd06e8e
2 changed files with 154 additions and 112 deletions

69
asm.cpp
View File

@ -1371,6 +1371,17 @@ int CLASS::callOpCode(std::string op, MerlinLine &line)
char c;
std::string s;
// 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 == "<<<")))
{
return 0;
}
}
if (op.length() == 4) // check for 4 digit 'L' opcodes
{
c = op[3] & 0x7F;
@ -1966,7 +1977,16 @@ restart:
off = mVec[0].offset;
len = mVec[0].length;
s = oper.substr(off, len);
sym = NULL;
if (expand_macrostack.size() > 0)
{
sym = findVariable(s, expand_macro.variables);
}
if (sym == NULL)
{
sym = findVariable(s, variables);
}
if (sym != NULL)
{
//printf("match |%s|\n",sym->var_text.c_str());
@ -2001,7 +2021,7 @@ restart:
done = true;
}
}
//printf("inoper=|%s| outoper=|%s|\n",operin.c_str(),oper.c_str());
//printf("inoper=|%s| outoper=|%s|\n",operin.c_str(),oper.c_str());
if (ct > 0)
{
outop = oper;
@ -2148,6 +2168,7 @@ void CLASS::process(void)
x = substituteVariables(line, outop);
if (x > 0)
{
line.printoperand = outop;
line.operand = outop;
}
x = parseOperand(line);
@ -2174,21 +2195,27 @@ void CLASS::process(void)
if (op.length() > 0)
{
TMacro *mac = NULL;
if (macrostack.size() == 0)
{
bool inoperand = false;
mac = findMacro(op);
if (mac == NULL)
{
if (op == ">>>") // specal merlin way of calling a macro
{
mac = findMacro(operand);
Poco::StringTokenizer tok(operand, ", ", Poco::StringTokenizer::TOK_TRIM |
Poco::StringTokenizer::TOK_IGNORE_EMPTY);
std::string s="";
if (tok.count()>0)
{
s=tok[0];
}
else
mac = findMacro(s);
inoperand = true;
}
}
if (mac == NULL)
{
x = callOpCode(op, line);
}
}
if (mac != NULL)
{
expand_macrostack.push(expand_macro);
@ -2206,9 +2233,35 @@ void CLASS::process(void)
expand_macro.sourceline = lineno;
expand_macro.variables.vars.clear();
// set the variables for the macro here SGQ
std::string parms = line.operand;
if (inoperand)
{
Poco::StringTokenizer tok(parms, ", ", Poco::StringTokenizer::TOK_TRIM |
Poco::StringTokenizer::TOK_IGNORE_EMPTY);
parms = "";
if (tok.count() > 1)
{
parms = tok[1];
}
}
Poco::StringTokenizer tok(parms, ",;", Poco::StringTokenizer::TOK_TRIM |
Poco::StringTokenizer::TOK_IGNORE_EMPTY);
uint32_t ct = 0;
for (auto itr = tok.begin(); itr != tok.end(); ++itr)
{
//evaluate each of these strings, check for errors on pass 2
std::string expr = *itr;
std::string v = "]" + Poco::NumberFormatter::format(ct + 1);
//printf("var: %s %s\n", v.c_str(), expr.c_str());
addVariable(v, expr, expand_macro.variables, true);
ct++;
}
x = 0;
expand_macro.currentline = 0;
}
}
//}
}
if ((x > 0) && (codeSkipped())) // has a psuedo-op turned off code generation? (LUP, IF, etc)

View File

@ -35,14 +35,6 @@ int CLASS::doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
{
UNUSED(opinfo);
if (a.macrostack.size()>0)
{
// if defining a macro, do nothing with this
return(0);
}
TEvaluator eval(a);
int64_t eval_value = 0;
@ -173,7 +165,7 @@ int CLASS::doMAC(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
// don't need to do anything on pass > 0
}
}
else if (op==">>>")
else if (op == ">>>")
{
// don't do anything here, let the macro call handler stuff do ths (asm.cpp)
}
@ -223,8 +215,6 @@ int CLASS::doLUP(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
std::string op = Poco::toUpper(line.opcode);
if (a.macrostack.size() == 0) // if defining a macro (size>0), don't process here
{
if (op == "LUP")
{
line.flags |= FLAG_NOLINEPRINT;
@ -280,7 +270,7 @@ int CLASS::doLUP(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
{
if (a.expand_macrostack.size() > 0)
{
a.expand_macro.currentline=a.curLUP.lupoffset;
a.expand_macro.currentline = a.curLUP.lupoffset;
}
else
{
@ -312,7 +302,6 @@ int CLASS::doLUP(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
//err = errUnexpectedOp;
}
}
}
out:
if (err > 0)
{