1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-16 08:15:31 +00:00

Fix types for smallp manipulation in arith.h

Introduce GetPosSmallp for converting an unsigned value to smallp
    Use [unsigned] long as input to Get...Smallp to avoid shortening input
This commit is contained in:
Nick Briggs 2022-08-15 13:26:53 -07:00
parent 4a02a1a24d
commit 3075cc93bb

View File

@ -22,6 +22,9 @@
#define MAX_FIXP 2147483647 /* == 0x7FFFFFFF */
#define MIN_FIXP (-2147483648) /* == 0x80000000 */
/**
* extract an integer value from a smallp
*/
static inline int GetSmalldata(LispPTR x) {
if ((SEGMASK & (int)x) == S_POSITIVE) return (int)(x & 0xFFFF);
if ((SEGMASK & (int)x) == S_NEGATIVE) return (int)(x | 0xFFFF0000);
@ -29,7 +32,11 @@ static inline int GetSmalldata(LispPTR x) {
return (0);
}
static inline LispPTR GetSmallp(int x) {
/**
* construct a smallp from an integer value
*/
static inline LispPTR GetSmallp(long x) {
if (x >= 0) {
if (x <= MAX_SMALL) return (LispPTR)(S_POSITIVE | x);
} else {
@ -39,6 +46,15 @@ static inline LispPTR GetSmallp(int x) {
return (S_POSITIVE | 0);
}
/**
* construct a smallp from an unsigned value
*/
static inline LispPTR GetPosSmallp(unsigned long x) {
if (x <= MAX_SMALL) return (LispPTR)(S_POSITIVE | x);
error("Not Smallp data");
return (S_POSITIVE | 0);
}
#define FIXP_VALUE(dest) *((int *)Addr68k_from_LADDR(dest))
#define FLOATP_VALUE(dest) *((float *)Addr68k_from_LADDR(dest))