jmeaster30 / ocean

A C-like programming language (get it like sea-like like an ocean lol)
GNU General Public License v3.0
0 stars 0 forks source link

Problems with arrays and layouts #73

Open jmeaster30 opened 9 months ago

jmeaster30 commented 9 months ago

When creating an array or layout there is no syntax for creating one directly on the stack. #43

This makes it so we have to do something like:

push vref myarray
alloc 5 u8
load

to get the array onto the stack. I wish there was just one instruction like:

alloc 5 u8

or

push 5 u8 default %pushes the default array of 5 u8s on the stack
push 5 u8 [1, 2, 3, 4, 5] %pushes the array [1, 2, 3, 4, 5] on the stack

or

new 5 u8 %pushes the default array of 5 u8s on the stack

Similar things for layouts

push layout main point

I kind of like alloc being the instruction and having store create a variable if a variable doesn't exist but I also like store requiring that the variable already exist

jmeaster30 commented 8 months ago

Well I made alloc array create an array and put it directly on the stack. alloc with any other type currently still makes the variable in the context

I think alloc making the variable on the stack makes the most sense but I may want to change the command to 'new' instead cause 'alloc' feels like it specifically messes with memory

Also does this conflict with the 'push' instruction? I think some serious consideration would have to be put into that as well. Something to note is Java bytecode doesn't really have a "push constant" instruction, they have a "load constant from constant pool" and a couple "load immediate X" but it goes from 0 to 5

jmeaster30 commented 8 months ago

Also java has a "newarray" and a "new" bytecode instruction which allocates memory in the VM's memory and puts the reference on the stack. However, I kind of want to have as much stuff on the stack as possible and generate code that can reference things from memory. Then we can probably do more with optimizing stuff but I also have no idea what I am talking about it is just a gut thing