mirror of
https://github.com/ksherlock/x65.git
synced 2025-01-16 23:30:02 +00:00
Context scope cleanup and fix for sequential subtraction in expressions
- Should clean up Merlin mode macros a bit - Fixes a numerical error
This commit is contained in:
parent
0fcdc9ca47
commit
73d67d0657
@ -101,6 +101,8 @@ Primarily tested with personal archive of sources written for Kick assmebler, DA
|
|||||||
* irp (indefinite repeat)
|
* irp (indefinite repeat)
|
||||||
|
|
||||||
**FIXED**
|
**FIXED**
|
||||||
|
* First line of a Merlin macro was sometimes ignored, two sequential subtractions were ignored in expressions.
|
||||||
|
* Pushing source contexts (macro, rept, include etc.) will always increment the scope depth.
|
||||||
* Fixed REPT / LUP to not destroy local symbols in the scope it was used in while also destroying local symbols within the repeating block correctly
|
* Fixed REPT / LUP to not destroy local symbols in the scope it was used in while also destroying local symbols within the repeating block correctly
|
||||||
* Switched over to inttypes.h from built-in types since the word unsigned was used a little too much in the code
|
* Switched over to inttypes.h from built-in types since the word unsigned was used a little too much in the code
|
||||||
* Removed the disassembler and put it into its own project [x65dsasm](http://github.com/sakrac/x65dsasm)
|
* Removed the disassembler and put it into its own project [x65dsasm](http://github.com/sakrac/x65dsasm)
|
||||||
|
39
x65.cpp
39
x65.cpp
@ -1399,7 +1399,6 @@ typedef struct sSourceContext {
|
|||||||
int16_t repeat; // how many times to repeat this code segment
|
int16_t repeat; // how many times to repeat this code segment
|
||||||
int16_t repeat_total; // initial number of repeats for this code segment
|
int16_t repeat_total; // initial number of repeats for this code segment
|
||||||
int16_t conditional_ctx; // conditional depth at root of this context
|
int16_t conditional_ctx; // conditional depth at root of this context
|
||||||
bool scoped_context;
|
|
||||||
void restart() { read_source = code_segment; }
|
void restart() { read_source = code_segment; }
|
||||||
bool complete() { repeat--; return repeat <= 0; }
|
bool complete() { repeat--; return repeat <= 0; }
|
||||||
} SourceContext;
|
} SourceContext;
|
||||||
@ -1424,7 +1423,6 @@ public:
|
|||||||
context.next_source = code_seg;
|
context.next_source = code_seg;
|
||||||
context.repeat = rept;
|
context.repeat = rept;
|
||||||
context.repeat_total = rept;
|
context.repeat_total = rept;
|
||||||
context.scoped_context = false;
|
|
||||||
stack.push_back(context);
|
stack.push_back(context);
|
||||||
currContext = &stack[stack.size()-1];
|
currContext = &stack[stack.size()-1];
|
||||||
}
|
}
|
||||||
@ -2705,12 +2703,16 @@ StatusCode Asm::PushContext(strref src_name, strref src_file, strref code_seg, i
|
|||||||
conditional_consumed[conditional_depth] = false;
|
conditional_consumed[conditional_depth] = false;
|
||||||
contextStack.push(src_name, src_file, code_seg, rept);
|
contextStack.push(src_name, src_file, code_seg, rept);
|
||||||
contextStack.curr().conditional_ctx = conditional_depth;
|
contextStack.curr().conditional_ctx = conditional_depth;
|
||||||
|
if (scope_depth >= (MAX_SCOPE_DEPTH - 1))
|
||||||
|
return ERROR_TOO_DEEP_SCOPE;
|
||||||
|
else
|
||||||
|
scope_address[++scope_depth] = CurrSection().GetPC();
|
||||||
return STATUS_OK;
|
return STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusCode Asm::PopContext()
|
StatusCode Asm::PopContext()
|
||||||
{
|
{
|
||||||
if (contextStack.curr().scoped_context && scope_depth) {
|
if (scope_depth) {
|
||||||
StatusCode ret = ExitScope();
|
StatusCode ret = ExitScope();
|
||||||
if (ret != STATUS_OK)
|
if (ret != STATUS_OK)
|
||||||
return ret;
|
return ret;
|
||||||
@ -2841,7 +2843,7 @@ StatusCode Asm::BuildMacro(Macro &m, strref arg_list)
|
|||||||
{
|
{
|
||||||
strref macro_src = m.macro, params;
|
strref macro_src = m.macro, params;
|
||||||
if (m.params_first_line) {
|
if (m.params_first_line) {
|
||||||
if (end_macro_directive)
|
if (end_macro_directive || Merlin())
|
||||||
params = macro_src.line();
|
params = macro_src.line();
|
||||||
else {
|
else {
|
||||||
params = macro_src.before('{');
|
params = macro_src.before('{');
|
||||||
@ -2873,7 +2875,6 @@ StatusCode Asm::BuildMacro(Macro &m, strref arg_list)
|
|||||||
int count = macro_src.substr_case_count(tag.get_strref());
|
int count = macro_src.substr_case_count(tag.get_strref());
|
||||||
dSize += count * ((int)a.get_len() - (int)tag.get_len());
|
dSize += count * ((int)a.get_len() - (int)tag.get_len());
|
||||||
}
|
}
|
||||||
macro_src.line(); // skip macro parameters
|
|
||||||
int mac_size = macro_src.get_len() + dSize + 32;
|
int mac_size = macro_src.get_len() + dSize + 32;
|
||||||
if (char *buffer = (char*)malloc(mac_size)) {
|
if (char *buffer = (char*)malloc(mac_size)) {
|
||||||
loadedData.push_back(buffer);
|
loadedData.push_back(buffer);
|
||||||
@ -2888,11 +2889,6 @@ StatusCode Asm::BuildMacro(Macro &m, strref arg_list)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PushContext(m.source_name, macexp.get_strref(), macexp.get_strref());
|
PushContext(m.source_name, macexp.get_strref(), macexp.get_strref());
|
||||||
if (scope_depth>=(MAX_SCOPE_DEPTH-1))
|
|
||||||
return ERROR_TOO_DEEP_SCOPE;
|
|
||||||
else
|
|
||||||
scope_address[++scope_depth] = CurrSection().GetPC();
|
|
||||||
contextStack.curr().scoped_context = true;
|
|
||||||
return STATUS_OK;
|
return STATUS_OK;
|
||||||
} else
|
} else
|
||||||
return ERROR_OUT_OF_MEMORY_FOR_MACRO_EXPANSION;
|
return ERROR_OUT_OF_MEMORY_FOR_MACRO_EXPANSION;
|
||||||
@ -2921,14 +2917,6 @@ StatusCode Asm::BuildMacro(Macro &m, strref arg_list)
|
|||||||
macexp.replace_bookend(param, a, label_end_char_range);
|
macexp.replace_bookend(param, a, label_end_char_range);
|
||||||
}
|
}
|
||||||
PushContext(m.source_name, macexp.get_strref(), macexp.get_strref());
|
PushContext(m.source_name, macexp.get_strref(), macexp.get_strref());
|
||||||
if (Merlin() || end_macro_directive) {
|
|
||||||
PushContext(m.source_name, macexp.get_strref(), macexp.get_strref());
|
|
||||||
if (scope_depth>=(MAX_SCOPE_DEPTH-1))
|
|
||||||
return ERROR_TOO_DEEP_SCOPE;
|
|
||||||
else
|
|
||||||
scope_address[++scope_depth] = CurrSection().GetPC();
|
|
||||||
contextStack.curr().scoped_context = true;
|
|
||||||
}
|
|
||||||
return STATUS_OK;
|
return STATUS_OK;
|
||||||
} else
|
} else
|
||||||
return ERROR_OUT_OF_MEMORY_FOR_MACRO_EXPANSION;
|
return ERROR_OUT_OF_MEMORY_FOR_MACRO_EXPANSION;
|
||||||
@ -3389,7 +3377,7 @@ StatusCode Asm::EvalExpression(strref expression, const struct EvalContext &etx,
|
|||||||
else if (op == EVOP_ADD)
|
else if (op == EVOP_ADD)
|
||||||
skip = true;
|
skip = true;
|
||||||
}
|
}
|
||||||
if (op == EVOP_SUB && sp && op_stack[sp-1]== EVOP_SUB)
|
if (op == EVOP_SUB && sp && prev_op == EVOP_SUB)
|
||||||
sp--;
|
sp--;
|
||||||
else {
|
else {
|
||||||
while (sp && !skip) {
|
while (sp && !skip) {
|
||||||
@ -4313,11 +4301,6 @@ StatusCode Asm::StringAction(StringSymbol *pStr, strref line)
|
|||||||
mac.replace("\\n", "\n");
|
mac.replace("\\n", "\n");
|
||||||
loadedData.push_back(macro);
|
loadedData.push_back(macro);
|
||||||
PushContext(contextStack.curr().source_name, mac.get_strref(), mac.get_strref());
|
PushContext(contextStack.curr().source_name, mac.get_strref(), mac.get_strref());
|
||||||
if (scope_depth >= (MAX_SCOPE_DEPTH - 1))
|
|
||||||
return ERROR_TOO_DEEP_SCOPE;
|
|
||||||
else
|
|
||||||
scope_address[++scope_depth] = CurrSection().GetPC();
|
|
||||||
contextStack.curr().scoped_context = true;
|
|
||||||
return STATUS_OK;
|
return STATUS_OK;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -4491,11 +4474,6 @@ StatusCode Asm::Directive_Rept(strref line, strref source_file)
|
|||||||
recur = read_source.scoped_block_skip();
|
recur = read_source.scoped_block_skip();
|
||||||
ctx.next_source = read_source;
|
ctx.next_source = read_source;
|
||||||
PushContext(ctx.source_name, ctx.source_file, recur, count);
|
PushContext(ctx.source_name, ctx.source_file, recur, count);
|
||||||
if (scope_depth>=(MAX_SCOPE_DEPTH-1))
|
|
||||||
return ERROR_TOO_DEEP_SCOPE;
|
|
||||||
else
|
|
||||||
scope_address[++scope_depth] = CurrSection().GetPC();
|
|
||||||
contextStack.curr().scoped_context = true;
|
|
||||||
}
|
}
|
||||||
return STATUS_OK;
|
return STATUS_OK;
|
||||||
}
|
}
|
||||||
@ -5687,9 +5665,6 @@ StatusCode Asm::BuildLine(strref line)
|
|||||||
strref code_line = line;
|
strref code_line = line;
|
||||||
list_flags = 0;
|
list_flags = 0;
|
||||||
|
|
||||||
if (line.find("macro")>=0)
|
|
||||||
printf("HEY!");
|
|
||||||
|
|
||||||
while (line && error == STATUS_OK) {
|
while (line && error == STATUS_OK) {
|
||||||
strref line_start = line;
|
strref line_start = line;
|
||||||
char char0 = line[0]; // first char including white space
|
char char0 = line[0]; // first char including white space
|
||||||
|
Loading…
x
Reference in New Issue
Block a user