Stack-Based Languages: Pros/Cons of a Register?

244 Views Asked by At

I'm currently designing an esoteric stack-based programming language for code golf (International Phonetic Esoteric Language/IPEL) that, in its current spec, has a stack of values that the user can modify.

However, after trying some simple challenges (and coming from a more procedural and OOP background), I've been considering adding a single register and its associated instructions (stack → reg, reg → stack, etc) for the user to use. (This was in the version -1 language spec, but I decided to axe it in favor of pure stack manipulation.)

What are the pros and cons of having a user-modifiable register in a stack-based language?

1

There are 1 best solutions below

1
On

It seems to me that the primary benefit of a stack-based language is that you don't have to worry about what registers might be used in subroutines, so you don't have to do any saving/restoring or register allocation.

Your single register sounds like it would mess that up.

You probably already have a call/execution stack, a value/parameter stack, and a symbol table. If those really won't do, then adding another value stack would probably be more useful than adding a register. The two stacks and symbol table you already have should really be enough, though.