mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 20:45:06 +02:00
Check for divide by zero
This commit is contained in:
parent
a6d2cc0b7a
commit
a247ba03ad
1 changed files with 9 additions and 9 deletions
18
srfi/143.sld
18
srfi/143.sld
|
@ -60,14 +60,17 @@
|
||||||
(er-macro-transformer
|
(er-macro-transformer
|
||||||
(lambda (expr rename compare)
|
(lambda (expr rename compare)
|
||||||
(let* ((fnc (cadr expr))
|
(let* ((fnc (cadr expr))
|
||||||
(args
|
|
||||||
"(void* data, int argc, closure _, object k, object i, object j)")
|
|
||||||
(op-str (caddr expr))
|
(op-str (caddr expr))
|
||||||
|
(zero-check? (and (> (length expr) 3) (cadddr expr)))
|
||||||
|
(args "(void* data, int argc, closure _, object k, object i, object j)")
|
||||||
(body
|
(body
|
||||||
(string-append
|
(string-append
|
||||||
" Cyc_check_fixnum(data, i);
|
" Cyc_check_fixnum(data, i);
|
||||||
Cyc_check_fixnum(data, j);
|
Cyc_check_fixnum(data, j); "
|
||||||
object result = obj_int2obj(obj_obj2int(i) " op-str " obj_obj2int(j));
|
(if zero-check?
|
||||||
|
" if (obj_obj2int(j) == 0) { Cyc_rt_raise_msg(data, \"Divide by zero\");}"
|
||||||
|
"")
|
||||||
|
" object result = obj_int2obj(obj_obj2int(i) " op-str " obj_obj2int(j));
|
||||||
return_closcall1(data, k, result); ")))
|
return_closcall1(data, k, result); ")))
|
||||||
`(define-c ,fnc ,args ,body)))))
|
`(define-c ,fnc ,args ,body)))))
|
||||||
(define-syntax cmp-op
|
(define-syntax cmp-op
|
||||||
|
@ -88,11 +91,8 @@
|
||||||
(bin-num-op fx+ "+")
|
(bin-num-op fx+ "+")
|
||||||
(bin-num-op fx- "-")
|
(bin-num-op fx- "-")
|
||||||
(bin-num-op fx* "*")
|
(bin-num-op fx* "*")
|
||||||
|
(bin-num-op fxquotient "/" #t)
|
||||||
;; TODO: need a 0 check for these next 2. maybe need another macro for that
|
(bin-num-op fxremainder "%" #t)
|
||||||
(bin-num-op fxquotient "/")
|
|
||||||
(bin-num-op fxremainder "%")
|
|
||||||
|
|
||||||
(cmp-op fx=? "==")
|
(cmp-op fx=? "==")
|
||||||
(cmp-op fx<? "<")
|
(cmp-op fx<? "<")
|
||||||
(cmp-op fx>? ">")
|
(cmp-op fx>? ">")
|
||||||
|
|
Loading…
Add table
Reference in a new issue