Quellcode durchsuchen

Shorten comparison/type check code

Lucas Stadler vor 8 Jahren
Ursprung
Commit
a9ffa6a0cc
1 geänderte Dateien mit 10 neuen und 13 gelöschten Zeilen
  1. 10 13
      scm/inc/compiler.scm

+ 10 - 13
scm/inc/compiler.scm

@ -33,6 +33,12 @@
33 33
(define (primcall-operand1 x)
34 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 42
(define (emit-expr x)
37 43
  (cond
38 44
    ((immediate? x)
@ -51,26 +57,17 @@
51 57
        (emit "shrl $6, %eax"))
52 58
       ((zero?)
53 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 62
       ((integer?)
60 63
        (emit-expr (primcall-operand1 x))
61 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 66
       ((boolean?)
67 67
        (emit-expr (primcall-operand1 x))
68 68
        (emit "andl $~a, %eax" #b0011111)
69 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 73
(define (compile-program x)