mes: Identify 64-bit bug when compiled with MesCC.

* src/math.c (divide): Add divide-by-zero error.
(modulo): Likewise.
* module/mes/guile.scm (%compiler): New variable.
* module/mescc/M1.scm (mesc?): New variable.
(hex2:immediate8): Use it to avoid divide-by-zero error.
* HACKING (Bugs): Add it.
This commit is contained in:
Jan Nieuwenhuizen 2019-05-27 21:33:20 +02:00
parent 952b92dfec
commit a22e5d3acc
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
4 changed files with 26 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@ -45,6 +45,7 @@
core:write-error
core:write-port
core:type
%compiler
equal2?
pmatch-car
pmatch-cdr
@ -83,6 +84,8 @@
(define <cell:symbol> 11)
(define <cell:vector> 15)
(define %compiler "gnuc")
(define (core:type x)
(cond ((guile:keyword? x) <cell:keyword>)
((guile:number? x) <cell:number>)

View File

@ -81,13 +81,16 @@
(if hex? (string-append "%0x" (dec->hex o))
(string-append "%" (number->string o))))
(define mesc? (string=? %compiler "mesc"))
(define (hex2:immediate8 o)
(if hex? (string-append "%0x" (dec->hex (modulo o #x100000000))
;; FIXME: #x100000000 => 0 divide-by-zero when compiled with 64 bit mesc
(if hex? (string-append "%0x" (dec->hex (if mesc? 0 (modulo o #x100000000)))
" %0x" (if (< o 0) "-1"
(dec->hex (quotient o #x100000000))))
(string-append "%" (number->string (dec->hex (modulo o #x100000000)))
(dec->hex (if mesc? o (quotient o #x100000000)))))
(string-append "%" (number->string (dec->hex (if mesc? 0 (modulo o #x100000000))))
" %" (if (< o 0) "-1"
(number->string (dec->hex (quotient o #x100000000)))))))
(number->string (dec->hex (if mesc? o (quotient o #x100000000))))))))
(define* (display-join o #:optional (sep ""))
(let loop ((o o))

View File

@ -128,9 +128,12 @@ divide (SCM x) ///((name . "/") (arity . n))
while (x != cell_nil)
{
assert_number ("divide", CAR (x));
long y = VALUE (CAR (x));
if (y == 0)
error (cstring_to_symbol ("divide-by-zero"), x);
if (!n)
break;
n /= VALUE (car (x));
n /= y;
x = cdr (x);
}
return MAKE_NUMBER (n);
@ -142,9 +145,12 @@ modulo (SCM a, SCM b)
assert_number ("modulo", a);
assert_number ("modulo", b);
long x = VALUE (a);
long y = VALUE (b);
if (y == 0)
error (cstring_to_symbol ("divide-by-zero"), a);
while (x < 0)
x += VALUE (b);
x = x ? x % VALUE (b) : 0;
x += y;
x = x ? x % y : 0;
return MAKE_NUMBER (x);
}