|
|
@ -38,49 +38,50 @@
|
|
38
|
38
|
(emit "sall $~a, %eax" boolean-shift) ; construct correctly tagged boolean value
|
|
39
|
39
|
(emit "xorl $~a, %eax" #b0011111))
|
|
40
|
40
|
|
|
41
|
|
(define (emit-expr x)
|
|
|
41
|
(define (emit-expr x si)
|
|
42
|
42
|
(cond
|
|
43
|
43
|
((immediate? x)
|
|
44
|
44
|
(emit "movl $~a, %eax" (immediate-rep x)))
|
|
45
|
|
((primcall? x)
|
|
46
|
|
(case (primcall-op x)
|
|
47
|
|
((add1)
|
|
48
|
|
(emit-expr (primcall-operand1 x))
|
|
49
|
|
(emit "addl $~a, %eax" (immediate-rep 1)))
|
|
50
|
|
((integer->char)
|
|
51
|
|
(emit-expr (primcall-operand1 x))
|
|
52
|
|
(emit "shl $6, %eax")
|
|
53
|
|
(emit "xorl $15, %eax"))
|
|
54
|
|
((char->integer)
|
|
55
|
|
(emit-expr (primcall-operand1 x))
|
|
56
|
|
(emit "shrl $6, %eax"))
|
|
57
|
|
((zero?)
|
|
58
|
|
(emit-expr (primcall-operand1 x))
|
|
59
|
|
(emit "cmpl $0, %eax") ; x == 0
|
|
60
|
|
(emit-compare))
|
|
61
|
|
((null?)
|
|
62
|
|
(emit-expr (primcall-operand1 x))
|
|
63
|
|
(emit "cmpl $~a, %eax" #b00101111)
|
|
64
|
|
(emit-compare))
|
|
65
|
|
((integer?)
|
|
66
|
|
(emit-expr (primcall-operand1 x))
|
|
67
|
|
(emit "andl $~a, %eax" #b11)
|
|
68
|
|
(emit-compare))
|
|
69
|
|
((char?)
|
|
70
|
|
(emit-expr (primcall-operand1 x))
|
|
71
|
|
(emit "andl $~a, %eax" #b11111111)
|
|
72
|
|
(emit "cmpl $~a, %eax" #b00001111)
|
|
73
|
|
(emit-compare))
|
|
74
|
|
((boolean?)
|
|
75
|
|
(emit-expr (primcall-operand1 x))
|
|
76
|
|
(emit "andl $~a, %eax" #b1111111)
|
|
77
|
|
(emit "cmpl $~a, %eax" #b0011111)
|
|
78
|
|
(emit-compare))
|
|
79
|
|
))))
|
|
|
45
|
((primcall? x) (emit-primitive-call x si))))
|
|
|
46
|
|
|
|
47
|
(define (emit-primitive-call x si)
|
|
|
48
|
(case (primcall-op x)
|
|
|
49
|
((add1)
|
|
|
50
|
(emit-expr (primcall-operand1 x) si)
|
|
|
51
|
(emit "addl $~a, %eax" (immediate-rep 1)))
|
|
|
52
|
((integer->char)
|
|
|
53
|
(emit-expr (primcall-operand1 x) si)
|
|
|
54
|
(emit "shl $6, %eax")
|
|
|
55
|
(emit "xorl $15, %eax"))
|
|
|
56
|
((char->integer)
|
|
|
57
|
(emit-expr (primcall-operand1 x) si)
|
|
|
58
|
(emit "shrl $6, %eax"))
|
|
|
59
|
((zero?)
|
|
|
60
|
(emit-expr (primcall-operand1 x) si)
|
|
|
61
|
(emit "cmpl $0, %eax") ; x == 0
|
|
|
62
|
(emit-compare))
|
|
|
63
|
((null?)
|
|
|
64
|
(emit-expr (primcall-operand1 x) si)
|
|
|
65
|
(emit "cmpl $~a, %eax" #b00101111)
|
|
|
66
|
(emit-compare))
|
|
|
67
|
((integer?)
|
|
|
68
|
(emit-expr (primcall-operand1 x) si)
|
|
|
69
|
(emit "andl $~a, %eax" #b11)
|
|
|
70
|
(emit-compare))
|
|
|
71
|
((char?)
|
|
|
72
|
(emit-expr (primcall-operand1 x) si)
|
|
|
73
|
(emit "andl $~a, %eax" #b11111111)
|
|
|
74
|
(emit "cmpl $~a, %eax" #b00001111)
|
|
|
75
|
(emit-compare))
|
|
|
76
|
((boolean?)
|
|
|
77
|
(emit-expr (primcall-operand1 x) si)
|
|
|
78
|
(emit "andl $~a, %eax" #b1111111)
|
|
|
79
|
(emit "cmpl $~a, %eax" #b0011111)
|
|
|
80
|
(emit-compare))))
|
|
80
|
81
|
|
|
81
|
82
|
(define (compile-program x)
|
|
82
|
83
|
(display ".globl scheme_entry\n\n")
|
|
83
|
84
|
(display "scheme_entry:\n")
|
|
84
|
85
|
|
|
85
|
|
(emit-expr x)
|
|
|
86
|
(emit-expr x 0)
|
|
86
|
87
|
(emit "ret"))
|