EXAPUNKS

EXAPUNKS

View Stats:
SUGGESTION: function macro / JUMP <variable> instruction
I started fiddling around with Redshift, and found myself being annoyed by the fact that I can't create any function to handle common tasks. This heavily limits the game complexity you can create, without resorting to creating an external editor where I add a macro to inline functions.

I was thinking of 2 methods:

1) Macro - quality of life improvement without adding functionality to the language. Similar to what @rep and @end do:
@def FUN_NAME NOTE DO STUFF @end @call FUN_NAME
This would just copy/paste the function contents, effectively inlining them. That way we can have functions without extra functionality to the CPUs. The drawback is no support for recursion, but code can be designed around that limitation.

2) Instruction - Just the option to read a label from memory when jumping. For the problem code that isn't too useful, and is more efficiently written by using @rep and "JUMP LABEL@{0,1}". But for large codebases this allows for calling functions by creating a stack of program pointers.
< >
Showing 1-9 of 9 comments
You can semi-do 2)

Use a file as memory or something
jump to a main routing area where it checks the number in the file against other stuff and decide where to jump from there. So somehting like

Not very efficient of course, and I bet the example isn't efficient either :P (untested too)
JUMP START MARK ROUTER SEEK -9999 COPY F X TEST X = 1 TJMP F1C NOTE Error HALT MARK START NOTE Have some variable COPY 10 X SEEK 9999 COPY X F SEEK -9999 COPY 1 F JUMP F1 MARK F1C SEEK 9999 SEEK -1 NOTE The changed variable COPY F X MARK F1 SEEK 9999 SEEK -1 COPY F X TEST X > 5 SUB X 5 X SEEK -1 COPY X F JUMP ROUTER
I haven't needed to try this yet but I've been thinking along the same lines, ASM code has PUSH and POP for managing the "stack" and while there is no stack in EXA there are files and these could be used LIFO queues. Not having RAM is a huge (and interesting) constraint

A function with 4 params would PUSH to a file and POP off in reverse order after the JUMP.
I can't think of how you could use RET though since you can't copy a MARK label to a register. If you could you could "JUMP F" back to a label set after a function call (JUMP).

With only an X (and sometimes a T) register though it'd be hard to manage this.

You would have a hard time using these pseudo functions with files though since you can only hold one at a time... perhaps you could use the end of a file you are holding and then clean up at the end.



You'd use ret similar to how you do in my example, you write a variable to the stack, and then you use that to jump to a label, but as you said you can't jump directly, have to do multiple tests on it to jump to a set label.
Probably easier if you use some extra program to generate the code for you.
The trouble with the example always comes down to needing to enumerate every return point from any function. It's not the end of the world though, and I'll consider it as a design option. But a macro from 1) is still good enough for most tasks.
I think in the end that by the time you implement this kind of high level functionality you'll realize that the overhead isn't worth it for most cases in exapunks. It might help you solve a level by abstracting some of the lower level code but I think most people then optimise after seeing the histogram if they didn't do too well and this would be the first to go.
The macro might hide it from sight but you'll feel when you see the histogram.
Well the topic opens with "Fiddling around in Redshift" ;)
True, True
I may just create a language superset this weekend that transpiles into the basic language, purely focused on working with Redshift. Possibly using files and DATA commands to manage a stack. It would still be nice to be able to set jump targets as variables, but oh well.
couldn't you use EXAs as functions with the M register?
< >
Showing 1-9 of 9 comments
Per page: 1530 50