Selaa lähdekoodia

Implement integer? and boolean? predicates

Lucas Stadler 8 vuotta sitten
vanhempi
commit
c9bc3c40e3
1 muutettua tiedostoa jossa 16 lisäystä ja 1 poistoa
  1. 16 1
      scm/inc/compiler.scm

+ 16 - 1
scm/inc/compiler.scm

56
        (emit "sete %al")                      ; set low byte of %eax to 1 if cmp succeeded
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
57
        (emit "sall $~a,  %eax" boolean-shift) ; construct correctly tagged boolean value
58
        (emit "xorl $31, %eax"))
58
        (emit "xorl $31, %eax"))
59
       ((integer?)
60
        (emit-expr (primcall-operand1 x))
61
        (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"))
66
       ((boolean?)
67
        (emit-expr (primcall-operand1 x))
68
        (emit "andl $~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"))
59
       ))))
74
       ))))
60
75
61
(define (compile-program x)
76
(define (compile-program x)
65
  (emit-expr x)
80
  (emit-expr x)
66
  (emit "ret"))
81
  (emit "ret"))
67
82
68
(compile-program '(zero? -1))
83
(compile-program '(boolean? #f))