Просмотр исходного кода

Shorten comparison/type check code

Lucas Stadler лет назад: 8
Родитель
Сommit
a9ffa6a0cc
1 измененных файлов с 10 добавлено и 13 удалено
  1. 10 13
      scm/inc/compiler.scm

+ 10 - 13
scm/inc/compiler.scm

33
(define (primcall-operand1 x)
33
(define (primcall-operand1 x)
34
  (cadr x))
34
  (cadr x))
35
35
36
(define (emit-compare)
37
  (emit "movl $0,  %eax")                ; zero %eax to put the result of the comparison into
38
  (emit "sete %al")                      ; set low byte of %eax to 1 if cmp succeeded
39
  (emit "sall $~a,  %eax" boolean-shift) ; construct correctly tagged boolean value
40
  (emit "xorl $31, %eax"))
41
36
(define (emit-expr x)
42
(define (emit-expr x)
37
  (cond
43
  (cond
38
    ((immediate? x)
44
    ((immediate? x)
51
        (emit "shrl $6, %eax"))
57
        (emit "shrl $6, %eax"))
52
       ((zero?)
58
       ((zero?)
53
        (emit-expr (primcall-operand1 x))
59
        (emit-expr (primcall-operand1 x))
54
        (emit "cmpl $0,  %eax")                ; x == 0
55
        (emit "movl $0,  %eax")                ; zero %eax to put the result of the comparison into
56
        (emit "sete %al")                      ; set low byte of %eax to 1 if cmp succeeded
57
        (emit "sall $~a,  %eax" boolean-shift) ; construct correctly tagged boolean value
58
        (emit "xorl $31, %eax"))
60
        (emit "cmpl $0,  %eax") ; x == 0
61
        (emit-compare))
59
       ((integer?)
62
       ((integer?)
60
        (emit-expr (primcall-operand1 x))
63
        (emit-expr (primcall-operand1 x))
61
        (emit "andl $~a, %eax" #b11)
64
        (emit "andl $~a, %eax" #b11)
62
        (emit "movl $0,  %eax")
63
        (emit "sete %al")
64
        (emit "sall $~a,  %eax" boolean-shift)
65
        (emit "xorl $31, %eax"))
65
        (emit-compare))
66
       ((boolean?)
66
       ((boolean?)
67
        (emit-expr (primcall-operand1 x))
67
        (emit-expr (primcall-operand1 x))
68
        (emit "andl $~a, %eax" #b0011111)
68
        (emit "andl $~a, %eax" #b0011111)
69
        (emit "cmpl $~a,  %eax" #b0011111)
69
        (emit "cmpl $~a,  %eax" #b0011111)
70
        (emit "movl $0,  %eax")
71
        (emit "sete %al")
72
        (emit "sall $~a,  %eax" boolean-shift)
73
        (emit "xorl $31, %eax"))
70
        (emit-compare))
74
       ))))
71
       ))))
75
72
76
(define (compile-program x)
73
(define (compile-program x)