Skip to content

Commit

Permalink
Fix some portability problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
augustss committed Mar 1, 2024
1 parent 18820d7 commit dda68dd
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ all: bin/mhs.exe bin/mhseval.exe
# 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
Expand Down
2 changes: 1 addition & 1 deletion generated/mhs.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static unsigned char data[] = {
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,
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/config-c64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/config-micro-64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/config-mingw-64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/config-stm32f4.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/config-unix-32.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/runtime/config-unix-64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/config-windows-64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions src/runtime/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ typedef intptr_t stackptr_t; /* Index into stack */
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
Expand Down
24 changes: 22 additions & 2 deletions src/runtime/mhsffi.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
#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;
funptr_t ffi_fun;
};
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);
Expand All @@ -30,7 +50,7 @@ void mhs_from_CIntPtr(intptr_t, int, intptr_t);
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);
Expand Down

0 comments on commit dda68dd

Please sign in to comment.