From: Charles Z. <ka...@be...> - 2018-05-22 04:33:14
|
Hi Bruno, Good news! I had done exactly that this past week and I managed to hack enough to get closures and nested functions working. There wasn't a need to directly modify the clisp functions themselves; I could just rip out enough of the functionality from compile/pass2 into a separate function so I could finish compiling everything. The trick was filling in just enough of fnode to get it to act as a surrogate to the LAP generated by Cleavir. Now I am able to get, for example, (lambda (n) (dotimes (i n) (print n)) compiled all the way to an executable function. CLEAVIR-CLISP> (funcall (cleavir-compile '(lambda (n) (dotimes (i n) (print i)))) 5) 0 1 2 3 4 NIL and even '(lambda (x z) (cons (lambda (y) (+ y z)) (lambda (w) (lambda (y) (+ x y w))))) now compiles and executes correctly. I found that SICL produces a graph structure that models enclosed function allocation, while CLISP prefers enclosing function allocation (so hence, for example, the two inner lambdas share the outer lambda closure vector). I wonder if there's a specific rationale for doing so in CLISP. The sharing can save on allocation, but there's a possibility of some garbage remaining. Also, I am keeping track of my branch here: https://gitlab.com/karlosz/clisp You can test it by having SICL in a quicklisp aware place and loading clisp/src/cleavir/load.lisp and testing the examples above with (cleavir-clisp:cleavir-compile form). If you are curious, the way I managed to hack the closures together and finish the compilation pipeline is listed in tools.lisp and the translate-simple-instruction -- enclose-instruction method. There are still some silly miscompilations with nested function calls, so not quite there yet! Charles On Mon, May 21, 2018 at 8:28 PM, Bruno Haible <br...@cl...> wrote: > Charles Zhang wrote: >> Quick update on the previous example: I cleaned up and added support >> for using more of CLISP's call ops, instead of just punting to the >> computed funcall routine. >> >> So now the form >> (lambda (x y) (if (= x y) (1+ x) (+ x y))) >> compiles to >> (LOAD 2) >> (PUSH) >> (LOAD 2) >> (PUSH) >> (CALLSR 1 47) > > Ah, cool, the FDEFINITION is optimized out! Nice. > > Bruno > -- Class of 2021 |