alandipert / gherkin

a functional programming language and interpreter written in GNU Bash 4
https://tailrecursion.com/~alan/Lisp/GherkinHistory.html
BSD 3-Clause "New" or "Revised" License
522 stars 31 forks source link

GC broken #36

Open quoll opened 10 years ago

quoll commented 10 years ago

GC events corrupt the heap.

This can be shown by setting the heap_increment (and hence, the size of the initial heap) to 500, then execute:

gherkin -e '(load-file "core")'

Gherkin reports bad array subscripts when accessing cdr (one of the two arrays used for the heap).

The reason for the bad subscripts is because data has been unexpectedly placed into the given position of cdr. In this case, the code is attempting to process a recur operation and tries to look up data created by the analysis. However, another operation should be the one being processed, not the recur. The block containing the recur has not be analyzed for the recur frame, which is what leads to the cdr being looked up inappropriately.

The above is just symptomatic, and is specific to the operations being run and the size of the heap. In this case the recur is occupying the position being processed, but it should have been a different operation. The operation that ought to be there has been dropped during the GC, and reused by the recur code. We need to find out why it was not preserved.