496
The Axe Parser Project / Re: Features Wishlist
« on: April 09, 2011, 05:15:53 am »
^ Not really. Pseudo-wrapping in the horizontal direction is smaller, but its not real wrapping because the half sprite on the right side of the screen would be shifted down by one pixel and additional clipping would be needed for the last row so it wouldn't leak into memory after the screen. This is better suited for an Axiom though since wrapping is rarely needed and can be done easily with 2 sprites.
Anyway, I came up with a new advanced syntax idea! I was thinking of allowing programmers to take advantage of the stack the z80 offers but I'm concerned about memory leaks this could cause and undesired conflicts when calling routines since Axe uses the same stack behind the scenes. But then I realized there is a way I could do it that would be both easy to use and be impossible to leak memory. The solution is to:
1) Only allow the pair if they are in the same scope. I define scope loosely... it has to fit on one line, but CAN intersect most single argument commands.
2) Require a pop for each push in that scope or else throw a syntax error.
3) Allow automatic integration into the right-hand side of binary operations.
For a non-technical explanation: Think of it as storing a value (maybe the result of a large computation) to a place you want to read later without having to use a temporary variable or do the computation again. You can nest as many of these as you want without concern about memory. I decided to use the pi character (π) to implement this. Storing to it pushes the variable and reading from it pops it.
For example here is code to swap the values of 2 variables using a temporary:
Another example:
When nesting, the most recent store to the stack is the one that gets read when you read from the stack. Here is a pairing example:
A->π
B->π
C->π
π->D
π->E
F->π
π->G
π->H
I'm hoping this will lead to more possibilities to optimize code. I know at least one individual will have a field day with this Let me know if anyone, especially asm programmers, have questions or concerns. It seems to work in my head, but I haven't tried implementing it so there may be some unforeseen problems.
Anyway, I came up with a new advanced syntax idea! I was thinking of allowing programmers to take advantage of the stack the z80 offers but I'm concerned about memory leaks this could cause and undesired conflicts when calling routines since Axe uses the same stack behind the scenes. But then I realized there is a way I could do it that would be both easy to use and be impossible to leak memory. The solution is to:
1) Only allow the pair if they are in the same scope. I define scope loosely... it has to fit on one line, but CAN intersect most single argument commands.
2) Require a pop for each push in that scope or else throw a syntax error.
3) Allow automatic integration into the right-hand side of binary operations.
For a non-technical explanation: Think of it as storing a value (maybe the result of a large computation) to a place you want to read later without having to use a temporary variable or do the computation again. You can nest as many of these as you want without concern about memory. I decided to use the pi character (π) to implement this. Storing to it pushes the variable and reading from it pops it.
For example here is code to swap the values of 2 variables using a temporary:
Code: [Select]
A->T B->A T->B
Here is the same code using the stack instead.Code: [Select]
A->π B->A π->B
Since each variable read or write is 3 bytes, but each stack read or write is only 1 byte, this code saves 4 bytes and is slightly faster.Another example:
Code: [Select]
{A*3}->X {A*3+1}->Y {A*3+2}->Z
Here is a case where you can nest them together:Code: [Select]
{A*3->π->π}->X {π+1}->Y {π+2}->Z
This saves a HUGE amount of memory.When nesting, the most recent store to the stack is the one that gets read when you read from the stack. Here is a pairing example:
A->π
B->π
C->π
π->D
π->E
F->π
π->G
π->H
I'm hoping this will lead to more possibilities to optimize code. I know at least one individual will have a field day with this Let me know if anyone, especially asm programmers, have questions or concerns. It seems to work in my head, but I haven't tried implementing it so there may be some unforeseen problems.