mirror of
https://github.com/bradgrantham/apple2a.git
synced 2024-10-31 23:09:39 +00:00
Reduce unnecessary push/pop in expression compilation.
This commit is contained in:
parent
e95f2cf67f
commit
9175c4c234
17
main.c
17
main.c
@ -371,18 +371,24 @@ static uint16_t parse_uint16(uint8_t **s_ptr) {
|
|||||||
*/
|
*/
|
||||||
static uint8_t *compile_expression(uint8_t *s) {
|
static uint8_t *compile_expression(uint8_t *s) {
|
||||||
int plus_count = 0;
|
int plus_count = 0;
|
||||||
|
char have_value_in_ax = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (*s >= '0' && *s <= '9') {
|
if (*s >= '0' && *s <= '9') {
|
||||||
// Parse number.
|
// Parse number.
|
||||||
uint16_t value = parse_uint16(&s);
|
uint16_t value;
|
||||||
|
|
||||||
|
if (have_value_in_ax) {
|
||||||
|
// Push on the number stack.
|
||||||
|
add_call(pushax);
|
||||||
|
}
|
||||||
|
|
||||||
|
value = parse_uint16(&s);
|
||||||
g_compiled[g_compiled_length++] = I_LDX;
|
g_compiled[g_compiled_length++] = I_LDX;
|
||||||
g_compiled[g_compiled_length++] = value >> 8;
|
g_compiled[g_compiled_length++] = value >> 8;
|
||||||
g_compiled[g_compiled_length++] = I_LDA;
|
g_compiled[g_compiled_length++] = I_LDA;
|
||||||
g_compiled[g_compiled_length++] = value & 0xFF;
|
g_compiled[g_compiled_length++] = value & 0xFF;
|
||||||
|
have_value_in_ax = 1;
|
||||||
// Push on the number stack.
|
|
||||||
add_call(pushax);
|
|
||||||
} else if (*s == '+') {
|
} else if (*s == '+') {
|
||||||
plus_count += 1;
|
plus_count += 1;
|
||||||
s += 1;
|
s += 1;
|
||||||
@ -391,9 +397,6 @@ static uint8_t *compile_expression(uint8_t *s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pop the last value from the number stack.
|
|
||||||
add_call(popax);
|
|
||||||
|
|
||||||
while (plus_count > 0) {
|
while (plus_count > 0) {
|
||||||
add_call(tosaddax);
|
add_call(tosaddax);
|
||||||
plus_count -= 1;
|
plus_count -= 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user