mirror of
https://github.com/marketideas/qasm.git
synced 2025-01-14 11:29:46 +00:00
macros with vars now working
This commit is contained in:
parent
21da3e7536
commit
d86bd06e8e
67
asm.cpp
67
asm.cpp
@ -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());
|
||||
@ -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)
|
||||
|
11
psuedo.cpp
11
psuedo.cpp
@ -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;
|
||||
@ -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;
|
||||
@ -312,7 +302,6 @@ int CLASS::doLUP(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
||||
//err = errUnexpectedOp;
|
||||
}
|
||||
}
|
||||
}
|
||||
out:
|
||||
if (err > 0)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user