This update was intended to be building decision trees into the language. I coded up some basic decision tree logic and looked at what I could improve to make my life easier. There was not much, so instead I turned towards making the language easier in general and here is what I changed:
ifstack ifelsestack – new logic operators, work just like ifgoto and ifelsegoto but instead of going to the selected label, they leave the selected item on the stack. So in practice:
FUNCTION: IF_TRUE condtion ifgoto B return IF_TRUE: A return
Can now be simplified to:
FUNCTION: A B condition ifelsestack return
This allows easy branching return structures without a ton of extra labels. I found it quite useful to make a function that returns either A or B, this used to be a hard to read goto block 4 lines long, now all easily done with one operator.
> (file insertion instruction) – this instruction will cause a file to be loaded in place in the instruction block. This allows for library creation and easier support code sharing across the boards. Usage is simple:
instructions: ... >import_library.il ...
var – Now that we have import libraries, we could end up with unintended naming collisions! So, to mitigate that issue, I have introduced var. Var works just like store, but creates the storage area in the local call stack created by using the call operator. Once the local call stack is removed via its matching return statement the variables will be removed.
New language Options
To help with readability, label names now allow underscores such as in: A_LABEL_NAME.
I have also added white space characters that will be ignored during parsing that you can use to meaningfully mark up your code. The current characters in the white space list are parenthesis () and commas , .
All Together Now
Overall I am quite happy with the new look of the language, its much more usable overall and is starting to look like a full language. Consider this importable library snippet as an example:
SPREAD_SHOT: (power var) (power 3 div) dupe dupe dupe #split shot power into 3 sections (aiming -1 add) aim fire (aiming 2 add) aim fire (aiming -1 add) aim fire SPREAD_SHOT DECSICION_ROOT (energy power >) ifelsestack return
We can now have functions that read like they have true function signatures, and group logically connected instructions into groups in complicated lines. We can also have locally named variables, and more efficiently build logical operations.