mirror of
https://github.com/marketideas/qasm.git
synced 2025-01-13 20:32:14 +00:00
macros with vars now working
This commit is contained in:
parent
21da3e7536
commit
d86bd06e8e
115
asm.cpp
115
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 = findVariable(s, variables);
|
||||
|
||||
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,41 +2195,73 @@ void CLASS::process(void)
|
||||
if (op.length() > 0)
|
||||
{
|
||||
TMacro *mac = NULL;
|
||||
if (macrostack.size() == 0)
|
||||
bool inoperand = false;
|
||||
mac = findMacro(op);
|
||||
if (mac == NULL)
|
||||
{
|
||||
mac = findMacro(op);
|
||||
if (mac == NULL)
|
||||
if (op == ">>>") // specal merlin way of calling a macro
|
||||
{
|
||||
|
||||
if (op == ">>>") // specal merlin way of calling a macro
|
||||
Poco::StringTokenizer tok(operand, ", ", Poco::StringTokenizer::TOK_TRIM |
|
||||
Poco::StringTokenizer::TOK_IGNORE_EMPTY);
|
||||
std::string s="";
|
||||
if (tok.count()>0)
|
||||
{
|
||||
mac = findMacro(operand);
|
||||
s=tok[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
x = callOpCode(op, line);
|
||||
}
|
||||
}
|
||||
if (mac != NULL)
|
||||
{
|
||||
expand_macrostack.push(expand_macro);
|
||||
expand_macro = *mac;
|
||||
|
||||
expand_macro.lines.clear();
|
||||
//printf("mac start=%u end=%u\n", expand_macro.start, expand_macro.end);
|
||||
for (uint32_t lc = expand_macro.start; lc < expand_macro.end; lc++)
|
||||
{
|
||||
//printf("pushing %s\n", lines[lc].wholetext.c_str());
|
||||
MerlinLine nl(lines[lc].wholetext); // create a new clean line (without errors,data)
|
||||
expand_macro.lines.push_back(nl);
|
||||
}
|
||||
expand_macro.running = true;
|
||||
expand_macro.sourceline = lineno;
|
||||
expand_macro.variables.vars.clear();
|
||||
// set the variables for the macro here SGQ
|
||||
expand_macro.currentline = 0;
|
||||
mac = findMacro(s);
|
||||
inoperand = true;
|
||||
}
|
||||
}
|
||||
if (mac == NULL)
|
||||
{
|
||||
x = callOpCode(op, line);
|
||||
}
|
||||
if (mac != NULL)
|
||||
{
|
||||
expand_macrostack.push(expand_macro);
|
||||
expand_macro = *mac;
|
||||
|
||||
expand_macro.lines.clear();
|
||||
//printf("mac start=%u end=%u\n", expand_macro.start, expand_macro.end);
|
||||
for (uint32_t lc = expand_macro.start; lc < expand_macro.end; lc++)
|
||||
{
|
||||
//printf("pushing %s\n", lines[lc].wholetext.c_str());
|
||||
MerlinLine nl(lines[lc].wholetext); // create a new clean line (without errors,data)
|
||||
expand_macro.lines.push_back(nl);
|
||||
}
|
||||
expand_macro.running = true;
|
||||
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)
|
||||
|
151
psuedo.cpp
151
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;
|
||||
@ -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,94 +215,91 @@ 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")
|
||||
{
|
||||
if (op == "LUP")
|
||||
line.flags |= FLAG_NOLINEPRINT;
|
||||
len = line.lineno - 1; // MerlinLine line numbers are +1 from actual array idx
|
||||
if (len >= 0)
|
||||
{
|
||||
line.flags |= FLAG_NOLINEPRINT;
|
||||
len = line.lineno - 1; // MerlinLine line numbers are +1 from actual array idx
|
||||
if (len >= 0)
|
||||
|
||||
shift = 0;
|
||||
eval_value = 0;
|
||||
int x = eval.evaluate(line.operand_expr, eval_value, shift);
|
||||
|
||||
a.LUPstack.push(a.curLUP);
|
||||
|
||||
if (a.expand_macrostack.size() > 0)
|
||||
{
|
||||
a.curLUP.lupoffset = a.expand_macro.currentline;
|
||||
}
|
||||
else
|
||||
{
|
||||
a.curLUP.lupoffset = len;
|
||||
}
|
||||
a.curLUP.lupct = eval_value & 0xFFFF; // evaluate here
|
||||
a.curLUP.luprunning++;
|
||||
|
||||
shift = 0;
|
||||
eval_value = 0;
|
||||
int x = eval.evaluate(line.operand_expr, eval_value, shift);
|
||||
if ((x < 0) || (eval_value <= 0) || (eval_value > 0x8000))
|
||||
{
|
||||
// merlin just ignores LUP if the value is out of range
|
||||
a.curLUP.lupct = 0;
|
||||
a.curLUP.lupskip = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
err = errUnexpectedOp;
|
||||
}
|
||||
}
|
||||
|
||||
a.LUPstack.push(a.curLUP);
|
||||
if (op == "--^")
|
||||
{
|
||||
line.flags |= FLAG_NOLINEPRINT;
|
||||
|
||||
if (a.expand_macrostack.size() > 0)
|
||||
if (a.curLUP.luprunning > 0)
|
||||
{
|
||||
|
||||
|
||||
lidx = line.lineno - 1;
|
||||
len = lidx - a.curLUP.lupoffset - 1;
|
||||
|
||||
if (a.curLUP.lupct > 0)
|
||||
{
|
||||
a.curLUP.lupct--;
|
||||
if (a.curLUP.lupct != 0)
|
||||
{
|
||||
a.curLUP.lupoffset = a.expand_macro.currentline;
|
||||
if (a.expand_macrostack.size() > 0)
|
||||
{
|
||||
a.expand_macro.currentline = a.curLUP.lupoffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
a.lineno = a.curLUP.lupoffset;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
else
|
||||
{
|
||||
a.curLUP.lupoffset = len;
|
||||
}
|
||||
a.curLUP.lupct = eval_value & 0xFFFF; // evaluate here
|
||||
a.curLUP.luprunning++;
|
||||
}
|
||||
// kind of a silent error here, just make sure we reinitialize
|
||||
a.curLUP.luprunning = 0;
|
||||
a.curLUP.lupct = 0;
|
||||
a.curLUP.lupskip = false;
|
||||
|
||||
if ((x < 0) || (eval_value <= 0) || (eval_value > 0x8000))
|
||||
{
|
||||
// merlin just ignores LUP if the value is out of range
|
||||
a.curLUP.lupct = 0;
|
||||
a.curLUP.lupskip = true;
|
||||
}
|
||||
//printf("start=%d end=%d len=%d\n", a.curLUP.lupoffset, lidx, len);
|
||||
if (a.LUPstack.size() > 0)
|
||||
{
|
||||
a.curLUP = a.LUPstack.top();
|
||||
a.LUPstack.pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
err = errUnexpectedOp;
|
||||
}
|
||||
}
|
||||
|
||||
if (op == "--^")
|
||||
else
|
||||
{
|
||||
line.flags |= FLAG_NOLINEPRINT;
|
||||
|
||||
if (a.curLUP.luprunning > 0)
|
||||
{
|
||||
|
||||
|
||||
lidx = line.lineno - 1;
|
||||
len = lidx - a.curLUP.lupoffset - 1;
|
||||
|
||||
if (a.curLUP.lupct > 0)
|
||||
{
|
||||
a.curLUP.lupct--;
|
||||
if (a.curLUP.lupct != 0)
|
||||
{
|
||||
if (a.expand_macrostack.size() > 0)
|
||||
{
|
||||
a.expand_macro.currentline=a.curLUP.lupoffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
a.lineno = a.curLUP.lupoffset;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
// kind of a silent error here, just make sure we reinitialize
|
||||
a.curLUP.luprunning = 0;
|
||||
a.curLUP.lupct = 0;
|
||||
a.curLUP.lupskip = false;
|
||||
|
||||
//printf("start=%d end=%d len=%d\n", a.curLUP.lupoffset, lidx, len);
|
||||
if (a.LUPstack.size() > 0)
|
||||
{
|
||||
a.curLUP = a.LUPstack.top();
|
||||
a.LUPstack.pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
err = errUnexpectedOp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
a.curLUP.lupskip = false;
|
||||
// SGQ - found a '--^' without a LUP, should we just ignore?
|
||||
//err = errUnexpectedOp;
|
||||
}
|
||||
a.curLUP.lupskip = false;
|
||||
// SGQ - found a '--^' without a LUP, should we just ignore?
|
||||
//err = errUnexpectedOp;
|
||||
}
|
||||
}
|
||||
out:
|
||||
|
Loading…
x
Reference in New Issue
Block a user