ref: 8a63b1475410f63d1e73974dcee090204cce4e39
parent: ee807a2cf3eaa7df64f6544dc72a8bf3fe9e54f3
parent: d35a5d87aaee4c5d6d446214adfc97050fb8629a
author: Jeff Bezanson <jeff.bezanson@gmail.com>
date: Thu Mar 28 17:17:32 EDT 2013
Merge pull request #6 from nroza/master preprocessor platform detection and extern decl
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,5 @@
/*.a
/*.da
/flisp
+/llt/*.o
+/llt/*.a
--- a/Makefile
+++ b/Makefile
@@ -9,10 +9,7 @@
LLTDIR = llt
LLT = $(LLTDIR)/libllt.a
-# OS flags: LINUX, WIN32, MACOSX
-# architecture flags: __CPU__=xxx, BITS64, ARCH_X86, ARCH_X86_64
-CONFIG = -DLINUX -DARCH_X86_64 -DBITS64 -D__CPU__=686
-FLAGS = -falign-functions -Wall -Wno-strict-aliasing -I$(LLTDIR) $(CFLAGS) -DUSE_COMPUTED_GOTO $(CONFIG)
+FLAGS = -falign-functions -Wall -Wno-strict-aliasing -I$(LLTDIR) $(CFLAGS) -DUSE_COMPUTED_GOTO
LIBFILES = $(LLT)
LIBS = $(LIBFILES) -lm
--- a/llt/Makefile
+++ b/llt/Makefile
@@ -7,10 +7,7 @@
DOBJS = $(SRCS:%.c=%.do)
TARGET = libllt.a
-# OS flags: LINUX, WIN32, MACOSX
-# architecture flags: __CPU__=xxx, BITS64, ARCH_X86, ARCH_X86_64
-CONFIG = -DLINUX -DARCH_X86_64 -DBITS64 -D__CPU__=686
-FLAGS = -Wall -Wno-strict-aliasing $(CFLAGS) $(CONFIG)
+FLAGS = -Wall -Wno-strict-aliasing $(CFLAGS)
LIBS =
DEBUGFLAGS = -g -DDEBUG $(FLAGS)
--- a/llt/dtypes.h
+++ b/llt/dtypes.h
@@ -16,46 +16,69 @@
We assume the LP64 convention for 64-bit platforms.
*/
-#ifdef WIN32
-#define STDCALL __stdcall
-# ifdef IMPORT_EXPORTS
-# define DLLEXPORT __declspec(dllimport)
-# else
-# define DLLEXPORT __declspec(dllexport)
-# endif
+
+#if defined(__gnu_linux__)
+# define LINUX
+#elif defined(__APPLE__) && defined(__MACH__)
+# define MACOSX
+#elif defined(_WIN32)
+# define WIN32
#else
-#define STDCALL
-#define DLLEXPORT __attribute__ ((visibility("default")))
+# error "unknown platform"
#endif
-#ifdef LINUX
-#include <features.h>
-#include <endian.h>
-#define LITTLE_ENDIAN __LITTLE_ENDIAN
-#define BIG_ENDIAN __BIG_ENDIAN
-#define PDP_ENDIAN __PDP_ENDIAN
-#define BYTE_ORDER __BYTE_ORDER
+
+#ifndef __SIZEOF_POINTER__
+# error "__SIZEOF_POINTER__ undefined"
#endif
+#if( 8 == __SIZEOF_POINTER__ )
+# define BITS64
+#elif( 4 == __SIZEOF_POINTER__ )
+# define BITS32
+#else
+# error "this is one weird machine"
+#endif
-#ifdef MACOSX
-#include <machine/endian.h>
-#define __LITTLE_ENDIAN LITTLE_ENDIAN
-#define __BIG_ENDIAN BIG_ENDIAN
-#define __PDP_ENDIAN PDP_ENDIAN
-#define __BYTE_ORDER BYTE_ORDER
+
+#if defined(WIN32)
+# define STDCALL __stdcall
+# if defined(IMPORT_EXPORTS)
+# define DLLEXPORT __declspec(dllimport)
+# else
+# define DLLEXPORT __declspec(dllexport)
+# endif
+#else
+# define STDCALL
+# define DLLEXPORT __attribute__ ((visibility("default")))
#endif
-#ifdef WIN32
-#define __LITTLE_ENDIAN 1234
-#define __BIG_ENDIAN 4321
-#define __PDP_ENDIAN 3412
-#define __BYTE_ORDER __LITTLE_ENDIAN
-#define __FLOAT_WORD_ORDER __LITTLE_ENDIAN
-#define LITTLE_ENDIAN __LITTLE_ENDIAN
-#define BIG_ENDIAN __BIG_ENDIAN
-#define PDP_ENDIAN __PDP_ENDIAN
-#define BYTE_ORDER __BYTE_ORDER
+#if defined(LINUX)
+# include <features.h>
+# include <endian.h>
+# define LITTLE_ENDIAN __LITTLE_ENDIAN
+# define BIG_ENDIAN __BIG_ENDIAN
+# define PDP_ENDIAN __PDP_ENDIAN
+# define BYTE_ORDER __BYTE_ORDER
+#elif defined(MACOSX)
+# include <machine/endian.h>
+# define __LITTLE_ENDIAN LITTLE_ENDIAN
+# define __BIG_ENDIAN BIG_ENDIAN
+# define __PDP_ENDIAN PDP_ENDIAN
+# define __BYTE_ORDER BYTE_ORDER
+#elif defined(WIN32)
+# define __LITTLE_ENDIAN 1234
+# define __BIG_ENDIAN 4321
+# define __PDP_ENDIAN 3412
+# define __BYTE_ORDER __LITTLE_ENDIAN
+# define __FLOAT_WORD_ORDER __LITTLE_ENDIAN
+# define LITTLE_ENDIAN __LITTLE_ENDIAN
+# define BIG_ENDIAN __BIG_ENDIAN
+# define PDP_ENDIAN __PDP_ENDIAN
+# define BYTE_ORDER __BYTE_ORDER
+#else
+# error "unknown platform"
#endif
+
#ifdef BOEHM_GC
// boehm GC allocator
--- a/llt/utils.h
+++ b/llt/utils.h
@@ -1,6 +1,33 @@
#ifndef __UTILS_H_
#define __UTILS_H_
+
+#if defined( __amd64__ ) || defined( _M_AMD64 )
+# define ARCH_X86_64
+# define __CPU__ 686
+#elif defined( _M_IX86 )//msvs, intel, digital mars, watcom
+# if ! defined( __386__ )
+# error "unsupported target: 16-bit x86"
+# endif
+# define ARCH_X86
+# define __CPU__ ( _M_IX86 + 86 )
+#elif defined( __i686__ )//gnu c
+# define ARCH_X86
+# define __CPU__ 686
+#elif defined( __i586__ )//gnu c
+# define ARCH_X86
+# define __CPU__ 586
+#elif defined( __i486__ )//gnu c
+# define ARCH_X86
+# define __CPU__ 486
+#elif defined( __i386__ )//gnu c
+# define ARCH_X86
+# define __CPU__ 386
+#else
+# error "unknown architecture"
+#endif
+
+
char *uint2str(char *dest, size_t len, uint64_t num, uint32_t base);
int str2int(char *str, size_t len, int64_t *res, uint32_t base);
int isdigit_base(char c, int base);
--- a/string.c
+++ b/string.c
@@ -47,6 +47,14 @@
return size_wrap(u8_charnum(str+start, stop-start));
}
+
+#if defined( __WIN32__ ) || defined( __linux__ )
+extern int wcwidth( wchar_t );
+#else
+# error "I need int wcwidth( wchar_t );"
+#endif
+
+
value_t fl_string_width(value_t *args, u_int32_t nargs)
{
argcount("string.width", nargs, 1);