Mayedl10 / BFIL

Brainfuck intermediate language
Do What The F*ck You Want To Public License
5 stars 0 forks source link

idea/todo: variables and arrays #13

Open Mayedl10 opened 8 months ago

Mayedl10 commented 8 months ago

make the compiler scan the tokens for unused memory addresses (ie. not reserved & not directly referenced) syntax:

var <name>
arr <name> <const size>

setVar <name> ~ <constant value>
setArr <name> <constant index> ~ <constant value>
fillArr <name> ~ <constant value>

This is equivalent to using memory addresses, but the programmer doesn't have to directly specify them. This way, there can also be local variables.

Mayedl10 commented 8 months ago

I'm just gonna paste my todo.md for this issue here. #

const <name> ~ <constant value>
var <name> ~ <constant value>
arr <name> <const size> # no initializer value(s)! arrays are size-prefixed, meaning that arr[0] is the size. bc of this, arrays' indexes start at 1 #

setVar <name> ~ <constant value>                    # not neccesary as it basically translates variable names to addresses at comp time. you can just use load. won't implement #

setArr <name> <constant index> ~ <constant value>   # array[index] = value      /       load [array+index] ~ value #

fillArr <name> ~ <constant value>

arrOut <arrayName>
vArrOut <arrayName> # value array output #

examples:

const newline ~ 10

var age ~ 16
arr name 7      # use the amount of usable space you want +1 to account for the size prefix #

setArr name 1 ~ 68
setArr name 2 ~ 97
setArr name 3 ~ 110
setArr name 4 ~ 105
setArr name 5 ~ 101
setArr name 6 ~ 108

arrOut name

fillArr name ~ 69

vArrOut name ~ ?10

aout 1 name[1]  # whoa indexing! basically works like this: foo[bar] = *(foo+bar). index values are constant and known at compile time #

note that some of this may change or not be implemented. It may also get delayed to a future update.

Mayedl10 commented 8 months ago

alr so either I don't add indexing or I add a second lexing/parsing process before the main one that just looks for [n]