Discussion:
[Larceny-users] compiling using the twobit heap
Dimitris Vardoulakis
2009-04-25 21:28:35 UTC
Permalink
Hi,
which file in the source code shows what happens when I type a
definition in the repl?
For example, I can type
(define (id x) x)
(procedure? id)
#t

and a procedure is created which I can then call.
However, when I use the "assemble" and "compile" functions to compile
a lambda expression the result I get isn't a procedure (doesn't
satisfy procedure?).
(define exp1 '(lambda (x) x))
(define cexp1 (assemble (compile exp1)))
(procedure? cexp1)
#f
cexp1
(#vu8(187 16 0 0 0 139 69 12 141 68 24 4 131 224 248 5 0 1 0 0 57 224
118 6 255 85 16 144 235 231 139 93 12 45 0 1 0 0 137 69 12 199 3 254
12 0 0 86 139 118 1 139 70 5 137 67 4 139 70 9 94 137 67 8 137 115 12
128 195 7 195)
.
#((data #f)
(codevector
#vu8(131 251 4 116 17 199 69 44 4 0 0 0 255 149 0 2 0 0 144 144
235 234 137 203 195))
(constantvector #((data #(#f #f 1 #f #f (x)))))))
So, what else is happening when I send sth to the repl directly, vs
calling "assemble" and "compile" myself?
--
Dimitris
William D Clinger
2009-04-26 04:40:51 UTC
Permalink
Post by Dimitris Vardoulakis
which file in the source code shows what happens when I type a
definition in the repl?
src/Asm/Shared/link-lop.sch

Apparently the link-lop-segment procedure is not available at
top level in the twobit heap. If you want to use it yourself,
I think the best way to get at it is to add it to the list of
exported procedures in src/Build/seal-twobit.sch, and then
rebuild twobit.heap.

Will
Felix Klock
2009-04-27 12:31:17 UTC
Permalink
Dimitris-
Post by Dimitris Vardoulakis
which file in the source code shows what happens when I type a
definition in the repl?
Note that what happens when you type a definition in the repl depends
on what evaluator you are using, which differs between larceny.heap
and twobit.heap. In particular, the twobit heap uses an interpreter
as its evaluator, so it may be misleading to compare output of its
evaluator with the output of the composition of compile and assemble.

At the end of this message, I have included some interactions [1] that
may make this concrete; note how different (e.g. longer) the machine
code in slot 0 is for the interpreted identity than for the compiled
identity.
Post by Dimitris Vardoulakis
So, what else is happening when I send sth to the repl directly, vs
calling "assemble" and "compile" myself?
For the larceny.heap, the evaluator is defined in src/Build/iasn-
larceny-heap.sch; see the internal definition of the twobit procedure
in that file. There you will see a direct invocation of the link-lop-
segment procedure that Will discussed in his message..

For the twobit.heap, the evaluator is defined in src/Lib/Interpreter/
interp.sch; the comments at the top of that file are helpful for
understanding the implementation therein.

-Felix

[1] Some interactions illustrating the difference between the larceny
and twobit heaps:

% ./larceny -heap twobit.heap
Larceny v0.97a4 (alpha test) (Apr 15 2009 15:44:34, precise:Posix
Unix:unified)
twobit.heap, built on Mon Apr 27 08:13:46 EDT 2009
Post by Dimitris Vardoulakis
(evaluator)
#<PROCEDURE interpret>
Post by Dimitris Vardoulakis
(procedure-ref (lambda (x) x) 0)
#vu8(131 251 4 116 17 199 69 44 4 0 0 0 255 149 0 2 0 0 144 144 235
234 139 94 13 139 123 255 187 8 0 0 0 247 195 3 0 0 128 116 13 49 192
255 85 4 163 0 0 0 144 144 235 235 137 157 196 0 0 0 131 195 4 137 200
255 149 216 1 0 0 144 139 133 196 0 0 0 193 224 8 13 162 0 0 0 137 3
131 195 3 137 218 49 201 247 199 1 0 0 0 116 13 137 248 137 211 255
149 236 1 0 0 144 144 144 137 124 10 1 139 94 9 137 223 139 69 12 5 8
1 0 0 57 224 118 5 255 85 16 235 239 45 0 1 0 0 137 69 12 137 80 248
137 120 252 141 72 249 139 70 5 139 88 13 255 77 8 116 22 141 67 249
168 7 117 15 139 64 4 137 222 187 4 0 0 0 131 192 255 255 224 255 149
248 1 0 0 144 144 235 224)
Post by Dimitris Vardoulakis
^D
% ./larceny -heap larceny.heap
Larceny v0.97a4 (alpha test) (Apr 15 2009 15:44:34, precise:Posix
Unix:unified)
larceny.heap, built on Wed Apr 15 15:50:02 EDT 2009
Post by Dimitris Vardoulakis
(evaluator)
#<PROCEDURE twobit>
Post by Dimitris Vardoulakis
(procedure-ref (lambda (x) x) 0)
#vu8(131 251 4 116 17 199 69 44 4 0 0 0 255 149 0 2 0 0 144 144 235
234 137 203 195)
Post by Dimitris Vardoulakis
(evaluator interpret)
#<PROCEDURE interpret>
Post by Dimitris Vardoulakis
(evaluator)
#<PROCEDURE interpret>
Post by Dimitris Vardoulakis
(procedure-ref (lambda (x) x) 0)
#vu8(131 251 4 116 17 199 69 44 4 0 0 0 255 149 0 2 0 0 144 144 235
234 139 94 13 139 123 255 187 8 0 0 0 247 195 3 0 0 128 116 13 49 192
255 85 4 163 0 0 0 144 144 235 235 137 157 196 0 0 0 131 195 4 137 200
255 149 216 1 0 0 144 139 133 196 0 0 0 193 224 8 13 162 0 0 0 137 3
131 195 3 137 218 49 201 247 199 1 0 0 0 116 13 137 248 137 211 255
149 236 1 0 0 144 144 144 137 124 10 1 139 94 9 137 223 139 69 12 5 8
1 0 0 57 224 118 5 255 85 16 235 239 45 0 1 0 0 137 69 12 137 80 248
137 120 252 141 72 249 139 70 5 139 88 13 255 77 8 116 22 141 67 249
168 7 117 15 139 64 4 137 222 187 4 0 0 0 131 192 255 255 224 255 149
248 1 0 0 144 144 235 224)
Post by Dimitris Vardoulakis
^D
%

Loading...