aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bench.tcl27
-rw-r--r--jim.c12
-rw-r--r--jim.h4
-rw-r--r--jimsh.c37
4 files changed, 53 insertions, 27 deletions
diff --git a/bench.tcl b/bench.tcl
index 202c69f..b0f6457 100644
--- a/bench.tcl
+++ b/bench.tcl
@@ -1,9 +1,18 @@
+set batchmode 0
+set benchmarks {}
+
proc bench {title script} {
- while {[string length $title] < 20} {
- append title " "
- }
- if {[catch {puts "$title - [time $script]"}]} {
- puts "$title - This test can't run on this interpreter"
+ global benchmarks batchmode
+
+ set Title [string range "$title [string repeat " " 20]" 0 20]
+
+ set failed [catch {time $script} res]
+ if {$failed} {
+ if {!$batchmode} {puts "$Title - This test can't run on this interpreter"}
+ lappend benchmarks $title F
+ } else {
+ if {!$batchmode} {puts "$Title - $res"}
+ lappend benchmarks $title [lindex $res 0]
}
}
@@ -271,6 +280,10 @@ proc miniloops {} {
### RUN ALL ####################################################################
+if {[string compare [lindex $argv 0] "-batch"] == 0} {
+ set batchmode 1
+}
+
bench {[while] busy loop} {whilebusyloop}
bench {[for] busy loop} {forbusyloop}
bench {mini loops} {miniloops}
@@ -286,3 +299,7 @@ bench {dynamic code} {dyncode}
bench {dynamic code (list)} {dyncode_list}
bench {PI digits} {pi_digits}
bench {expand} {expand}
+
+if {$batchmode} {
+ puts [list [info patchlevel] $benchmarks]
+} \ No newline at end of file
diff --git a/jim.c b/jim.c
index d288c9f..0507294 100644
--- a/jim.c
+++ b/jim.c
@@ -1,7 +1,7 @@
/* Jim - A small embeddable Tcl interpreter
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
*
- * $Id: jim.c,v 1.80 2005/03/08 11:32:33 antirez Exp $
+ * $Id: jim.c,v 1.81 2005/03/08 13:45:20 patthoyts Exp $
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -9211,10 +9211,10 @@ static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc,
int cmd, result = JIM_OK;
static const char *commands[] = {
"body", "commands", "exists", "globals", "level", "locals",
- "vars", "version", NULL
+ "vars", "version", "patchlevel", NULL
};
enum {INFO_BODY, INFO_COMMANDS, INFO_EXISTS, INFO_GLOBALS, INFO_LEVEL,
- INFO_LOCALS, INFO_VARS, INFO_VERSION};
+ INFO_LOCALS, INFO_VARS, INFO_VERSION, INFO_PATCHLEVEL};
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "command ?args ...?");
@@ -9302,6 +9302,7 @@ static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc,
Jim_SetResult(interp, argv[2]->internalRep.cmdValue.cmdPtr->bodyObjPtr);
break;
}
+ case INFO_PATCHLEVEL: /* tcl compatability */
case INFO_VERSION: {
char buf[(JIM_INTEGER_SPACE * 3) + 1];
sprintf(buf, "%d.%d.%d",
@@ -9568,12 +9569,10 @@ void Jim_PrintErrorMessage(Jim_Interp *interp)
}
}
-int Jim_InteractivePrompt(void)
+int Jim_InteractivePrompt(Jim_Interp *interp)
{
- Jim_Interp *interp = Jim_CreateInterp();
int retcode = JIM_OK;
- Jim_RegisterCoreCommands(interp);
printf("Welcome to Jim version %d.%d.%d, "
"Copyright (c) 2005 Salvatore Sanfilippo\n",
JIM_MAJOR_VERSION, JIM_MINOR_VERSION, JIM_PATCH_LEVEL);
@@ -9596,6 +9595,5 @@ int Jim_InteractivePrompt(void)
}
}
}
- Jim_FreeInterp(interp);
return 0;
}
diff --git a/jim.h b/jim.h
index 9d2cbc6..bf59b34 100644
--- a/jim.h
+++ b/jim.h
@@ -1,7 +1,7 @@
/* Jim - A small embeddable Tcl interpreter
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
*
- * $Id: jim.h,v 1.42 2005/03/07 20:34:16 antirez Exp $
+ * $Id: jim.h,v 1.43 2005/03/08 13:45:20 patthoyts Exp $
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -704,7 +704,7 @@ JIM_STATIC int JIM_API(Jim_RegisterApi) (Jim_Interp *interp,
JIM_STATIC void JIM_API(Jim_PrintErrorMessage) (Jim_Interp *interp);
/* interactive mode */
-JIM_STATIC int JIM_API(Jim_InteractivePrompt) (void);
+JIM_STATIC int JIM_API(Jim_InteractivePrompt) (Jim_Interp *interp);
/* Misc */
JIM_STATIC void JIM_API(Jim_Panic) (const char *fmt, ...);
diff --git a/jimsh.c b/jimsh.c
index 2b43948..41fca1f 100644
--- a/jimsh.c
+++ b/jimsh.c
@@ -4,28 +4,39 @@
#define JIM_EMBEDDED
#include "jim.h"
-int main(int argc, char **argv)
+int main(int argc, char *const argv[])
{
- int retcode;
+ int retcode, n;
Jim_Interp *interp;
+ Jim_Obj *listObj, *argObj[2];
Jim_InitEmbedded(); /* This is the first function embedders should call. */
- if (argc == 1)
- return Jim_InteractivePrompt();
+ /* Create and initialize the interpreter */
+ interp = Jim_CreateInterp();
+ Jim_RegisterCoreCommands(interp);
- /* Load the program */
- if (argc != 2) {
- fprintf(stderr, "usage: jimsh [FILENAME] [ARGUMENTS ...]\n");
- exit(1);
+ listObj = Jim_NewListObj(interp, NULL, 0);
+ for (n = 2; n < argc; n++) {
+ Jim_Obj *obj = Jim_NewStringObjNoAlloc(interp, argv[n], -1);
+ Jim_ListAppendElement(interp, listObj, obj);
}
- /* Run it */
- interp = Jim_CreateInterp();
- Jim_RegisterCoreCommands(interp);
- if ((retcode = Jim_EvalFile(interp, argv[1])) == JIM_ERR) {
- Jim_PrintErrorMessage(interp);
+ argObj[0] = Jim_NewStringObj(interp, "argv0", -1);
+ argObj[1] = Jim_NewStringObj(interp, "argv", -1);
+ for (n = 0; n < 2; n++) Jim_IncrRefCount(argObj[n]);
+ Jim_SetVariable(interp, argObj[0], Jim_NewStringObjNoAlloc(interp, argv[0], -1));
+ Jim_SetVariable(interp, argObj[1], listObj);
+
+ if (argc == 1) {
+ retcode = Jim_InteractivePrompt(interp);
+ } else {
+ if ((retcode = Jim_EvalFile(interp, argv[1])) == JIM_ERR) {
+ Jim_PrintErrorMessage(interp);
+ }
}
+
+ for (n = 0; n < 2; n++) Jim_DecrRefCount(interp, argObj[n]);
Jim_FreeInterp(interp);
return retcode;
}