Archive for September, 2008

I am an idiot.

Posted in LISP, nonsense, programming with tags , , on September 11, 2008 by bbarrett

I have just figured out where I am going wrong. All my variables are stored on the LISP stack, which is a std::vector<Cell> instance, (Cell is the variable type). Some of these Cells themselves contain Standard C++ Library objects (lists use std::list<>, functions are std::vector<Instruction>, strings are std::strings), and references to those objects are stored on the C++ stack during operation.

A few functions deep, when stuff keeps being added to the stack, it eventually will reallocate and… boom, all my iterators and references die a horrible death. Took quite a while to figure out that this was going on, I was preoccupied with assuming there was an issue with the Cell’s implementation of the Rule Of Three. I had already had issues with that, as I mentioned before.

For the moment, a “quick fix” is to manually set the initial stack size quite high. I think with this my current implementation works fine, but I hate such an ugly fix, which is too brittle anyway. I could choose std::list<>, so elements won’t be moved around in memory, but there might be another way.

That took far too long to diagnose…

Quick update

Posted in Uncategorized with tags on September 7, 2008 by bbarrett

I’ve been pushing off writing the update for some time, being both too busy to finish my implementation and plagued with issues with the code as it is right now. In an effort to move me forward, I will write a note that I hope will motivate me to action.

I am very close to completing a large re-organisation of the codebase. I think the only major outstanding bug is that my call stack is being corrupted somehow. From inspection of the code, a function should remove all its arguments and push its result, but somewhere (1 place in particular) this isn’t occuring. While debugging it, I decided that this might be a good opportunity to throw together a quick debugger for my new language, but currently only implemented at the Interpreter “byte code” level. It allows me to step through, and over code, to inspect variables and to examine the contents of the stack. This gives the advantage that I can skip large bodies of C++ which have nothing to do with the problem when it is a “high level” issue, rather than a bad pointer or something.

On the subject of bad pointers, I fixed a bug with my variable class. Apparently my assignment operator made the assumption that the old and new objects shared the same type. Obviously, some serious pointer corruption issues occur when calling delete on standard library objects throught the wrong type. I really can’t believe that I missed that.

Since I am finished working tomorrow, I should have more time to get this thing working. I have some ideas once I get to that stage to start doing some things in this langauge that aren’t in LISP (AFAIK, the poor language has how many illegitimate children?).