ref: dda68ddb858f384a2d660af1f46b9f928bb048fb
parent: 18820d704a3ca7b7ecdac94cbf067e5b2a60ad4f
author: Lennart Augustsson <lennart@augustsson.net>
date: Fri Mar 1 12:32:12 EST 2024
Fix some portability problems.
--- a/Makefile.windows
+++ b/Makefile.windows
@@ -6,7 +6,7 @@
# Compile mhs from distribution, with C compiler
bin/mhs.exe: src/runtime/*.c src/runtime/config*.h #generated/mhs.c
@-mkdir bin
- cl /O2 src/runtime/eval-windows-64.c generated/mhs.c /Febin/mhs.exe
+ cl /O2 /Isrc/runtime src/runtime/eval-windows-64.c generated/mhs.c /Febin/mhs.exe
# Compile combinator evaluator
bin/mhseval.exe: src/runtime/*.c src/runtime/config*.h src/runtime/comb.c
--- a/generated/mhs.c
+++ b/generated/mhs.c
@@ -87,7 +87,7 @@
89,32,66,32,80,32,75,32,64,32,64,32,83,39,32,67,32,64,32,67,
32,83,39,32,64,32,64,32,66,32,67,32,95,53,56,32,64,32,64,32,
64,32,64,32,64,32,58,49,54,54,53,32,64,10,65,32,102,114,111,109,
-85,84,70,56,32,34,48,46,57,46,54,46,48,34,32,64,32,58,49,54,
+85,84,70,56,32,34,48,46,57,46,55,46,48,34,32,64,32,58,49,54,
54,52,32,64,10,65,32,83,39,32,67,39,32,95,48,32,95,50,51,32,
64,32,64,32,64,32,83,32,83,39,32,83,39,32,64,32,95,49,51,48,
32,95,49,54,48,57,32,64,32,95,49,51,52,32,64,32,64,32,83,39,
--- a/src/runtime/config-c64.h
+++ b/src/runtime/config-c64.h
@@ -38,7 +38,7 @@
/*
* Number of bits in a word. Only 32 and 64 are supported.
*/
-#define WORD_SIZE 16
+//#define WORD_SIZE 16
/*
* Find First Set
--- a/src/runtime/config-micro-64.h
+++ b/src/runtime/config-micro-64.h
@@ -38,7 +38,7 @@
/*
* Number of bits in a word. Only 32 and 64 are supported.
*/
-#define WORD_SIZE 64
+//#define WORD_SIZE 64
/*
* Find First Set
--- a/src/runtime/config-mingw-64.h
+++ b/src/runtime/config-mingw-64.h
@@ -33,7 +33,7 @@
/*
* Number of bits in a word. Only 32 and 64 are supported.
*/
-#define WORD_SIZE 64
+//#define WORD_SIZE 64
/*
* Find First Set
--- a/src/runtime/config-stm32f4.h
+++ b/src/runtime/config-stm32f4.h
@@ -38,7 +38,7 @@
/*
* Number of bits in a word. Only 32 and 64 are supported.
*/
-#define WORD_SIZE 32
+//#define WORD_SIZE 32
/*
* Find First Set
--- a/src/runtime/config-unix-32.h
+++ b/src/runtime/config-unix-32.h
@@ -1,7 +1,7 @@
#include "config-unix-64.h"
-#undef WORD_SIZE
-#define WORD_SIZE 32
+//#undef WORD_SIZE
+//#define WORD_SIZE 32
#undef FFS
#define FFS ffs
--- a/src/runtime/config-unix-64.h
+++ b/src/runtime/config-unix-64.h
@@ -36,7 +36,7 @@
/*
* Number of bits in a word. Only 32 and 64 are supported.
*/
-#define WORD_SIZE 64
+//#define WORD_SIZE 64
/*
* Find First Set
--- a/src/runtime/config-windows-64.h
+++ b/src/runtime/config-windows-64.h
@@ -33,7 +33,7 @@
/*
* Number of bits in a word. Only 32 and 64 are supported.
*/
-#define WORD_SIZE 64
+//#define WORD_SIZE 64
/*
* This is Windows
--- a/src/runtime/eval.c
+++ b/src/runtime/eval.c
@@ -48,15 +48,6 @@
typedef uintptr_t counter_t; /* Statistics counter, can be smaller since overflow doesn't matter */
#define PRIcounter PRIuPTR
typedef uintptr_t bits_t; /* One word of bits */
-#if WORD_SIZE == 64
-typedef double flt_t;
-#elif WORD_SIZE == 32
-typedef float flt_t;
-#elif WORD_SIZE == 16
-typedef uint16_t flt_t; /* No floats, but we need something */
-#else
-#error Unknown WORD_SIZE
-#endif
#if !defined(MALLOC)
#define MALLOC malloc
--- a/src/runtime/mhsffi.h
+++ b/src/runtime/mhsffi.h
@@ -1,6 +1,26 @@
#include <inttypes.h>
#include <stdlib.h>
+#if INTPTR_MAX == 0x7fff
+#define WORD_SIZE 16
+#elif INTPTR_MAX == 0x7fffffff
+#define WORD_SIZE 32
+#elif INTPTR_MAX == 0x7fffffffffffffff
+#define WORD_SIZE 64
+#else
+#error Unknown WORD_SIZE
+#endif
+
+#if WORD_SIZE == 64
+typedef double flt_t;
+#elif WORD_SIZE == 32
+typedef float flt_t;
+#elif WORD_SIZE == 16
+typedef uint16_t flt_t; /* No floats, but we need something */
+#else
+#error Unknown WORD_SIZE
+#endif
+
typedef void (*funptr_t)(int);
struct ffi_entry {const char *ffi_name;
@@ -8,7 +28,7 @@
};
extern struct ffi_entry *xffi_table;
-void mhs_from_Double(intptr_t, int, double);
+void mhs_from_Double(intptr_t, int, flt_t);
void mhs_from_Int(intptr_t, int, intptr_t);
void mhs_from_Word(intptr_t, int, uintptr_t);
void mhs_from_Word8(intptr_t, int, uintptr_t);
@@ -30,7 +50,7 @@
void mhs_from_CUIntPtr(intptr_t, int, uintptr_t);
void mhs_from_Unit(intptr_t, int);
-double mhs_to_Double(intptr_t, int);
+flt_t mhs_to_Double(intptr_t, int);
intptr_t mhs_to_Int(intptr_t, int);
uintptr_t mhs_to_Word(intptr_t, int);
uint8_t mhs_to_Word8(intptr_t, int);
--
⑨