Camto / calc

calc= is a small concatenative programming language for doing math in chats.
https://camto.github.io/calc
MIT License
13 stars 1 forks source link

Suggestion: Define enums as shorthand for sequential variables #4

Closed ghost closed 4 years ago

ghost commented 4 years ago

If you want to design a VM in calc= and are laying out your opcode definitions, you end up with code looking like this:

PUSH = 0; POP = 1; ADD = 2; SUB = 4; INC = 5; DEC = 7; MUL = 8; DIV = 9; JMP = 10; JZ = 11;

However, this can be easily simplified with a new enum declaration which is identical to the former code in function but more elegant in structure:

enum 10 PUSH, POP, ADD, SUB, INC, DEC, MUL, DIV, JMP, JZ

You define an enum of 10 values and then each of the next 10 identifiers (e.g. PUSH, POP) get defined relative to the first identifier (which is 0). Thus, we end up with PUSH=0, POP=1, etc... up to JZ=11.

Camto commented 4 years ago

Sounds great, but too much of a breaking change for the rewrite, which I want to keep very close to the current version. I'll think about it for the potential calc= v2.