aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2010-01-24 10:48:25 +1000
committerSteve Bennett <steveb@workware.net.au>2010-10-15 11:02:39 +1000
commitd495fb19428bfc640aa4d0e9245bc8f23c31f380 (patch)
treeb80832b727b297f43584d274485742976e6d7529
parente68eadfbfe66d350b9656e3a4a91f7520e2bfba4 (diff)
downloadjimtcl-d495fb19428bfc640aa4d0e9245bc8f23c31f380.zip
jimtcl-d495fb19428bfc640aa4d0e9245bc8f23c31f380.tar.gz
jimtcl-d495fb19428bfc640aa4d0e9245bc8f23c31f380.tar.bz2
Bugs, features, tests
The result of boolean ops on doubles is an int *: e.g. 0.5 < 0.1 should be 0, not 0.1 Implement jimsh -e <cmd> Allow jim to be built in a different location *: e.g. mkdir build; cd build; ../configure ...; make jimsh Add dict.test
-rw-r--r--Makefile.in7
-rwxr-xr-xconfigure3
-rw-r--r--configure.ac1
-rw-r--r--jim.c1
-rw-r--r--jimsh.c37
-rw-r--r--tests/dict.test45
6 files changed, 79 insertions, 15 deletions
diff --git a/Makefile.in b/Makefile.in
index bf172e3..dac7c1a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -15,7 +15,8 @@ CFLAGS += -DJIM_TCL_COMPAT
# Emulate tinytcl
LIBJIM := libtcl6.a
-CFLAGS += -Wall -g -Os -I. @EXTRA_CFLAGS@
+CFLAGS += -Wall -g -Os -I@SRCDIR@ @EXTRA_CFLAGS@
+VPATH := @SRCDIR@
.EXPORT_ALL_VARIABLES:
@@ -50,8 +51,8 @@ $(LIBJIM): $(OBJS) $(EXTENSIONS_OBJS)
$(AR) cr $@ $^
$(RANLIB) $@
-load_extensions.c: make-jim-load-extensions.sh
- sh make-jim-load-extensions.sh $@ $(EXTENSIONS)
+load_extensions.c: @SRCDIR@/make-jim-load-extensions.sh
+ sh @SRCDIR@/make-jim-load-extensions.sh $@ $(EXTENSIONS)
install:
diff --git a/configure b/configure
index 2a6b066..ff19821 100755
--- a/configure
+++ b/configure
@@ -649,6 +649,7 @@ SET_MAKE
JIM_NOFORK
JIM_EXTENSIONS
EXTRA_CFLAGS
+SRCDIR
LIBDL
LIBOBJS
LTLIBOBJS'
@@ -2861,6 +2862,8 @@ JIM_EXTENSIONS=$JIM_EXTENSIONS
EXTRA_CFLAGS=$EXTRA_CFLAGS
+SRCDIR=`dirname $0`
+
{ $as_echo "$as_me:$LINENO: checking for dlopen in -ldl" >&5
$as_echo_n "checking for dlopen in -ldl... " >&6; }
diff --git a/configure.ac b/configure.ac
index d5e3048..b6bb4ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,6 +45,7 @@ AC_CHECK_FUNCS([ualarm],EXTRA_CFLAGS="$EXTRA_CFLAGS -DHAVE_UALARM")
AC_SUBST(JIM_EXTENSIONS,$JIM_EXTENSIONS)
AC_SUBST(EXTRA_CFLAGS,$EXTRA_CFLAGS)
+AC_SUBST(SRCDIR,`dirname $0`)
AC_CHECK_LIB(dl, dlopen,AC_SUBST(LIBDL,-ldl))
diff --git a/jim.c b/jim.c
index 207db79..9841bfc 100644
--- a/jim.c
+++ b/jim.c
@@ -7083,6 +7083,7 @@ trydouble:
}
goto retry_as_string;
}
+ intresult = 0;
Jim_DecrRefCount(interp, A);
Jim_DecrRefCount(interp, B);
switch(expr->opcode[i]) {
diff --git a/jimsh.c b/jimsh.c
index d94668d..732bec9 100644
--- a/jimsh.c
+++ b/jimsh.c
@@ -120,9 +120,23 @@ static void JimLoadJimRc(Jim_Interp *interp)
}
}
+static void JimSetArgv(Jim_Interp *interp, int argc, char *const argv[])
+{
+ int n;
+ Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
+
+ /* Populate argv and argv0 global vars */
+ for (n = 0; n < argc; n++) {
+ Jim_Obj *obj = Jim_NewStringObj(interp, argv[n], -1);
+ Jim_ListAppendElement(interp, listObj, obj);
+ }
+
+ Jim_SetVariableStr(interp, "argv", listObj);
+}
+
int main(int argc, char *const argv[])
{
- int retcode, n;
+ int retcode;
Jim_Interp *interp;
Jim_Obj *listObj;
@@ -143,23 +157,22 @@ int main(int argc, char *const argv[])
Jim_ListAppendElement(interp, listObj, JimGetExePath(interp, argv[0]));
Jim_SetVariableStr(interp, JIM_LIBPATH, listObj);
- /* Populate argv and argv0 global vars */
- listObj = Jim_NewListObj(interp, NULL, 0);
- for (n = 2; n < argc; n++) {
- Jim_Obj *obj = Jim_NewStringObj(interp, argv[n], -1);
- Jim_ListAppendElement(interp, listObj, obj);
- }
-
- Jim_SetVariableStr(interp, "argv", listObj);
-
if (argc == 1) {
Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, "1");
+ JimSetArgv(interp, 0, NULL);
JimLoadJimRc(interp);
retcode = Jim_InteractivePrompt(interp);
} else {
- Jim_SetVariableStr(interp, "argv0", Jim_NewStringObj(interp, argv[1], -1));
Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, "0");
- retcode = Jim_EvalFile(interp, argv[1]);
+ if (argc > 2 && strcmp(argv[1], "-e") == 0) {
+ JimSetArgv(interp, argc - 3, argv + 3);
+ retcode = Jim_Eval(interp, argv[2]);
+ }
+ else {
+ Jim_SetVariableStr(interp, "argv0", Jim_NewStringObj(interp, argv[1], -1));
+ JimSetArgv(interp, argc - 2, argv + 2);
+ retcode = Jim_EvalFile(interp, argv[1]);
+ }
if (retcode == JIM_ERR || retcode == JIM_ERR_ADDSTACK) {
Jim_PrintErrorMessage(interp);
}
diff --git a/tests/dict.test b/tests/dict.test
new file mode 100644
index 0000000..abccdb3
--- /dev/null
+++ b/tests/dict.test
@@ -0,0 +1,45 @@
+package require testing
+
+section "basic dict"
+
+test dict-1.1 "Basic dict" {
+ set d [dict create]
+ dict set d fruit apple
+ dict set d car holden
+ #puts "d=$d"
+ #puts "d(fruit)=$d(fruit)"
+ dict get $d car
+} {holden}
+
+catch {unset d}
+
+test dict-2.1 "Dict via reference" {
+ set d [dict create]
+ dict set d fruit apple
+ dict set d car holden
+
+ # now create a dictionary reference
+ set dref [ref $d dict]
+ dict get [getref $dref] car
+} {holden}
+
+test dict-2.2 "Modify dict via reference" {
+ # Get the value out of the refernence
+ set d [getref $dref]
+ # Modify it
+ dict set d car toyota
+ # And put the new value back
+ setref $dref $d
+ # Finally check it
+ dict get [getref $dref] car
+} {toyota}
+
+test dict-2.3 "Modify dict via reference - one line" {
+ # Get the value out of the refernence
+ set d [getref $dref]
+ setref $dref [dict set d car toyota]
+ # Finally check it
+ dict get [getref $dref] car
+} {toyota}
+
+testreport