diff --git a/msvc/ecl-threads.def b/msvc/ecl-threads.def index de351d234..a03b0e0bd 100755 --- a/msvc/ecl-threads.def +++ b/msvc/ecl-threads.def @@ -159,6 +159,7 @@ EXPORTS imod object_to_char object_to_fixnum + object_to_unsigned_integer object_to_float object_to_double aref_bv diff --git a/msvc/ecl.def b/msvc/ecl.def index 7d8e6aae2..86282cd6f 100644 --- a/msvc/ecl.def +++ b/msvc/ecl.def @@ -159,6 +159,7 @@ EXPORTS imod object_to_char object_to_fixnum + object_to_unsigned_integer object_to_float object_to_double aref_bv diff --git a/src/c/cmpaux.d b/src/c/cmpaux.d index 503037ec6..1033620d9 100644 --- a/src/c/cmpaux.d +++ b/src/c/cmpaux.d @@ -86,6 +86,24 @@ object_to_fixnum(cl_object x) } } +cl_index +object_to_unsigned_integer(cl_object x) +{ + switch (type_of(x)) { + case t_fixnum: + case t_bignum: + return fixnnint(x); + case t_ratio: + return (cl_index)number_to_double(x); + case t_shortfloat: + return (cl_index)sf(x); + case t_longfloat: + return (cl_index)lf(x); + default: + FEerror("~S cannot be coerced to a C unsigned int.", 1, x); + } +} + float object_to_float(cl_object x) { diff --git a/src/cmp/cmpffi.lsp b/src/cmp/cmpffi.lsp index fe1471314..b528aee55 100644 --- a/src/cmp/cmpffi.lsp +++ b/src/cmp/cmpffi.lsp @@ -134,7 +134,7 @@ (wt loc) (return-from wt-coerce-loc)) (case dest-rep-type - ((:int :unsigned-int :long :unsigned-long :byte :unsigned-byte :fixnum) + ((:int :long :byte :fixnum) (case loc-rep-type ((:int :unsigned-int :long :unsigned-long :byte :unsigned-byte :fixnum :float :double) @@ -145,6 +145,17 @@ loc ")")) (otherwise (coercion-error)))) + ((:unsigned-int :unsigned-long :unsigned-byte) + (case loc-rep-type + ((:int :unsigned-int :long :unsigned-long :byte :unsigned-byte :fixnum + :float :double) + (wt "((" (rep-type-name dest-rep-type) ")" loc ")")) + ((:object) + (ensure-valid-object-type dest-type) + (wt (if (subtypep (loc-type loc) 'fixnum) "fix(" "object_to_unsigned_integer(") + loc ")")) + (otherwise + (coercion-error)))) ((:char :unsigned-char) (case loc-rep-type ((:char :unsigned-char) @@ -178,8 +189,10 @@ (coercion-error)))) ((:object) (case loc-rep-type - ((:int :unsigned-int :long :unsigned-long) + ((:int :long) (wt "make_integer(" loc ")")) + ((:unsigned-int :unsigned-long) + (wt "make_unsigned_integer(" loc ")")) ((:byte :unsigned-byte :fixnum) (wt "MAKE_FIXNUM(" loc ")")) ((:float) diff --git a/src/h/external.h b/src/h/external.h index c22a0c20b..bd88c600e 100644 --- a/src/h/external.h +++ b/src/h/external.h @@ -374,6 +374,7 @@ extern cl_fixnum ifloor(cl_fixnum x, cl_fixnum y); extern cl_fixnum imod(cl_fixnum x, cl_fixnum y); extern char object_to_char(cl_object x); extern cl_fixnum object_to_fixnum(cl_object x); +extern cl_index object_to_unsigned_integer(cl_object x); extern float object_to_float(cl_object x); extern double object_to_double(cl_object x); extern int aref_bv(cl_object x, cl_index index);