Closed ap29600 closed 2 years ago
Stack should be used for storing values that size know in compile time.
ref
introduces value aliasing and makes static analysis useless
you can alternatively call the mmap syscall and get some memory, this is obviously a bit overkill but unless there isnt any malloc functionality this is the only way to not clobber any memory. Also don forget to call munmap
yep, makes sense to me.
here another way you can implement putd without mem
A simple operation that pushes a pointer to the element that is currenlty on the top of the stack.
With this functionality it's possible to allocate a temporary buffer on the stack by repeatedly pushing 0, and this enables to implement putd without a static buffer in memory, so putd can now be in the standard library.
As a sidenote, building
gol.porth
will now fail due to the macro name collision.There is one drawback, and that is that this will create a discrepancy between simulation and compilation, as there is no easy way to implement this in python I think. Assuming that the stack is contiguous in memory in the bootstrapped version, there should really be no problem after that.