Compiling into Linklets

31 views
Skip to first unread message

Paulo Matos

unread,
Jul 2, 2019, 6:42:58 AM7/2/19
to Racket Users
Hi,

I am slowly getting the hang of linklets and I am playing with them in
my spare free time.

As far as I understand the current way to obtain linklets is to use
bootstrap-run.rkt in racket/src/expander.

I wrote a simple interactive program split into two modules:
factorial-input.rkt:
#lang racket/base

(require "factorial.rkt")

(let loop ()
(printf "Enter a number: ")
(define n (read))
(cond
[(exact-positive-integer? n)
(printf "~a! = ~a~n" n (factorial n))]
[else
(printf "Invalid value~n")
(loop)]))


factorial.rkt:
#lang racket/base

(provide factorial)

(define (factorial n)
(if (= n 1)
1
(* n (factorial (- n 1)))))

Now I would like to compile the whole thing into linklets, so I try from
today's master branch HEAD:
racket/src/expander $ racket bootstrap-run.rkt --linklets -s -o
factorial-input.ll.rkt -t
/home/pmatos/Projects/redjacket/examples/factorial-input.rkt

First thing that tripped me up was that the output went to the terminal
instead of the file factorial-input.ll.rkt.

However, the biggest concern I had was that even though one of the lines
in the terminal says:
compile: /home/pmatos/Projects/redjacket/examples/factorial.rkt

followed by:
#hasheq((#f
.
#hasheq((0
.
(linklet
((.get-syntax-literal!)
(.set-transformer!)
((read 1/read))
(factorial)
(print-values))
()
(void)
(call-with-values
(lambda ()
((letrec-values (((loop_1)
(lambda ()
(begin
'loop
(let-values ((()
(begin
(printf
"Enter a
number: ")
(values))))
(let-values (((n_2) (1/read)))
(if (exact-positive-integer?
n_2)
(let-values ()
(printf
"~a! = ~a~n"
n_2
(factorial n_2)))
(let-values ()
(begin
(printf
"Invalid value~n")
(loop_1))))))))))
loop_1)))
print-values)
(void)))
(data
.
(linklet
((deserialize-module-path-indexes
syntax-module-path-index-shift
syntax-shift-phase-level
module-use
deserialize))
(.mpi-vector)
(define-values (.inspector) (current-code-inspector))
(define-values
(.mpi-vector)
(deserialize-module-path-indexes
'#(#('#%read)
#&factorial-input
#("factorial.rkt" 1)
#(racket/base)
#("private/base.rkt" 3)
#("pre-base.rkt" 4)
#("modbeg.rkt" 5))
'#(0 2 6 1 3)))))
(decl
.
(linklet
((deserialize-module-path-indexes
syntax-module-path-index-shift
syntax-shift-phase-level
module-use
deserialize)
(.mpi-vector))
(self-mpi requires provides phase-to-link-modules)
(define-values
(self-mpi)
(unsafe-vector*-ref .mpi-vector 3))
(define-values
(requires)
(let-values (((data)
'#(#()
#()
#()
#(#:cons #:list 3 0 #:mpi 4 #:mpi 1
()))))
(deserialize
.mpi-vector
#f
#f
'0
(unsafe-vector*-ref data 0)
'0
(unsafe-vector*-ref data 1)
(unsafe-vector*-ref data 2)
(unsafe-vector*-ref data 3))))
(define-values
(provides)
(let-values (((data) '#(#() #() #() #(#hasheqv()))))
(deserialize
.mpi-vector
#f
#f
'0
(unsafe-vector*-ref data 0)
'0
(unsafe-vector*-ref data 1)
(unsafe-vector*-ref data 2)
(unsafe-vector*-ref data 3))))
(define-values
(phase-to-link-modules)
(hasheqv
0
(list
(module-use (unsafe-vector*-ref .mpi-vector 0) 0)
(module-use (unsafe-vector*-ref .mpi-vector 1) 0)
(module-use (unsafe-vector*-ref .mpi-vector 2) 0))))))
(name . factorial-input)
(pre . (configure-runtime))
(side-effects . (0))))
(configure-runtime
.
#hasheq((#f
.
#hasheq((0
.
(linklet
((.get-syntax-literal!)
(.set-transformer!)
(configure))
()
(void)
(configure #f)
(void)))
(data
.
(linklet
((deserialize-module-path-indexes
syntax-module-path-index-shift
syntax-shift-phase-level
module-use
deserialize))
(.mpi-vector)
(define-values
(.inspector)
(current-code-inspector))
(define-values
(.mpi-vector)
(deserialize-module-path-indexes
'#(#(racket/runtime-config)
#&(factorial-input configure-runtime)
#('#%kernel))
'#(0 1 2)))))
(decl
.
(linklet
((deserialize-module-path-indexes
syntax-module-path-index-shift
syntax-shift-phase-level
module-use
deserialize)
(.mpi-vector))
(self-mpi requires provides
phase-to-link-modules)
(define-values
(self-mpi)
(unsafe-vector*-ref .mpi-vector 1))
(define-values
(requires)
(let-values (((data)
'#(#()
#()
#()
#(#:cons
#:list
3
0
#:mpi
2
#:mpi
0
()))))
(deserialize
.mpi-vector
#f
#f
'0
(unsafe-vector*-ref data 0)
'0
(unsafe-vector*-ref data 1)
(unsafe-vector*-ref data 2)
(unsafe-vector*-ref data 3))))
(define-values
(provides)
(let-values (((data)
'#(#() #() #() #(#hasheqv()))))
(deserialize
.mpi-vector
#f
#f
'0
(unsafe-vector*-ref data 0)
'0
(unsafe-vector*-ref data 1)
(unsafe-vector*-ref data 2)
(unsafe-vector*-ref data 3))))
(define-values
(phase-to-link-modules)
(hasheqv
0
(list
(module-use
(unsafe-vector*-ref .mpi-vector 0)
0))))))
(name . (factorial-input configure-runtime))
(side-effects . (0)))))))


This linklet does not contain the definition of factorial. This is
probably my bad assumption but I thought I would get a linklet directory
with everything in the original application. Is there a current way to
do this?

Or the solution is to go manually through the requires in the original
source and run the linklet extraction for each of them?

--
Paulo Matos
Reply all
Reply to author
Forward
0 new messages