Explorar el Código

Implement basic - and *

Although multiplication doesn't work, because the `mul` instruction
seems to be a bit special.
Lucas Stadler %!s(int64=8) %!d(string=hace) años
padre
commit
a361ef0cbb
Se han modificado 2 ficheros con 18 adiciones y 1 borrados
  1. 10 0
      scm/inc/compiler.scm
  2. 8 1
      scm/inc/tests.scm

+ 10 - 0
scm/inc/compiler.scm

@ -159,6 +159,16 @@
159 159
     (emit "movl %eax, ~a(%rsp)" si) ; move second arg on the stack
160 160
     (emit-expr (primcall-operand1 x) (- si wordsize) env)
161 161
     (emit "addl ~a(%rsp), %eax" si))
162
    ((-)
163
     (emit-expr (primcall-operand2 x) si env)
164
     (emit "movl %eax, ~a(%rsp)" si) ; move second arg on the stack
165
     (emit-expr (primcall-operand1 x) (- si wordsize) env)
166
     (emit "subl ~a(%rsp), %eax" si))
167
    ((*)
168
     (emit-expr (primcall-operand2 x) si env)
169
     (emit "movl %eax, ~a(%rsp)" si) ; move second arg on the stack
170
     (emit-expr (primcall-operand1 x) (- si wordsize) env)
171
     (emit "mull ~a(%rsp), %eax" si))
162 172
    ((cons)
163 173
     (emit-expr (primcall-operand1 x) si env)
164 174
     (emit "movl %eax, 0(%rsi)") ; set the car

+ 8 - 1
scm/inc/tests.scm

@ -106,7 +106,14 @@
106 106
    ["(+ 0 0)" "0\n"]
107 107
    ["(+ 41 1)" "42\n"]
108 108
    ["(+ 1 41)" "42\n"]
109
    ["(+ -10 11)" "1\n"]])
109
    ["(+ -10 11)" "1\n"]
110
111
    ["(- 1 2)" "-1\n"]
112
    ["(- 42 0)" "42\n"]
113
    ["(- 0 42)" "-42\n"]
114
115
    ;["(* 3 4)" "12\n"]
116
    ])
110 117
111 118
(do-tests "3.5 - local variables"
112 119
  '[["(let ((x 3) (y 4)) (+ x y))" "7\n"]