blob: a2dde2d3858d7699f13d80d18623c3a51b55b7df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
(define-module (modules tuple-generator tuple-generator)
#:use-module (ice-9 receive)
#:use-module (modules utils t-factory)
#:use-module (modules ast syntax-tree)
#:use-module (modules ast assembly-tree)
#:export (t-program))
(define (t-program p)
(make-program (t-function (program-function p))))
(define (t-function f)
(make-subroutine (t-id (function-id f))
(t-stmt (function-stmt f))
#f))
(define (t-stmt s)
(receive (src instrs) (t-expr (stmt-expr s))
(append instrs
(list (make-instruction (make-register 'eax) 'mov src #f)
(make-instruction #f 'ret #f #f)))))
(define (t-expr e)
(cond
((unary? e)
(receive (src instrs) (t-expr (unary-expr e))
(let ((dest (make-temporary)))
(values dest
(append instrs
(list (make-instruction dest 'mov src #f)
(make-instruction dest (unary-operator e) #f #f)))))))
(#t (values e '()))))
(define (t-id i)
(id-symbol i))
|