









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The process of running functional abstract machine (fae) programs natively by simplifying the representation of continuations and replacing symbols with numbers. Steps such as building simpler continuations as records, applying continuations as records, replacing symbols with numbers, and eliminating datatypes using a single datatype and case. The ultimate goal is to optimize the fae program for efficient execution.
Typology: Study notes
1 / 17
This page cannot be seen from the preview
Don't miss anything!










->^ alpha)
-> alpha
(define
(interp a-fae
sc^ k)
...[add^ (l
r)^ (interp
l sc(lambda
(v1)(interp^ r sc(lambda
(v2)(k (num+^ v1 v2))))))]
SubCache (FAE-Value
->^ alpha)
-> alpha
(define
(interp
a-fae
sc^ k)
...[num (n)
(k (numV
n))]
...)
SubCache FAE-Cont
->^ FAE-Value
(define
(interp
a-fae
sc^ k)
...[num (n)
(continue
k (numV
n))]
[add (l
r) (interp
l sc^
(addSecondK
r sc k))]
...); continue
: FAE-Cont
FAE-Value
-> FAE-Value
(define
(continue
k v) (type-case
FAE-Cont
k
[mtK ()
v] [addSecondK (r sc
k)(interp^ r sc
(doAddK
v k))]
(define-type
...[id^ (name
symbol?)] ...)(define-type
...[cid^ (pos
number?)] ...)
:^ FAE CSubCache
->^ CFae
(define
(compile a-fae
sc)
(type-case
FAE a-fae ...[id (name)
(cid^
(locate
name^
sc))]
[fun (param body-expr)(cfun (compile
body-expr
(aCSub
param
sc)))]
(interp^ a-fae
sc^ k) (type-case
CFAE^ a-fae[cnum (n) (continue
...)] [cadd (l r) (interp
...)] [csub (l r) (interp
...)] [cid (pos) (continue
...)] [cfun (body-expr) (continue
...)] [capp (fun-expr
arg-expr) (interp
...)]
[cif0 (test-expr
then-expr
else-expr) (interp
...)]))
(define^ (continue
k v) (type-case
CFAE-Cont
k [mtK ()^ v][addSecondK
(r sc^ k) (interp
...)] [doAddK (v
k) (continue
...)] [subSecondK
(r sc^ k) (interp
...)] [doSubK (v
k) (continue
...)] [appArgK (arg-expr
sc^ k) (interp
...)]
[doAppK (fun-val
k) (interp
...)] [doIfK (then-expr
else-expr
sc^ k) (if
(numzero?
v)(interp ...)(interp ...))]))
(interp a-fae sc
k)
(type-case
CFAE a-fae ...[cadd (l
r)(interp l
sc(addSecondKr^ sc k))] ...))
fae-reg
(cnum^
0))
(define
sc-reg
empty) ; interp
: -> void (define
(interp)(type-case^ CFAE
fae-reg ...[cadd^ (l r)(begin
(set!^ fae-reg
l) (set!^ k-reg(addSecondK
r sc-reg
k-reg)) (interp))] ...))^
(type-case
CFAE^ fae-reg ...[cadd (l
r)...(set!^ k-reg
(addSecondK
r sc-reg
k-reg))
...])
(case (fst^ fae-reg)...[(9)...(set!^ k-reg (kons
1 (kons^
(rst^ (rst
fae-reg)) (kons^ sc-reg
k-reg))))
...])
memory^
(make-vector
2048))
(define
ptr^ 0) ; kons^
: number
number
->^ number
(define
(kons^
a b) (begin(vector-set!
memory
ptr^ a) (vector-set!
memory
(+ ptr
(set!^ ptr
(+ ptr
2)) (- ptr^
2))) ; fst^ : number
->^ number (define
(fst^ n)(vector-ref^
memory^
n))
; rst^ : number
->^ number (define
(rst^ n)(vector-ref^
memory^
(+ n 1)))