On 2010-11-18, at 8:11 AM, Oleg Parashchenko wrote:
Hello,
I compiled to GVM the following test program:
(declare (standard-bindings) (fixnum) (not safe)) (define mkadder (lambda (n) (lambda (x) (+ x n)))) (define add1 (mkadder 1)) (add1 1)
In the produced GVM code (below, slightly edited for mail posting), I see that the code of the lambda uses a closure in the register 4, but nowhere in the code I see an assigment to this register. What do I miss?
**** #<primitive | test2.o7|> = #line 2 "............" #1 0 entry-point 0 () ~#mkadder = '#<procedure ~#mkadder> #line 6 -1 = +0 +1 = '1 +0 = #3 -2 = . -3 = . -4 = . jump* 4 #2 #2 4 jump 4 ~#mkadder 1 #3 4 return-point ~#add1 = +1 #line 7 +1 = '1 +0 = -1 jump* 4 #4 #4 4 jump 0 ~#add1 1
**** #<procedure ~#mkadder> = #line 2 "................" #1 0 entry-point 1 () close -1 = (#2 +1) +1 = -1 jump 0 +0 #2 0 closure-entry-point 1 () +4 = +4(1) +1 = (##fx+ +1 +4) jump 0 +0
The setting of register 4 (i.e. "+4" in the GVM code) is a side effect of the jump instruction when a closure is being jumped to. Note that register 4 is unused at the moment of the jump because parameters are passed in 4 registers (+0=return address, +1=1st param, +2=2nd param, +3=3rd param). Register 4 will be set to the closure being called (i.e. register 4 is a "self" pointer). In your code this happens in the instruction "jump 0 +#add1 1" (the 0 is the new frame size and 1 is the argument count). The jumps with a star, i.e. "jump*", indicate that the jump includes a poll instruction (to check for stack overflow and interrupts).
What is your interest in the GVM code generated by Gambit?
Marc