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

Implement integer->char and char->integer

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

+ 9 - 2
scm/inc/compiler.scm

38
     (case (primcall-op x)
38
     (case (primcall-op x)
39
       ((add1)
39
       ((add1)
40
        (emit-expr (primcall-operand1 x))
40
        (emit-expr (primcall-operand1 x))
41
        (emit "addl $~a, %eax" (immediate-rep 1)))))))
41
        (emit "addl $~a, %eax" (immediate-rep 1)))
42
       ((integer->char)
43
        (emit-expr (primcall-operand1 x))
44
        (emit "shl $6, %eax")
45
        (emit "xorl $15, %eax"))
46
       ((char->integer)
47
        (emit-expr (primcall-operand1 x))
48
        (emit "shrl $6, %eax"))))))
42
49
43
(define (compile-program x)
50
(define (compile-program x)
44
  (display ".globl scheme_entry\n\n")
51
  (display ".globl scheme_entry\n\n")
47
  (emit-expr x)
54
  (emit-expr x)
48
  (emit "ret"))
55
  (emit "ret"))
49
56
50
(compile-program '(add1 41))
57
(compile-program '(char->integer #\y))