aboutsummaryrefslogtreecommitdiff
path: root/ecos
diff options
context:
space:
mode:
authoroharboe <oharboe>2008-11-05 10:03:18 +0000
committeroharboe <oharboe>2008-11-05 10:03:18 +0000
commit88c0d231e1d734a124bf1f0de8058373167d54cd (patch)
tree300922dec8d80ef998191412700cac4ea97182a2 /ecos
parent3efd2c496a35a45cc7380416e2d083c3f90c9e82 (diff)
downloadjimtcl-88c0d231e1d734a124bf1f0de8058373167d54cd.zip
jimtcl-88c0d231e1d734a124bf1f0de8058373167d54cd.tar.gz
jimtcl-88c0d231e1d734a124bf1f0de8058373167d54cd.tar.bz2
sync ecos snapshot
Diffstat (limited to 'ecos')
-rw-r--r--ecos/language/tcl/jim/current/src/jim.c63
1 files changed, 53 insertions, 10 deletions
diff --git a/ecos/language/tcl/jim/current/src/jim.c b/ecos/language/tcl/jim/current/src/jim.c
index 79f846c..e9c4954 100644
--- a/ecos/language/tcl/jim/current/src/jim.c
+++ b/ecos/language/tcl/jim/current/src/jim.c
@@ -8734,6 +8734,7 @@ int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc,
{
int i, retcode;
Jim_CallFrame *callFramePtr;
+ int num_args;
/* Check arity */
if (argc < cmd->arityMin || (cmd->arityMax != -1 &&
@@ -8764,19 +8765,47 @@ int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc,
Jim_IncrRefCount(cmd->bodyObjPtr);
interp->framePtr = callFramePtr;
interp->numLevels ++;
+
/* Set arguments */
- for (i = 0; i < cmd->arityMin-1; i++) {
- Jim_Obj *objPtr;
+ Jim_ListLength(interp, cmd->argListObjPtr, &num_args);
- Jim_ListIndex(interp, cmd->argListObjPtr, i, &objPtr, JIM_NONE);
- Jim_SetVariable(interp, objPtr, argv[i+1]);
+ /* If last argument is 'args', don't set it here */
+ if (cmd->arityMax == -1) {
+ num_args--;
}
+
+ for (i = 0; i < num_args; i++) {
+ Jim_Obj *argObjPtr;
+ Jim_Obj *nameObjPtr;
+ Jim_Obj *valueObjPtr;
+
+ Jim_ListIndex(interp, cmd->argListObjPtr, i, &argObjPtr, JIM_NONE);
+ if (i + 1 >= cmd->arityMin) {
+ /* The name is the first element of the list */
+ Jim_ListIndex(interp, argObjPtr, 0, &nameObjPtr, JIM_NONE);
+ }
+ else {
+ /* The element arg is the name */
+ nameObjPtr = argObjPtr;
+ }
+
+ if (i + 1 >= argc) {
+ /* No more values, so use default */
+ /* The value is the second element of the list */
+ Jim_ListIndex(interp, argObjPtr, 1, &valueObjPtr, JIM_NONE);
+ }
+ else {
+ valueObjPtr = argv[i+1];
+ }
+ Jim_SetVariable(interp, nameObjPtr, valueObjPtr);
+ }
+ /* Set optional arguments */
if (cmd->arityMax == -1) {
Jim_Obj *listObjPtr, *objPtr;
- listObjPtr = Jim_NewListObj(interp, argv+cmd->arityMin,
- argc-cmd->arityMin);
- Jim_ListIndex(interp, cmd->argListObjPtr, i, &objPtr, JIM_NONE);
+ i++;
+ listObjPtr = Jim_NewListObj(interp, argv+i, argc-i);
+ Jim_ListIndex(interp, cmd->argListObjPtr, num_args, &objPtr, JIM_NONE);
Jim_SetVariable(interp, objPtr, listObjPtr);
}
/* Eval the body */
@@ -10932,17 +10961,31 @@ static int Jim_ProcCoreCommand(Jim_Interp *interp, int argc,
}
Jim_ListLength(interp, argv[2], &argListLen);
arityMin = arityMax = argListLen+1;
+
if (argListLen) {
const char *str;
int len;
- Jim_Obj *lastArgPtr;
+ Jim_Obj *argPtr;
- Jim_ListIndex(interp, argv[2], argListLen-1, &lastArgPtr, JIM_NONE);
- str = Jim_GetString(lastArgPtr, &len);
+ /* Check for 'args' and adjust arityMin and arityMax if necessary */
+ Jim_ListIndex(interp, argv[2], argListLen-1, &argPtr, JIM_NONE);
+ str = Jim_GetString(argPtr, &len);
if (len == 4 && memcmp(str, "args", 4) == 0) {
arityMin--;
arityMax = -1;
}
+
+ /* Check for default arguments and reduce arityMin if necessary */
+ while (arityMin > 1) {
+ int len;
+ Jim_ListIndex(interp, argv[2], arityMin - 2, &argPtr, JIM_NONE);
+ Jim_ListLength(interp, argPtr, &len);
+ if (len != 2) {
+ /* No default argument */
+ break;
+ }
+ arityMin--;
+ }
}
if (argc == 4) {
return Jim_CreateProcedure(interp, Jim_GetString(argv[1], NULL),