diff options
author | antirez <antirez> | 2005-02-27 14:04:40 +0000 |
---|---|---|
committer | antirez <antirez> | 2005-02-27 14:04:40 +0000 |
commit | aa9c81b676276a6367b8e30a40073569251c49fe (patch) | |
tree | fa4e8c0bf088965a942152675cebf4571ba9fd77 | |
parent | 3b61d32c6d192a7200dbe76f4ba19dd4bc0aef4e (diff) | |
download | jimtcl-aa9c81b676276a6367b8e30a40073569251c49fe.zip jimtcl-aa9c81b676276a6367b8e30a40073569251c49fe.tar.gz jimtcl-aa9c81b676276a6367b8e30a40073569251c49fe.tar.bz2 |
Pat's patch for [load] on win32!
Pat's match for nan/inf modified a bit.
-rw-r--r-- | Makefile.vc | 14 | ||||
-rw-r--r-- | bench.tcl | 11 | ||||
-rw-r--r-- | jim.c | 99 | ||||
-rw-r--r-- | jim.h | 54 |
4 files changed, 126 insertions, 52 deletions
diff --git a/Makefile.vc b/Makefile.vc index d2405a3..3871222 100644 --- a/Makefile.vc +++ b/Makefile.vc @@ -24,22 +24,24 @@ DEFS =-DWIN32 LIBS = -all: jim +all: jim jim-win32 jim: setup $(OUTDIR)\jim.exe +jim-win32: setup $(OUTDIR)\jim-win32.dll $(OUTDIR)\jim.exe: $(OBJS) $(LD) $(LDFLAGS) -out:$@ $** $(LIBS) +$(OUTDIR)\jim-win32.dll: $(TMPDIR)\jim-win32.obj + $(LD) $(LDFLAGS) -dll -out:$@ $** $(LIBS) + #------------------------------------------------------------------------- setup: @if not exist $(OUTDIR) mkdir $(OUTDIR) @if not exist $(TMPDIR) mkdir $(TMPDIR) -test: testapp - @if exist ztest.mk del ztest.mk >NUL - @$(OUTDIR)\testapp.exe - kviewer ztest.mk +test: jim + $(OUTDIR)\jim.exe test.tcl clean: @if exist $(TMPDIR) rmdir /q /s $(TMPDIR) >NUL @@ -52,7 +54,7 @@ realclean: clean .SUFFIXES:.c .cpp {$(SRCDIR)}.c{$(TMPDIR)}.obj:: - $(CC) $(CFLAGS) $(DEFS) $(INC) -Fo$(TMPDIR)^\ -c @<< + $(CC) $(CFLAGS) $(DEFS) $(INC) -Fa$(TMPDIR)^\ -Fo$(TMPDIR)^\ -c @<< $< << @@ -176,6 +176,16 @@ proc nestedloops {} { } } +### ROTATE ##################################################################### + +proc rotate {count} { + set v 1 + for {set n 0} {$n < $count} {incr n} { + set v [expr {$v <<< 1}] + } +} + + ### RUN ALL #################################################################### bench {busy loop} {x} @@ -186,3 +196,4 @@ bench {ary} {ary 100000} bench {repeat} {use_repeat} bench {upvar} {upvartest} bench {nested loops} {nestedloops} +bench {rotate} {rotate 100000}
\ No newline at end of file @@ -27,6 +27,16 @@ #include <errno.h> #include <time.h> +/* Include the platform dependent libraries for + * dynamic loading of libraries. */ +#ifdef WIN32 +#define STRICT +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#else +#include <dlfcn.h> +#endif + #include "jim.h" #ifdef HAVE_BACKTRACE @@ -315,10 +325,15 @@ int Jim_DoubleToString(char *buf, double doubleValue) if (*s == '.') return len; s++; } - s[0] = '.'; - s[1] = '0'; - s[2] = '\0'; - return len+2; + /* Add a final ".0" if it's a number. But not + * for NaN or InF */ + if (isdigit((int)buf[0])) { + s[0] = '.'; + s[1] = '0'; + s[2] = '\0'; + return len+2; + } + return len; } int Jim_StringToDouble(char *str, double *doublePtr) @@ -4931,6 +4946,7 @@ int Jim_GetReturnCode(Jim_Interp *interp, Jim_Obj *objPtr, int *intPtr) * ---------------------------------------------------------------------------*/ static int JimParseExprOperator(struct JimParserCtx *pc); static int JimParseExprNumber(struct JimParserCtx *pc); +static int JimParseExprIrrational(struct JimParserCtx *pc); /* Operators table */ typedef struct Jim_ExprOperator { @@ -5086,6 +5102,11 @@ int JimParseExpression(struct JimParserCtx *pc) pc->tt = JIM_TT_NONE; /* Make sure it's sensed as a new word. */ return JimParseListStr(pc); break; + case 'N': case 'I': + case 'n': case 'i': + if (JimParseExprIrrational(pc) == JIM_ERR) + return JimParseExprOperator(pc); + break; default: return JimParseExprOperator(pc); break; @@ -5112,6 +5133,24 @@ int JimParseExprNumber(struct JimParserCtx *pc) return JIM_OK; } +int JimParseExprIrrational(struct JimParserCtx *pc) +{ + const char *Tokens[] = {"NaN", "nan", "NAN", "Inf", "inf", "INF", NULL}; + const char **token; + for (token = Tokens; *token != NULL; token++) { + int len = strlen(*token); + if (strncmp(*token, pc->p, len) == 0) { + pc->tstart = pc->p; + pc->tend = pc->p + len - 1; + pc->p += len; + pc->tline = pc->linenr; + pc->tt = JIM_TT_EXPR_NUMBER; + return JIM_OK; + } + } + return JIM_ERR; +} + int JimParseExprOperator(struct JimParserCtx *pc) { int i; @@ -5622,15 +5661,24 @@ int Jim_EvalExpression(Jim_Interp *interp, Jim_Obj *exprObjPtr, wC = wA%wB; break; case JIM_EXPROP_ROTL: { - unsigned long uA = (unsigned jim_wide)wA&0xFFFFFFFF; + /* uint32_t would be better. But not everyone has inttypes.h?*/ + unsigned long uA = (unsigned long)wA; +#ifdef _MSC_VER + wC = _rotl(uA,(unsigned long)wB); +#else const unsigned int S = sizeof(unsigned long) * 8; - wC = (jim_wide)((uA<<wB)|(uA>>(S-wB))); + wC = (unsigned long)((uA<<wB)|(uA>>(S-wB))); +#endif break; } case JIM_EXPROP_ROTR: { - unsigned long uA = (unsigned jim_wide)wA&0xFFFFFFFF; + unsigned long uA = (unsigned long)wA; +#ifdef _MSC_VER + wC = _rotr(uA,(unsigned long)wB); +#else const unsigned int S = sizeof(unsigned long) * 8; - wC = (jim_wide)((uA>>wB)|(uA<<(S-wB))); + wC = (unsigned long)((uA>>wB)|(uA<<(S-wB))); +#endif break; } @@ -5830,8 +5878,30 @@ int Jim_GetBoolFromExpr(Jim_Interp *interp, Jim_Obj *exprObjPtr, int *boolPtr) * Dynamic libraries support (WIN32 not supported) * ---------------------------------------------------------------------------*/ -#ifndef WIN32 -#include <dlfcn.h> +#ifdef WIN32 +#define RTLD_LAZY 0 +void * dlopen(const char *path, int mode) +{ + return (void *)LoadLibraryA(path); +} +int dlclose(void *handle) +{ + FreeLibrary((HANDLE)handle); + return 0; +} +void *dlsym(void *handle, const char *symbol) +{ + return GetProcAddress((HMODULE)handle, symbol); +} +static char win32_dlerror_string[121]; +const char *dlerror() +{ + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), + LANG_NEUTRAL, win32_dlerror_string, 120, NULL); + return win32_dlerror_string; +} +#endif /* WIN32 */ + #define JIM_LIBPATH_LEN 1024 int Jim_LoadLibrary(Jim_Interp *interp, char *pathName) { @@ -5905,15 +5975,6 @@ err: Jim_DecrRefCount(interp, libPathObjPtr); return JIM_ERR; } -#else -int Jim_LoadLibrary(Jim_Interp *interp, char *pathName) -{ - pathName = pathName; - Jim_SetResultString(interp, - "Dynamic libraries not supported under WIN32", -1); - return JIM_ERR; -} -#endif /* ! WIN32 */ /* ----------------------------------------------------------------------------- * Eval @@ -37,7 +37,7 @@ /* MSC has _stricmp instead of strcasecmp */ #ifdef _MSC_VER - #define strcasecmp _stricmp +# define strcasecmp _stricmp #endif /* _MSC_VER */ /* ----------------------------------------------------------------------------- @@ -57,33 +57,33 @@ #define JIM_MAX_NESTING_DEPTH 5000 /* default max nesting depth */ #ifdef HAVE_LONG_LONG - #ifdef _MSC_VER /* MSC compiler */ - #define jim_wide _int64 - #ifndef LLONG_MAX - #define LLONG_MAX 9223372036854775807I64 - #endif - #ifndef LLONG_MIN - #define LLONG_MIN (-LLONG_MAX - 1I64) - #endif - #define JIM_WIDE_MIN LLONG_MIN - #define JIM_WIDE_MAX LLONG_MAX - #define JIM_LL_MODIFIER "I64d" - #else /* Other compilers (mainly GCC) */ - #define jim_wide long long - #ifndef LLONG_MAX - #define LLONG_MAX 9223372036854775807LL - #endif - #ifndef LLONG_MIN - #define LLONG_MIN (-LLONG_MAX - 1LL) - #endif - #define JIM_WIDE_MIN LLONG_MIN - #define JIM_WIDE_MAX LLONG_MAX - #define JIM_LL_MODIFIER "lld" - #endif +# ifdef _MSC_VER /* MSC compiler */ +# define jim_wide _int64 +# ifndef LLONG_MAX +# define LLONG_MAX 9223372036854775807I64 +# endif +# ifndef LLONG_MIN +# define LLONG_MIN (-LLONG_MAX - 1I64) +# endif +# define JIM_WIDE_MIN LLONG_MIN +# define JIM_WIDE_MAX LLONG_MAX +# define JIM_LL_MODIFIER "I64d" +# else /* Other compilers (mainly GCC) */ +# define jim_wide long long +# ifndef LLONG_MAX +# define LLONG_MAX 9223372036854775807LL +# endif +# ifndef LLONG_MIN +# define LLONG_MIN (-LLONG_MAX - 1LL) +# endif +# define JIM_WIDE_MIN LLONG_MIN +# define JIM_WIDE_MAX LLONG_MAX +# define JIM_LL_MODIFIER "lld" +# endif #else - #define jim_wide long - #define JIM_WIDE_MIN LONG_MIN - #define JIM_WIDE_MAX LONG_MAX +# define jim_wide long +# define JIM_WIDE_MIN LONG_MIN +# define JIM_WIDE_MAX LONG_MAX #endif /* Some function get an integer argument with flags to change |