Sunday, July 4, 2010

Log 070410

The unserialization code works, for as far as I tested it on some primitive types and lists of those. I went for a full compile for change, which is a day long wait.

How many mistakes can you make in reading silly stuff, or implementing a straightforward API for that? The basic primitives for a reader are look, skip, and possibly, is_end; everything else is easily derivable from that. When interfacing with C what do I find: get, unget (limited to one char), fget, but no funget, and a bunch of other silly stuff. Now, I should have been more careful implementing the unserialization code, but man...

Saturday, July 3, 2010

A Piece of History

Sigh, its a long time since I've been working on this compiler. I started about five and a half years ago, after spending too much time on thinking about SAT solving and P?=NP, and decided I needed to think about something simple for change - I just puzzle 24 hrs a day, can't stop it. The development has been slow, due to much reading, intervening work, and after some medication, a series of psychoses, but ah well, it's getting there.

Games

And now, for something completely else. Hi was originally intended by me as a high-level language for writing games, though I think I am ending up with something which is more suitable for scientific calculations. Now simple functional languages aren't even that good at game code due to the fact unions of types are usually used for situations where in an OO language you'ld use simple inheritance which gives a much simpler approach. I.e., in a functional language, in a game, where you'ld want to manipulate a list of different character types, you'ld need to know a-priori what kind of characters go into that list, whereas in an OO language, you'ld define a list on an abstract interface for characters and derive different characters implementing that interface.

You can work around that problem a bit if you implement type classes, existential types, and simple coercions, which is what I did in Hi. (This actually means you're looking at a very complex solver, which cannot solve all puzzles presented. But, I don't care as long as it typechecks the constraints it is given, for the code it is presented. I rely on the programmer to guide the typechecker through it, and the fact that most programs just are not that complex.)

Since I am looking a looong compiles. I started patching up simple skeletal animation. (I don't know a lot of this, I ended up coding something simple with a small number of control points, where simulations are made a-la a physics engine. I minimize the square-root of the averaged squared distance to where I want those control points to be subject to a number of constraints.)

Friday, July 2, 2010

Log 070210

Typos, lots of typos and looooong compiles. It's not grabbing a coffee anymore, more like, make coffee, do laundry, create offspring, wave them off to high-school, and find out it still didn't finish. Good news is there don't seem to be logical errors in the compiler. I spotted one missed type error, usually that means I didn't pass a type constraint to the solver.

Wrote the AST serialization and unserialization code.

On Bootstrapping

The one big error I made in this project is that I should have sticked with ML as long as possible. Instead of writing an ML to C compiler, I went for an ML based AST-interpreter of Hi, which meant I could start writing in Hi as soon as possible, which is an advantage since I could debug various of the language but also means I am in deep now.

The other mistake was probably, not sure here, having started in ML (ocaml) instead of C in the first place. Not sure on this one.

Log 070210

Writing the unit tests for the serialization code. Since this is code which has to be compiled by the ocaml interpreted Hi to C, stage 1, compiler, I am again looking at not-even-snail-speed compiles. Got rid of a few bugs... (Guess I should print again. For some reason, staring at a screen for too long makes one word-blind.)

Woke up. Serialization works, now for the reverse, and the serialization code for the AST. I serialize text representations of integers since these are the closest primitives I had in the language. At some point, I should just serialize/write the bit representation directly. But that's, again, for later.

My mind is getting better; there were some thoughts again when I went to bed. One performance thought, I followed my stack representation faithfully, which means that when I push the first thunk in a series, inheriting code follows that thunk, and expansion with extra arguments (through a C call and a copy of the original thunk) is done afterwards, if necessary. Where I guessed necessary wouldn't be quite often. It doesn't make sense; I should factor that out and just generate the right code for the first thunk at some point - I'll leave it for now.

Thursday, July 1, 2010

Serialization, readers, writers, message queues and file descriptors

I looked at my serialization code, decided it was wrong, started rewriting it. So, first I rewrote it with abstract readers and writers. Great, to do that the right way I would need multiple parameter type classes; a reader r is some abstract construct reading things of type t. Solved that problem, in my head at least, it ain't difficult in my setting. Decided the multiple parameter type classes are for later, restricted the IO type to word. But then again, I already interface with C, and actually, file descriptors are then a better option than implementing heavy-weight reader and writer interfaces. Looked at file descriptors if I could use those as message queues for IPC, and behold, supported in Linux, not Posix, so not portable? What now?

Oh god, mmap for IPC?