User blog:LittlePeng9/Analysis of Loader's program

In this blog post I'm going to analyse how loader.c program works, based on full.c Loader provided. You can check out that last program here.

Note that I don't fully understand structure of the program itself, so if you could help me understand some parts of it, I'll be really thankful.

Analysis
typedef int Tree; typedef int INT; typedef int TREE; typedef int BitStream; Tree lastRight, accumulate; This is the header. Multiple types are defined, I suppose just for simplicity, or because this is required by compression Loader used to get 512-character program. DESCEND is defined to be the same as xx, if I understand correctly. It's used once on program, and the first thing I don't understand is what it's for. Two universal variables are also defined. TREE Pair (TREE yy, TREE xx) { return yy - ~yy << xx; } TREE Right (TREE xx) { return lastRight = xx % 2 ? 0 : 1 + Right (xx / 2); } TREE Left (TREE xx) { return xx / 2 >> Right (xx); } As Loader's program works on integers (of defined type TREE) way of encoding expressions is needed. Simple pairing is enough for this (function used is \(\langle yy,xx\rangle\rightarrow 2^{xx}(2\cdot yy+1)). Functions Left and Right just reverse the process. Note that when using function Right, result is stored in lastRight variable. Left function calls Right function, so lastRight is again overwriten with the result. // Encoding // PI(A,B) = Pair(0,Pair(A,B)) // LAMBDA(A,B) = Pair(1,Pair(A,B)) // APPLY(A,B) = Pair(2,Pair(A,B)) // STAR = Pair(3,0) = 7 // BOX = Pair(3,1) = 14 // VAR(n) = Pair(4+2n,0) = 9 + 4n [n >= 0] // The empty context is 0, and the context Gamma,A is Pair (A,Gamma). // STAR and BOX are the only terms x with (x&2)!=0 At this point Loader explains in comment the encoding used. As of yet I'm not exactly sure what each of these mean, but I guess I'll learn as I'm getting into the program.
 * 1) define DESCEND xx

Details of the above encodings are only needed to understand the program itself, because the Turing machine I'm going to make (YES, this will happen!) will use more obvious encoding. This is shorthand for special case of not-yet-defined function Subst. Basically, if xx encodes some CoC expression, Lift will replace every variable with different variable. I guess this is used when some new variable is introduced.
 * 1) define Lift(xx) Subst (4, 13, -4, xx)

Rest of analysis coming soon.