RAPL

Check-in [cc0ac3e341]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:added param to incrRefCoutn decrRefCount and newObj for being able to check garbage collection and refcounting for rapl
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:cc0ac3e34155949ce7b7ef26bde436a7a4b50058
User & Date: arnulf 2012-03-04 21:22:21
Context
2012-03-10
15:56
make the debugging info dependent of a flag variable check-in: a36c72ccf5 user: arnulf tags: trunk
2012-03-04
21:22
added param to incrRefCoutn decrRefCount and newObj for being able to check garbage collection and refcounting for rapl check-in: cc0ac3e341 user: arnulf tags: trunk
21:20
init the options within the constructor otherwise we have problems in allocating Rapl Objects as the interp does not yet exist!! check-in: 55b325702b user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to rapl_array_obj_type.js.

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

      if (obj_ptr.obj_type == array_obj.interp.interpolated_obj_type) {
        /* An interpolated object in array form */
        var token = obj_ptr.twoPtrValue.ptr1();

        var_obj_ptr = token[0].objPtr;
        key_obj_ptr = obj_ptr.twoPtrValue.ptr2();
        var_obj_ptr.incrRefCount();
        key_obj_ptr.incrRefCount();
      } else {
        var_obj_ptr = new Array();
        key_obj_ptr = new Array();
        array_obj.arrayParseVarKey(obj_ptr, var_obj_ptr, key_obj_ptr);
	var_obj_ptr = var_obj_ptr[0];
	key_obj_ptr = key_obj_ptr[0];
      }
................................................................................
    var key_obj_ptr;
    var parts;

    str = obj_ptr.getString();
    len = obj_ptr.getStringLength();
    parts = array_obj.interp.getArrayNameParts(str, len);
    array_obj.interp.panic(parts == null, "arrayParseVarKey() called for non-array (%s)", str);
    var_obj_ptr = array_obj.interp.string_obj_type.newStringObj(parts[0], parts[0].length);
    key_obj_ptr = array_obj.interp.string_obj_type.newStringObj(parts[1], parts[1].length);
    var_obj_ptr.incrRefCount();
    key_obj_ptr.incrRefCount();
    var_ptr_ptr[0] = var_obj_ptr;
    key_ptr_ptr[0] = key_obj_ptr;
  },

  /* ==================== arraySet ================================== */
  /* Helper of setVariable() to deal with array variable names.
   * Also used by unsetVariable() with val_obj_ptr = null. 
................................................................................
    var index_ptr = new Array();

    array_obj.setFromAny(obj_ptr);
    if (array_obj.interp.script_obj_type.substObj(obj_ptr.arrayValue.indexObjPtr(), subst_key_obj_ptr, array_obj.FUNCTION_FLAGS_NONE) != array_obj.OK) {
      return null;
    }
    subst_key_obj_ptr = subst_key_obj_ptr[0]
    subst_key_obj_ptr.incrRefCount();
    var_ptr = array_obj.interp.variable_obj_type.lookupSimpleVar(obj_ptr.arrayValue.varNameObjPtr(), 0, create_part1, err_msg_ptr, index_ptr);
    if (var_ptr != null) {
      array_obj.interp.variable_obj_type.handleVariableTrace(obj_ptr.arrayValue.varNameObjPtr(), subst_key_obj_ptr, array_obj.TRACE_OP_READ, "read", var_ptr);
    }
    retcode = array_obj.interp.dict_obj_type.expandArrayVariable(obj_ptr.arrayValue.varNameObjPtr(), subst_key_obj_ptr, flags, result_var_ptr);
    subst_key_obj_ptr.decrRefCount();
    return retcode;
  },

  /* ==================== expandArray ================================== */
  /* This function is used to expand array get in the form
   * of $var(INDEX). The function is mainly used by EvalObj()
   * to deal with tokens of type TOKEN_VAR_ARRAY_NAME. obj_ptr points to an
................................................................................
    var subst_key_obj_ptr = new Array();

    array_obj.setFromAny(obj_ptr);
    if (array_obj.interp.script_obj_type.substObj(obj_ptr.arrayValue.indexObjPtr(), subst_key_obj_ptr, array_obj.FUNCTION_FLAGS_NONE) != array_obj.OK) {
        return null;
    }
    subst_key_obj_ptr = subst_key_obj_ptr[0]
    subst_key_obj_ptr.incrRefCount();
    var name_obj_ptr = obj_ptr.arrayValue.varNameObjPtr();
    res_obj_ptr = array_obj.interp.dict_obj_type.expandArrayVariable(name_obj_ptr, subst_key_obj_ptr, 0);
    subst_key_obj_ptr.decrRefCount();
    return res_obj_ptr;
  },

});

ArrayObjType.prototype.constructor = ArrayObjType;

R.ArrayObjType = ArrayObjType;

}, "0.0.1", {});







|
|







 







|
|
|
|







 







|





|







 







|


|










42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

      if (obj_ptr.obj_type == array_obj.interp.interpolated_obj_type) {
        /* An interpolated object in array form */
        var token = obj_ptr.twoPtrValue.ptr1();

        var_obj_ptr = token[0].objPtr;
        key_obj_ptr = obj_ptr.twoPtrValue.ptr2();
        var_obj_ptr.incrRefCount("I_ARRAY_OBJ_TYPE_1");
        key_obj_ptr.incrRefCount("I_ARRAY_OBJ_TYPE_2");
      } else {
        var_obj_ptr = new Array();
        key_obj_ptr = new Array();
        array_obj.arrayParseVarKey(obj_ptr, var_obj_ptr, key_obj_ptr);
	var_obj_ptr = var_obj_ptr[0];
	key_obj_ptr = key_obj_ptr[0];
      }
................................................................................
    var key_obj_ptr;
    var parts;

    str = obj_ptr.getString();
    len = obj_ptr.getStringLength();
    parts = array_obj.interp.getArrayNameParts(str, len);
    array_obj.interp.panic(parts == null, "arrayParseVarKey() called for non-array (%s)", str);
    var_obj_ptr = array_obj.interp.string_obj_type.newStringObj(parts[0], parts[0].length, "ARRAY_OBJ_TYPE_1");
    key_obj_ptr = array_obj.interp.string_obj_type.newStringObj(parts[1], parts[1].length, "ARRAY_OBJ_TYPE_2");
    var_obj_ptr.incrRefCount("I_ARRAY_OBJ_TYPE_3");
    key_obj_ptr.incrRefCount("I_ARRAY_OBJ_TYPE_4");
    var_ptr_ptr[0] = var_obj_ptr;
    key_ptr_ptr[0] = key_obj_ptr;
  },

  /* ==================== arraySet ================================== */
  /* Helper of setVariable() to deal with array variable names.
   * Also used by unsetVariable() with val_obj_ptr = null. 
................................................................................
    var index_ptr = new Array();

    array_obj.setFromAny(obj_ptr);
    if (array_obj.interp.script_obj_type.substObj(obj_ptr.arrayValue.indexObjPtr(), subst_key_obj_ptr, array_obj.FUNCTION_FLAGS_NONE) != array_obj.OK) {
      return null;
    }
    subst_key_obj_ptr = subst_key_obj_ptr[0]
    subst_key_obj_ptr.incrRefCount("I_ARRAY_OBJ_TYPE_5");
    var_ptr = array_obj.interp.variable_obj_type.lookupSimpleVar(obj_ptr.arrayValue.varNameObjPtr(), 0, create_part1, err_msg_ptr, index_ptr);
    if (var_ptr != null) {
      array_obj.interp.variable_obj_type.handleVariableTrace(obj_ptr.arrayValue.varNameObjPtr(), subst_key_obj_ptr, array_obj.TRACE_OP_READ, "read", var_ptr);
    }
    retcode = array_obj.interp.dict_obj_type.expandArrayVariable(obj_ptr.arrayValue.varNameObjPtr(), subst_key_obj_ptr, flags, result_var_ptr);
    subst_key_obj_ptr.decrRefCount("D_ARRAY_OBJ_TYPE_1");
    return retcode;
  },

  /* ==================== expandArray ================================== */
  /* This function is used to expand array get in the form
   * of $var(INDEX). The function is mainly used by EvalObj()
   * to deal with tokens of type TOKEN_VAR_ARRAY_NAME. obj_ptr points to an
................................................................................
    var subst_key_obj_ptr = new Array();

    array_obj.setFromAny(obj_ptr);
    if (array_obj.interp.script_obj_type.substObj(obj_ptr.arrayValue.indexObjPtr(), subst_key_obj_ptr, array_obj.FUNCTION_FLAGS_NONE) != array_obj.OK) {
        return null;
    }
    subst_key_obj_ptr = subst_key_obj_ptr[0]
    subst_key_obj_ptr.incrRefCount("I_ARRAY_OBJ_TYPE_6");
    var name_obj_ptr = obj_ptr.arrayValue.varNameObjPtr();
    res_obj_ptr = array_obj.interp.dict_obj_type.expandArrayVariable(name_obj_ptr, subst_key_obj_ptr, 0);
    subst_key_obj_ptr.decrRefCount("D_ARRAY_OBJ_TYPE_2");
    return res_obj_ptr;
  },

});

ArrayObjType.prototype.constructor = ArrayObjType;

R.ArrayObjType = ArrayObjType;

}, "0.0.1", {});

Changes to rapl_command.js.

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  /* ==================== decrCmdRefCount ===================================== */
  decrCmdRefCount: function () {
    var cmd_ptr = this;

    cmd_ptr.ref_count--;
    if (cmd_ptr.ref_count == 0) {
      if (cmd_ptr.is_proc) {
        cmd_ptr.u.proc.arg_list_obj_ptr.decrRefCount();
        cmd_ptr.u.proc.body_obj_ptr.decrRefCount();
        if (cmd_ptr.u.proc.static_vars) {
          cmd_ptr.u.proc.static_vars = null;
        }
        if (cmd_ptr.u.proc.prev_cmd) {
          /* Delete any pushed command too */
          cmd_ptr.u.proc.prev_cmd.decrCmdRefCount();
        }
................................................................................
      }
    }
//print("CMD4!");
    return r;
  },

  /* ==================== requireExactArgc ===================================== */
  requireExactArgc: function (args, argc, name, msg) {
    if (args.length != argc) {
      throw "wrong # of args: "+name+" "+argc+" arguments expected, got "+args.length+" "+args+"!";
    }
  },

  /* ==================== requireMinArgc ===================================== */
  requireMinArgc: function (args, argc, name, msg) {
    if (args.length < argc) {
      throw "wrong # of args: "+name+" "+argc+" arguments expected at least, got "+args.length+" "+args+"!";
    }
  },

  /* ==================== requireArgcRange ===================================== */
  requireArgcRange: function (args, min, max, name, msg) {
    if (args.length < min || args.length > max) {
      throw "wrong # of args: "+name+" "+min+" to "+max+" arguments expected, got "+args.length+" "+args+"!";
    }
  },

  /* ==================== addCommandTrace ===================================== */
  addCommandTrace: function(trace_obj) {







|
|







 







|






|






|







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  /* ==================== decrCmdRefCount ===================================== */
  decrCmdRefCount: function () {
    var cmd_ptr = this;

    cmd_ptr.ref_count--;
    if (cmd_ptr.ref_count == 0) {
      if (cmd_ptr.is_proc) {
        cmd_ptr.u.proc.arg_list_obj_ptr.decrRefCount("D_COMMAND_1");
        cmd_ptr.u.proc.body_obj_ptr.decrRefCount("D_COMMAND_2");
        if (cmd_ptr.u.proc.static_vars) {
          cmd_ptr.u.proc.static_vars = null;
        }
        if (cmd_ptr.u.proc.prev_cmd) {
          /* Delete any pushed command too */
          cmd_ptr.u.proc.prev_cmd.decrCmdRefCount();
        }
................................................................................
      }
    }
//print("CMD4!");
    return r;
  },

  /* ==================== requireExactArgc ===================================== */
  old_requireExactArgc: function (args, argc, name, msg) {
    if (args.length != argc) {
      throw "wrong # of args: "+name+" "+argc+" arguments expected, got "+args.length+" "+args+"!";
    }
  },

  /* ==================== requireMinArgc ===================================== */
  old_requireMinArgc: function (args, argc, name, msg) {
    if (args.length < argc) {
      throw "wrong # of args: "+name+" "+argc+" arguments expected at least, got "+args.length+" "+args+"!";
    }
  },

  /* ==================== requireArgcRange ===================================== */
  old_requireArgcRange: function (args, min, max, name, msg) {
    if (args.length < min || args.length > max) {
      throw "wrong # of args: "+name+" "+min+" to "+max+" arguments expected, got "+args.length+" "+args+"!";
    }
  },

  /* ==================== addCommandTrace ===================================== */
  addCommandTrace: function(trace_obj) {

Changes to rapl_command_obj_type.js.

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
...
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
...
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
...
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
...
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
...
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
    cmd_ptr.ns_ptr = ns_ptr;
    cmd_ptr.u.proc.cmd_proc = intp.command_obj_type.callProcedure;
    cmd_ptr.u.proc.arg_list_obj_ptr = arg_list_obj_ptr;
    cmd_ptr.u.proc.body_obj_ptr = body_obj_ptr;
    cmd_ptr.file_name = intp.curr_file_name;
    cmd_ptr.line_no = intp.curr_line_no;
    cmd_ptr.last_line_no = intp.last_line_no;
    arg_list_obj_ptr.incrRefCount();
    body_obj_ptr.incrRefCount();

    /* Create the statics hash table. */
    if (statics_list_obj_ptr) {
      var len;
      var i;

      len = intp.list_obj_type.listLength(statics_list_obj_ptr);
................................................................................
            }
            if (!err) {
              if (intp.validName("static variable", name_obj_ptr) != intp.OK) {
                err = true;
              } else {
                var_ptr = new R.Variable(intp, name_obj_ptr.getString(), "VAR_UNDEFINED", intp.frame_ptr, null);
                var_ptr.obj_ptr = init_obj_ptr;
                init_obj_ptr.incrRefCount();
                var_ptr.link_frame_ptr = null;
                if (intp.default_obj.addHashEntry(cmd_ptr.u.proc.static_vars, name_obj_ptr.getString(), var_ptr) != intp.OK) {
                  intp.setResultFormatted("static variable name \"%#s\" duplicated in statics list", name_obj_ptr);
                  init_obj_ptr.decrRefCount();
                  // var_ptr.free();
                  err = true;
                }
              }
            }
          } else {
            intp.setResultFormatted("too many fields in static specifier \"%#s\"", obj_ptr);
................................................................................
       * qualifiers. To create the new command in the right namespace, we
       * generate a fully qualified name for it.
       */
      if (ns_ptr != intp.global_ns_ptr) {
        full_cmd_name = ns_ptr.full_name+"::";
      }
      full_cmd_name += cmd_name.getString();
      full_cmd_name = intp.string_obj_type.newStringObj(full_cmd_name, -1);
      /* It may already exist, so we try to delete the old one.
       * Note that reference count means that it won't be deleted yet if
       * it exists in the call stack.
       *
       * BUT, if 'local' is in force, instead of deleting the existing
       * proc, we stash a reference to the old proc here.
       */
................................................................................
      intp.setResult(cmd_name);
      return intp.OK;
    }
    if (cmd_Ptr.u.proc.static_vars) {
      cmd_ptr.u.proc.static_vars = null;
    }
    //    cmd_ptr.u.proc.static_vars.free();
    arg_list_obj_ptr.decrRefCount();
    body_obj_ptr.decrRefCount();
    //    cmd_ptr.free();
    return intp.ERROR;
  },

  /* ==================== setProcArg ================================== */
  setProcArg: function(arg_name_ptr, arg_val_ptr) {
    var cmd = this;
................................................................................
      cmd.interp.frame_ptr = cmd.interp.frame_ptr.parent_call_frame;
      obj_ptr = cmd.interp.variable_obj_type.getVariable(arg_val_ptr, cmd.FUNCTION_FLAGS_LEAVE_ERR_MSG);
      cmd.interp.frame_ptr = saved_call_frame;
      if (!obj_ptr) {
        return cmd.ERROR;
      }
      /* It exists, so perform the binding. */
      obj_ptr = cmd.interp.string_obj_type.newStringObj(var_name.substring(1), -1);
      obj_ptr.incrRefCount();
      retcode = cmd.interp.variable_obj_type.setVariableLink(obj_ptr, arg_val_ptr, cmd.interp.frame_ptr.parent_call_frame);
      obj_ptr.decrRefCount();
    } else {
      retcode = cmd.interp.variable_obj_type.setVariable(arg_name_ptr, arg_val_ptr);
    }
    return retcode;
  },

  /* ==================== setWrongArgs ================================== */
  /**
   * Sets the interp result to be an error message indicating the required proc args.
   */
  setWrongArgs: function(proc_name_ptr, cmd_ptr) {
    var cmd = this;
    /* Create a nice error message, consistent with Tcl 8.5 */
    var arg_msg = cmd.interp.string_obj_type.newStringObj("", 0);
    var i;
    var param_info = cmd_ptr.u.proc.arg_list_obj_ptr.paramInfo.params();

    for (i = 0; i < param_info.arg_list.length; i++) {
      cmd.interp.string_obj_type.appendString(arg_msg, " ", 1);
      if (i == param_info.args_pos) {
        if (param_info.arg_list[i].default_obj_ptr) {
................................................................................
          cmd.interp.string_obj_type.appendString(arg_msg, "?", 1);
        } else {
          cmd.interp.string_obj_type.appendObj(arg_msg, param_info.arg_list[i].name_obj_ptr);
        }
      }
    }
    cmd.interp.setResultFormatted("wrong # args: should be \"%#s%#s\"", proc_name_ptr, arg_msg);
    arg_msg.freeObj();
  },

  /* ==================== callProcedure ================================== */
  /* Call a procedure implemented in Tcl.
   * It's possible to speed-up a lot this function, currently
   * the call frames are not cached, but allocated and
   * destroied every time. What is expecially costly is
................................................................................
    call_frame_ptr.argv = argv;
    call_frame_ptr.argc = argc;
    call_frame_ptr.proc_args_obj_ptr = cmd_ptr.u.proc.arg_list_obj_ptr;
    call_frame_ptr.proc_body_obj_ptr = cmd_ptr.u.proc.body_obj_ptr;
    call_frame_ptr.static_vars = cmd_ptr.u.proc.static_vars;
    call_frame_ptr.file_name_obj = file_name_obj;
    call_frame_ptr.line = linenr;
    cmd_ptr.u.proc.arg_list_obj_ptr.incrRefCount();
    cmd_ptr.u.proc.body_obj_ptr.incrRefCount();
    intp.frame_ptr = call_frame_ptr;
    /* Install a new stack for local procs */
    prev_local_procs = intp.local_procs;
    intp.local_procs = null;
    /* How many optional args are available */
    optargs = (argc - 1 - param_info.req_arity);
    /* Step 'i' along the actual args, and step 'd' along the formal args */
................................................................................
//    } else {
//        JimFreeCallFrame(interp, callFramePtr, JIM_FCF_NOHT);
//    }
    /* Handle the EVAL return code */
    while (retcode == cmd.EVAL) {
      var result_script_obj_ptr = intp.getResult();

      result_script_obj_ptr.incrRefCount();
      /* Result must be a list */
      retcode = intp.eval_statement.evalObjList(result_script_obj_ptr, file_name_obj, line_no);
      if (retcode == cmd.RETURN) {
        /* If the result of the tailcall invokes 'return', push
         * it up to the caller
         */
        intp.return_level++;
      }
      result_script_obj_ptr.decrRefCount();
    }
    /* Handle the RETURN return code */
    if (retcode == cmd.RETURN) {
      if (--intp.return_level <= 0) {
        retcode = intp.return_code;
        intp.return_code = cmd.OK;
        intp.return_level = 0;
      }
    } else {
      if (retcode == cmd.ERROR) {
        intp.add_stack_trace++;
        intp.error_proc.decrRefCount();
        intp.error_proc = argv[0];
        intp.error_proc.incrRefCount();
      }
    }
    /* Delete any local procs */
    intp.deleteLocalProcs();
    intp.local_procs = prev_local_procs;
    return retcode;
  },







|
|







 







|



|







 







|







 







|
|







 







|
|

|













|







 







|







 







|
|







 







|








|











|

|







243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
...
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
...
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
...
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
...
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
...
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
    cmd_ptr.ns_ptr = ns_ptr;
    cmd_ptr.u.proc.cmd_proc = intp.command_obj_type.callProcedure;
    cmd_ptr.u.proc.arg_list_obj_ptr = arg_list_obj_ptr;
    cmd_ptr.u.proc.body_obj_ptr = body_obj_ptr;
    cmd_ptr.file_name = intp.curr_file_name;
    cmd_ptr.line_no = intp.curr_line_no;
    cmd_ptr.last_line_no = intp.last_line_no;
    arg_list_obj_ptr.incrRefCount("I_COMMAND_OBJ_TYPE_1");
    body_obj_ptr.incrRefCount("I_COMMAND_OBJ_TYPE_2");

    /* Create the statics hash table. */
    if (statics_list_obj_ptr) {
      var len;
      var i;

      len = intp.list_obj_type.listLength(statics_list_obj_ptr);
................................................................................
            }
            if (!err) {
              if (intp.validName("static variable", name_obj_ptr) != intp.OK) {
                err = true;
              } else {
                var_ptr = new R.Variable(intp, name_obj_ptr.getString(), "VAR_UNDEFINED", intp.frame_ptr, null);
                var_ptr.obj_ptr = init_obj_ptr;
                init_obj_ptr.incrRefCount("I_COMMAND_OBJ_TYPE_3");
                var_ptr.link_frame_ptr = null;
                if (intp.default_obj.addHashEntry(cmd_ptr.u.proc.static_vars, name_obj_ptr.getString(), var_ptr) != intp.OK) {
                  intp.setResultFormatted("static variable name \"%#s\" duplicated in statics list", name_obj_ptr);
                  init_obj_ptr.decrRefCount("D_COMMAND_OBJ_TYPE_1");
                  // var_ptr.free();
                  err = true;
                }
              }
            }
          } else {
            intp.setResultFormatted("too many fields in static specifier \"%#s\"", obj_ptr);
................................................................................
       * qualifiers. To create the new command in the right namespace, we
       * generate a fully qualified name for it.
       */
      if (ns_ptr != intp.global_ns_ptr) {
        full_cmd_name = ns_ptr.full_name+"::";
      }
      full_cmd_name += cmd_name.getString();
      full_cmd_name = intp.string_obj_type.newStringObj(full_cmd_name, -1, "COMMAND_OBJ_TYPE_1");
      /* It may already exist, so we try to delete the old one.
       * Note that reference count means that it won't be deleted yet if
       * it exists in the call stack.
       *
       * BUT, if 'local' is in force, instead of deleting the existing
       * proc, we stash a reference to the old proc here.
       */
................................................................................
      intp.setResult(cmd_name);
      return intp.OK;
    }
    if (cmd_Ptr.u.proc.static_vars) {
      cmd_ptr.u.proc.static_vars = null;
    }
    //    cmd_ptr.u.proc.static_vars.free();
    arg_list_obj_ptr.decrRefCount("D_COMMAND_OBJ_TYPE_2");
    body_obj_ptr.decrRefCount("D_COMMAND_OBJ_TYPE_3");
    //    cmd_ptr.free();
    return intp.ERROR;
  },

  /* ==================== setProcArg ================================== */
  setProcArg: function(arg_name_ptr, arg_val_ptr) {
    var cmd = this;
................................................................................
      cmd.interp.frame_ptr = cmd.interp.frame_ptr.parent_call_frame;
      obj_ptr = cmd.interp.variable_obj_type.getVariable(arg_val_ptr, cmd.FUNCTION_FLAGS_LEAVE_ERR_MSG);
      cmd.interp.frame_ptr = saved_call_frame;
      if (!obj_ptr) {
        return cmd.ERROR;
      }
      /* It exists, so perform the binding. */
      obj_ptr = cmd.interp.string_obj_type.newStringObj(var_name.substring(1), -1, "COMMAND_OBJ_TYPE_2");
      obj_ptr.incrRefCount("I_COMMAND_OBJ_TYPE_4");
      retcode = cmd.interp.variable_obj_type.setVariableLink(obj_ptr, arg_val_ptr, cmd.interp.frame_ptr.parent_call_frame);
      obj_ptr.decrRefCount("D_COMMAND_OBJ_TYPE_3");
    } else {
      retcode = cmd.interp.variable_obj_type.setVariable(arg_name_ptr, arg_val_ptr);
    }
    return retcode;
  },

  /* ==================== setWrongArgs ================================== */
  /**
   * Sets the interp result to be an error message indicating the required proc args.
   */
  setWrongArgs: function(proc_name_ptr, cmd_ptr) {
    var cmd = this;
    /* Create a nice error message, consistent with Tcl 8.5 */
    var arg_msg = cmd.interp.string_obj_type.newStringObj("", 0, "COMMAND_OBJ_TYPE_3");
    var i;
    var param_info = cmd_ptr.u.proc.arg_list_obj_ptr.paramInfo.params();

    for (i = 0; i < param_info.arg_list.length; i++) {
      cmd.interp.string_obj_type.appendString(arg_msg, " ", 1);
      if (i == param_info.args_pos) {
        if (param_info.arg_list[i].default_obj_ptr) {
................................................................................
          cmd.interp.string_obj_type.appendString(arg_msg, "?", 1);
        } else {
          cmd.interp.string_obj_type.appendObj(arg_msg, param_info.arg_list[i].name_obj_ptr);
        }
      }
    }
    cmd.interp.setResultFormatted("wrong # args: should be \"%#s%#s\"", proc_name_ptr, arg_msg);
    arg_msg.freeObj("COMMAND_OBJ_TYPE_1");
  },

  /* ==================== callProcedure ================================== */
  /* Call a procedure implemented in Tcl.
   * It's possible to speed-up a lot this function, currently
   * the call frames are not cached, but allocated and
   * destroied every time. What is expecially costly is
................................................................................
    call_frame_ptr.argv = argv;
    call_frame_ptr.argc = argc;
    call_frame_ptr.proc_args_obj_ptr = cmd_ptr.u.proc.arg_list_obj_ptr;
    call_frame_ptr.proc_body_obj_ptr = cmd_ptr.u.proc.body_obj_ptr;
    call_frame_ptr.static_vars = cmd_ptr.u.proc.static_vars;
    call_frame_ptr.file_name_obj = file_name_obj;
    call_frame_ptr.line = linenr;
    cmd_ptr.u.proc.arg_list_obj_ptr.incrRefCount("I_COMMAND_OBJ_TYPE_5");
    cmd_ptr.u.proc.body_obj_ptr.incrRefCount("I_COMMAND_OBJ_TYPE_6");
    intp.frame_ptr = call_frame_ptr;
    /* Install a new stack for local procs */
    prev_local_procs = intp.local_procs;
    intp.local_procs = null;
    /* How many optional args are available */
    optargs = (argc - 1 - param_info.req_arity);
    /* Step 'i' along the actual args, and step 'd' along the formal args */
................................................................................
//    } else {
//        JimFreeCallFrame(interp, callFramePtr, JIM_FCF_NOHT);
//    }
    /* Handle the EVAL return code */
    while (retcode == cmd.EVAL) {
      var result_script_obj_ptr = intp.getResult();

      result_script_obj_ptr.incrRefCount("I_COMMAND_OBJ_TYPE_7");
      /* Result must be a list */
      retcode = intp.eval_statement.evalObjList(result_script_obj_ptr, file_name_obj, line_no);
      if (retcode == cmd.RETURN) {
        /* If the result of the tailcall invokes 'return', push
         * it up to the caller
         */
        intp.return_level++;
      }
      result_script_obj_ptr.decrRefCount("D_COMMAND_OBJ_TYPE_4");
    }
    /* Handle the RETURN return code */
    if (retcode == cmd.RETURN) {
      if (--intp.return_level <= 0) {
        retcode = intp.return_code;
        intp.return_code = cmd.OK;
        intp.return_level = 0;
      }
    } else {
      if (retcode == cmd.ERROR) {
        intp.add_stack_trace++;
        intp.error_proc.decrRefCount("D_COMMAND_OBJ_TYPE_5");
        intp.error_proc = argv[0];
        intp.error_proc.incrRefCount("I_COMMAND_OBJ_TYPE_8");
      }
    }
    /* Delete any local procs */
    intp.deleteLocalProcs();
    intp.local_procs = prev_local_procs;
    return retcode;
  },

Changes to rapl_dict_obj_type.js.

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
..
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
...
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
...
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
        var key_obj_ptr = new Array();
        var val_obj_ptr = new Array();

        dct.interp.list_obj_type.listIndex(obj_ptr, i, key_obj_ptr, dct.FUNCTION_FLAGS_NONE);
        dct.interp.list_obj_type.listIndex(obj_ptr, i + 1, val_obj_ptr, dct.FUNCTION_FLAGS_NONE);
        key_obj_ptr = key_obj_ptr[0];
        val_obj_ptr = val_obj_ptr[0];
        key_obj_ptr.incrRefCount();
        val_obj_ptr.incrRefCount();
        ht[key_obj_ptr.getString()] = val_obj_ptr;
        key_obj_ptr.decrRefCount();
      }
      obj_ptr.freeIntRep();
      obj_ptr.obj_type = dct.interp.dict_obj_type;
      obj_ptr.ptr(ht);
      return dct.OK;
    }
  },
................................................................................
  dupInternalRep: function(src_ptr, dup_ptr) {
    var dct = this;
    var ht = src_ptr.ptr();
    var dup_ht = new Object();

    for (var z in ht) {
      dup_ht[z] = ht[z];
      dup_ht[z].incrRefCount();
    }
    dup_ptr.ptr(dup_ht);
    dup_ptr.obj_type = dct.interp.dict_obj_type;
  },

  /* ==================== updateString ===================================== */
  updateString: function(obj_ptr) {
................................................................................
  addElement: function(obj_ptr, key_obj_ptr, value_obj_ptr) {
    var dct = this;
    var ht = obj_ptr.ptr();
    var my_name = dct.escape_key(key_obj_ptr.getString());

    if (value_obj_ptr == null) {  /* unset */
      if (typeof ht[my_name] != "undefined") {
        ht[my_name].decrRefCount();
        delete ht[my_name];
      }
      return dct.OK;
    }
    if (typeof ht[my_name] != "undefined") {
      ht[my_name].decrRefCount();
    }
    value_obj_ptr.incrRefCount();
    ht[my_name] = value_obj_ptr;
    return dct.OK;
  },

  /* ==================== dictAddElement ===================================== */
  dictAddElement: function(obj_ptr, key_obj_ptr, value_obj_ptr) {
    var dct = this;
................................................................................
        return dct.ERROR;
      }
    }
    ht = dict_ptr.ptr();
    /* Turn the hash table into a flat vector of RaplObjects. */
    objv = new Array();
    for (var z in ht) {
      objv[i++] = dct.interp.string_obj_type.newStringObj(z, -1);
      objv[i++] = ht[z];
    }
    len_ptr[0] = i;
    obj_ptr_ptr[0] = objv;
    return dct.OK;
  },

................................................................................
    if (obj_ptr == null) {
      if (new_obj_ptr == null) { /* Cannot remove a key from non existing var */
        return dct.ERROR;
      }
      var_obj_ptr = dct.newDictObj(null, 0);
      obj_ptr = var_obj_ptr;
      if (dct.interp.variable_obj_type.setVariable(var_name_ptr, obj_ptr) != dct.OK) {
        var_obj_ptr.decrRefCount();
        return dct.ERROR;
      }
    }
    if ((shared = obj_ptr.isShared())) {
      var_obj_ptr = obj_ptr.duplicateObj();
      objPtr = var_obj_ptr;
    }
................................................................................
        err = true;
      }
    }
    if (!err) {
      obj_ptr.invalidateStringRep();
      var_obj_ptr.invalidateStringRep();
      // FIXME have to understand why next line is necessary!!
      var_obj_ptr.incrRefCount();
      if (dct.interp.variable_obj_type.setVariable(var_name_ptr, var_obj_ptr) != dct.OK) {
        err = true;
      }
      var_obj_ptr.decrRefCount();
    }
    if (!err) {
      dct.interp.setResult(var_obj_ptr);
      return dct.OK;
    }
    if (shared) {
      var_obj_ptr.freeNewObj();







|
|

|







 







|







 







|





|

|







 







|







 







|







 







|



|







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
..
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
...
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
...
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
        var key_obj_ptr = new Array();
        var val_obj_ptr = new Array();

        dct.interp.list_obj_type.listIndex(obj_ptr, i, key_obj_ptr, dct.FUNCTION_FLAGS_NONE);
        dct.interp.list_obj_type.listIndex(obj_ptr, i + 1, val_obj_ptr, dct.FUNCTION_FLAGS_NONE);
        key_obj_ptr = key_obj_ptr[0];
        val_obj_ptr = val_obj_ptr[0];
        key_obj_ptr.incrRefCount("I_DICT_OBJ_TYPE_1");
        val_obj_ptr.incrRefCount("I_DICT_OBJ_TYPE_2");
        ht[key_obj_ptr.getString()] = val_obj_ptr;
        key_obj_ptr.decrRefCount("D_DICT_OBJ_TYPE_1");
      }
      obj_ptr.freeIntRep();
      obj_ptr.obj_type = dct.interp.dict_obj_type;
      obj_ptr.ptr(ht);
      return dct.OK;
    }
  },
................................................................................
  dupInternalRep: function(src_ptr, dup_ptr) {
    var dct = this;
    var ht = src_ptr.ptr();
    var dup_ht = new Object();

    for (var z in ht) {
      dup_ht[z] = ht[z];
      dup_ht[z].incrRefCount("I_DICT_OBJ_TYPE_3");
    }
    dup_ptr.ptr(dup_ht);
    dup_ptr.obj_type = dct.interp.dict_obj_type;
  },

  /* ==================== updateString ===================================== */
  updateString: function(obj_ptr) {
................................................................................
  addElement: function(obj_ptr, key_obj_ptr, value_obj_ptr) {
    var dct = this;
    var ht = obj_ptr.ptr();
    var my_name = dct.escape_key(key_obj_ptr.getString());

    if (value_obj_ptr == null) {  /* unset */
      if (typeof ht[my_name] != "undefined") {
        ht[my_name].decrRefCount("D_DICT_OBJ_TYPE_2");
        delete ht[my_name];
      }
      return dct.OK;
    }
    if (typeof ht[my_name] != "undefined") {
      ht[my_name].decrRefCount("D_DICT_OBJ_TYPE_3");
    }
    value_obj_ptr.incrRefCount("I_DICT_OBJ_TYPE_4");
    ht[my_name] = value_obj_ptr;
    return dct.OK;
  },

  /* ==================== dictAddElement ===================================== */
  dictAddElement: function(obj_ptr, key_obj_ptr, value_obj_ptr) {
    var dct = this;
................................................................................
        return dct.ERROR;
      }
    }
    ht = dict_ptr.ptr();
    /* Turn the hash table into a flat vector of RaplObjects. */
    objv = new Array();
    for (var z in ht) {
      objv[i++] = dct.interp.string_obj_type.newStringObj(z, -1, "DICT_OBJ_TYPE_1");
      objv[i++] = ht[z];
    }
    len_ptr[0] = i;
    obj_ptr_ptr[0] = objv;
    return dct.OK;
  },

................................................................................
    if (obj_ptr == null) {
      if (new_obj_ptr == null) { /* Cannot remove a key from non existing var */
        return dct.ERROR;
      }
      var_obj_ptr = dct.newDictObj(null, 0);
      obj_ptr = var_obj_ptr;
      if (dct.interp.variable_obj_type.setVariable(var_name_ptr, obj_ptr) != dct.OK) {
        var_obj_ptr.decrRefCount("D_DICT_OBJ_TYPE_4");
        return dct.ERROR;
      }
    }
    if ((shared = obj_ptr.isShared())) {
      var_obj_ptr = obj_ptr.duplicateObj();
      objPtr = var_obj_ptr;
    }
................................................................................
        err = true;
      }
    }
    if (!err) {
      obj_ptr.invalidateStringRep();
      var_obj_ptr.invalidateStringRep();
      // FIXME have to understand why next line is necessary!!
      var_obj_ptr.incrRefCount("I_DICT_OBJ_TYPE_5");
      if (dct.interp.variable_obj_type.setVariable(var_name_ptr, var_obj_ptr) != dct.OK) {
        err = true;
      }
      var_obj_ptr.decrRefCount("D_DICT_OBJ_TYPE_5");
    }
    if (!err) {
      dct.interp.setResult(var_obj_ptr);
      return dct.OK;
    }
    if (shared) {
      var_obj_ptr.freeNewObj();

Changes to rapl_eval_statement.js.

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
...
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
...
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
...
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
...
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
...
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
...
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
...
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
...
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
...
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
...
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
...
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
...
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
...
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
...
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
...
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
    case stmt.TOKEN_VAR_ARRAY_NAME:
    case stmt.TOKEN_VAR:
      result_var_ptr[0] = null;
      obj_ptr = stmt.interp.variable_obj_type.getVariable(token.obj_ptr, stmt.FUNCTION_FLAGS_LEAVE_ERR_MSG, result_var_ptr);
      result_var_ptr = result_var_ptr[0];
      /* special case for ::itcl::type type variable !! */
      if (obj_ptr == null && result_var_ptr != null && token.obj_ptr.getString() == "type") {
        obj_ptr = stmt.interp.string_obj_type.newStringObj(result_var_ptr.namespace.full_name, -1);
        obj_ptr.incrRefCount();
      }
      if (stmt.interp.frame_ptr.type == stmt.CALL_TYPE_MACROEXPAND) {
        /* if we are expanding a macro and we find a not escaped variable not in the
	 * parameter/argument list, for the macro, we ignore that and return the variable
	 * as "$var_name" instead
	 */
        if (obj_ptr == null) {
          obj_ptr = stmt.interp.string_obj_type.newStringObj("$"+token.obj_ptr.getString(), -1);
	  stmt.interp.setResult(stmt.interp.empty_string_obj);
	} else {
          /* if we are expanding a macro and the variable is a list put it into {} to be safe */
          if (obj_ptr.obj_type = stmt.interp.list_obj_type) {
            obj_ptr = stmt.interp.string_obj_type.newStringObj("{"+obj_ptr.getString()+"}", -1);
	  }
	}
      } else {
        if (stmt.had_macro_cmd) {
          obj_ptr = stmt.interp.string_obj_type.newStringObj("$"+token.obj_ptr.getString(), -1);
	}
      }
      break;
    case stmt.TOKEN_ARRAY_NAME_VAR:
      obj_ptr = JimExpandDictSugar(stmt.interp, token.obj_ptr);
      break;
    case stmt.TOKEN_EXPRSUGAR:
................................................................................
      if (!stmt.in_quotes) {
        obj_ptr = token.obj_ptr;
      } else {
        if (token.obj_ptr.len == 0) {
          /* we have a single pair of {} within quotes,
	   * so make a corresponding string object 
	   */
	  obj_ptr = stmt.interp.string_obj_type.newStringObj("{}", -1);
	} else {
        switch (stmt.interp.script_obj_type.substObj(token.obj_ptr, result_ptr, stmt.FUNCTION_FLAGS_LEAVE_ERR_MSG)) {
        case stmt.OK:
	  obj_ptr = result_ptr[0];
	  /* special handling for expand in quotes !! */
	  if (obj_ptr.len == 1 && obj_ptr.bytes.substring(0,1) == "*") {
            obj_ptr.len = 3;
................................................................................
      retcode = stmt.substOneToken(script, idx + i, result_ptr);
      intv2[j] = result_ptr[0];
if (stmt.eval_ipol_debug > 1) {
print("RES!"+result_ptr[0]+"!"+intv2+"!"+retcode+"!");
script.dumpToken(i+idx);
}
      if (intv2[j] != null) {
        intv2[j].incrRefCount();
      }
      switch(retcode) {
      case stmt.OK:
      case stmt.RETURN:
        break;
      case stmt.BREAK:
        if (flags & stmt.SUBST_FLAG) {
................................................................................
          continue;
        }
        /* XXX: Ditto continue outside loop */
        /* fall through to error */
      default:
        while (j--) {
          if (intv2[j] != null) {
            intv2[j].decrRefCount();
	  }
        }
        intv2 = null;
	stmt.in_quotes = my_in_quotes;
        return null;
      }
      total_len += intv2[j].toString().length;
      j++;
    }

    /* Fast path return for a single token */
    if (word_tokens == 1 && intv2[0]) {
      intv2[0].decrRefCount();
      stmt.in_quotes = my_in_quotes;
      return intv2[0];
    }

    /* Concatenate every token in an unique
     * object. 
     */
    obj_ptr = stmt.interp.string_obj_type.newStringObjNoAlloc(null, 0);

    if (word_tokens == 4 && token.length > i + idx + 2 && token[i + idx + 0].token == stmt.TOKEN_ESC && token[i + idx + 1].token == stmt.TOKEN_ESC
        && token[i + idx + 2].token == stmt.TOKEN_VAR) {
      /* May be able to do fast interpolated object  -> array */
      obj_ptr.obj_type = obj_ptr.interpolatedObjType;
      obj_ptr.twoPtrValue.ptr1(token);
      obj_ptr.twoPtrValue.ptr2(intv2[idx + 2]);
      intv2[idx + 2].incrRefCount();
    }

    obj_ptr.bytes = "";
    obj_ptr.length = total_len;
    for (i = 0; i < j; i++) {
      if (intv2[i]) {
        obj_ptr.bytes += intv2[i].toString();
        intv2[i].decrRefCount();
      }
    }
//    obj_ptr.bytes[total_len] = '\0';
    obj_ptr.len = total_len;
    /* Free the intv2 vector. */
    intv2 = null;
if (stmt.eval_ipol_debug > 1) {
................................................................................
      retcode = stmt.evalObjList(script_obj_ptr, stmt.interp.empty_obj, 1);
      if (stmt.macro_cmd_level == stmt.eval_level) {
        stmt.had_macro_cmd = false;
      }
      stmt.eval_level--;
      return retcode;
    }
    script_obj_ptr.incrRefCount();     /* Make sure it's shared. */
    script = script_obj_ptr.interp.script_obj_type.getScript(script_obj_ptr);
    if (script == null) {
      stmt.interp.setResultString("error in parsing script: \""+script_obj_ptr+"\"");
      if (stmt.macro_cmd_level == stmt.eval_level) {
        stmt.had_macro_cmd = false;
      }
      stmt.eval_level--;
................................................................................

    /* Check for one of the following common scripts used by for, while
     *
     *   {}
     *   incr a
     */
    if (script.len == 0) {
      script_obj_ptr.decrRefCount();
      if (stmt.macro_cmd_level == stmt.eval_level) {
        stmt.had_macro_cmd = false;
      }
      stmt.eval_level--;
      return stmt.OK;
    }
    if (script.len == 3
................................................................................
        && script.script_object.tokens[2].obj_ptr.obj_typ.type_name == "variable") {

      var obj_ptr = stmt.interp.getVariable(script.script_object.tokens[2].obj_ptr, stmt.TOKENNONE);

      if (obj_ptr && !obj_ptr.isShared() && obj_ptrobj_type.name == "int") {
//        JimWideValue(obj_ptr)++;
        obj_ptr.invalidateStringRep();
        script_obj_ptr.decrRefCount();
        stmt.interp.setResult(obj_ptr);
        if (stmt.macro_cmd_level == stmt.eval_level) {
          stmt.had_macro_cmd = false;
        }
        stmt.eval_level--;
        return stmt.OK;
      }
................................................................................
          case stmt.TOKEN_VAR:
	    var result_var_ptr = new Array();
	    result_var_ptr[0] = null;
            word_obj_ptr = stmt.interp.variable_obj_type.getVariable(token[i].obj_ptr, stmt.FUNCTION_FLAGS_LEAVE_ERR_MSG, result_var_ptr);
	    result_var_ptr = result_var_ptr[0];
            /* special case for ::itcl::type type variable !! */
            if (word_obj_ptr == null && result_var_ptr != null && token[i].obj_ptr.getString() == "type") {
              word_obj_ptr = stmt.interp.string_obj_type.newStringObj(result_var_ptr.namespace.full_name, -1);
              word_obj_ptr.incrRefCount();
            }
            break;
          case stmt.TOKEN_EXPRSUGAR:
            word_obj_ptr = stmt.expandExprSugar(token[i].obj_ptr);
            break;
          case stmt.TOKEN_ARRAY_NAME_VAR:
            word_obj_ptr = stmt.expandDictSugar(token[i].obj_ptr);
................................................................................
	if (!had_comment) {
          if (!word_obj_ptr) {
            if (retcode == stmt.OK) {
              retcode = stmt.ERROR;
            }
            break;
          }
          word_obj_ptr.incrRefCount();
          if (!expand) {
	    if (!had_comment) {
              argv.push(word_obj_ptr);
	    }
          } else {
            /* Need to expand word_obj_ptr into multiple args from argv[j] ... */
            var len = stmt.interp.list_obj_type.listLength(word_obj_ptr);
................................................................................
            var k;
  
//print("EXPAND!"+argc+"!"+len+"!"+newargc+"!"+word_obj_ptr.toDebugString()+"!");
            /* Now copy in the expanded version */
            for (k = 0; k < len; k++) {
              argv.push(word_obj_ptr.listValue.elem()[k]);
	      j++;
              word_obj_ptr.listValue.elem()[k].incrRefCount();
            }
            /* The original object reference is no longer needed,
             * after the expansion it is no longer present on
             * the argument vector, but the single elements are
             * in its place. 
	     */
            word_obj_ptr.decrRefCount();
            /* And update the indexes */
            j--;
            argc += len - 1;
          }
        }
      }
      if (had_comment) {
................................................................................
            retcode = stmt.interp.unknownFcn(argc, argv, script.script_object.file_name_obj, line_no);
	  } else {
            /* we do not call unknown, if we had only the empty string as command and no arguments */
	  }
        }
      }
//      /* Finished with the command, so decrement ref counts of each argument */
      j = argv.length - 1;
      for (; j > 0; j--) {
        argv[j].decrRefCount();
      }
      argv = new Array();
    }

    /* Possibly add to the error stack trace */
    stmt.addErrorToStack(retcode, script.script_object.file_name_obj, line_no);

    /* Note that we don't have to decrement ref_count, because the
     * following code transfers our use of the reference again to
     * the script object. */
    script_obj_ptr.freeIntRep();
    script_obj_ptr.obj_type = stmt.interp.script_obj_type;
    script_obj_ptr.setIntRepPtr(script);
    script_obj_ptr.decrRefCount();
//print("EVALOBJ end level!"+stmt.eval_level+"!"+retcode+"!");
    if (stmt.macro_cmd_level == stmt.eval_level) {
      stmt.had_macro_cmd = false;
    }
    stmt.eval_level--;
    return retcode;
  },
................................................................................
    var stmt = this;
    var i;
    var retcode;
    var cmd_ptr;

    /* Incr refcount of arguments. */
    for (i = 0; i < objc; i++) {
      objv[i].incrRefCount();
    }
    /* Command lookup */
    cmd_ptr = stmt.interp.getCommand(objv[0], stmt.interp.FUNCTION_FLAGS_LEAVE_ERR_MSG);
//print("EOV!"+cmd_ptr.toDebugString()+"!");
    if (cmd_ptr == null) {
      retcode = stmt.interp.unknown(objc, objv, file_name_obj, line_no);
    } else {
................................................................................
        stmt.interp.cmd_priv_data = cmd_ptr.u.native_fcn.priv_data;
        retcode = cmd_ptr.u.native_fcn.cmd_proc(stmt.interp, objv);
      }
      cmd_ptr.decrCmdRefCount();
    }
    /* Decr refcount of arguments and return the retcode */
    for (i = 0; i < objc; i++) {
      objv[i].decrRefCount();
    }
    return retcode;
  },

  /* ==================== evalObjVector ===================================== */
  evalObjVector: function(objc, objv) {
    var stmt = this;
................................................................................
      if (my_str.match(" ") != null) {
        my_str += sep+"{"+args[i]+"}";
      } else {
        my_str += sep+args[i];
      }
      sep = " ";
    }
    my_ptr = stmt.interp.string_obj_type.newStringObj(my_str, -1);
    my_ptr.incrRefCount();
    ret_code = stmt.evalObj(my_ptr);
    my_ptr.decrRefCount();
    return ret_code;
  },

  /* ==================== evalObjList ===================================== */
  /* If list_ptr is a list, call evalObjVector() with the given source info.
   * Otherwise eval with evalObj()
   */
  evalObjList: function (list_ptr, file_name_obj, linenr) {
    var stmt = this;
    var retcode = stmt.OK;

    stmt.interp.panic(!list_ptr.isListObj(), "evalObjList() called without list arg");
    if (list_ptr.listValue.len()) {
      list_ptr.incrRefCount();
      retcode = stmt.evalObjVector(list_ptr.listValue.len(), list_ptr.listValue.elem(), file_name_obj, linenr);
      list_ptr.decrRefCount();
    }
    return retcode;
  },

  /* ==================== commandMatchObj ===================================== */
  /* Returns 1 if match, 0 if no match or -<error> on error (e.g. -stmt.ERROR, -stmt.BREAK)*/
  commandMatchObj: function(command_obj, pattern_obj, string_obj, nocase) {
................................................................................
    var parms = new Array();
    var argc = 0;
    var eq = new Array();
    var rc;

    parms[argc++] = command_obj;
    if (nocase) {
      parms[argc++] = stmt.interp.string_obj_type.newStringObj("-nocase", -1);
    }
    parms[argc++] = pattern_obj;
    parms[argc++] = string_obj;
    rc = stmt.evalObjVector(argc, parms);
    if (rc != stmt.OK || stmt.interp.int_obj_type.getLong(stmt.interp.getResult(), eq) != stmt.OK) {
      eq[0] = -rc;
    }
................................................................................
  addErrorToStack: function(retcode, file_name_obj, line) {
    var stmt = this;
    var rc = retcode;

    if (rc == stmt.ERROR && !stmt.interp.error_flag) {
        /* This is the first error, so save the file/line information and reset the stack */
        stmt.interp.error_flag = 1;
        file_name_obj.incrRefCount();
        stmt.interp.error_file_name_obj.decrRefCount();
        stmt.interp.error_file_name_obj = file_name_obj;
        stmt.interp.error_line = line;
        stmt.resetStackTrace();
        /* Always add a level where the error first occurs */
        stmt.interp.add_stack_trace++;
    }

................................................................................
         * don't clear the addStackTrace flag
         * so we can pick it up at the next level
         */
        if (file_name_obj.getStringLength()) {
          stmt.interp.add_stack_trace = 0;
        }

        stmt.interp.error_proc.decrRefCount();
        file_name_obj.interp.error_proc = stmt.interp.empty_obj;
        stmt.interp.error_proc.incrRefCount();
    } else {
      if (rc == stmt.RETURN && stmt.interp.return_code == stmt.ERROR) {
        /* Propagate the addStackTrace value through 'return -code error' */
      } else {
        stmt.interp.add_stack_trace = 0;
      }
    }
  },

  /* ==================== resetStackTrace ===================================== */
  resetStackTrace: function() {
    var stmt = this;
    stmt.interp.stack_trace.decrRefCount();
    stmt.interp.stack_trace = stmt.interp.list_obj_type.newListObj(null, 0);
    stmt.interp.stack_trace.incrRefCount();
  },

  /* ==================== setStackTrace ===================================== */
  setStackTrace: function(stack_trace_obj) {
    var stmt = this;
    var len;

    /* Increment reference first in case these are the same object */
    stack_trace_obj.incrRefCount();
    stmt.interp.stack_trace.decrRefCount();
    stmt.interp.stack_trace = stack_trace_obj;
    stmt.interp_error_flag = 1;

    /* This is a bit ugly.
     * If the filename of the last entry of the stack trace is empty,
     * the next stack level should be added.
     */
................................................................................
    }
    if (!procname && !file_name_obj.getStringLength()) {
      /* No useful info here */
      return;
    }

    if (stmt.interp.stack_trace.isShared()) {
      stmt.interp.stack_trace.decrRefCount();
      stmt.interp.stack_trace = file_name_obj.duplicateObj(stmt.interp.stack_trace);
      stmt.interp.stack_trace.incrRefCount();
    }

    /* If we have no procname but the previous element did, merge with that frame */
    if (!procname && file_name_obj.getStringLength()) {
      /* Just a filename. Check the previous entry */
      var len = stmt.interp.list_obj_type.listLength(stmt.interp.stack_trace);

................................................................................
            stmt.interp.list_obj_type.listSetIndex(stmt.interp.stack_trace, len - 2, file_name_obj, 0);
            stmt.interp.list_obj_type.listSetIndex(stmt.interp.stack_trace, len - 1, stmt.interp.int_obj_type.newIntObj(linenr), 0);
            return;
          }
        }
      }
    }
    stmt.interp.list_obj_type.listAppendElement(stmt.interp.stack_trace, stmt.interp.string_obj_type.newStringObj(procname, -1));
    stmt.interp.list_obj_type.listAppendElement(stmt.interp.stack_trace, file_name_obj);
    stmt.interp.list_obj_type.listAppendElement(stmt.interp.stack_trace, stmt.interp.int_obj_type.newIntObj(linenr));
  },

});

EvalStatement.prototype.constructor = EvalStatement;

R.EvalStatement = EvalStatement;

}, "0.0.1", {});







|
|







|




|




|







 







|







 







|







 







|












|







|







|







|







 







|







 







|







 







|







 







|
|







 







|







 







|






|







 







|
<
|













|







 







|







 







|







 







|
|

|













|

|







 







|







 







|
|







 







|

|












|

|








|
|







 







|

|







 







|











86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
...
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
...
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
...
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
...
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
...
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
...
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
...
588
589
590
591
592
593
594
595

596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
...
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
...
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
...
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
...
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
...
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
...
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
...
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
...
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
    case stmt.TOKEN_VAR_ARRAY_NAME:
    case stmt.TOKEN_VAR:
      result_var_ptr[0] = null;
      obj_ptr = stmt.interp.variable_obj_type.getVariable(token.obj_ptr, stmt.FUNCTION_FLAGS_LEAVE_ERR_MSG, result_var_ptr);
      result_var_ptr = result_var_ptr[0];
      /* special case for ::itcl::type type variable !! */
      if (obj_ptr == null && result_var_ptr != null && token.obj_ptr.getString() == "type") {
        obj_ptr = stmt.interp.string_obj_type.newStringObj(result_var_ptr.namespace.full_name, -1, "EVAL_STATEMENT_1");
        obj_ptr.incrRefCount("I_EVAL_STATEMENT_1");
      }
      if (stmt.interp.frame_ptr.type == stmt.CALL_TYPE_MACROEXPAND) {
        /* if we are expanding a macro and we find a not escaped variable not in the
	 * parameter/argument list, for the macro, we ignore that and return the variable
	 * as "$var_name" instead
	 */
        if (obj_ptr == null) {
          obj_ptr = stmt.interp.string_obj_type.newStringObj("$"+token.obj_ptr.getString(), -1, "EVAL_STATEMENT_2");
	  stmt.interp.setResult(stmt.interp.empty_string_obj);
	} else {
          /* if we are expanding a macro and the variable is a list put it into {} to be safe */
          if (obj_ptr.obj_type = stmt.interp.list_obj_type) {
            obj_ptr = stmt.interp.string_obj_type.newStringObj("{"+obj_ptr.getString()+"}", -1, "EVAL_STATEMENT_3");
	  }
	}
      } else {
        if (stmt.had_macro_cmd) {
          obj_ptr = stmt.interp.string_obj_type.newStringObj("$"+token.obj_ptr.getString(), -1, "EVAL_STATEMENT_4");
	}
      }
      break;
    case stmt.TOKEN_ARRAY_NAME_VAR:
      obj_ptr = JimExpandDictSugar(stmt.interp, token.obj_ptr);
      break;
    case stmt.TOKEN_EXPRSUGAR:
................................................................................
      if (!stmt.in_quotes) {
        obj_ptr = token.obj_ptr;
      } else {
        if (token.obj_ptr.len == 0) {
          /* we have a single pair of {} within quotes,
	   * so make a corresponding string object 
	   */
	  obj_ptr = stmt.interp.string_obj_type.newStringObj("{}", -1, "EVAL_STATEMENT_5");
	} else {
        switch (stmt.interp.script_obj_type.substObj(token.obj_ptr, result_ptr, stmt.FUNCTION_FLAGS_LEAVE_ERR_MSG)) {
        case stmt.OK:
	  obj_ptr = result_ptr[0];
	  /* special handling for expand in quotes !! */
	  if (obj_ptr.len == 1 && obj_ptr.bytes.substring(0,1) == "*") {
            obj_ptr.len = 3;
................................................................................
      retcode = stmt.substOneToken(script, idx + i, result_ptr);
      intv2[j] = result_ptr[0];
if (stmt.eval_ipol_debug > 1) {
print("RES!"+result_ptr[0]+"!"+intv2+"!"+retcode+"!");
script.dumpToken(i+idx);
}
      if (intv2[j] != null) {
        intv2[j].incrRefCount("I_EVAL_STATEMENT_2");
      }
      switch(retcode) {
      case stmt.OK:
      case stmt.RETURN:
        break;
      case stmt.BREAK:
        if (flags & stmt.SUBST_FLAG) {
................................................................................
          continue;
        }
        /* XXX: Ditto continue outside loop */
        /* fall through to error */
      default:
        while (j--) {
          if (intv2[j] != null) {
            intv2[j].decrRefCount("D_EVAL_STATEMENT_1");
	  }
        }
        intv2 = null;
	stmt.in_quotes = my_in_quotes;
        return null;
      }
      total_len += intv2[j].toString().length;
      j++;
    }

    /* Fast path return for a single token */
    if (word_tokens == 1 && intv2[0]) {
      intv2[0].decrRefCount("D_EVAL_STATEMENT_2");
      stmt.in_quotes = my_in_quotes;
      return intv2[0];
    }

    /* Concatenate every token in an unique
     * object. 
     */
    obj_ptr = stmt.interp.string_obj_type.newStringObjNoAlloc(null, 0, "EVAL_STATEMENT_6");

    if (word_tokens == 4 && token.length > i + idx + 2 && token[i + idx + 0].token == stmt.TOKEN_ESC && token[i + idx + 1].token == stmt.TOKEN_ESC
        && token[i + idx + 2].token == stmt.TOKEN_VAR) {
      /* May be able to do fast interpolated object  -> array */
      obj_ptr.obj_type = obj_ptr.interpolatedObjType;
      obj_ptr.twoPtrValue.ptr1(token);
      obj_ptr.twoPtrValue.ptr2(intv2[idx + 2]);
      intv2[idx + 2].incrRefCount("I_EVAL_STATEMENT_3");
    }

    obj_ptr.bytes = "";
    obj_ptr.length = total_len;
    for (i = 0; i < j; i++) {
      if (intv2[i]) {
        obj_ptr.bytes += intv2[i].toString();
        intv2[i].decrRefCount("D_EVAL_STATEMENT_3");
      }
    }
//    obj_ptr.bytes[total_len] = '\0';
    obj_ptr.len = total_len;
    /* Free the intv2 vector. */
    intv2 = null;
if (stmt.eval_ipol_debug > 1) {
................................................................................
      retcode = stmt.evalObjList(script_obj_ptr, stmt.interp.empty_obj, 1);
      if (stmt.macro_cmd_level == stmt.eval_level) {
        stmt.had_macro_cmd = false;
      }
      stmt.eval_level--;
      return retcode;
    }
    script_obj_ptr.incrRefCount("I_EVAL_STATEMENT_4");     /* Make sure it's shared. */
    script = script_obj_ptr.interp.script_obj_type.getScript(script_obj_ptr);
    if (script == null) {
      stmt.interp.setResultString("error in parsing script: \""+script_obj_ptr+"\"");
      if (stmt.macro_cmd_level == stmt.eval_level) {
        stmt.had_macro_cmd = false;
      }
      stmt.eval_level--;
................................................................................

    /* Check for one of the following common scripts used by for, while
     *
     *   {}
     *   incr a
     */
    if (script.len == 0) {
      script_obj_ptr.decrRefCount("D_EVAL_STATEMENT_4");
      if (stmt.macro_cmd_level == stmt.eval_level) {
        stmt.had_macro_cmd = false;
      }
      stmt.eval_level--;
      return stmt.OK;
    }
    if (script.len == 3
................................................................................
        && script.script_object.tokens[2].obj_ptr.obj_typ.type_name == "variable") {

      var obj_ptr = stmt.interp.getVariable(script.script_object.tokens[2].obj_ptr, stmt.TOKENNONE);

      if (obj_ptr && !obj_ptr.isShared() && obj_ptrobj_type.name == "int") {
//        JimWideValue(obj_ptr)++;
        obj_ptr.invalidateStringRep();
        script_obj_ptr.decrRefCount("D_EVAL_STATEMENT_5");
        stmt.interp.setResult(obj_ptr);
        if (stmt.macro_cmd_level == stmt.eval_level) {
          stmt.had_macro_cmd = false;
        }
        stmt.eval_level--;
        return stmt.OK;
      }
................................................................................
          case stmt.TOKEN_VAR:
	    var result_var_ptr = new Array();
	    result_var_ptr[0] = null;
            word_obj_ptr = stmt.interp.variable_obj_type.getVariable(token[i].obj_ptr, stmt.FUNCTION_FLAGS_LEAVE_ERR_MSG, result_var_ptr);
	    result_var_ptr = result_var_ptr[0];
            /* special case for ::itcl::type type variable !! */
            if (word_obj_ptr == null && result_var_ptr != null && token[i].obj_ptr.getString() == "type") {
              word_obj_ptr = stmt.interp.string_obj_type.newStringObj(result_var_ptr.namespace.full_name, -1, "EVAL_STATEMENT_7");
              word_obj_ptr.incrRefCount("I_EVAL_STATEMENT_5");
            }
            break;
          case stmt.TOKEN_EXPRSUGAR:
            word_obj_ptr = stmt.expandExprSugar(token[i].obj_ptr);
            break;
          case stmt.TOKEN_ARRAY_NAME_VAR:
            word_obj_ptr = stmt.expandDictSugar(token[i].obj_ptr);
................................................................................
	if (!had_comment) {
          if (!word_obj_ptr) {
            if (retcode == stmt.OK) {
              retcode = stmt.ERROR;
            }
            break;
          }
          word_obj_ptr.incrRefCount("I_EVAL_STATEMENT_6");
          if (!expand) {
	    if (!had_comment) {
              argv.push(word_obj_ptr);
	    }
          } else {
            /* Need to expand word_obj_ptr into multiple args from argv[j] ... */
            var len = stmt.interp.list_obj_type.listLength(word_obj_ptr);
................................................................................
            var k;
  
//print("EXPAND!"+argc+"!"+len+"!"+newargc+"!"+word_obj_ptr.toDebugString()+"!");
            /* Now copy in the expanded version */
            for (k = 0; k < len; k++) {
              argv.push(word_obj_ptr.listValue.elem()[k]);
	      j++;
              word_obj_ptr.listValue.elem()[k].incrRefCount("I_EVAL_STATEMENT_7");
            }
            /* The original object reference is no longer needed,
             * after the expansion it is no longer present on
             * the argument vector, but the single elements are
             * in its place. 
	     */
            word_obj_ptr.decrRefCount("D_EVAL_STATEMENT_6");
            /* And update the indexes */
            j--;
            argc += len - 1;
          }
        }
      }
      if (had_comment) {
................................................................................
            retcode = stmt.interp.unknownFcn(argc, argv, script.script_object.file_name_obj, line_no);
	  } else {
            /* we do not call unknown, if we had only the empty string as command and no arguments */
	  }
        }
      }
//      /* Finished with the command, so decrement ref counts of each argument */
      for (j = 0; j < argv.length; j++) {

        argv[j].decrRefCount("D_EVAL_STATEMENT_7");
      }
      argv = new Array();
    }

    /* Possibly add to the error stack trace */
    stmt.addErrorToStack(retcode, script.script_object.file_name_obj, line_no);

    /* Note that we don't have to decrement ref_count, because the
     * following code transfers our use of the reference again to
     * the script object. */
    script_obj_ptr.freeIntRep();
    script_obj_ptr.obj_type = stmt.interp.script_obj_type;
    script_obj_ptr.setIntRepPtr(script);
    script_obj_ptr.decrRefCount("D_EVAL_STATEMENT_8");
//print("EVALOBJ end level!"+stmt.eval_level+"!"+retcode+"!");
    if (stmt.macro_cmd_level == stmt.eval_level) {
      stmt.had_macro_cmd = false;
    }
    stmt.eval_level--;
    return retcode;
  },
................................................................................
    var stmt = this;
    var i;
    var retcode;
    var cmd_ptr;

    /* Incr refcount of arguments. */
    for (i = 0; i < objc; i++) {
      objv[i].incrRefCount("I_EVAL_STATEMENT_8");
    }
    /* Command lookup */
    cmd_ptr = stmt.interp.getCommand(objv[0], stmt.interp.FUNCTION_FLAGS_LEAVE_ERR_MSG);
//print("EOV!"+cmd_ptr.toDebugString()+"!");
    if (cmd_ptr == null) {
      retcode = stmt.interp.unknown(objc, objv, file_name_obj, line_no);
    } else {
................................................................................
        stmt.interp.cmd_priv_data = cmd_ptr.u.native_fcn.priv_data;
        retcode = cmd_ptr.u.native_fcn.cmd_proc(stmt.interp, objv);
      }
      cmd_ptr.decrCmdRefCount();
    }
    /* Decr refcount of arguments and return the retcode */
    for (i = 0; i < objc; i++) {
      objv[i].decrRefCount("D_EVAL_STATEMENT_9");
    }
    return retcode;
  },

  /* ==================== evalObjVector ===================================== */
  evalObjVector: function(objc, objv) {
    var stmt = this;
................................................................................
      if (my_str.match(" ") != null) {
        my_str += sep+"{"+args[i]+"}";
      } else {
        my_str += sep+args[i];
      }
      sep = " ";
    }
    my_ptr = stmt.interp.string_obj_type.newStringObj(my_str, -1, "EVAL_STATEMENT_8");
    my_ptr.incrRefCount("I_EVAL_STATEMENT_9");
    ret_code = stmt.evalObj(my_ptr);
    my_ptr.decrRefCount("D_EVAL_STATEMENT_10");
    return ret_code;
  },

  /* ==================== evalObjList ===================================== */
  /* If list_ptr is a list, call evalObjVector() with the given source info.
   * Otherwise eval with evalObj()
   */
  evalObjList: function (list_ptr, file_name_obj, linenr) {
    var stmt = this;
    var retcode = stmt.OK;

    stmt.interp.panic(!list_ptr.isListObj(), "evalObjList() called without list arg");
    if (list_ptr.listValue.len()) {
      list_ptr.incrRefCount("I_EVAL_STATEMENT_10");
      retcode = stmt.evalObjVector(list_ptr.listValue.len(), list_ptr.listValue.elem(), file_name_obj, linenr);
      list_ptr.decrRefCount("D_EVAL_STATEMENT_11");
    }
    return retcode;
  },

  /* ==================== commandMatchObj ===================================== */
  /* Returns 1 if match, 0 if no match or -<error> on error (e.g. -stmt.ERROR, -stmt.BREAK)*/
  commandMatchObj: function(command_obj, pattern_obj, string_obj, nocase) {
................................................................................
    var parms = new Array();
    var argc = 0;
    var eq = new Array();
    var rc;

    parms[argc++] = command_obj;
    if (nocase) {
      parms[argc++] = stmt.interp.string_obj_type.newStringObj("-nocase", -1, "EVAL_STATEMENT_9");
    }
    parms[argc++] = pattern_obj;
    parms[argc++] = string_obj;
    rc = stmt.evalObjVector(argc, parms);
    if (rc != stmt.OK || stmt.interp.int_obj_type.getLong(stmt.interp.getResult(), eq) != stmt.OK) {
      eq[0] = -rc;
    }
................................................................................
  addErrorToStack: function(retcode, file_name_obj, line) {
    var stmt = this;
    var rc = retcode;

    if (rc == stmt.ERROR && !stmt.interp.error_flag) {
        /* This is the first error, so save the file/line information and reset the stack */
        stmt.interp.error_flag = 1;
        file_name_obj.incrRefCount("I_EVAL_STATEMENT_11");
        stmt.interp.error_file_name_obj.decrRefCount("D_EVAL_STATEMENT_12");
        stmt.interp.error_file_name_obj = file_name_obj;
        stmt.interp.error_line = line;
        stmt.resetStackTrace();
        /* Always add a level where the error first occurs */
        stmt.interp.add_stack_trace++;
    }

................................................................................
         * don't clear the addStackTrace flag
         * so we can pick it up at the next level
         */
        if (file_name_obj.getStringLength()) {
          stmt.interp.add_stack_trace = 0;
        }

        stmt.interp.error_proc.decrRefCount("D_EVAL_STATEMENT_13");
        file_name_obj.interp.error_proc = stmt.interp.empty_obj;
        stmt.interp.error_proc.incrRefCount("I_EVAL_STATEMENT_12");
    } else {
      if (rc == stmt.RETURN && stmt.interp.return_code == stmt.ERROR) {
        /* Propagate the addStackTrace value through 'return -code error' */
      } else {
        stmt.interp.add_stack_trace = 0;
      }
    }
  },

  /* ==================== resetStackTrace ===================================== */
  resetStackTrace: function() {
    var stmt = this;
    stmt.interp.stack_trace.decrRefCount("D_EVAL_STATEMENT_14");
    stmt.interp.stack_trace = stmt.interp.list_obj_type.newListObj(null, 0);
    stmt.interp.stack_trace.incrRefCount("I_EVAL_STATEMENT_13");
  },

  /* ==================== setStackTrace ===================================== */
  setStackTrace: function(stack_trace_obj) {
    var stmt = this;
    var len;

    /* Increment reference first in case these are the same object */
    stack_trace_obj.incrRefCount("I_EVAL_STATEMENT_14");
    stmt.interp.stack_trace.decrRefCount("D_EVAL_STATEMENT_15");
    stmt.interp.stack_trace = stack_trace_obj;
    stmt.interp_error_flag = 1;

    /* This is a bit ugly.
     * If the filename of the last entry of the stack trace is empty,
     * the next stack level should be added.
     */
................................................................................
    }
    if (!procname && !file_name_obj.getStringLength()) {
      /* No useful info here */
      return;
    }

    if (stmt.interp.stack_trace.isShared()) {
      stmt.interp.stack_trace.decrRefCount("D_EVAL_STATEMENT_16");
      stmt.interp.stack_trace = file_name_obj.duplicateObj(stmt.interp.stack_trace);
      stmt.interp.stack_trace.incrRefCount("I_EVAL_STATEMENT_15");
    }

    /* If we have no procname but the previous element did, merge with that frame */
    if (!procname && file_name_obj.getStringLength()) {
      /* Just a filename. Check the previous entry */
      var len = stmt.interp.list_obj_type.listLength(stmt.interp.stack_trace);

................................................................................
            stmt.interp.list_obj_type.listSetIndex(stmt.interp.stack_trace, len - 2, file_name_obj, 0);
            stmt.interp.list_obj_type.listSetIndex(stmt.interp.stack_trace, len - 1, stmt.interp.int_obj_type.newIntObj(linenr), 0);
            return;
          }
        }
      }
    }
    stmt.interp.list_obj_type.listAppendElement(stmt.interp.stack_trace, stmt.interp.string_obj_type.newStringObj(procname, -1, "EVAL_STATEMENT_10"));
    stmt.interp.list_obj_type.listAppendElement(stmt.interp.stack_trace, file_name_obj);
    stmt.interp.list_obj_type.listAppendElement(stmt.interp.stack_trace, stmt.interp.int_obj_type.newIntObj(linenr));
  },

});

EvalStatement.prototype.constructor = EvalStatement;

R.EvalStatement = EvalStatement;

}, "0.0.1", {});

Changes to rapl_expr.js.

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
...
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
...
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
...
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
...
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
...
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
...
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
...
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
...
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
...
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
....
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
....
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
....
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
R.extend(Expr, R.Token, {
  my_name: "Expr",

  /* ==================== exprPush ================================== */
  exprPush: function(e, obj_ptr) {
    var exp = this;

    obj_ptr.incrRefCount();
    e.stack[e.stacklen++] = obj_ptr;
  },

  /* ==================== exprPop ================================== */
  exprPop: function(e) {
    return e.stack[--e.stacklen];
  },
................................................................................
      if (intresult) {
        exp.exprPush(e, exp.interp.int_obj_type.newIntObj(wC));
      } else {
        ExprPush(e, exp.interp.double_obj_type.newDoubleObj(dC));
      }
    }

    A.decrRefCount();

    return rc;
  },

  /* ==================== randDouble ================================== */
  randDouble: function() {
    var x;
................................................................................
        exp.prngSeed(wA, 64);
        exp.exprPush(e, exp.interp.double_obj_type.newDoubleObj(exp.randDouble()));
        break;
      default:
        abort();
      }
    }
    A.decrRefCount();
    return rc;
  },

  /* ==================== exprOpNone ================================== */
  exprOpNone: function(e) {
    var exp = this;

................................................................................
        dC = sqrt(dA);
        break;
      default:
        abort();
      }
      exp.exprPush(e, exp.interp.double_obj_type.newDoubleObj(dC));
    }
    A.decrRefCount();
    return rc;
  },

  /* A binary operation on two ints */

  /* ==================== exprOpIntBin ================================== */
  exprOpIntBin: function(e) {
................................................................................
        wC = (uA << uB) | (uA >> (S - uB));
        break;
      default:
        abort();
      }
      exp.exprPush(e, exp.interp.int_obj_type.newIntObj(wC));
    }
    A.decrRefCount();
    B.decrRefCount();
    return rc;
  },


  /* A binary operation on two ints or two doubles (or two strings for some ops) */

  /* ==================== exprOpBin ================================== */
................................................................................
	  }
	}
        exp.exprPush(e, exp.interp.int_obj_type.newIntObj(wC));
      } else {
        exp.exprPush(e, exp.interp.double_obj_type.newDoubleObj(dC));
      }
    }
    A.decrRefCount();
    B.decrRefCount();
    return rc;
  },

  /* ==================== exprOpStrBin ================================== */
  exprOpStrBin: function(e) {
    var exp = this;
    var obj_ptr = exp.interp.default_obj;
................................................................................
    case exp.TOKEN_EXPROP_STRNI:
      wC = !exp.interp.list_obj_type.searchList(B, A);
      break;
    default:
      abort();
    }
    exp.exprPush(e, exp.interp.int_obj_type.newIntObj(wC));
    A.decrRefCount();
    B.decrRefCount();
    return exp.OK;
  },

  /* ==================== exprBool ================================== */
  exprBool: function(obj) {
    var exp = this;
    var l = new Array();
................................................................................
    case true:
      /* true so continue */
      break;
    case -1:
      /* Invalid */
      rc = exp.ERROR;
    }
    A.decrRefCount();
    skip.decrRefCount();
    return rc;
  },

  /* ==================== exprOpOrLeft ================================== */
  exprOpOrLeft: function(e) {
    var exp = this;
    var skip = exp.exprPop(e);
................................................................................
      exp.exprPush(e, exp.interp.int_obj_type.newIntObj(1));
      break;
    case -1:
      /* Invalid */
      rc = exp.ERROR;
      break;
    }
    A.decrRefCount();
    skip.decrRefCount();
    return rc;
  },

  /* ==================== exprOpAndOrRight ================================== */
  exprOpAndOrRight: function(e) {
    var exp = this;
    var A = exp.exprPop(e);
................................................................................
      exp.exprPush(e, exp.interp.int_obj_type.newIntObj(1));
      break;
    case -1:
      /* Invalid */
      rc = exp.ERROR;
      break;
    }
    A.decrRefCount();
    return rc;
  },

  /* ==================== exprOpTernaryLeft ================================== */
  exprOpTernaryLeft: function(e) {
    var exp = this;
    var skip = exp.exprPop(e);
................................................................................
      /* true so do nothing */
      break;
    case -1:
      /* Invalid */
      rc = exp.ERROR;
      break;
    }
    A.decrRefCount();
    skip.decrRefCount();
    return rc;
  },

  /* ==================== exprOpColonLeft ================================== */
  exprOpColonLeft: function(e) {
    var exp = this;
    var skip = exp.exprPop(e);
................................................................................
    /* No need to check for A as non-boolean */
    if (exp.exprBool(A)) {
      /* true, so skip RHS opcodes */
      e.skip = exp.wideValue(skip);
      /* Repush B as the answer */
      exp.exprPush(e, B);
    }
    skip.decrRefCount();
    A.decrRefCount();
    B.decrRefCount();
    return exp.OK;
  },

  /* ==================== exprOpNull ================================== */
  exprOpNull: function(e) {
    return exp.OK;
  },
................................................................................
      /* STEP 1 -- Check if there are the conditions to run the specialized
       * version of while */

      switch (expr.len) {
      case 1:
        if (expr.token_list[0].token == exp.TPOKEN_EXPR_INT) {
          exprResultPtrPtr[0] = expr.token_list[0].obj_ptr;
          exprResultPtrPtr[0].incrRefCount();
          return exp.OK;
        }
        if (expr.token_list[0].token == exp.TOKEN_VAR) {
          obj_ptr = exp.interp.variable_obj_type.getVariable(expr.token_list[0].obj_ptr, exp.FUNCTION_FLAGS_LEAVE_ERR_MSG);
          if (obj_ptr) {
            exprResultPtrPtr[0] = obj_ptr;
            exprResultPtrPtr[0].incrRefCount();
            return exp.OK;
          }
        }
        break;
      case 2:
        if (expr.token_list[1].token == exp.TOKEN_EXPROP_NOT && expr.token_list[0].token == exp.TOKEN_VAR) {
          var wide_value = new Array();

          obj_ptr = exp.interp.variable_obj_type.getVariable(expr.token_list[0].obj_ptr, exp.FUNCTION_FLAGS_NONE);
          if (obj_ptr && exp.interp.int_obj_type.isWide(obj_ptr) && exp.interp.int_obj_type.getWide(obj_ptr, wide_value) == exp.OK) {
            vwide_valeu = wide_value[0];
            exprResultPtrPtr[0] = wide_value ? exp.interp.false_obj : exp.interp.true_obj;
            exprResultPtrPtr[0].incrRefCount();
            return exp.OK;
          }
        }
        break;
      case 3:
        if (expr.token_list[0].token == exp.TOKEN_VAR && (expr.token_list[1].token == exp.TOKEN_EXPR_INT || expr.token_list[1].token == exp.TOKEN_VAR)) {
          switch (expr.token_list[2].token) {
................................................................................
                case exp.TOKEN_EXPROP_NUMNE:
                  cmpRes = wide_valueA != wide_valueB;
                  break;
                default:   /*notreached */
                  cmpRes = 0;
                }
                exprResultPtrPtr[0] = cmpRes ? exp.interp.true_obj : exp.interp.false_obj;
                exprResultPtrPtr[0].incrRefCount();
                return exp.OK;
              }
            }
          }
        }
        break;
      }
................................................................................
      }
    }
    expr.inUse--;
    if (retcode == exp.OK) {
      exprResultPtrPtr[0] = exp.exprPop(e);
    } else {
      for (i = 0; i < e.stacklen; i++) {
        e.stack[i].decrRefCount();
      }
    }
    return retcode;
  },

  /* ==================== getBoolFromExpr ================================== */
  getBoolFromExpr: function(expr_obj_ptr, bool_ptr) {
................................................................................
    if (retcode != exp.OK) {
      return retcode;
    }
    expr_result_ptr = expr_result_ptr[0];

    if (exp.interp.int_obj_type.getWideNoErr(expr_result_ptr, wide_value) != exp.OK) {
      if (exp.interp.int_obj_type.getDouble(expr_result_ptr, double_value) != exp.OK) {
        expr_result_ptr.decrRefCount();
        return exp.ERROR;
      } else {
        double_value = double_value[0]
        expr_result_ptr.decrRefCount();
        bool_ptr[0] = double_value != 0 ? 1 : 0;
        return exp.OK;
      }
    }
    wide_value = wide_value[0];
    bool_ptr[0] = wide_value != 0 ? 1 : 0;

    expr_result_ptr.decrRefCount();
    return exp.OK;
  },

});

Expr.prototype.constructor = Expr;

R.Expr = Expr;

}, "0.0.1", {});







|







 







|







 







|







 







|







 







|
|







 







|
|







 







|
|







 







|
|







 







|
|







 







|







 







|
|







 







|
|
|







 







|






|












|







 







|







 







|







 







|



|







|










29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
...
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
...
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
...
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
...
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
...
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
...
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
...
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
...
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
...
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
....
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
....
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
....
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
R.extend(Expr, R.Token, {
  my_name: "Expr",

  /* ==================== exprPush ================================== */
  exprPush: function(e, obj_ptr) {
    var exp = this;

    obj_ptr.incrRefCount("I_EXPR_1");
    e.stack[e.stacklen++] = obj_ptr;
  },

  /* ==================== exprPop ================================== */
  exprPop: function(e) {
    return e.stack[--e.stacklen];
  },
................................................................................
      if (intresult) {
        exp.exprPush(e, exp.interp.int_obj_type.newIntObj(wC));
      } else {
        ExprPush(e, exp.interp.double_obj_type.newDoubleObj(dC));
      }
    }

    A.decrRefCount("D_EXPR_1");

    return rc;
  },

  /* ==================== randDouble ================================== */
  randDouble: function() {
    var x;
................................................................................
        exp.prngSeed(wA, 64);
        exp.exprPush(e, exp.interp.double_obj_type.newDoubleObj(exp.randDouble()));
        break;
      default:
        abort();
      }
    }
    A.decrRefCount("D_EXPR_2");
    return rc;
  },

  /* ==================== exprOpNone ================================== */
  exprOpNone: function(e) {
    var exp = this;

................................................................................
        dC = sqrt(dA);
        break;
      default:
        abort();
      }
      exp.exprPush(e, exp.interp.double_obj_type.newDoubleObj(dC));
    }
    A.decrRefCount("D_EXPR_3");
    return rc;
  },

  /* A binary operation on two ints */

  /* ==================== exprOpIntBin ================================== */
  exprOpIntBin: function(e) {
................................................................................
        wC = (uA << uB) | (uA >> (S - uB));
        break;
      default:
        abort();
      }
      exp.exprPush(e, exp.interp.int_obj_type.newIntObj(wC));
    }
    A.decrRefCount("D_EXPR_4");
    B.decrRefCount("D_EXPR_5");
    return rc;
  },


  /* A binary operation on two ints or two doubles (or two strings for some ops) */

  /* ==================== exprOpBin ================================== */
................................................................................
	  }
	}
        exp.exprPush(e, exp.interp.int_obj_type.newIntObj(wC));
      } else {
        exp.exprPush(e, exp.interp.double_obj_type.newDoubleObj(dC));
      }
    }
    A.decrRefCount("D_EXPR_6");
    B.decrRefCount("D_EXPR_7");
    return rc;
  },

  /* ==================== exprOpStrBin ================================== */
  exprOpStrBin: function(e) {
    var exp = this;
    var obj_ptr = exp.interp.default_obj;
................................................................................
    case exp.TOKEN_EXPROP_STRNI:
      wC = !exp.interp.list_obj_type.searchList(B, A);
      break;
    default:
      abort();
    }
    exp.exprPush(e, exp.interp.int_obj_type.newIntObj(wC));
    A.decrRefCount("D_EXPR_8");
    B.decrRefCount("D_EXPR_9");
    return exp.OK;
  },

  /* ==================== exprBool ================================== */
  exprBool: function(obj) {
    var exp = this;
    var l = new Array();
................................................................................
    case true:
      /* true so continue */
      break;
    case -1:
      /* Invalid */
      rc = exp.ERROR;
    }
    A.decrRefCount("D_EXPR_10");
    skip.decrRefCount("D_EXPR_11");
    return rc;
  },

  /* ==================== exprOpOrLeft ================================== */
  exprOpOrLeft: function(e) {
    var exp = this;
    var skip = exp.exprPop(e);
................................................................................
      exp.exprPush(e, exp.interp.int_obj_type.newIntObj(1));
      break;
    case -1:
      /* Invalid */
      rc = exp.ERROR;
      break;
    }
    A.decrRefCount("D_EXPR_12");
    skip.decrRefCount("D_EXPR_13");
    return rc;
  },

  /* ==================== exprOpAndOrRight ================================== */
  exprOpAndOrRight: function(e) {
    var exp = this;
    var A = exp.exprPop(e);
................................................................................
      exp.exprPush(e, exp.interp.int_obj_type.newIntObj(1));
      break;
    case -1:
      /* Invalid */
      rc = exp.ERROR;
      break;
    }
    A.decrRefCount("D_EXPR_14");
    return rc;
  },

  /* ==================== exprOpTernaryLeft ================================== */
  exprOpTernaryLeft: function(e) {
    var exp = this;
    var skip = exp.exprPop(e);
................................................................................
      /* true so do nothing */
      break;
    case -1:
      /* Invalid */
      rc = exp.ERROR;
      break;
    }
    A.decrRefCount("D_EXPR_15");
    skip.decrRefCount("D_EXPR_16");
    return rc;
  },

  /* ==================== exprOpColonLeft ================================== */
  exprOpColonLeft: function(e) {
    var exp = this;
    var skip = exp.exprPop(e);
................................................................................
    /* No need to check for A as non-boolean */
    if (exp.exprBool(A)) {
      /* true, so skip RHS opcodes */
      e.skip = exp.wideValue(skip);
      /* Repush B as the answer */
      exp.exprPush(e, B);
    }
    skip.decrRefCount("D_EXPR_17");
    A.decrRefCount("D_EXPR_18");
    B.decrRefCount("D_EXPR_19");
    return exp.OK;
  },

  /* ==================== exprOpNull ================================== */
  exprOpNull: function(e) {
    return exp.OK;
  },
................................................................................
      /* STEP 1 -- Check if there are the conditions to run the specialized
       * version of while */

      switch (expr.len) {
      case 1:
        if (expr.token_list[0].token == exp.TPOKEN_EXPR_INT) {
          exprResultPtrPtr[0] = expr.token_list[0].obj_ptr;
          exprResultPtrPtr[0].incrRefCount("I_EXPR_2");
          return exp.OK;
        }
        if (expr.token_list[0].token == exp.TOKEN_VAR) {
          obj_ptr = exp.interp.variable_obj_type.getVariable(expr.token_list[0].obj_ptr, exp.FUNCTION_FLAGS_LEAVE_ERR_MSG);
          if (obj_ptr) {
            exprResultPtrPtr[0] = obj_ptr;
            exprResultPtrPtr[0].incrRefCount("I_EXPR_3");
            return exp.OK;
          }
        }
        break;
      case 2:
        if (expr.token_list[1].token == exp.TOKEN_EXPROP_NOT && expr.token_list[0].token == exp.TOKEN_VAR) {
          var wide_value = new Array();

          obj_ptr = exp.interp.variable_obj_type.getVariable(expr.token_list[0].obj_ptr, exp.FUNCTION_FLAGS_NONE);
          if (obj_ptr && exp.interp.int_obj_type.isWide(obj_ptr) && exp.interp.int_obj_type.getWide(obj_ptr, wide_value) == exp.OK) {
            vwide_valeu = wide_value[0];
            exprResultPtrPtr[0] = wide_value ? exp.interp.false_obj : exp.interp.true_obj;
            exprResultPtrPtr[0].incrRefCount("I_EXPR_4");
            return exp.OK;
          }
        }
        break;
      case 3:
        if (expr.token_list[0].token == exp.TOKEN_VAR && (expr.token_list[1].token == exp.TOKEN_EXPR_INT || expr.token_list[1].token == exp.TOKEN_VAR)) {
          switch (expr.token_list[2].token) {
................................................................................
                case exp.TOKEN_EXPROP_NUMNE:
                  cmpRes = wide_valueA != wide_valueB;
                  break;
                default:   /*notreached */
                  cmpRes = 0;
                }
                exprResultPtrPtr[0] = cmpRes ? exp.interp.true_obj : exp.interp.false_obj;
                exprResultPtrPtr[0].incrRefCount("I_EXPR_5");
                return exp.OK;
              }
            }
          }
        }
        break;
      }
................................................................................
      }
    }
    expr.inUse--;
    if (retcode == exp.OK) {
      exprResultPtrPtr[0] = exp.exprPop(e);
    } else {
      for (i = 0; i < e.stacklen; i++) {
        e.stack[i].decrRefCount("D_EXPR_20");
      }
    }
    return retcode;
  },

  /* ==================== getBoolFromExpr ================================== */
  getBoolFromExpr: function(expr_obj_ptr, bool_ptr) {
................................................................................
    if (retcode != exp.OK) {
      return retcode;
    }
    expr_result_ptr = expr_result_ptr[0];

    if (exp.interp.int_obj_type.getWideNoErr(expr_result_ptr, wide_value) != exp.OK) {
      if (exp.interp.int_obj_type.getDouble(expr_result_ptr, double_value) != exp.OK) {
        expr_result_ptr.decrRefCount("D_EXPR_21");
        return exp.ERROR;
      } else {
        double_value = double_value[0]
        expr_result_ptr.decrRefCount("D_EXPR_22");
        bool_ptr[0] = double_value != 0 ? 1 : 0;
        return exp.OK;
      }
    }
    wide_value = wide_value[0];
    bool_ptr[0] = wide_value != 0 ? 1 : 0;

    expr_result_ptr.decrRefCount("D_EXPR_23");
    return exp.OK;
  },

});

Expr.prototype.constructor = Expr;

R.Expr = Expr;

}, "0.0.1", {});

Changes to rapl_expr_obj_type.js.

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
...
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
...
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
...
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
...
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
...
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
...
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
    if (obj_ptr.obj_type == exp.interp.source_obj_type) {
      file_name_obj = obj_ptr.sourceValue.fileNameObj();
      line = obj_ptr.sourceValue.lineNumber();
    } else {
      file_name_obj = exp.interp.empty_obj;
      line = 1;
    }
    file_name_obj.incrRefCount();

    /* Initially tokenise the expression into tokenlist */
    script.scriptTokenListInit();
    parser.parserInit(script.text, script.text_len, line);
    while (!parser.parse_info.eof) {
      if (parser.parseExpression() != exp.OK) {
        script.scriptTokenListFree();
        exp.interp.setResultFormatted("xxx1 syntax error in expression: \"%#s\"", obj_ptr);
        expr = null;
        /* Free the old internal rep and set the new one. */
        file_name_obj.decrRefCount();
        obj_ptr.freeIntRep();
        obj_ptr.setIntRepPtr(expr);
        obj_ptr.obj_type = exp.interp.expr_obj_type;
        return rc;
      }
      script.scriptAddParseToken(parser.parse_info.start, parser.parse_info.end - parser.parse_info.start + 1, parser.parse_info.token, parser.parse_info.line, script.text);
    }
................................................................................
    }
    /* Now create the expression bytecode from the tokenlist */
    expr = exp.exprCreateByteCode(script, file_name_obj);
    /* No longer need the token list */
    script.scriptTokenListFree(script.parse_token_list);
    if (!expr) {
      /* Free the old internal rep and set the new one. */
      file_name_obj.decrRefCount();
      obj_ptr.freeIntRep();
      obj_ptr.setIntRepPtr(expr);
      obj_ptr.obj_type = exp.interp.expr_obj_type;
      return rc;
    }
    if (debug_info) {
      print("==== Expr ====");
................................................................................
    /* Check program correctness. */
    if (exp.exprCheckCorrectness(expr) != exp.OK) {
        exp.exprFreeByteCode(expr);
print("YY");
        exp.interp.setResultFormatted("syntax error in expression: \"%#s\"", obj_ptr);
        expr = null;
        /* Free the old internal rep and set the new one. */
        file_name_obj.decrRefCount();
        obj_ptr.freeIntRep();
        obj_ptr.setIntRepPtr(expr);
        obj_ptr.obj_type = exp.interp.expr_obj_type;
        return rc;
    }
    rc = exp.OK;
    /* Free the old internal rep and set the new one. */
    file_name_obj.decrRefCount();
    obj_ptr.freeIntRep();
    obj_ptr.setIntRepPtr(expr);
    obj_ptr.obj_type = exp.interp.expr_obj_type;
    return rc;
  },

  /* ==================== freeInternalRep ===================================== */
................................................................................
  /* ==================== exprFreeByteCode ================================== */
  exprFreeByteCode: function(expr) {
    var exp = this;
    var obj_ptr = exp.interp.default_obj;
    var i;

    for (i = 0; i < expr.len; i++) {
      expr.token_list[i].obj_ptr.decrRefCount();
    }
//    obj_ptr.free(expr.token_list);
//    obj_ptr.free(expr);
  },

  /* ==================== exprCheckCorrectness ================================== */
  /* Check if an expr program looks correct. */
................................................................................
      case exp.TOKEN_QUOTE_ESC:
      case exp.TOKEN_ESC:
      case exp.TOKEN_VAR:
      case exp.TOKEN_BRACE:
      case exp.TOKEN_VAR_ARRAY_NAME:
      case exp.TOKEN_EXPRSUGAR:
      case exp.TOKEN_CMD:
        token.obj_ptr = exp.interp.string_obj_type.newStringObj(script.getText(t.start, t.len), t.len);
        token.token = t.token;
        if (t.token == exp.TOKEN_CMD) {
            /* Only commands need source info */
            exp.interp.source_obj_type.setSourceInfo(token.obj_ptr, file_name_obj, t.line);
        }
        expr.token_list[expr.len] = token;
        expr.len++;
................................................................................
            ok = 1;
            break;
          }
          if (exp.exprAddOperator(expr, tt) != exp.OK) {
            /* Free the stack used for the compilation. */
            exp.freeStack(stack);
            for (i = 0; i < expr.len; i++) {
              expr.token_list[i].obj_ptr.incrRefCount();
            }
            if (!ok) {
              exp.exprFreeByteCode(expr);
              return null;
            }
            return expr;
          }
        }
        if (!ok) {
          exp.interp.setResultString("Unexpected close parenthesis", -1);
          /* Free the stack used for the compilation. */
          exp.freeStack(stack);
          for (i = 0; i < expr.len; i++) {
            expr.token_list[i].obj_ptr.incrRefCount();
          }
          if (!ok) {
            exp.exprFreeByteCode(expr);
            return null;
          }
          return expr;
        }
................................................................................
          /* Note that right-to-left associativity of ?: operator is handled later */
          if (op.arity != 1 && tt_op.precedence >= op.precedence) {
            if (exp.exprAddOperator(expr, tt) != exp.OK) {
              ok = 0;
              /* Free the stack used for the compilation. */
              exp.freeStack(stack);
              for (i = 0; i < expr.len; i++) {
                expr.token_list[i].obj_ptr.incrRefCount();
              }
              if (!ok) {
                exp.exprFreeByteCode(expr);
                return null;
              }
              return expr;
            }
................................................................................
      if (tt.token == exp.TOKEN_SUBEXPR_START) {
        ok = 0;
        exp.interp.setResultString("Missing close parenthesis", -1);
        /* Free the stack used for the compilation. */
        exp.freeStack(stack);
        for (i = 0; i < expr.len; i++) {
          if (expr.token_list[i].obj_ptr != null) {
            expr.token_list[i].obj_ptr.incrRefCount();
	  }
        }
        if (!ok) {
          exp.exprFreeByteCode(expr);
          return null;
        }
        return expr;
................................................................................
    if (ok && have_ternary) {
      exp.exprTernaryReorderExpression(expr);
    }
    /* Free the stack used for the compilation. */
    exp.freeStack(stack);
    for (i = 0; i < expr.len; i++) {
      if (expr.token_list[i].obj_ptr != null) {
        expr.token_list[i].obj_ptr.incrRefCount();
      }
    }
    if (!ok) {
      exp.exprFreeByteCode(expr);
      return null;
    }
    return expr;







|










|







 







|







 







|







|







 







|







 







|







 







|













|







 







|







 







|







 







|







52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
...
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
...
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
...
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
...
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
...
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
...
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
    if (obj_ptr.obj_type == exp.interp.source_obj_type) {
      file_name_obj = obj_ptr.sourceValue.fileNameObj();
      line = obj_ptr.sourceValue.lineNumber();
    } else {
      file_name_obj = exp.interp.empty_obj;
      line = 1;
    }
    file_name_obj.incrRefCount("I_EXPR_OBJ_TYPE_1");

    /* Initially tokenise the expression into tokenlist */
    script.scriptTokenListInit();
    parser.parserInit(script.text, script.text_len, line);
    while (!parser.parse_info.eof) {
      if (parser.parseExpression() != exp.OK) {
        script.scriptTokenListFree();
        exp.interp.setResultFormatted("xxx1 syntax error in expression: \"%#s\"", obj_ptr);
        expr = null;
        /* Free the old internal rep and set the new one. */
        file_name_obj.decrRefCount("D_EXPR_OBJ_TYPE_1");
        obj_ptr.freeIntRep();
        obj_ptr.setIntRepPtr(expr);
        obj_ptr.obj_type = exp.interp.expr_obj_type;
        return rc;
      }
      script.scriptAddParseToken(parser.parse_info.start, parser.parse_info.end - parser.parse_info.start + 1, parser.parse_info.token, parser.parse_info.line, script.text);
    }
................................................................................
    }
    /* Now create the expression bytecode from the tokenlist */
    expr = exp.exprCreateByteCode(script, file_name_obj);
    /* No longer need the token list */
    script.scriptTokenListFree(script.parse_token_list);
    if (!expr) {
      /* Free the old internal rep and set the new one. */
      file_name_obj.decrRefCount("D_EXPR_OBJ_TYPE_2");
      obj_ptr.freeIntRep();
      obj_ptr.setIntRepPtr(expr);
      obj_ptr.obj_type = exp.interp.expr_obj_type;
      return rc;
    }
    if (debug_info) {
      print("==== Expr ====");
................................................................................
    /* Check program correctness. */
    if (exp.exprCheckCorrectness(expr) != exp.OK) {
        exp.exprFreeByteCode(expr);
print("YY");
        exp.interp.setResultFormatted("syntax error in expression: \"%#s\"", obj_ptr);
        expr = null;
        /* Free the old internal rep and set the new one. */
        file_name_obj.decrRefCount("D_EXPR_OBJ_TYPE_3");
        obj_ptr.freeIntRep();
        obj_ptr.setIntRepPtr(expr);
        obj_ptr.obj_type = exp.interp.expr_obj_type;
        return rc;
    }
    rc = exp.OK;
    /* Free the old internal rep and set the new one. */
    file_name_obj.decrRefCount("D_EXPR_OBJ_TYPE_4");
    obj_ptr.freeIntRep();
    obj_ptr.setIntRepPtr(expr);
    obj_ptr.obj_type = exp.interp.expr_obj_type;
    return rc;
  },

  /* ==================== freeInternalRep ===================================== */
................................................................................
  /* ==================== exprFreeByteCode ================================== */
  exprFreeByteCode: function(expr) {
    var exp = this;
    var obj_ptr = exp.interp.default_obj;
    var i;

    for (i = 0; i < expr.len; i++) {
      expr.token_list[i].obj_ptr.decrRefCount("D_EXPR_OBJ_TYPE_5");
    }
//    obj_ptr.free(expr.token_list);
//    obj_ptr.free(expr);
  },

  /* ==================== exprCheckCorrectness ================================== */
  /* Check if an expr program looks correct. */
................................................................................
      case exp.TOKEN_QUOTE_ESC:
      case exp.TOKEN_ESC:
      case exp.TOKEN_VAR:
      case exp.TOKEN_BRACE:
      case exp.TOKEN_VAR_ARRAY_NAME:
      case exp.TOKEN_EXPRSUGAR:
      case exp.TOKEN_CMD:
        token.obj_ptr = exp.interp.string_obj_type.newStringObj(script.getText(t.start, t.len), t.len, "EXPR_OBJ_TYPE_1");
        token.token = t.token;
        if (t.token == exp.TOKEN_CMD) {
            /* Only commands need source info */
            exp.interp.source_obj_type.setSourceInfo(token.obj_ptr, file_name_obj, t.line);
        }
        expr.token_list[expr.len] = token;
        expr.len++;
................................................................................
            ok = 1;
            break;
          }
          if (exp.exprAddOperator(expr, tt) != exp.OK) {
            /* Free the stack used for the compilation. */
            exp.freeStack(stack);
            for (i = 0; i < expr.len; i++) {
              expr.token_list[i].obj_ptr.incrRefCount("I_EXPR_OBJ_TYPE_2");
            }
            if (!ok) {
              exp.exprFreeByteCode(expr);
              return null;
            }
            return expr;
          }
        }
        if (!ok) {
          exp.interp.setResultString("Unexpected close parenthesis", -1);
          /* Free the stack used for the compilation. */
          exp.freeStack(stack);
          for (i = 0; i < expr.len; i++) {
            expr.token_list[i].obj_ptr.incrRefCount("I_EXPR_OBJ_TYPE_3");
          }
          if (!ok) {
            exp.exprFreeByteCode(expr);
            return null;
          }
          return expr;
        }
................................................................................
          /* Note that right-to-left associativity of ?: operator is handled later */
          if (op.arity != 1 && tt_op.precedence >= op.precedence) {
            if (exp.exprAddOperator(expr, tt) != exp.OK) {
              ok = 0;
              /* Free the stack used for the compilation. */
              exp.freeStack(stack);
              for (i = 0; i < expr.len; i++) {
                expr.token_list[i].obj_ptr.incrRefCount("I_EXPR_OBJ_TYPE_4");
              }
              if (!ok) {
                exp.exprFreeByteCode(expr);
                return null;
              }
              return expr;
            }
................................................................................
      if (tt.token == exp.TOKEN_SUBEXPR_START) {
        ok = 0;
        exp.interp.setResultString("Missing close parenthesis", -1);
        /* Free the stack used for the compilation. */
        exp.freeStack(stack);
        for (i = 0; i < expr.len; i++) {
          if (expr.token_list[i].obj_ptr != null) {
            expr.token_list[i].obj_ptr.incrRefCount("I_EXPR_OBJ_TYPE_5");
	  }
        }
        if (!ok) {
          exp.exprFreeByteCode(expr);
          return null;
        }
        return expr;
................................................................................
    if (ok && have_ternary) {
      exp.exprTernaryReorderExpression(expr);
    }
    /* Free the stack used for the compilation. */
    exp.freeStack(stack);
    for (i = 0; i < expr.len; i++) {
      if (expr.token_list[i].obj_ptr != null) {
        expr.token_list[i].obj_ptr.incrRefCount("I_EXPR_OBJ_TYPE_6");
      }
    }
    if (!ok) {
      exp.exprFreeByteCode(expr);
      return null;
    }
    return expr;

Changes to rapl_interp.js.

32
33
34
35
36
37
38







39
40
41
42
43
44
45
..
58
59
60
61
62
63
64

65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
...
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
...
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
...
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
...
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
...
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
....
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
  intp.var_frame_ptr     = null;
  intp.frame_ptr         = null;
  intp.top_frame_ptr     = null;

  R.Base.interp_oid++;
  intp.oid = R.Base.interp_oid;








  intp.array_obj_type = new R.ArrayObjType(intp);
  intp.coerced_double_obj_type = new R.CoercedDoubleObjType(intp);
  intp.command_obj_type = new R.CommandObjType(intp);
  intp.compared_string_obj_type = new R.ComparedStringObjType(intp);
  intp.dict_obj_type = new R.DictObjType(intp);
  intp.double_obj_type = new R.DoubleObjType(intp);
  intp.expr_obj_type = new R.ExprObjType(intp);
................................................................................
  intp.regexp_obj_type = new R.RegexpObjType(intp);
  intp.return_code_obj_type = new R.ReturnCodeObjType(intp);
  intp.scan_fmt_string_obj_type = new R.ScanFmtStringObjType(intp);
  intp.script_line_obj_type = new R.ScriptLineObjType(intp);
  intp.script_obj_type = new R.ScriptObjType(intp);
  intp.source_obj_type = new R.SourceObjType(intp);
  intp.string_obj_type = new R.StringObjType(intp);

  intp.variable_obj_type = new R.VariableObjType(intp);


  intp.free_obj_list    = null;
  intp.live_obj_list    = null;
  intp.free_call_frame_list = null;
  intp.live_call_frame_list = null;
  intp.default_obj      = new R.RaplObject(intp);
  intp.empty_string_obj = intp.string_obj_type.newStringObj("", 0);
  intp.empty_string_obj.incrRefCount();
  intp.empty_obj        = intp.string_obj_type.newEmptyStringObj();
  intp.empty_obj.incrRefCount();
  intp.true_obj         = intp.int_obj_type.newIntObj(1);
  intp.true_obj.incrRefCount();
  intp.false_obj        = intp.int_obj_type.newIntObj(0);
  intp.false_obj.incrRefCount();
  intp.result           = intp.empty_obj;
  intp.result.incrRefCount();
  intp.error_proc       = intp.string_obj_type.newEmptyStringObj();
  intp.error_proc.incrRefCount();
  intp.error_flag       =  0;
  intp.error_file_name_obj = intp.string_obj_type.newEmptyStringObj();
  intp.error_file_name_obj.incrRefCount();
  intp.error_line       = -1;
  intp.stack_trace      = intp.string_obj_type.newEmptyStringObj();
  intp.stack_trace.incrRefCount();
  intp.current_script_obj   = intp.string_obj_type.newEmptyStringObj();
  intp.current_script_obj.incrRefCount();
  intp.add_stack_trace  = 0;
  intp.unknown          = intp.string_obj_type.newStringObj("unknown", -1);
  intp.unknown_called   = 0;
  intp.call_frame        = new R.CallFrame(intp, intp.CALL_TYPE_NAMESPACE);

  intp.return_code      = null;
  intp.return_level     = null;
  intp.local_procs      = null;
  intp.command_resolver = null;
................................................................................
    var cmd_obj;
    var cmd_ptr;

    if (func == null) {
      throw "No such subcommand: "+ name +" " + subcmd;
    }
    name = path.shift();
    cmd = intp.getCommand(intp.string_obj_type.newStringObj(name, -1));
    if (cmd == null) {
      ens = new Object();
      ens["subcmds"] = new R.Command(intp, "subcmds", null, null);
      ens["subcmds"].setCommandType(intp.COMMAND_INFO_SUBCMDS);
      ens["subcmds"].is_proc = false;
      ens["subcmds"].u.native_fcn.cmd_proc = intp.infoSubcommands;
      cmd_obj = new R.Command(intp, name, null, ens);
................................................................................
	 */
        cmd_obj.ns_ptr = intp.global_ns_ptr;
      } else {
        cmd_obj.ns_ptr = intp.frame_ptr.ns_ptr;
      }
      cmd = intp.global_ns_ptr.registerCommand(name, cmd_obj, "NAMESPACE", "NAMESPACE_PROC");
    }
    cmd_ptr = intp.getCommand(intp.string_obj_type.newStringObj(name, -1));
    if (cmd_ptr == null) {
      throw "Not an ensemble command 1: '"+name+"'";
    }
    ens = cmd_ptr.ensemble;
    if (ens == null) {
      throw "Not an ensemble command 1: '"+name+"'";
    }
................................................................................
      list_obj_ptr = intp.listObjType.newListObj(result, 1);
      intp.rewrite_name_obj = result[0];
      intp.listObjType.insertElements(list_obj_ptr, -1, argc, argv_idx, argv);
    } else {
      list_obj_ptr = intp.listObjType.newListObj(result, 1);
    }
    if (msg != null) {
      intp.listObjType.listAppendElement(list_obj_ptr, intp.string_obj_type.newStringObj(msg, -1));
    }
    list_obj_ptr.incrRefCount();
    obj_ptr = intp.list_obj_type.listJoin(list_obj_ptr, " ", 1);
    list_obj_ptr.decrRefCount();
    obj_ptr.incrRefCount();
    intp.setResultFormatted("wrong # args: should be \"%#s\"", obj_ptr);
    obj_ptr.decrRefCount();
  },

  /* ==================== setEmptyResult ================================== */
  setEmptyResult: function() {
    var intp = this;

    intp.setResult(intp.empty_obj);
  },

  /* ==================== setResult ================================== */
  setResult: function(obj_ptr) {
    var intp = this;

    obj_ptr.incrRefCount();
    intp.result.decrRefCount();
    intp.result = obj_ptr;
  },

  /* ==================== setResultString ================================== */
  setResultString: function(str) {
    var intp = this;

    intp.result.decrRefCount();
    intp.result = intp.string_obj_type.newStringObj(str, -1);
    intp.result.incrRefCount();
  },

  /* ==================== setResultBool ================================== */
  setResultBool: function(val) {
    var intp = this;

    if (val == true) {
................................................................................
	default:
	  i++;
	}
      }
    }
    buf += format.substring(start_idx, i);
    len = buf.length;
    intp.setResult(intp.string_obj_type.newStringObjNoAlloc(buf, len));
  },

  /* ==================== getResult ===================================== */
  getResult: function() {
    var intp = this;

    return intp.result;
................................................................................
   *
   *----------------------------------------------------------------------
   */
  setObjErrorCode: function(error_obj_ptr) {
    var intp = this;

    if (intp.error_code) {
      intp.error_code.decrRefCount();
    }
    intp.error_code = error_obj_ptr;
    intp.error_code.incrRefCount();
  },

  /* ==================== setErrorCode ===================================== */
  /*
   *----------------------------------------------------------------------
   *
   * setErrorCode --
................................................................................
   *      arguments to this function, in a list form with each argument becoming
   *      one element of the list.
   *
   *----------------------------------------------------------------------
   */
  setErrorCode: function(args) {
    var intp = this;
    var error_obj = intp.string_obj_type.newStringObj("", -1);
    var i;

    /*
     * Scan through the arguments one at a time, appending them to the
     * error_code field as list elements.
     */
     for (i = 0; i < args.length; i++) {
        intp.list_obj_type.listAppendElement(error_obj, intp.string_obj_type.newStringObj(args[i], -1));
     }
     intp.setObjErrorCode(error_obj);
  },

  /* ==================== getCallFrameByInteger ===================================== */
  /* Similar to getCallFrameByLevel() but the level is specified
   * as a relative integer like in the [info level ?level?] command.
................................................................................
//print("objectify!"+typeof text+"!"+(text instanceof R.RaplObject)+"!");
      if (text instanceof R.RaplObject) {
//print("objectify3a");
        return text;
      }
    }
//print("objectify4!"+text+"!");
    var result = this.string_obj_type.newStringObj(text, -1);
//print("objectify5");
    return result;
  },

  /* ==================== eval_meta ===================================== */
  eval_meta: function (meta) {
print("eval_meta!"+meta.mySelf()+"!"+meta.statements_len+"!");







>
>
>
>
>
>
>







 







>

>

<
<
<
<
<
|
|
|
|

|

|

|
|
|

|
|

|
|
|
|

|







 







|







 







|







 







|

|

|
|

|













|
|







|
|
|







 







|







 







|


|







 







|







|







 







|







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
..
65
66
67
68
69
70
71
72
73
74
75





76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
...
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
...
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
...
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
...
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
...
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
....
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
  intp.var_frame_ptr     = null;
  intp.frame_ptr         = null;
  intp.top_frame_ptr     = null;

  R.Base.interp_oid++;
  intp.oid = R.Base.interp_oid;

  intp.free_obj_list    = null;
  intp.live_obj_list    = null;

  intp.free_call_frame_list = null;
  intp.live_call_frame_list = null;

  intp.default_obj      = new R.RaplObject(intp);
  intp.array_obj_type = new R.ArrayObjType(intp);
  intp.coerced_double_obj_type = new R.CoercedDoubleObjType(intp);
  intp.command_obj_type = new R.CommandObjType(intp);
  intp.compared_string_obj_type = new R.ComparedStringObjType(intp);
  intp.dict_obj_type = new R.DictObjType(intp);
  intp.double_obj_type = new R.DoubleObjType(intp);
  intp.expr_obj_type = new R.ExprObjType(intp);
................................................................................
  intp.regexp_obj_type = new R.RegexpObjType(intp);
  intp.return_code_obj_type = new R.ReturnCodeObjType(intp);
  intp.scan_fmt_string_obj_type = new R.ScanFmtStringObjType(intp);
  intp.script_line_obj_type = new R.ScriptLineObjType(intp);
  intp.script_obj_type = new R.ScriptObjType(intp);
  intp.source_obj_type = new R.SourceObjType(intp);
  intp.string_obj_type = new R.StringObjType(intp);
// FIXME check why it would return undefined!!
  intp.variable_obj_type = new R.VariableObjType(intp);
//print("intp.variable_obj_type!"+intp.variable_obj_type+"!");






  intp.empty_string_obj = intp.string_obj_type.newStringObj("", 0, "INTERP_1");
  intp.empty_string_obj.incrRefCount("I_INTERP_1");
  intp.empty_obj        = intp.string_obj_type.newEmptyStringObj("INTERP_2");
  intp.empty_obj.incrRefCount("I_INTERP_2");
  intp.true_obj         = intp.int_obj_type.newIntObj(1);
  intp.true_obj.incrRefCount("I_INTERP_3");
  intp.false_obj        = intp.int_obj_type.newIntObj(0);
  intp.false_obj.incrRefCount("I_INTERP_4");
  intp.result           = intp.empty_obj;
  intp.result.incrRefCount("I_INTERP_5");
  intp.error_proc       = intp.string_obj_type.newEmptyStringObj("INTERP_3");
  intp.error_proc.incrRefCount("I_INTERP_6");
  intp.error_flag       =  0;
  intp.error_file_name_obj = intp.string_obj_type.newEmptyStringObj("INTERP_4");
  intp.error_file_name_obj.incrRefCount("I_INTERP_7");
  intp.error_line       = -1;
  intp.stack_trace      = intp.string_obj_type.newEmptyStringObj("INTERP_5");
  intp.stack_trace.incrRefCount("I_INTERP_8");
  intp.current_script_obj   = intp.string_obj_type.newEmptyStringObj("INTERP_6");
  intp.current_script_obj.incrRefCount("I_INTERP_9");
  intp.add_stack_trace  = 0;
  intp.unknown          = intp.string_obj_type.newStringObj("unknown", -1, "INTERP_7");
  intp.unknown_called   = 0;
  intp.call_frame        = new R.CallFrame(intp, intp.CALL_TYPE_NAMESPACE);

  intp.return_code      = null;
  intp.return_level     = null;
  intp.local_procs      = null;
  intp.command_resolver = null;
................................................................................
    var cmd_obj;
    var cmd_ptr;

    if (func == null) {
      throw "No such subcommand: "+ name +" " + subcmd;
    }
    name = path.shift();
    cmd = intp.getCommand(intp.string_obj_type.newStringObj(name, -1, "INTERP_8"));
    if (cmd == null) {
      ens = new Object();
      ens["subcmds"] = new R.Command(intp, "subcmds", null, null);
      ens["subcmds"].setCommandType(intp.COMMAND_INFO_SUBCMDS);
      ens["subcmds"].is_proc = false;
      ens["subcmds"].u.native_fcn.cmd_proc = intp.infoSubcommands;
      cmd_obj = new R.Command(intp, name, null, ens);
................................................................................
	 */
        cmd_obj.ns_ptr = intp.global_ns_ptr;
      } else {
        cmd_obj.ns_ptr = intp.frame_ptr.ns_ptr;
      }
      cmd = intp.global_ns_ptr.registerCommand(name, cmd_obj, "NAMESPACE", "NAMESPACE_PROC");
    }
    cmd_ptr = intp.getCommand(intp.string_obj_type.newStringObj(name, -1, "INTERP_9"));
    if (cmd_ptr == null) {
      throw "Not an ensemble command 1: '"+name+"'";
    }
    ens = cmd_ptr.ensemble;
    if (ens == null) {
      throw "Not an ensemble command 1: '"+name+"'";
    }
................................................................................
      list_obj_ptr = intp.listObjType.newListObj(result, 1);
      intp.rewrite_name_obj = result[0];
      intp.listObjType.insertElements(list_obj_ptr, -1, argc, argv_idx, argv);
    } else {
      list_obj_ptr = intp.listObjType.newListObj(result, 1);
    }
    if (msg != null) {
      intp.listObjType.listAppendElement(list_obj_ptr, intp.string_obj_type.newStringObj(msg, -1, "INTERP_10"));
    }
    list_obj_ptr.incrRefCount("I_INTERP_10");
    obj_ptr = intp.list_obj_type.listJoin(list_obj_ptr, " ", 1);
    list_obj_ptr.decrRefCount("D_INTERP_1");
    obj_ptr.incrRefCount("I_INTERP_11");
    intp.setResultFormatted("wrong # args: should be \"%#s\"", obj_ptr);
    obj_ptr.decrRefCount("D_INTERP_2");
  },

  /* ==================== setEmptyResult ================================== */
  setEmptyResult: function() {
    var intp = this;

    intp.setResult(intp.empty_obj);
  },

  /* ==================== setResult ================================== */
  setResult: function(obj_ptr) {
    var intp = this;

    obj_ptr.incrRefCount("I_INTERP_12");
    intp.result.decrRefCount("D_INTERP_3");
    intp.result = obj_ptr;
  },

  /* ==================== setResultString ================================== */
  setResultString: function(str) {
    var intp = this;

    intp.result.decrRefCount("D_INTERP_4");
    intp.result = intp.string_obj_type.newStringObj(str, -1, "INTERP11");
    intp.result.incrRefCount("I_INTERP_13");
  },

  /* ==================== setResultBool ================================== */
  setResultBool: function(val) {
    var intp = this;

    if (val == true) {
................................................................................
	default:
	  i++;
	}
      }
    }
    buf += format.substring(start_idx, i);
    len = buf.length;
    intp.setResult(intp.string_obj_type.newStringObjNoAlloc(buf, len, "INTERP_12"));
  },

  /* ==================== getResult ===================================== */
  getResult: function() {
    var intp = this;

    return intp.result;
................................................................................
   *
   *----------------------------------------------------------------------
   */
  setObjErrorCode: function(error_obj_ptr) {
    var intp = this;

    if (intp.error_code) {
      intp.error_code.decrRefCount("D_INTERP_5");
    }
    intp.error_code = error_obj_ptr;
    intp.error_code.incrRefCount("I_INTERP_14");
  },

  /* ==================== setErrorCode ===================================== */
  /*
   *----------------------------------------------------------------------
   *
   * setErrorCode --
................................................................................
   *      arguments to this function, in a list form with each argument becoming
   *      one element of the list.
   *
   *----------------------------------------------------------------------
   */
  setErrorCode: function(args) {
    var intp = this;
    var error_obj = intp.string_obj_type.newStringObj("", -1, "INTERP_13");
    var i;

    /*
     * Scan through the arguments one at a time, appending them to the
     * error_code field as list elements.
     */
     for (i = 0; i < args.length; i++) {
        intp.list_obj_type.listAppendElement(error_obj, intp.string_obj_type.newStringObj(args[i], -1, "INNTERP_14"));
     }
     intp.setObjErrorCode(error_obj);
  },

  /* ==================== getCallFrameByInteger ===================================== */
  /* Similar to getCallFrameByLevel() but the level is specified
   * as a relative integer like in the [info level ?level?] command.
................................................................................
//print("objectify!"+typeof text+"!"+(text instanceof R.RaplObject)+"!");
      if (text instanceof R.RaplObject) {
//print("objectify3a");
        return text;
      }
    }
//print("objectify4!"+text+"!");
    var result = this.string_obj_type.newStringObj(text, -1, "INTERP_15");
//print("objectify5");
    return result;
  },

  /* ==================== eval_meta ===================================== */
  eval_meta: function (meta) {
print("eval_meta!"+meta.mySelf()+"!"+meta.statements_len+"!");

Changes to rapl_itcl_component.js.

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    }
    if (option_flags & i_component.itcl_component_options.ITCL_COMPONENT_INHERIT) {
      if (typeof options["-inherit"] != "undefined") {
        if (i_component.interp.int_obj_type.getBool(options["-inherit"], val) != i_component.OK) {
          return i_component.ERROR;
        }
      } else {
        if (i_component.interp.int_obj_type.getBool(i_component.interp.string_obj_type.newStringObj("1", -1), val) != i_component.OK) {
          return i_component.ERROR;
        }
      }
      i_component.flag_inherit = val[0];
    }
    if (option_flags & i_component.itcl_component_options.ITCL_COMPONENT_PUBLIC) {
      i_component.flag_public = options["-public"];







|







101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    }
    if (option_flags & i_component.itcl_component_options.ITCL_COMPONENT_INHERIT) {
      if (typeof options["-inherit"] != "undefined") {
        if (i_component.interp.int_obj_type.getBool(options["-inherit"], val) != i_component.OK) {
          return i_component.ERROR;
        }
      } else {
        if (i_component.interp.int_obj_type.getBool(i_component.interp.string_obj_type.newStringObj("1", -1, "ITCL_COMPONENT_1"), val) != i_component.OK) {
          return i_component.ERROR;
        }
      }
      i_component.flag_inherit = val[0];
    }
    if (option_flags & i_component.itcl_component_options.ITCL_COMPONENT_PUBLIC) {
      i_component.flag_public = options["-public"];

Changes to rapl_itcl_delegate.js.

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
        var_obj_ptr = i_delegate.interp.variable_obj_type.getVariable(i_delegate.to_part, i_delegate.FUNCTION_FLAGS_NONE, var_ptr);
	if (var_obj_ptr == null) {
          i_delegate.interp.setResultString("delegateCget to_part: \""+i_delegate.to_part.getString()+"\" not found");
	  return i_delegate.ERROR;
	}
	var_ptr = var_ptr[0];
	objv.push(var_obj_ptr);
	objv.push(i_delegate.interp.string_obj_type.newStringObj("cget", -1));
        objv.push(option_name);
        return i_delegate.interp.eval_statement.evalObjVector(objv.length, objv);
      } else {
        // FIXME need code here !!
        i_delegate.interp.setResultString("delegateCget no to_part not yet implemented");
	return i_deledate.ERROR;
      }
................................................................................
        var_obj_ptr = i_delegate.interp.variable_obj_type.getVariable(i_delegate.to_part, i_delegate.FUNCTION_FLAGS_NONE, var_ptr);
	if (var_obj_ptr == null) {
          i_delegate.interp.setResultString("delegateConfigure to_part: \""+i_delegate.to_part.getString()+"\" not found");
	  return i_delegate.ERROR;
	}
	var_ptr = var_ptr[0];
	objv.push(var_obj_ptr);
	objv.push(i_delegate.interp.string_obj_type.newStringObj("configure", -1));
        objv.push(option_name);
	if (option_value != null) {
          objv.push(option_value);
	}
        return i_delegate.interp.eval_statement.evalObjVector(objv.length, objv);
      } else {
        // FIXME need code here !!







|







 







|







134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
        var_obj_ptr = i_delegate.interp.variable_obj_type.getVariable(i_delegate.to_part, i_delegate.FUNCTION_FLAGS_NONE, var_ptr);
	if (var_obj_ptr == null) {
          i_delegate.interp.setResultString("delegateCget to_part: \""+i_delegate.to_part.getString()+"\" not found");
	  return i_delegate.ERROR;
	}
	var_ptr = var_ptr[0];
	objv.push(var_obj_ptr);
	objv.push(i_delegate.interp.string_obj_type.newStringObj("cget", -1, "ITCL_DELEGATE_1"));
        objv.push(option_name);
        return i_delegate.interp.eval_statement.evalObjVector(objv.length, objv);
      } else {
        // FIXME need code here !!
        i_delegate.interp.setResultString("delegateCget no to_part not yet implemented");
	return i_deledate.ERROR;
      }
................................................................................
        var_obj_ptr = i_delegate.interp.variable_obj_type.getVariable(i_delegate.to_part, i_delegate.FUNCTION_FLAGS_NONE, var_ptr);
	if (var_obj_ptr == null) {
          i_delegate.interp.setResultString("delegateConfigure to_part: \""+i_delegate.to_part.getString()+"\" not found");
	  return i_delegate.ERROR;
	}
	var_ptr = var_ptr[0];
	objv.push(var_obj_ptr);
	objv.push(i_delegate.interp.string_obj_type.newStringObj("configure", -1, "ITCL_DELEGATE_2"));
        objv.push(option_name);
	if (option_value != null) {
          objv.push(option_value);
	}
        return i_delegate.interp.eval_statement.evalObjVector(objv.length, objv);
      } else {
        // FIXME need code here !!

Changes to rapl_itcl_function.js.

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
...
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
    switch (args.length) {
    case 0:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_PARAMS;
      break;
    case 1:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_BODY;
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount();
      break;
    case 2:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_INIT;
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount();
      i_fcn.body = args[1];
      i_fcn.body.incrRefCount();
      break;
    case 3:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_COMPLETE;
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount();
      i_fcn.init_code = args[1];
      i_fcn.body = args[2];
      i_fcn.body.incrRefCount();
      break;
    }
//print("fcn storeInfo!"+args+"!");
    if (i_fcn.param_obj != null) {
      if (i_fcn.interp.param_obj_type.setFromAny(i_fcn.param_obj) != i_fcn.OK) {
        return i_fcn.ERROR;
      }
................................................................................
    switch (args.length) {
    case 0:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_PARAMS;
      break;
    case 1:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_BODY;
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount();
      break;
    case 2:
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount();
      if (i_fcn.interp.class_type == i_fcn.ITCL_TYPE_CLASS) {
        i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_COMPLETE;
        i_fcn.body = args[1];
        i_fcn.body.incrRefCount();
      } else {
        i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_INIT;
        i_fcn.init_code = args[1];
        i_fcn.init_code.incrRefCount();
      }
      break;
    case 3:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_COMPLETE;
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount();
      i_fcn.init_code = args[1];
      i_fcn.body = args[2];
      i_fcn.body.incrRefCount();
      break;
    default:
      i_fcn.interp.setResultString("should be: "+i_fcn.type+" <name> args ?init? ?body?");
      return i_fcn.ERROR;
    }
    if (i_fcn.param_obj != null) {
      if (i_fcn.interp.param_obj_type.setFromAny(i_fcn.param_obj) != i_fcn.OK) {
................................................................................
  storeDestructorInfo: function (args) {
    var i_fcn = this;

    switch (args.length) {
    case 0:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_COMPLETE;
      i_fcn.body = args[0];
      i_fcn.body.incrRefCount();
      break;
    default:
      i_fcn.interp.setResultString("should be: "+i_fcn.type+" <name> ?body?");
      return i_fcn.ERROR;
    }
    i_fcn.orig_state = i_fcn.state;
    i_fcn.orig_body = i_fcn.body;
................................................................................
  storeTypeConstructorInfo: function (args) {
    var i_fcn = this;

    switch (args.length) {
    case 0:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_COMPLETE;
      i_fcn.body = args[0];
      i_fcn.body.incrRefCount();
      break;
    default:
      i_fcn.interp.setResultString("should be: "+i_fcn.type+" <name> ?body?");
      return i_fcn.ERROR;
    }
    i_fcn.orig_state = i_fcn.state;
    i_fcn.orig_body = i_fcn.body;
................................................................................
      var cmd_obj = new R.Command(i_fcn.interp, i_fcn.fcn_name, [i_fcn.param_obj, i_fcn.body], null);
      cmd_obj.setCommandType(i_fcn.interp.COMMAND_PROC);
      cmd_obj.is_proc = true;
      cmd_obj.u.proc.cmd_proc = i_fcn.interp.command_obj_type.callProcedure;
      cmd_obj.u.proc.arg_list_obj_ptr = i_fcn.param_obj;
      cmd_obj.u.proc.body_obj_ptr = i_fcn.body;
      cmd_obj.ns_ptr = i_fcn.class_info.ns_ptr;
      i_fcn.param_obj.incrRefCount();
      i_fcn.body.incrRefCount();
      i_fcn.interp.global_ns_ptr.registerCommand(i_fcn.fcn_name, cmd_obj, i_fcn.getItclClassTypeString(i_fcn.class_info.class_type), i_fcn.getItclFunctionTypeString(i_fcn.type));
    }
    return i_fcn.OK;
  },

  /* ==================== changeBody ===================================== */
  changeBody: function (params, body) {







|




|

|




|


|







 







|



|



|



|





|


|







 







|







 







|







 







|
|







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
...
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
    switch (args.length) {
    case 0:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_PARAMS;
      break;
    case 1:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_BODY;
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount("I_ITCL_FUNCTION_1");
      break;
    case 2:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_INIT;
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount("I_ITCL_FUNCTION_2");
      i_fcn.body = args[1];
      i_fcn.body.incrRefCount("I_ITCL_FUNCTION_3");
      break;
    case 3:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_COMPLETE;
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount("I_ITCL_FUNCTION_4");
      i_fcn.init_code = args[1];
      i_fcn.body = args[2];
      i_fcn.body.incrRefCount("I_ITCL_FUNCTION_5");
      break;
    }
//print("fcn storeInfo!"+args+"!");
    if (i_fcn.param_obj != null) {
      if (i_fcn.interp.param_obj_type.setFromAny(i_fcn.param_obj) != i_fcn.OK) {
        return i_fcn.ERROR;
      }
................................................................................
    switch (args.length) {
    case 0:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_PARAMS;
      break;
    case 1:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_BODY;
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount("I_ITCL_FUNCTION_6");
      break;
    case 2:
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount("I_ITCL_FUNCTION_7");
      if (i_fcn.interp.class_type == i_fcn.ITCL_TYPE_CLASS) {
        i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_COMPLETE;
        i_fcn.body = args[1];
        i_fcn.body.incrRefCount("I_ITCL_FUNCTION_8");
      } else {
        i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_NO_INIT;
        i_fcn.init_code = args[1];
        i_fcn.init_code.incrRefCount("I_ITCL_FUNCTION_9");
      }
      break;
    case 3:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_COMPLETE;
      i_fcn.param_obj = args[0];
      i_fcn.param_obj.incrRefCount("I_ITCL_FUNCTION_10");
      i_fcn.init_code = args[1];
      i_fcn.body = args[2];
      i_fcn.body.incrRefCount("I_ITCL_FUNCTION_11");
      break;
    default:
      i_fcn.interp.setResultString("should be: "+i_fcn.type+" <name> args ?init? ?body?");
      return i_fcn.ERROR;
    }
    if (i_fcn.param_obj != null) {
      if (i_fcn.interp.param_obj_type.setFromAny(i_fcn.param_obj) != i_fcn.OK) {
................................................................................
  storeDestructorInfo: function (args) {
    var i_fcn = this;

    switch (args.length) {
    case 0:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_COMPLETE;
      i_fcn.body = args[0];
      i_fcn.body.incrRefCount("I_ITCL_FUNCTION_12");
      break;
    default:
      i_fcn.interp.setResultString("should be: "+i_fcn.type+" <name> ?body?");
      return i_fcn.ERROR;
    }
    i_fcn.orig_state = i_fcn.state;
    i_fcn.orig_body = i_fcn.body;
................................................................................
  storeTypeConstructorInfo: function (args) {
    var i_fcn = this;

    switch (args.length) {
    case 0:
      i_fcn.state = i_fcn.ITCL_FUNCTION_STATE_COMPLETE;
      i_fcn.body = args[0];
      i_fcn.body.incrRefCount("I_ITCL_FUNCTION_13");
      break;
    default:
      i_fcn.interp.setResultString("should be: "+i_fcn.type+" <name> ?body?");
      return i_fcn.ERROR;
    }
    i_fcn.orig_state = i_fcn.state;
    i_fcn.orig_body = i_fcn.body;
................................................................................
      var cmd_obj = new R.Command(i_fcn.interp, i_fcn.fcn_name, [i_fcn.param_obj, i_fcn.body], null);
      cmd_obj.setCommandType(i_fcn.interp.COMMAND_PROC);
      cmd_obj.is_proc = true;
      cmd_obj.u.proc.cmd_proc = i_fcn.interp.command_obj_type.callProcedure;
      cmd_obj.u.proc.arg_list_obj_ptr = i_fcn.param_obj;
      cmd_obj.u.proc.body_obj_ptr = i_fcn.body;
      cmd_obj.ns_ptr = i_fcn.class_info.ns_ptr;
      i_fcn.param_obj.incrRefCount("I_ITCL_FUNCTION_14");
      i_fcn.body.incrRefCount("I_ITCL_FUNCTION_15");
      i_fcn.interp.global_ns_ptr.registerCommand(i_fcn.fcn_name, cmd_obj, i_fcn.getItclClassTypeString(i_fcn.class_info.class_type), i_fcn.getItclFunctionTypeString(i_fcn.type));
    }
    return i_fcn.OK;
  },

  /* ==================== changeBody ===================================== */
  changeBody: function (params, body) {

Changes to rapl_itcl_obj_type.js.

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
...
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
...
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
...
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
    }
    if (!(class_name.charAt(0) == ':' && class_name.charAt(1) == ':')) {
      if (itcl.interp.frame_ptr.ns_ptr.full_name == "::") {
        class_name = itcl.interp.frame_ptr.ns_ptr.full_name+class_name
      } else {
        class_name = itcl.interp.frame_ptr.ns_ptr.full_name+"::"+class_name
      }
      full_class_name = itcl.interp.string_obj_type.newStringObj(class_name, -1);
    } else {
      full_class_name = itcl.class_name;
    }
    full_class_name.incrRefCount();
    itcl.interp.full_class_name = full_class_name.getString();
    /*
     *  Make sure that a class with the given name does not
     *  already exist in the current namespace context.  If a
     *  namespace exists, that's okay.  It may have been created
     *  to contain stubs during a "namespace import" operation.
     *  We'll just replace the namespace data below with the
................................................................................
     *    .  =>  reserved for member access like:  class.publicVar
     */
    tail = itcl.interp.namespace_obj_type.nsTail(class_name);
    if (tail.indexOf(".") >= 0) {
      itcl.interp.setResultString("bad class name \""+tail+"\"");
      return TCL_ERROR;
    }
    itcl.class_name.incrRefCount();
    /*
     *  Allocate class definition data.
     */
    class_info = new R.ItclClass(itcl.interp, itcl.class_name, full_class_name, itcl.interp.class_type);
    itcl.interp.curr_class_info = class_info;
    /*
     *  Initialize the heritage info--each class starts with its
................................................................................
      ns_ptr = itcl.interp.getCurrentNamespace();
      my_name += ns_ptr.full_name;
      if (ns_ptr.parent_ptr != null) {
        my_name += "::";
      }
    }
    my_name += class_name;
    var name_obj_ptr = itcl.interp.string_obj_type.newStringObj(my_name, -1);
    name_obj_ptr.incrRefCount();
    if (class_ns_ptr != null) {
      var old_cmd_ptr = itcl.interp.global_ns_ptr.findCommand(name_obj_ptr.getString(), null, 0);
      if (old_cmd_ptr != null) {
        // deleteCommandFromToken(old_cmd_ptr);
      }
    } else {
      class_ns_ptr = itcl.interp.variable_obj_type.findNamespace(full_class_name.getString(), null, /* flags */ itcl.NAMESPACE_CREATE_IF_UNKNOWN);
................................................................................
       */
      // FIXME !! need code here !!! right no we use the namespace getCommand to 
      // alias to ::itcl::internal::<name>

      obj_ptr.obj_type = itcl.interp.itcl_obj_type;
      /* for ::itcl::type add the special variable type */
      if (class_info.class_type == itcl.ITCL_TYPE_CLASS) {
        full_class_name.incrRefCount();
        var type_variable = new R.Variable(itcl.interp, "type", "VAR_TYPE_VAR", null, full_class_name);
        type_variable.setProtection(itcl.PROTECTION_PROTECTED);
        type_variable.namespace = class_info.ns_ptr;
        class_info.ns_ptr.variables[itcl.escape_key(itcl.escape_key("type"))] = type_variable;
      }
      /*
       *  Build the name resolution tables for all data members.
................................................................................
      }
      if (cmd_ptr != null) {
//print("CMD_PTR!"+cmd_ptr+"!"+itcl.interp.frame_ptr.toDebugString()+"!");
        if (cmd_ptr.is_proc) {
           my_args.push(args[1]);
           for (var k = 2; k < args.length; k++) {
             my_args.push(args[k]);
             args[k].incrRefCount();
           }
          retcode = cmd_ptr.u.proc.cmd_proc(cmd_ptr, itcl.interp.empty_obj, -1, my_args.length, my_args);
          return retcode;
        } else {
           my_args.push(args[0]);
           my_args.push(args[1]);
           for (var k = 2; k < args.length; k++) {
             my_args.push(args[k]);
             args[k].incrRefCount();
           }
          itcl.interp.cmd_priv_data = cmd_ptr.u.native_fcn.privdata;
          retcode = cmd_ptr.u.native_fcn.cmd_proc(itcl.interp, my_args, cmd_ptr);
          return retcode;
	}
      }
      itcl.interp.setResultString("direct classname function call for: \""+cmd_name+"\" not yet implemented");
................................................................................
  callClassCommand: function(ns_ptr, fcn_name, class_object, args) {
    var i_obj = this;
//print("callClassCommand1!"+ns_ptr+"!"+fcn_name+"!"+class_object+"!"+args+"!");
    var class_only = 1;
    var ret_code;
    var cmd_obj;
    var my_ns_ptr;
    var name_ptr = i_obj.interp.string_obj_type.newStringObj(fcn_name, -1);
    /* we need to add the command as the first argument !!! */
    var my_args = new Array();
    var save_class_object;

    cmd_obj = ns_ptr.getClassCommand(ns_ptr, fcn_name, class_only);
    if (cmd_obj == null) {
      my_ns_ptr = i_obj.interp.frame_ptr.ns_ptr.getNamespace("::itcl::internal");
................................................................................
        dlg_info = class_ptr.delegated_methods["*"];
        to_part = dlg_info.to_part;
      }
      if (to_part != null) {
	var var_ptr = class_object.variables[i_obj.escape_key(to_part.getString())];
        var obj2 = i_obj.interp.class_objects[i_obj.escape_key(var_ptr.obj_ptr.getString())];
        var my_args = new Array();
        my_args.push(i_obj.interp.string_obj_type.newStringObj(obj2.object_name, -1));
        my_args.push(i_obj.interp.string_obj_type.newStringObj(fcn_name, -1));
	for (var j = 0; j < args.length; j++) {
          my_args.push(args[j]);
	}
        ret_code = i_obj.classObjectCommand(obj2.class_info.ns_ptr, obj2, my_args);
        return ret_code;
      }
    }
    name_ptr.incrRefCount();
    my_args.push(name_ptr);
    for (var k = 0; k < args.length; k++) {
      my_args.push(args[k]);
      args[k].incrRefCount();
    }
    save_class_object = i_obj.interp.frame_ptr.class_object;
    if (cmd_obj != null) {
      i_obj.interp.frame_ptr.setClassObject(class_object);
      cmd_obj.incrCmdRefCount();
      if (cmd_obj.is_proc) {
        ret_code = cmd_obj.u.proc.cmd_proc(cmd_obj, i_obj.interp.empty_obj, -1, my_args.length, my_args);







|



|







 







|







 







|
|







 







|







 







|








|







 







|







 







|
|







|



|







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
...
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
...
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
...
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
    }
    if (!(class_name.charAt(0) == ':' && class_name.charAt(1) == ':')) {
      if (itcl.interp.frame_ptr.ns_ptr.full_name == "::") {
        class_name = itcl.interp.frame_ptr.ns_ptr.full_name+class_name
      } else {
        class_name = itcl.interp.frame_ptr.ns_ptr.full_name+"::"+class_name
      }
      full_class_name = itcl.interp.string_obj_type.newStringObj(class_name, -1, "ITCL_OBJ_TYPE_1");
    } else {
      full_class_name = itcl.class_name;
    }
    full_class_name.incrRefCount("I_ITCL_OBJ_TYPE_1");
    itcl.interp.full_class_name = full_class_name.getString();
    /*
     *  Make sure that a class with the given name does not
     *  already exist in the current namespace context.  If a
     *  namespace exists, that's okay.  It may have been created
     *  to contain stubs during a "namespace import" operation.
     *  We'll just replace the namespace data below with the
................................................................................
     *    .  =>  reserved for member access like:  class.publicVar
     */
    tail = itcl.interp.namespace_obj_type.nsTail(class_name);
    if (tail.indexOf(".") >= 0) {
      itcl.interp.setResultString("bad class name \""+tail+"\"");
      return TCL_ERROR;
    }
    itcl.class_name.incrRefCount("I_ITCL_OBJ_TYPE_2");
    /*
     *  Allocate class definition data.
     */
    class_info = new R.ItclClass(itcl.interp, itcl.class_name, full_class_name, itcl.interp.class_type);
    itcl.interp.curr_class_info = class_info;
    /*
     *  Initialize the heritage info--each class starts with its
................................................................................
      ns_ptr = itcl.interp.getCurrentNamespace();
      my_name += ns_ptr.full_name;
      if (ns_ptr.parent_ptr != null) {
        my_name += "::";
      }
    }
    my_name += class_name;
    var name_obj_ptr = itcl.interp.string_obj_type.newStringObj(my_name, -1, "ITCL_OBJ_TYPE_2");
    name_obj_ptr.incrRefCount("I_ITCL_OBJ_TYPE_3");
    if (class_ns_ptr != null) {
      var old_cmd_ptr = itcl.interp.global_ns_ptr.findCommand(name_obj_ptr.getString(), null, 0);
      if (old_cmd_ptr != null) {
        // deleteCommandFromToken(old_cmd_ptr);
      }
    } else {
      class_ns_ptr = itcl.interp.variable_obj_type.findNamespace(full_class_name.getString(), null, /* flags */ itcl.NAMESPACE_CREATE_IF_UNKNOWN);
................................................................................
       */
      // FIXME !! need code here !!! right no we use the namespace getCommand to 
      // alias to ::itcl::internal::<name>

      obj_ptr.obj_type = itcl.interp.itcl_obj_type;
      /* for ::itcl::type add the special variable type */
      if (class_info.class_type == itcl.ITCL_TYPE_CLASS) {
        full_class_name.incrRefCount("I_ITCL_OBJ_TYPE_4");
        var type_variable = new R.Variable(itcl.interp, "type", "VAR_TYPE_VAR", null, full_class_name);
        type_variable.setProtection(itcl.PROTECTION_PROTECTED);
        type_variable.namespace = class_info.ns_ptr;
        class_info.ns_ptr.variables[itcl.escape_key(itcl.escape_key("type"))] = type_variable;
      }
      /*
       *  Build the name resolution tables for all data members.
................................................................................
      }
      if (cmd_ptr != null) {
//print("CMD_PTR!"+cmd_ptr+"!"+itcl.interp.frame_ptr.toDebugString()+"!");
        if (cmd_ptr.is_proc) {
           my_args.push(args[1]);
           for (var k = 2; k < args.length; k++) {
             my_args.push(args[k]);
             args[k].incrRefCount("I_ITCL_OBJ_TYPE_5");
           }
          retcode = cmd_ptr.u.proc.cmd_proc(cmd_ptr, itcl.interp.empty_obj, -1, my_args.length, my_args);
          return retcode;
        } else {
           my_args.push(args[0]);
           my_args.push(args[1]);
           for (var k = 2; k < args.length; k++) {
             my_args.push(args[k]);
             args[k].incrRefCount("I_ITCL_OBJ_TYPE_6");
           }
          itcl.interp.cmd_priv_data = cmd_ptr.u.native_fcn.privdata;
          retcode = cmd_ptr.u.native_fcn.cmd_proc(itcl.interp, my_args, cmd_ptr);
          return retcode;
	}
      }
      itcl.interp.setResultString("direct classname function call for: \""+cmd_name+"\" not yet implemented");
................................................................................
  callClassCommand: function(ns_ptr, fcn_name, class_object, args) {
    var i_obj = this;
//print("callClassCommand1!"+ns_ptr+"!"+fcn_name+"!"+class_object+"!"+args+"!");
    var class_only = 1;
    var ret_code;
    var cmd_obj;
    var my_ns_ptr;
    var name_ptr = i_obj.interp.string_obj_type.newStringObj(fcn_name, -1, "ITCL_OBJ_TYPE_3");
    /* we need to add the command as the first argument !!! */
    var my_args = new Array();
    var save_class_object;

    cmd_obj = ns_ptr.getClassCommand(ns_ptr, fcn_name, class_only);
    if (cmd_obj == null) {
      my_ns_ptr = i_obj.interp.frame_ptr.ns_ptr.getNamespace("::itcl::internal");
................................................................................
        dlg_info = class_ptr.delegated_methods["*"];
        to_part = dlg_info.to_part;
      }
      if (to_part != null) {
	var var_ptr = class_object.variables[i_obj.escape_key(to_part.getString())];
        var obj2 = i_obj.interp.class_objects[i_obj.escape_key(var_ptr.obj_ptr.getString())];
        var my_args = new Array();
        my_args.push(i_obj.interp.string_obj_type.newStringObj(obj2.object_name, -1, "ITCL_OBJ_TYPE_4"));
        my_args.push(i_obj.interp.string_obj_type.newStringObj(fcn_name, -1, "ITCL_OBJ_TYPE_5"));
	for (var j = 0; j < args.length; j++) {
          my_args.push(args[j]);
	}
        ret_code = i_obj.classObjectCommand(obj2.class_info.ns_ptr, obj2, my_args);
        return ret_code;
      }
    }
    name_ptr.incrRefCount("I_ITCL_OBJ_TYPE_7");
    my_args.push(name_ptr);
    for (var k = 0; k < args.length; k++) {
      my_args.push(args[k]);
      args[k].incrRefCount("I_ITCL_OBJ_TYPE_8");
    }
    save_class_object = i_obj.interp.frame_ptr.class_object;
    if (cmd_obj != null) {
      i_obj.interp.frame_ptr.setClassObject(class_object);
      cmd_obj.incrCmdRefCount();
      if (cmd_obj.is_proc) {
        ret_code = cmd_obj.u.proc.cmd_proc(cmd_obj, i_obj.interp.empty_obj, -1, my_args.length, my_args);

Changes to rapl_itcl_object.js.

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
    var self_obj_ptr;
    var value_ptr;
    var this_obj_ptr;
    var my_obj_ptr;

//print("initItclObject!"+i_obj.toDebugString()+"!");
    /* add to class instances */
    my_obj_ptr = i_obj.interp.string_obj_type.newStringObj(i_obj.object_name, -1);
    my_obj_ptr.incrRefCount();
    i_obj.class_info.instances.push(my_obj_ptr);
    /* Create a new call frame */
    result = i_obj.interp.namespace_obj_type.pushStackFrame(frame_ptr_ptr, i_obj.class_info.ns_ptr, i_obj.CALL_TYPE_PROC);
    if (result != i_obj.OK) {
      return i_obj.ERROR;
    }
    i_obj.interp.frame_ptr.class_object = i_obj;
    i_obj.this_variable = new R.Variable(i_obj.interp, "this", "VAR_THIS_VAR", null, i_obj.class_info.ns_ptr);
    i_obj.this_variable.setProtection(i_obj.PROTECTION_PROTECTED);
    i_obj.variables[i_obj.escape_key(i_obj.escape_key("this"))] = i_obj.this_variable;
    /* next line is needed here for access of constructor to this variable etc. */
    i_obj.interp.setClassObject(i_obj.object_name, i_obj);
//FIXME need to use variable_obj_type here !!!
    this_obj_ptr = i_obj.interp.string_obj_type.newStringObj("this", -1);
    value_ptr = i_obj.interp.string_obj_type.newStringObj(i_obj.object_name, -1);
    this_obj_ptr.incrRefCount();
    value_ptr.incrRefCount();
    i_obj.interp.variable_obj_type.setVariable(this_obj_ptr, value_ptr);
    this_obj_ptr.decrRefCount();
    value_ptr.decrRefCount();
    if (i_obj.class_info.class_type == i_obj.ITCL_TYPE_CLASS) {
      i_obj.this_variable = new R.Variable(i_obj.interp, "self", "VAR_SELF_VAR", null, i_obj.class_info.ns_ptr);
      i_obj.this_variable.setProtection(i_obj.PROTECTION_PROTECTED);
      i_obj.variables[i_obj.escape_key(i_obj.escape_key("self"))] = i_obj.this_variable;
    }
    self_obj_ptr = i_obj.interp.string_obj_type.newStringObj("self", -1);
    value_ptr = i_obj.interp.string_obj_type.newStringObj(i_obj.object_name, -1);
    self_obj_ptr.incrRefCount();
    value_ptr.incrRefCount();
    i_obj.interp.variable_obj_type.setVariable(self_obj_ptr, value_ptr);
    self_obj_ptr.decrRefCount();
    value_ptr.decrRefCount();

    if (i_obj.class_info.class_type == i_obj.ITCL_TYPE_CLASS) {
      i_obj.this_variable = new R.Variable(i_obj.interp, "type", "VAR_TYPE_VAR", null, i_obj.class_info.ns_ptr);
      i_obj.this_variable.setProtection(i_obj.PROTECTION_PROTECTED);
      i_obj.variables[i_obj.escape_key(i_obj.escape_key("type"))] = i_obj.this_variable;
    }
    self_obj_ptr = i_obj.interp.string_obj_type.newStringObj("type", -1);
    value_ptr = i_obj.interp.string_obj_type.newStringObj(i_obj.class_info.class_name, -1);
    self_obj_ptr.incrRefCount();
    value_ptr.incrRefCount();
    i_obj.interp.variable_obj_type.setVariable(self_obj_ptr, value_ptr);
    self_obj_ptr.decrRefCount();
    value_ptr.decrRefCount();

    if (i_obj.class_info.class_type == i_obj.ITCL_TYPE_CLASS) {
      i_obj.this_variable = new R.Variable(i_obj.interp, "selfns", "VAR_SELF_VAR", null, i_obj.class_info.ns_ptr);
      i_obj.this_variable.setProtection(i_obj.PROTECTION_PROTECTED);
      i_obj.variables[i_obj.escape_key(i_obj.escape_key("selfns"))] = i_obj.this_variable;
    }
    self_obj_ptr = i_obj.interp.string_obj_type.newStringObj("selfns", -1);
    value_ptr = i_obj.interp.string_obj_type.newStringObj(i_obj.class_info.ns_ptr.full_name, -1);
    self_obj_ptr.incrRefCount();
    value_ptr.incrRefCount();
    i_obj.interp.variable_obj_type.setVariable(self_obj_ptr, value_ptr);
    self_obj_ptr.decrRefCount();
    value_ptr.decrRefCount();

    if (i_obj.initObjectVariables() != i_obj.OK) {
      err = true;
      ret_code = i_obj.ERROR;
    }
    if (!err) {
      if (i_obj.initObjectCommands() != i_obj.OK) {
................................................................................
//print("NS!"+i_obj.interp.frame_ptr.ns_ptr.toDebugString()+"!");
    save_ns_ptr = i_obj.interp.frame_ptr.ns_ptr;
    i_obj.interp.frame_ptr.ns_ptr = class_obj.ns_ptr;
    for (var option_name in class_obj.options) {
      var option_obj = class_obj.options[option_name];
      i_obj.class_options[option_name] = option_obj;
      /* set the itcl_options array for that option name to the defaultvalue of the option */
      obj_ptr = i_obj.interp.string_obj_type.newStringObj("itcl_options("+option_name+")", -1);
      if (option_obj.default_value != null) {
        obj_ptr.incrRefCount()
        if (i_obj.interp.variable_obj_type.setVariable(obj_ptr, option_obj.default_value) != i_obj.OK) {
          i_obj.interp.frame_ptr.ns_ptr = save_ns_ptr;
          return i_obj.ERROR;
        }
        obj_ptr.decrRefCount()
      }
      if (i_obj.class_info.class_type == i_obj.ITCL_TYPE_CLASS) {
        /* set the options array for ::itcl::type for that option name to the defaultvalue of the option */
        obj_ptr = i_obj.interp.string_obj_type.newStringObj("options("+option_name+")", -1);
        if (option_obj.default_value != null) {
          obj_ptr.incrRefCount()
          if (i_obj.interp.variable_obj_type.setVariable(obj_ptr, option_obj.default_value) != i_obj.OK) {
            i_obj.interp.frame_ptr.ns_ptr = save_ns_ptr;
            return i_obj.ERROR;
          }
          obj_ptr.decrRefCount()
	} else {
          if (default_value_ptr == null) {
            default_value_ptr = i_obj.interp.string_obj_type.newStringObj("", -1);
	  }
          obj_ptr.incrRefCount()
          default_value_ptr.incrRefCount()
          if (i_obj.interp.variable_obj_type.setVariable(obj_ptr, default_value_ptr) != i_obj.OK) {
            i_obj.interp.frame_ptr.ns_ptr = save_ns_ptr;
            return i_obj.ERROR;
          }
          obj_ptr.decrRefCount()
          default_value_ptr.decrRefCount()
	}
      }
    }
    i_obj.interp.frame_ptr.ns_ptr = save_ns_ptr;
    return i_obj.OK;
  },

................................................................................
      var_ptr.setProtection(class_var_ptr.protection);
      if (class_var_ptr.type == i_obj.ITCL_TYPE_VARIABLE) {
        i_obj.class_info.ns_ptr.variables[i_obj.escape_key(var_name)] = var_ptr;
      } else {
        i_obj.variables[i_obj.escape_key(var_name)] = var_ptr;
      }
      if (class_var_ptr.init_val != null) {
	var_name_ptr = i_obj.interp.string_obj_type.newStringObj(var_name, -1);
        var_name_ptr.incrRefCount();
	i_obj.interp.variable_obj_type.setVariable(var_name_ptr, class_var_ptr.init_val);
        var_name_ptr.decrRefCount();
      }
      if (var_ptr.config_code != null) {
        var_ptr.setConfigCode(class_var_ptr.config_code);
      }
      var_ptr.setClassName(i_obj.class_info.full_name);
      var_ptr.setState(class_var_ptr.state);
    }







|
|













|
|
|
|

|
|





|
|
|
|

|
|






|
|
|
|

|
|






|
|
|
|

|
|







 







|

|




|



|

|




|


|

|
|




|
|







 







|
|

|







108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
    var self_obj_ptr;
    var value_ptr;
    var this_obj_ptr;
    var my_obj_ptr;

//print("initItclObject!"+i_obj.toDebugString()+"!");
    /* add to class instances */
    my_obj_ptr = i_obj.interp.string_obj_type.newStringObj(i_obj.object_name, -1, "ITCL_OBJECT_1");
    my_obj_ptr.incrRefCount("I_ITCL_OBJECT_1");
    i_obj.class_info.instances.push(my_obj_ptr);
    /* Create a new call frame */
    result = i_obj.interp.namespace_obj_type.pushStackFrame(frame_ptr_ptr, i_obj.class_info.ns_ptr, i_obj.CALL_TYPE_PROC);
    if (result != i_obj.OK) {
      return i_obj.ERROR;
    }
    i_obj.interp.frame_ptr.class_object = i_obj;
    i_obj.this_variable = new R.Variable(i_obj.interp, "this", "VAR_THIS_VAR", null, i_obj.class_info.ns_ptr);
    i_obj.this_variable.setProtection(i_obj.PROTECTION_PROTECTED);
    i_obj.variables[i_obj.escape_key(i_obj.escape_key("this"))] = i_obj.this_variable;
    /* next line is needed here for access of constructor to this variable etc. */
    i_obj.interp.setClassObject(i_obj.object_name, i_obj);
//FIXME need to use variable_obj_type here !!!
    this_obj_ptr = i_obj.interp.string_obj_type.newStringObj("this", -1, "ITCL_OBJECT_2");
    value_ptr = i_obj.interp.string_obj_type.newStringObj(i_obj.object_name, -1, "ITCL_OBJECT_3");
    this_obj_ptr.incrRefCount("I_ITCL_OBJECT_2");
    value_ptr.incrRefCount("I_ITCL_OBJECT_3");
    i_obj.interp.variable_obj_type.setVariable(this_obj_ptr, value_ptr);
    this_obj_ptr.decrRefCount("D_ITCL_OBJECT_1");
    value_ptr.decrRefCount("D_ITCL_OBJECT_2");
    if (i_obj.class_info.class_type == i_obj.ITCL_TYPE_CLASS) {
      i_obj.this_variable = new R.Variable(i_obj.interp, "self", "VAR_SELF_VAR", null, i_obj.class_info.ns_ptr);
      i_obj.this_variable.setProtection(i_obj.PROTECTION_PROTECTED);
      i_obj.variables[i_obj.escape_key(i_obj.escape_key("self"))] = i_obj.this_variable;
    }
    self_obj_ptr = i_obj.interp.string_obj_type.newStringObj("self", -1, "ITCL_OBJECT_3");
    value_ptr = i_obj.interp.string_obj_type.newStringObj(i_obj.object_name, -1, "ITCL_OBJECT_4");
    self_obj_ptr.incrRefCount("I_ITCL_OBJECT_4");
    value_ptr.incrRefCount("I_ITCL_OBJECT_5");
    i_obj.interp.variable_obj_type.setVariable(self_obj_ptr, value_ptr);
    self_obj_ptr.decrRefCount("D_ITCL_OBJECT_3");
    value_ptr.decrRefCount("D_ITCL_OBJECT_4");

    if (i_obj.class_info.class_type == i_obj.ITCL_TYPE_CLASS) {
      i_obj.this_variable = new R.Variable(i_obj.interp, "type", "VAR_TYPE_VAR", null, i_obj.class_info.ns_ptr);
      i_obj.this_variable.setProtection(i_obj.PROTECTION_PROTECTED);
      i_obj.variables[i_obj.escape_key(i_obj.escape_key("type"))] = i_obj.this_variable;
    }
    self_obj_ptr = i_obj.interp.string_obj_type.newStringObj("type", -1, "ITCL_OBJECT_5");
    value_ptr = i_obj.interp.string_obj_type.newStringObj(i_obj.class_info.class_name, -1, "ITCL_OBJECT_6");
    self_obj_ptr.incrRefCount("I_ITCL_OBJECT_6");
    value_ptr.incrRefCount("I_ITCL_OBJECT_7");
    i_obj.interp.variable_obj_type.setVariable(self_obj_ptr, value_ptr);
    self_obj_ptr.decrRefCount("D_ITCL_OBJECT_5");
    value_ptr.decrRefCount("D_ITCL_OBJECT_6");

    if (i_obj.class_info.class_type == i_obj.ITCL_TYPE_CLASS) {
      i_obj.this_variable = new R.Variable(i_obj.interp, "selfns", "VAR_SELF_VAR", null, i_obj.class_info.ns_ptr);
      i_obj.this_variable.setProtection(i_obj.PROTECTION_PROTECTED);
      i_obj.variables[i_obj.escape_key(i_obj.escape_key("selfns"))] = i_obj.this_variable;
    }
    self_obj_ptr = i_obj.interp.string_obj_type.newStringObj("selfns", -1, "ITCL_OBJECT_7");
    value_ptr = i_obj.interp.string_obj_type.newStringObj(i_obj.class_info.ns_ptr.full_name, -1, "ITCL_OBJECT_8");
    self_obj_ptr.incrRefCount("I_ITCL_OBJECT_8");
    value_ptr.incrRefCount("I_ITCL_OBJECT_9");
    i_obj.interp.variable_obj_type.setVariable(self_obj_ptr, value_ptr);
    self_obj_ptr.decrRefCount("D_ITCL_OBJECT_7");
    value_ptr.decrRefCount("D_ITCL_OBJECT_8");

    if (i_obj.initObjectVariables() != i_obj.OK) {
      err = true;
      ret_code = i_obj.ERROR;
    }
    if (!err) {
      if (i_obj.initObjectCommands() != i_obj.OK) {
................................................................................
//print("NS!"+i_obj.interp.frame_ptr.ns_ptr.toDebugString()+"!");
    save_ns_ptr = i_obj.interp.frame_ptr.ns_ptr;
    i_obj.interp.frame_ptr.ns_ptr = class_obj.ns_ptr;
    for (var option_name in class_obj.options) {
      var option_obj = class_obj.options[option_name];
      i_obj.class_options[option_name] = option_obj;
      /* set the itcl_options array for that option name to the defaultvalue of the option */
      obj_ptr = i_obj.interp.string_obj_type.newStringObj("itcl_options("+option_name+")", -1, "ITCL_OBJECT_9");
      if (option_obj.default_value != null) {
        obj_ptr.incrRefCount("I_ITCL_OBJECT_10")
        if (i_obj.interp.variable_obj_type.setVariable(obj_ptr, option_obj.default_value) != i_obj.OK) {
          i_obj.interp.frame_ptr.ns_ptr = save_ns_ptr;
          return i_obj.ERROR;
        }
        obj_ptr.decrRefCount("D_ITCL_OBJECT_9")
      }
      if (i_obj.class_info.class_type == i_obj.ITCL_TYPE_CLASS) {
        /* set the options array for ::itcl::type for that option name to the defaultvalue of the option */
        obj_ptr = i_obj.interp.string_obj_type.newStringObj("options("+option_name+")", -1, "ITCL_OBJECT_10");
        if (option_obj.default_value != null) {
          obj_ptr.incrRefCount("I_ITCL_OBJECT_11")
          if (i_obj.interp.variable_obj_type.setVariable(obj_ptr, option_obj.default_value) != i_obj.OK) {
            i_obj.interp.frame_ptr.ns_ptr = save_ns_ptr;
            return i_obj.ERROR;
          }
          obj_ptr.decrRefCount("D_ITCL_OBJECT_10")
	} else {
          if (default_value_ptr == null) {
            default_value_ptr = i_obj.interp.string_obj_type.newStringObj("", -1, "ITCL_OBJECT_11");
	  }
          obj_ptr.incrRefCount("I_ITCL_OBJECT_12")
          default_value_ptr.incrRefCount("I_ITCL_OBJECT_13")
          if (i_obj.interp.variable_obj_type.setVariable(obj_ptr, default_value_ptr) != i_obj.OK) {
            i_obj.interp.frame_ptr.ns_ptr = save_ns_ptr;
            return i_obj.ERROR;
          }
          obj_ptr.decrRefCount("D_ITCL_OBJECT_11")
          default_value_ptr.decrRefCount("D_ITCL_OBJECT_12")
	}
      }
    }
    i_obj.interp.frame_ptr.ns_ptr = save_ns_ptr;
    return i_obj.OK;
  },

................................................................................
      var_ptr.setProtection(class_var_ptr.protection);
      if (class_var_ptr.type == i_obj.ITCL_TYPE_VARIABLE) {
        i_obj.class_info.ns_ptr.variables[i_obj.escape_key(var_name)] = var_ptr;
      } else {
        i_obj.variables[i_obj.escape_key(var_name)] = var_ptr;
      }
      if (class_var_ptr.init_val != null) {
	var_name_ptr = i_obj.interp.string_obj_type.newStringObj(var_name, -1, "ITCL_OBJECT_12");
        var_name_ptr.incrRefCount("I_ITCL_OBJECT_14");
	i_obj.interp.variable_obj_type.setVariable(var_name_ptr, class_var_ptr.init_val);
        var_name_ptr.decrRefCount("D_ITCL_OBJECT_13");
      }
      if (var_ptr.config_code != null) {
        var_ptr.setConfigCode(class_var_ptr.config_code);
      }
      var_ptr.setClassName(i_obj.class_info.full_name);
      var_ptr.setState(class_var_ptr.state);
    }

Changes to rapl_list_obj_type.js.

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
...
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
      if (parser.parse_info.token != lst.TOKEN_STR && parser.parse_info.token != lst.TOKEN_ESC) {
        continue;
      }
      element_ptr = lst.parserGetTokenObj(parser);
      script.interp.source_obj_type.setSourceInfo(element_ptr, file_name_obj, parser.parse_info.line);
      lst._listAppendElement(obj_ptr, element_ptr);
    }
    file_name_obj.decrRefCount();
    return lst.OK;
  },

  /* ==================== freeInternalRep ===================================== */
  freeInternalRep: function(obj_ptr) {
    var lst = this;
    var i;

    for (i = 0; i < obj_ptr.listValue.len(); i++) {
      obj_ptr.listValue.elem()[i].decrRefCount();
    }
    obj_ptr.listValue.elem(null);
  },

  /* ==================== dupInternalRep ===================================== */
  dupInternalRep: function(src_ptr, dup_ptr) {
    var lst = this;
................................................................................
        token += parser.parse_info.text.substring(start, start + len);
        token += '\0';
      } else {
        /* Else convert the escape chars. */
        len = lst.interp.default_obj.escapeBackslash(token, parser.parse_info.text.substring(start, start + len), len);
      }
    }
    return lst.interp.string_obj_type.newStringObjNoAlloc(token, len);
  },

  /* ==================== backslashQuoteString ===================================== */
  /* Returns the representation of a string
   * using backslash to quote special chars. 
   */
  backslashQuoteString: function(str, len, result_len) {
................................................................................
            lst.interp.setResultString("list index out of range", -1);
        }
        return lst.ERROR;
    }
    if (idx < 0) {
      idx = list_ptr.listValue.len() + idx;
    }
    list_ptr.listValue.elem[idx].decrRefCount();
    list_ptr.listValue.elem[idx] = new_obj_ptr;
    new_obj_ptr.incrRefCount();
    return lst.OK;
  },

  /* ==================== setListIndex ===================================== */
  /* Modify the list stored into the variable named 'var_name_ptr'







|









|







 







|







 







|







83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
...
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
      if (parser.parse_info.token != lst.TOKEN_STR && parser.parse_info.token != lst.TOKEN_ESC) {
        continue;
      }
      element_ptr = lst.parserGetTokenObj(parser);
      script.interp.source_obj_type.setSourceInfo(element_ptr, file_name_obj, parser.parse_info.line);
      lst._listAppendElement(obj_ptr, element_ptr);
    }
    file_name_obj.decrRefCount("D_LIST_OBJ_TYPE_1");
    return lst.OK;
  },

  /* ==================== freeInternalRep ===================================== */
  freeInternalRep: function(obj_ptr) {
    var lst = this;
    var i;

    for (i = 0; i < obj_ptr.listValue.len(); i++) {
      obj_ptr.listValue.elem()[i].decrRefCount("D_LIST_OBJ_TYPE_2");
    }
    obj_ptr.listValue.elem(null);
  },

  /* ==================== dupInternalRep ===================================== */
  dupInternalRep: function(src_ptr, dup_ptr) {
    var lst = this;
................................................................................
        token += parser.parse_info.text.substring(start, start + len);
        token += '\0';
      } else {
        /* Else convert the escape chars. */
        len = lst.interp.default_obj.escapeBackslash(token, parser.parse_info.text.substring(start, start + len), len);
      }
    }
    return lst.interp.string_obj_type.newStringObjNoAlloc(token, len, "LIST_OBJ_TYPE_1");
  },

  /* ==================== backslashQuoteString ===================================== */
  /* Returns the representation of a string
   * using backslash to quote special chars. 
   */
  backslashQuoteString: function(str, len, result_len) {
................................................................................
            lst.interp.setResultString("list index out of range", -1);
        }
        return lst.ERROR;
    }
    if (idx < 0) {
      idx = list_ptr.listValue.len() + idx;
    }
    list_ptr.listValue.elem[idx].decrRefCount("D_LIST_OBJ_TYPE_3");
    list_ptr.listValue.elem[idx] = new_obj_ptr;
    new_obj_ptr.incrRefCount();
    return lst.OK;
  },

  /* ==================== setListIndex ===================================== */
  /* Modify the list stored into the variable named 'var_name_ptr'

Changes to rapl_local_var_name_obj_type.js.

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

  /* ==================== freeInternalRep ===================================== */
  freeInternalRep: function(obj_ptr) {
    var local_var_name_obj = this;
    var name_ptr = obj_ptr.ptrAndLongRep.ptr();

    if (name_ptr) {
      name_ptr.decrRefCount();
    }
    obj_ptr.obj_type = null;
  },

  /* ==================== dupInternalRep ===================================== */
  dupInternalRep: function(src_ptr, dup_ptr) {
    var local_var_name_obj = this;







|







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

  /* ==================== freeInternalRep ===================================== */
  freeInternalRep: function(obj_ptr) {
    var local_var_name_obj = this;
    var name_ptr = obj_ptr.ptrAndLongRep.ptr();

    if (name_ptr) {
      name_ptr.decrRefCount("D_LOCAL_VAR_NAME_OBJ_TYPE_1");
    }
    obj_ptr.obj_type = null;
  },

  /* ==================== dupInternalRep ===================================== */
  dupInternalRep: function(src_ptr, dup_ptr) {
    var local_var_name_obj = this;

Changes to rapl_main.js.

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
RP.Env.mod_names.push("pkg-trace");
RP.Env.mod_names.push("pkg-array");
for (var i = 0; i < RP.Env.mod_names.length; i++) {
   var mod_name_part = RP.Env.mod_names[i];
//print("MD!"+mod_name_part+"!");
//  print("RE0!"+mod_name_part+"!"+typeof RP.Env.mods["rapl-"+mod_name_part].fn+"!");
   try {
   RAPL.Env.mods["rapl-"+mod_name_part].fn(RP, "rapl-"+mod_name_part);
   } catch(e) {
print("ERROR!"+e+"!"+mod_name_part+"!");
   }
}

if (false) {
var ab = new ArrayBuffer(1024);
var int32View = new Int32Array(ab);
var int16View = new Int16Array(ab);
var uint8View = new Uint8Array(ab);
var int16View = new Int16Array(ab);
int32View[0] = parseInt("8040201", 16);
datav = new DataView(ab);
print("AB!"+int16View[0]+"!"+int16View[1]+"!"+uint8View[0]+"!"+uint8View[1]+"!"+uint8View[2]+"!"+uint8View[3]+"!");
}







|




<
<
<
<
<
<
<
<
<
<
<
99
100
101
102
103
104
105
106
107
108
109
110











RP.Env.mod_names.push("pkg-trace");
RP.Env.mod_names.push("pkg-array");
for (var i = 0; i < RP.Env.mod_names.length; i++) {
   var mod_name_part = RP.Env.mod_names[i];
//print("MD!"+mod_name_part+"!");
//  print("RE0!"+mod_name_part+"!"+typeof RP.Env.mods["rapl-"+mod_name_part].fn+"!");
   try {
     RAPL.Env.mods["rapl-"+mod_name_part].fn(RP, "rapl-"+mod_name_part);
   } catch(e) {
print("ERROR!"+e+"!"+mod_name_part+"!");
   }
}











Changes to rapl_namespace.js.

853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
          return NULL;
	}
        var var_obj = class_ptr[0].getThisVariable();
	return var_obj;
      }
    }
    part1_ptr = interp.string_obj_type.newStringObj(part1, -1);
    part1_ptr.incrRefCount();
    my_var_obj = namesp.interp.variable_obj_type.lookupSimpleVar(part1_ptr, flags, create_part1, err_msg_ptr, index_ptr);
    err_msg_ptr = err_msg_ptr[0];
    part1_ptr.decrRefCount();
if (namesp.variable_debug) {
print("lookupVariableEx2!"+name+"!"+my_var_obj+"!");
}
    if (my_var_obj == null) {
      if ((msg != null) && (flags & namesp.FUNCTION_FLAGS_LEAVE_ERR_MSG)) {
        namesp.VarErrMsg(interp, part1, part2, msg, namesp.var_lookup_msg, -1); 
	namesp.SetErrorCode(interp, "RAPL", "LOOKUP", "VARNAME", part1, null);







|


|







853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
          return NULL;
	}
        var var_obj = class_ptr[0].getThisVariable();
	return var_obj;
      }
    }
    part1_ptr = interp.string_obj_type.newStringObj(part1, -1);
    part1_ptr.incrRefCount("I_NAMESPACE_1");
    my_var_obj = namesp.interp.variable_obj_type.lookupSimpleVar(part1_ptr, flags, create_part1, err_msg_ptr, index_ptr);
    err_msg_ptr = err_msg_ptr[0];
    part1_ptr.decrRefCount("D_NAMESPACE_1");
if (namesp.variable_debug) {
print("lookupVariableEx2!"+name+"!"+my_var_obj+"!");
}
    if (my_var_obj == null) {
      if ((msg != null) && (flags & namesp.FUNCTION_FLAGS_LEAVE_ERR_MSG)) {
        namesp.VarErrMsg(interp, part1, part2, msg, namesp.var_lookup_msg, -1); 
	namesp.SetErrorCode(interp, "RAPL", "LOOKUP", "VARNAME", part1, null);

Changes to rapl_namespace_obj_type.js.

623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
     * easy to do things like:
     *
     *    namespace [namespace current]::bar { ... }
     */

    curr_ns_ptr = namesp.interp.current_namespace;
    if (curr_ns_ptr == namesp.getGlobalNamespace()) {
      namesp.interp.setResult(namesp.interp.string_obj_type.newStringObj("::", 2));
    } else {
      namesp.interp.setResult(interp, namesp.interp.string_obj_type.newStringObj(curr_ns_ptr.fullName, -1));
    }
    return namesp.OK;
  },

  /* ==================== getGlobalNamespace ===================================== */
  getGlobalNamespace: function() {
    var namesp = this;







|

|







623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
     * easy to do things like:
     *
     *    namespace [namespace current]::bar { ... }
     */

    curr_ns_ptr = namesp.interp.current_namespace;
    if (curr_ns_ptr == namesp.getGlobalNamespace()) {
      namesp.interp.setResult(namesp.interp.string_obj_type.newStringObj("::", 2, "NAMESPACE_OBJ_TYPE_1"));
    } else {
      namesp.interp.setResult(interp, namesp.interp.string_obj_type.newStringObj(curr_ns_ptr.fullName, -1, "NAMESPACE_OBJ_TYPE_2"));
    }
    return namesp.OK;
  },

  /* ==================== getGlobalNamespace ===================================== */
  getGlobalNamespace: function() {
    var namesp = this;

Changes to rapl_obj.js.

41
42
43
44
45
46
47




48
49
50
51
52
53
54
...
467
468
469
470
471
472
473
474

475
476
477
478
479
480
481
...
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503



504
505
506
507
508
509
510
511
512
513
514
515
516
517
...
524
525
526
527
528
529
530

531
532
533
534
535
536
537

























538
539
540
541
542
543
544
...
759
760
761
762
763
764
765
766
767
768
769



770
771
772
773
774
775
776
777



778
779
780
781
782
783
784
785
786
787
788
789




790
791
792
793
794
795
796
....
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
     * For being able to distinguish between the getter and setter method we use the arguments
     * argument to see if we have any arguments and decide from that.
     */
    value1: null,
    value2: null,
    value3: null,
  };





  /* ==================== arrayValue ================================= */
  obj.arrayValue = {  /* Array type */
    varNameObjPtr: function() {
      if (arguments.length == 0) {
        var x = "ArrayValue varNameObjptr";
        return obj.internalRep.value1;
................................................................................
  newObj: function () {
    var obj = this;
    var my_obj;
    /* -- Check if there are objects in the free list -- */
    if (obj.interp.free_obj_list != null) {
      /* -- Unlink the object from the free list -- */
      my_obj = obj.interp.free_obj_list;
      obj.interp.free_obj_list = my_obj.next_ptr;

    } else {
      /* -- No ready to use objects: allocate a new one -- */
      my_obj = new R.RaplObject(obj.interp);
    }
    /* Object is returned with ref_count of 0. Every
     * kind of GC implemented should take care to don't try
     * to scan objects with ref_count == 0. */
................................................................................
    /* All the other fields are left not initialized to save time.
     * The caller will probably want to set them to the right
     * value anyway. */

    /* -- Put the object into the live list -- */
    my_obj.prev_obj_ptr = null;
    my_obj.next_obj_ptr = obj.interp.live_obj_list;
    if (obj.interp.live_obj_ptr != null) {
      obj.interp.live_obj_list.prev_obj_ptr = my_obj;
    }
    obj.interp.live_obj_list = my_obj;
    my_obj.obj_type = null;
    my_obj.bytes = null;
    return my_obj;
  },

  /* ==================== freeNewObj ===================================== */
  freeNewObj: function() {
    var obj = this;

    obj.freeObj();



  },

  /* ==================== freeObj ===================================== */
  /* Free an Obj. Actually Objs are never freed, but
   * just moved to the free obj list, where they will be
   * reused by newObj(). */
  freeObj: function() {
    var obj = this;
//print("freeObj!"+obj.mySelf()+"!"+obj.obj_type+"!"+obj.GetString()+"!");
    /* Check if the object was already freed, panic. */
    obj.panic(obj.ref_count != 0, "!!! "+obj.mySelf()+" freed with bad ref_count "+obj.ref_count+", type="+((obj.obj_type  != null) ? obj.obj_type.name : "<none>")+"!"+obj.toDebugString()+"!");
    obj.freeIntRep();
    /* Free the string representation */
    if (obj.bytes != null) {
................................................................................
    if (obj.next_obj_ptr != null) {
      obj.next_obj_ptr.prev_obj_ptr = obj.prev_obj_ptr;
    }
    if (obj.interp.live_obj_list == obj) {
      obj.interp.live_obj_list = obj.next_obj_ptr;
    }
    /* Link the object into the free objects list */

    obj.prev_obj_ptr = null;
    obj.next_obj_ptr = obj.interp.free_obj_list;
    if (obj.interp.free_obj_list != null) {
      obj.interp.free_obj_list.prev_obj_ptr = obj;
    }
    obj.interp.free_obj_list = obj;
    obj.ref_count = -1;

























  },
				          
  /* ==================== invalidateStringRep ===================================== */
  invalidateStringRep: function() {
    var obj = this;

    if (obj.bytes != null) {
................................................................................
  getIntRepPtr: function() {
    var obj = this;

     return obj.ptr();
  },

  /* ==================== incrRefCount ================================== */
  incrRefCount: function() {
    var obj = this;

    obj.ref_count++;



    return obj.ref_count;
  },

  /* ==================== decrRefCount ================================== */
  decrRefCount: function() {
    var obj = this;

    obj.ref_count--;



    if (obj.ref_count <= 0) {
      obj.freeObj();
    }
  },

  /* ==================== toDebugString ===================================== */
  toDebugString: function () {
    var obj = this;
    var str = obj.mySelf()+"\n";
    str += "  ref_count: "+obj.ref_count+"\n";
    str += "  len: "+obj.len+"\n";
    str += "  obj_type: "+((obj.obj_type == null) ? "<null>" : obj.obj_type.type_name)+"\n";




    str += "  bytes: "+((obj.bytes == null) ? "<null>" : obj.getString())+"\n";
    if (obj.obj_type != null) {
      if (obj.obj_type.type_name == "list") {
        str += "  list_elem: "+obj.listValue.elem()+"\n";
      }
    }
    return str;
................................................................................
            /* Drop the space calcuated for this
             * element that is instead null. */
            len--;
          }
        }
      }
      p += '\0';
      return obj.interp.string_obj_type.newStringObjNoAlloc(p, len);
    }
  },

  /* ==================== duplicateObj ===================================== */
  duplicateObj: function () {
    var obj = this;
    var dup_ptr;







>
>
>
>







 







|
>







 







|









|



>
>
>






|







 







>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|



>
>
>




|



>
>
>

|










>
>
>
>







 







|







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
...
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
...
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
...
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
...
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
....
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
     * For being able to distinguish between the getter and setter method we use the arguments
     * argument to see if we have any arguments and decide from that.
     */
    value1: null,
    value2: null,
    value3: null,
  };
  obj.allocated = null;
  obj.freed = null;
  obj.incr_lst = new Array();
  obj.decr_lst = new Array();

  /* ==================== arrayValue ================================= */
  obj.arrayValue = {  /* Array type */
    varNameObjPtr: function() {
      if (arguments.length == 0) {
        var x = "ArrayValue varNameObjptr";
        return obj.internalRep.value1;
................................................................................
  newObj: function () {
    var obj = this;
    var my_obj;
    /* -- Check if there are objects in the free list -- */
    if (obj.interp.free_obj_list != null) {
      /* -- Unlink the object from the free list -- */
      my_obj = obj.interp.free_obj_list;
      obj.interp.free_obj_list = my_obj.next_obj_ptr;
R.Base.free_objs--;
    } else {
      /* -- No ready to use objects: allocate a new one -- */
      my_obj = new R.RaplObject(obj.interp);
    }
    /* Object is returned with ref_count of 0. Every
     * kind of GC implemented should take care to don't try
     * to scan objects with ref_count == 0. */
................................................................................
    /* All the other fields are left not initialized to save time.
     * The caller will probably want to set them to the right
     * value anyway. */

    /* -- Put the object into the live list -- */
    my_obj.prev_obj_ptr = null;
    my_obj.next_obj_ptr = obj.interp.live_obj_list;
    if (obj.interp.live_obj_list != null) {
      obj.interp.live_obj_list.prev_obj_ptr = my_obj;
    }
    obj.interp.live_obj_list = my_obj;
    my_obj.obj_type = null;
    my_obj.bytes = null;
    return my_obj;
  },

  /* ==================== freeNewObj ===================================== */
  freeNewObj: function(where) {
    var obj = this;

    obj.freeObj();
    if (typeof where != "undefined") {
      obj.freed = where;
    }
  },

  /* ==================== freeObj ===================================== */
  /* Free an Obj. Actually Objs are never freed, but
   * just moved to the free obj list, where they will be
   * reused by newObj(). */
  freeObj: function(where) {
    var obj = this;
//print("freeObj!"+obj.mySelf()+"!"+obj.obj_type+"!"+obj.GetString()+"!");
    /* Check if the object was already freed, panic. */
    obj.panic(obj.ref_count != 0, "!!! "+obj.mySelf()+" freed with bad ref_count "+obj.ref_count+", type="+((obj.obj_type  != null) ? obj.obj_type.name : "<none>")+"!"+obj.toDebugString()+"!");
    obj.freeIntRep();
    /* Free the string representation */
    if (obj.bytes != null) {
................................................................................
    if (obj.next_obj_ptr != null) {
      obj.next_obj_ptr.prev_obj_ptr = obj.prev_obj_ptr;
    }
    if (obj.interp.live_obj_list == obj) {
      obj.interp.live_obj_list = obj.next_obj_ptr;
    }
    /* Link the object into the free objects list */
R.Base.free_objs++;
    obj.prev_obj_ptr = null;
    obj.next_obj_ptr = obj.interp.free_obj_list;
    if (obj.interp.free_obj_list != null) {
      obj.interp.free_obj_list.prev_obj_ptr = obj;
    }
    obj.interp.free_obj_list = obj;
    obj.ref_count = -1;
    if (typeof where != "undefined") {
      obj.freed = where;
    }
  },
				          
  /* ==================== dumpObjLists ===================================== */
  dumpObjLists: function() {
    var obj = this;
    var obj_ptr;

    print("live_list!"+obj.interp.live_obj_list+"!");
    obj_ptr = obj.interp.live_obj_list;
    while (obj_ptr != null) {
      print(obj_ptr.toDebugString());
//      print(obj_ptr.mySelf());
      obj_ptr = obj_ptr.next_obj_ptr;
    }

    print("free_list!"+R.Base.free_objs+"!"+obj.interp.free_obj_list+"!");
    obj_ptr = obj.interp.free_obj_list;
    while (obj_ptr != null) {
      print(obj_ptr.toDebugString());
//      print(obj_ptr.mySelf());
      obj_ptr = obj_ptr.next_obj_ptr;
    }
  },
				          
  /* ==================== invalidateStringRep ===================================== */
  invalidateStringRep: function() {
    var obj = this;

    if (obj.bytes != null) {
................................................................................
  getIntRepPtr: function() {
    var obj = this;

     return obj.ptr();
  },

  /* ==================== incrRefCount ================================== */
  incrRefCount: function(where) {
    var obj = this;

    obj.ref_count++;
    if (typeof where != "undefined") {
      obj.incr_lst.push(where);
    }
    return obj.ref_count;
  },

  /* ==================== decrRefCount ================================== */
  decrRefCount: function(where) {
    var obj = this;

    obj.ref_count--;
    if (typeof where != "undefined") {
      obj.decr_lst.push(where);
    }
    if (obj.ref_count <= 0) {
      obj.freeObj(where);
    }
  },

  /* ==================== toDebugString ===================================== */
  toDebugString: function () {
    var obj = this;
    var str = obj.mySelf()+"\n";
    str += "  ref_count: "+obj.ref_count+"\n";
    str += "  len: "+obj.len+"\n";
    str += "  obj_type: "+((obj.obj_type == null) ? "<null>" : obj.obj_type.type_name)+"\n";
    str += "  allocated: "+obj.allocated+"\n";
    str += "  freed: "+obj.freed+"\n";
    str += "  incr: "+obj.incr_lst+"\n";
    str += "  decr: "+obj.decr_lst+"\n";
    str += "  bytes: "+((obj.bytes == null) ? "<null>" : obj.getString())+"\n";
    if (obj.obj_type != null) {
      if (obj.obj_type.type_name == "list") {
        str += "  list_elem: "+obj.listValue.elem()+"\n";
      }
    }
    return str;
................................................................................
            /* Drop the space calcuated for this
             * element that is instead null. */
            len--;
          }
        }
      }
      p += '\0';
      return obj.interp.string_obj_type.newStringObjNoAlloc(p, len, "OBJ_1");
    }
  },

  /* ==================== duplicateObj ===================================== */
  duplicateObj: function () {
    var obj = this;
    var dup_ptr;

Changes to rapl_parsed_var_name_obj_type.js.

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  /* ==================== freeInternalRep ===================================== */
  freeInternalRep: function(obj_ptr) {
    var parsed_var_name_obj = this;
    var array_ptr = obj_ptr.twoPtrValue.ptr1();
    var elem = obj_ptr.twoPtrValue.ptr2();

    if (array_ptr != null) {
	array_ptr.decrRefCount();
    }
    obj_ptr.obj_type = null;
  },

  /* ==================== dupInternalRep ===================================== */
  dupInternalRep: function(src_ptr, dup_ptr) {
    var parsed_var_name_obj = this;
    var array_ptr = src_ptr.twoPtrValue.ptr1();
    var elem = src_ptr.twoPtrValue.ptr2();
    var elem_copy;
    var elem_len;

    if (array_ptr != null) {
	array_ptr.incrRefCount();
	elem_len = elem.length;
	elem_copy = elem
	elem = elem_copy;
    }

    dup_ptr.twoPtrValue.ptr1(array_ptr);
    dup_ptr.twoPtrValue.ptr2(elem);







|













|







50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  /* ==================== freeInternalRep ===================================== */
  freeInternalRep: function(obj_ptr) {
    var parsed_var_name_obj = this;
    var array_ptr = obj_ptr.twoPtrValue.ptr1();
    var elem = obj_ptr.twoPtrValue.ptr2();

    if (array_ptr != null) {
	array_ptr.decrRefCount("D_PARSED_VAR_NAME_OBJ_TYPE_1");
    }
    obj_ptr.obj_type = null;
  },

  /* ==================== dupInternalRep ===================================== */
  dupInternalRep: function(src_ptr, dup_ptr) {
    var parsed_var_name_obj = this;
    var array_ptr = src_ptr.twoPtrValue.ptr1();
    var elem = src_ptr.twoPtrValue.ptr2();
    var elem_copy;
    var elem_len;

    if (array_ptr != null) {
	array_ptr.incrRefCount("I_PARSED_VAR_NAME_OBJ_TYPE_1");
	elem_len = elem.length;
	elem_copy = elem
	elem = elem_copy;
    }

    dup_ptr.twoPtrValue.ptr1(array_ptr);
    dup_ptr.twoPtrValue.ptr2(elem);

Changes to rapl_pkg_corecmd.js.

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
...
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
...
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
...
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
...
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
...
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
....
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
....
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
....
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
....
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
....
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
    if (args.length == 2) {
      retcode = interp.eval_expression.evalExpression(args[1], expr_result_ptr);
    } else {
      if (args.length > 2) {
        var obj_ptr;

        obj_ptr = interp.default_obj.concatObj(args.length - 1, args.splice(1));
        obj_ptr.incrRefCount();
        retcode = interp.eval_expression.evalExpression(obj_ptr, expr_result_ptr);
        obj_ptr.decrRefCount();
      } else {
        interp.wrongNumArgs(1, arg, "expression ?...?");
        return interp.ERROR;
      }
    }
    if (retcode != interp.OK) {
      return retcode;
    }
    expr_result_ptr = expr_result_ptr[0];
    interp.setResult(expr_result_ptr);
    expr_result_ptr.decrRefCount();
    return interp.OK;
  });

  /* ==================== command file join ===================================== */
  interp.registerSubCommand("::file", "join", function (interp, args) {
    if (args.length < 2) {
      interp.wrongNumArgs(1, args, "file_name_part ?file_name_part ...?");
................................................................................
        if (expr.token_list[1].tken == interp.TOKEN_EXPR_INT) {
          if (interp.default_obj.getWide(expr.token_list[1].obj_ptr, stop) == interp.ERROR) {
            evalstart = true;
          }
	  stop = stop[0];
        } else {
            stop_var_name_ptr = expr.token_list[1].obj_ptr;
            stop_var_name_ptr.incrRefCount();
            /* Keep the compiler happy */
            stop = 0;
        }
      }
      if (!evalstart) {
        /* Initialization */
        proc_epoch = interp.proc_epoch;
        var_name_ptr = expr.token_list[0].obj_ptr;
        var_name_ptr.incrRefCount();

        obj_ptr = interp.variable_obj_type.getVariable(var_name_ptr, interp.FUNCTION_FLAGS_NONE);
	current_val = new Array();
        if (obj_ptr == null || interp.default_obj.getWide(obj_ptr, current_val) != interp.OK) {
          testcond = true;
        }
	current_val = current_val[0];
................................................................................
            }
          }
        }
      }
    }
    if (out) {
      if (stop_var_name_ptr) {
        stop_var_name_ptr.decrRefCount();
      }
    }
    if (var_name_ptr) {
      var_name_ptr.decrRefCount();
    }
    if (retval == interp.CONTINUE || retval == interp.BREAK || retval == interp.OK) {
      interp.setEmptyResult();
      return interp.OK;
    }
    return retval;
  });
................................................................................
      join_str = " ";
      join_str_len = 1;
    } else {
      join_str = args[2].getString();
      join_str_len = args[2].getStringLength();
    }
    list_len = interp.list_obj_type.listLength(args[1]);
    res_obj_ptr = interp.string_obj_type.newStringObj(null, 0);
    /* Split */
    for (i = 0; i < list_len; i++) {
      var obj_ptr = new Array();

      obj_ptr[0] = null;
      interp.list_obj_type.listIndex(args[1], i, obj_ptr, interp.FUNCTION_FLAGS_NONE);
      obj_ptr = obj_ptr[0];
................................................................................
        return interp.ERROR;
    }
    if (args.length == 3) {
      if (args[1] != "-nonewline") {
        interp.setResultString("The second argument must be -nonewline", -1);
        return interp.ERROR;
      } else {
        print(args[2]);
      }
    } else {
      print(args[1]);
    }
    return interp.OK;
  });

  /* ==================== command proc ===================================== */
  interp.registerCommand("::proc", function (interp, args) {
    var full_name;
................................................................................
    if (match == null) {
      interp.setResultBool(interp.false_obj);
      return interp.OK;
    }
    var j = 0;
    for (; i < match.length; i++) {
      if (args.length > i) {
        interp.variable_obj_type.setVariable(args[i], interp.string_obj_type.newStringObj(match[j], -1));
	j++;
      }
    }
    interp.setResultBool(interp.true_obj);
    return interp.OK;

  });
................................................................................
    var ret_code;

    if (args.length != 2) {
      interp.wrongNumArgs(1, args, 1, "filename");
      return interp.ERROR;
    }
    script_obj_ptr = args[1];
    script_obj_ptr.incrRefCount();
    prev_script_obj = interp.current_script_obj;

    interp.current_script_obj = script_obj_ptr;
    ret_code = interp.source(interp, script_obj_ptr);
    interp.current_script_obj = prev_script_obj;
    script_obj_ptr.decrRefCount();
    return ret_code;
  });

  /* ==================== command split ===================================== */
  interp.registerCommand("::split", function (interp, args) {
//print("split!"+args+"!");
    var script_obj_ptr;
................................................................................
        var sc_len = split_len;
        var sl = interp.default_obj.utf8_tounicode(str.substring(idx), c);
	var sc_idx2 = 0;
        while (sc_len--) {
          var pc = new Array();
          sc_idx += interp.default_obj.utf8_tounicode(sc.charAt(sc_idx), pc);
          if (c[0] == pc[0]) {
            obj_ptr = interp.string_obj_type.newStringObj(str.substring(no_match_start), (idx - no_match_start));
            interp.list_obj_type.listAppendElement(res_obj_ptr, obj_ptr);
            no_match_start = idx + sl;
            break;
          }
        }
        idx += sl;
      }
      obj_ptr = interp.string_obj_type.newStringObj(str.substring(no_match_start), (idx - no_match_start));
      interp.list_obj_type.listAppendElement(res_obj_ptr, obj_ptr);
    } else {
      /* This handles the special case of splitchars eq {}
       * Optimise by sharing common (ASCII) characters
       */
      while (str_len--) {
        var n = interp.default_obj.utf8_tounicode(str, c);
        interp.list_obj_type.listAppendElement(res_obj_ptr, interp.string_obj_type.newStringObjUtf8(str.substring(idx), 1));
        idx += n;
      }
    }
    interp.setResult(res_obj_ptr);
    return interp.OK;
  });

................................................................................
	}
        if (have_glob_opt) {
          if (pat_obj.stringMatchObj(str_obj, 0)) {
            script = case_list[i + 1];
	  }
	}
        if (have_regexp_opt) {
          command = interp.string_obj_type.newStringObj("regexp", -1);
          have_command_opt = 1;
	}
	var subst_key_obj_ptr = new Array();
        if (interp.script_obj_type.substObj(str_obj, subst_key_obj_ptr, interp.FUNCTION_FLAGS_NONE) != interp.OK) {
	  return interp.ERROR;
	}
	subst_key_obj_ptr = subst_key_obj_ptr[0];
................................................................................
        break;
      }
//        interp.setVar("a", xx);
//        interp.variable_obj_type.setVariable(yy, xx);
    }
//print("TT!"+((sec_msec()-t0)*1000/n + " microseconds per iteration")+"!");
    if (ret_code == interp.OK) {
      interp.setResult(interp.string_obj_type.newStringObj((sec_msec()-t0)*1000/n + " microseconds per iteration", -1));
    }
    return ret_code;
  });

  /* ==================== command uplevel ===================================== */
  interp.registerCommand("::uplevel", function (interp, args) {
//print("uplevel!"+args+"!");
................................................................................
	var j = i;
	var k = i;
        var my_args2 = new Array();
        for (; k < args.length; k++) {
          my_args2.push(args[k]);
	}
        var my_obj_ptr = interp.default_obj.concatObj(my_args2.length, my_args2);
        my_obj_ptr.incrRefCount();
        retcode = interp.eval_statement.evalObj(my_obj_ptr);
        my_obj_ptr.decrRefCount();
      }
      interp.var_frame_ptr = saved_var_call_frame;
      interp.frame_ptr = saved_call_frame;
      return retcode;
    } else {
      interp.wrongNumArgs(1, args, "?level? command ?arg ...?");
      return interp.ERROR;
................................................................................
        /*
         * Create a local link "tail" to the variable "var_name" in the
         * current namespace.
         */
        if (tail == var_name) {
          tail_ptr = var_name_ptr;
        } else {
	  tail_ptr = interp.string_obj_type.newStringObj(tail, -1);
	  tail_ptr.incrRefCount();
        }
        result = interp.variable_obj_type.objMakeUpvar(null, var_name_ptr, /*other_p2*/ null,
	      /*other_flags*/ interp.NAMESPACE_LOOKUP_NAMESPACE_ONLY,
	      /*my_name*/ tail_ptr, /*my_flags*/ 0, -1);
        if (tail != var_name) {
	  tail_ptr.decrRefCount();
        }
        if (result != interp.OK) {
          return result;
        }
      }
    }
    return interp.OK;







|

|










|







 







|








|







 







|



|







 







|







 







|


|







 







|







 







|





|







 







|







|







|







 







|







 







|







 







|

|







 







|
|





|







173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
...
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
...
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
...
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
...
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
...
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
....
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
....
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
....
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
....
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
....
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
    if (args.length == 2) {
      retcode = interp.eval_expression.evalExpression(args[1], expr_result_ptr);
    } else {
      if (args.length > 2) {
        var obj_ptr;

        obj_ptr = interp.default_obj.concatObj(args.length - 1, args.splice(1));
        obj_ptr.incrRefCount("I_PKG_CORECMD_1");
        retcode = interp.eval_expression.evalExpression(obj_ptr, expr_result_ptr);
        obj_ptr.decrRefCount("D_PKG_CORE_CMD_1");
      } else {
        interp.wrongNumArgs(1, arg, "expression ?...?");
        return interp.ERROR;
      }
    }
    if (retcode != interp.OK) {
      return retcode;
    }
    expr_result_ptr = expr_result_ptr[0];
    interp.setResult(expr_result_ptr);
    expr_result_ptr.decrRefCount("D_PKG_CORE_CMD_2");
    return interp.OK;
  });

  /* ==================== command file join ===================================== */
  interp.registerSubCommand("::file", "join", function (interp, args) {
    if (args.length < 2) {
      interp.wrongNumArgs(1, args, "file_name_part ?file_name_part ...?");
................................................................................
        if (expr.token_list[1].tken == interp.TOKEN_EXPR_INT) {
          if (interp.default_obj.getWide(expr.token_list[1].obj_ptr, stop) == interp.ERROR) {
            evalstart = true;
          }
	  stop = stop[0];
        } else {
            stop_var_name_ptr = expr.token_list[1].obj_ptr;
            stop_var_name_ptr.incrRefCount("I_PKG_CORECMD_2");
            /* Keep the compiler happy */
            stop = 0;
        }
      }
      if (!evalstart) {
        /* Initialization */
        proc_epoch = interp.proc_epoch;
        var_name_ptr = expr.token_list[0].obj_ptr;
        var_name_ptr.incrRefCount("I_PKG_CORECMD_3");

        obj_ptr = interp.variable_obj_type.getVariable(var_name_ptr, interp.FUNCTION_FLAGS_NONE);
	current_val = new Array();
        if (obj_ptr == null || interp.default_obj.getWide(obj_ptr, current_val) != interp.OK) {
          testcond = true;
        }
	current_val = current_val[0];
................................................................................
            }
          }
        }
      }
    }
    if (out) {
      if (stop_var_name_ptr) {
        stop_var_name_ptr.decrRefCount("D_PKG_CORE_CMD_3");
      }
    }
    if (var_name_ptr) {
      var_name_ptr.decrRefCount("D_PKG_CORE_CMD_4");
    }
    if (retval == interp.CONTINUE || retval == interp.BREAK || retval == interp.OK) {
      interp.setEmptyResult();
      return interp.OK;
    }
    return retval;
  });
................................................................................
      join_str = " ";
      join_str_len = 1;
    } else {
      join_str = args[2].getString();
      join_str_len = args[2].getStringLength();
    }
    list_len = interp.list_obj_type.listLength(args[1]);
    res_obj_ptr = interp.string_obj_type.newStringObj(null, 0, "PKG_CORE_1");
    /* Split */
    for (i = 0; i < list_len; i++) {
      var obj_ptr = new Array();

      obj_ptr[0] = null;
      interp.list_obj_type.listIndex(args[1], i, obj_ptr, interp.FUNCTION_FLAGS_NONE);
      obj_ptr = obj_ptr[0];
................................................................................
        return interp.ERROR;
    }
    if (args.length == 3) {
      if (args[1] != "-nonewline") {
        interp.setResultString("The second argument must be -nonewline", -1);
        return interp.ERROR;
      } else {
        print(args[2].getString());
      }
    } else {
      print(args[1].getString());
    }
    return interp.OK;
  });

  /* ==================== command proc ===================================== */
  interp.registerCommand("::proc", function (interp, args) {
    var full_name;
................................................................................
    if (match == null) {
      interp.setResultBool(interp.false_obj);
      return interp.OK;
    }
    var j = 0;
    for (; i < match.length; i++) {
      if (args.length > i) {
        interp.variable_obj_type.setVariable(args[i], interp.string_obj_type.newStringObj(match[j], -1, "PKG_CORE_2"));
	j++;
      }
    }
    interp.setResultBool(interp.true_obj);
    return interp.OK;

  });
................................................................................
    var ret_code;

    if (args.length != 2) {
      interp.wrongNumArgs(1, args, 1, "filename");
      return interp.ERROR;
    }
    script_obj_ptr = args[1];
    script_obj_ptr.incrRefCount("I_PKG_CORECMD_4");
    prev_script_obj = interp.current_script_obj;

    interp.current_script_obj = script_obj_ptr;
    ret_code = interp.source(interp, script_obj_ptr);
    interp.current_script_obj = prev_script_obj;
    script_obj_ptr.decrRefCount("D_PKG_CORE_CMD_5");
    return ret_code;
  });

  /* ==================== command split ===================================== */
  interp.registerCommand("::split", function (interp, args) {
//print("split!"+args+"!");
    var script_obj_ptr;
................................................................................
        var sc_len = split_len;
        var sl = interp.default_obj.utf8_tounicode(str.substring(idx), c);
	var sc_idx2 = 0;
        while (sc_len--) {
          var pc = new Array();
          sc_idx += interp.default_obj.utf8_tounicode(sc.charAt(sc_idx), pc);
          if (c[0] == pc[0]) {
            obj_ptr = interp.string_obj_type.newStringObj(str.substring(no_match_start), (idx - no_match_start), "PKG_CORE_3");
            interp.list_obj_type.listAppendElement(res_obj_ptr, obj_ptr);
            no_match_start = idx + sl;
            break;
          }
        }
        idx += sl;
      }
      obj_ptr = interp.string_obj_type.newStringObj(str.substring(no_match_start), (idx - no_match_start), "PKG_CORE_4");
      interp.list_obj_type.listAppendElement(res_obj_ptr, obj_ptr);
    } else {
      /* This handles the special case of splitchars eq {}
       * Optimise by sharing common (ASCII) characters
       */
      while (str_len--) {
        var n = interp.default_obj.utf8_tounicode(str, c);
        interp.list_obj_type.listAppendElement(res_obj_ptr, interp.string_obj_type.newStringObjUtf8(str.substring(idx), 1, "PKG_CORE_5"));
        idx += n;
      }
    }
    interp.setResult(res_obj_ptr);
    return interp.OK;
  });

................................................................................
	}
        if (have_glob_opt) {
          if (pat_obj.stringMatchObj(str_obj, 0)) {
            script = case_list[i + 1];
	  }
	}
        if (have_regexp_opt) {
          command = interp.string_obj_type.newStringObj("regexp", -1, "PKG_CORE_6");
          have_command_opt = 1;
	}
	var subst_key_obj_ptr = new Array();
        if (interp.script_obj_type.substObj(str_obj, subst_key_obj_ptr, interp.FUNCTION_FLAGS_NONE) != interp.OK) {
	  return interp.ERROR;
	}
	subst_key_obj_ptr = subst_key_obj_ptr[0];
................................................................................
        break;
      }
//        interp.setVar("a", xx);
//        interp.variable_obj_type.setVariable(yy, xx);
    }
//print("TT!"+((sec_msec()-t0)*1000/n + " microseconds per iteration")+"!");
    if (ret_code == interp.OK) {
      interp.setResult(interp.string_obj_type.newStringObj((sec_msec()-t0)*1000/n + " microseconds per iteration", -1, "PKG_CORE_7"));
    }
    return ret_code;
  });

  /* ==================== command uplevel ===================================== */
  interp.registerCommand("::uplevel", function (interp, args) {
//print("uplevel!"+args+"!");
................................................................................
	var j = i;
	var k = i;
        var my_args2 = new Array();
        for (; k < args.length; k++) {
          my_args2.push(args[k]);
	}
        var my_obj_ptr = interp.default_obj.concatObj(my_args2.length, my_args2);
        my_obj_ptr.incrRefCount("I_PKG_CORECMD_5");
        retcode = interp.eval_statement.evalObj(my_obj_ptr);
        my_obj_ptr.decrRefCount("D_PKG_CORE_CMD_6");
      }
      interp.var_frame_ptr = saved_var_call_frame;
      interp.frame_ptr = saved_call_frame;
      return retcode;
    } else {
      interp.wrongNumArgs(1, args, "?level? command ?arg ...?");
      return interp.ERROR;
................................................................................
        /*
         * Create a local link "tail" to the variable "var_name" in the
         * current namespace.
         */
        if (tail == var_name) {
          tail_ptr = var_name_ptr;
        } else {
	  tail_ptr = interp.string_obj_type.newStringObj(tail, -1, "PKG_CORE_8");
	  tail_ptr.incrRefCount("I_PKG_CORECMD_6");
        }
        result = interp.variable_obj_type.objMakeUpvar(null, var_name_ptr, /*other_p2*/ null,
	      /*other_flags*/ interp.NAMESPACE_LOOKUP_NAMESPACE_ONLY,
	      /*my_name*/ tail_ptr, /*my_flags*/ 0, -1);
        if (tail != var_name) {
	  tail_ptr.decrRefCount("D_PKG_CORE_CMD_7");
        }
        if (result != interp.OK) {
          return result;
        }
      }
    }
    return interp.OK;

Changes to rapl_pkg_dictcmd.js.

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
      /* key not found we will create the key */
      value_ptr = interp.list_obj_type.newListObj(null, 0);
    } else {
      value_ptr = value_ptr[0];
      if (value_ptr.isShared()) {
        interp.list_obj_type.setFromAny(value_ptr);
        value_ptr2 = interp.list_obj_type.newListObj(null, 0);
	value_ptr2.incrRefCount();
        interp.list_obj_type.dupInternalRep(value_ptr, value_ptr2);
	value_ptr = value_ptr2;
      }
    }
    for (var i = 3; i < args.length; i++) {
      interp.list_obj_type.listAppendElement(value_ptr, args[i]);
    }
................................................................................
      interp.wrongNumArgs(1, args, "dictionaryValue ?key ...?");
      return interp.ERROR;
    }
    obj_ptr = args[1];
    if (obj_ptr.isShared()) {
      /* make a copy to not overwrite the original dict !! */
      dup_ptr = interp.default_obj.newObj();
      dup_ptr.incrRefCount();
      interp.dict_obj_type.dupInternalRep(obj_ptr, dup_ptr);
      obj_ptr = dup_ptr;
    }
    interp.dict_obj_type.setFromAny(obj_ptr);
    obj_ptr.incrRefCount();
    for (var i = 2; i < args.length; i++) {
      ret_code = interp.dict_obj_type.addElement(obj_ptr, args[i], null);
    }
    obj_ptr.invalidateStringRep();
    interp.setResult(obj_ptr);
    return interp.OK;
  });







|







 







|




|







127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
      /* key not found we will create the key */
      value_ptr = interp.list_obj_type.newListObj(null, 0);
    } else {
      value_ptr = value_ptr[0];
      if (value_ptr.isShared()) {
        interp.list_obj_type.setFromAny(value_ptr);
        value_ptr2 = interp.list_obj_type.newListObj(null, 0);
	value_ptr2.incrRefCount("I_PKG_DICTCMD_1");
        interp.list_obj_type.dupInternalRep(value_ptr, value_ptr2);
	value_ptr = value_ptr2;
      }
    }
    for (var i = 3; i < args.length; i++) {
      interp.list_obj_type.listAppendElement(value_ptr, args[i]);
    }
................................................................................
      interp.wrongNumArgs(1, args, "dictionaryValue ?key ...?");
      return interp.ERROR;
    }
    obj_ptr = args[1];
    if (obj_ptr.isShared()) {
      /* make a copy to not overwrite the original dict !! */
      dup_ptr = interp.default_obj.newObj();
      dup_ptr.incrRefCount("I_PKG_DICTCMD_2");
      interp.dict_obj_type.dupInternalRep(obj_ptr, dup_ptr);
      obj_ptr = dup_ptr;
    }
    interp.dict_obj_type.setFromAny(obj_ptr);
    obj_ptr.incrRefCount("I_PKG_DICTCMD_3");
    for (var i = 2; i < args.length; i++) {
      ret_code = interp.dict_obj_type.addElement(obj_ptr, args[i], null);
    }
    obj_ptr.invalidateStringRep();
    interp.setResult(obj_ptr);
    return interp.OK;
  });

Changes to rapl_pkg_infocmd.js.

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
      interp.wrongNumArgs(1, args, "script ?missing?");
      return interp.ERROR;
    }

    interp.setResultBool(interp.scriptIsComplete(s, len, missing));
    missing = missing[0];
    if (missing != ' ' && args.length == 3) {
      interp.variable_obj_type.setVariable(args[2], interp.string_obj_type.newStringObj(missing, 1));
    }
    return interp.OK;
  });

  /* ==================== command info exists ===================================== */
  interp.registerSubCommand("::info", "exists", function (interp, args) {
    var result_ptr = new Array();
................................................................................

  /* ==================== command info globals ===================================== */
  interp.registerSubCommand("::info", "globals", function (interp, args) {
    var lst = new Array();
    var var_info = interp.global_ns_ptr.variables;

    for (var z in var_info) {
      lst.push(interp.string_obj_type.newStringObj(z, -1));
    }
    interp.setResult(interp.list_obj_type.newListObj(lst, lst.length));
    return interp.OK;
  });

  /* ==================== command info isensemble ===================================== */
  interp.registerSubCommand("::info", "isensemble", function (interp, args) {
................................................................................
    if (args.length == 1) {
      var i;
      var list_obj_ptr = interp.list_obj_type.newListObj(null, 0);

      // FIXME need to use a variable or define for 5 in the next line!!
      for (i = 0; i < 5; i++) {
        interp.list_obj_type.listAppendElement(list_obj_ptr, interp.int_obj_type.newIntObj(i));
        interp.list_obj_type.listAppendElement(list_obj_ptr, interp.string_obj_type.newStringObj(interp.getResultString(i), -1));
      }
      interp.setResult(list_obj_ptr);
    }
    if (args.length == 2) {
      var code = new Array();
      var my_name;








|







 







|







 







|







93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
      interp.wrongNumArgs(1, args, "script ?missing?");
      return interp.ERROR;
    }

    interp.setResultBool(interp.scriptIsComplete(s, len, missing));
    missing = missing[0];
    if (missing != ' ' && args.length == 3) {
      interp.variable_obj_type.setVariable(args[2], interp.string_obj_type.newStringObj(missing, 1, "PKG_INFOCMD_1"));
    }
    return interp.OK;
  });

  /* ==================== command info exists ===================================== */
  interp.registerSubCommand("::info", "exists", function (interp, args) {
    var result_ptr = new Array();
................................................................................

  /* ==================== command info globals ===================================== */
  interp.registerSubCommand("::info", "globals", function (interp, args) {
    var lst = new Array();
    var var_info = interp.global_ns_ptr.variables;

    for (var z in var_info) {
      lst.push(interp.string_obj_type.newStringObj(z, -1, "PKG_INFOCMD_2"));
    }
    interp.setResult(interp.list_obj_type.newListObj(lst, lst.length));
    return interp.OK;
  });

  /* ==================== command info isensemble ===================================== */
  interp.registerSubCommand("::info", "isensemble", function (interp, args) {
................................................................................
    if (args.length == 1) {
      var i;
      var list_obj_ptr = interp.list_obj_type.newListObj(null, 0);

      // FIXME need to use a variable or define for 5 in the next line!!
      for (i = 0; i < 5; i++) {
        interp.list_obj_type.listAppendElement(list_obj_ptr, interp.int_obj_type.newIntObj(i));
        interp.list_obj_type.listAppendElement(list_obj_ptr, interp.string_obj_type.newStringObj(interp.getResultString(i), -1, "PKG_INFOCMD_3"));
      }
      interp.setResult(list_obj_ptr);
    }
    if (args.length == 2) {
      var code = new Array();
      var my_name;

Changes to rapl_pkg_itclcmd.js.

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
...
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
...
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
...
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
...
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
...
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
...
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
      param_name_ptr = new Array();
      ret = interp.list_obj_type.listIndex(arglist, i, param_name_ptr, 0);
      param_name_ptr = param_name_ptr[0];
      if (param_name_ptr.getString() == "args") {
        if (args.length > i + 1) {
          value_ptr = args[1 + i];
          my_args = new Array();
	  value_ptr.incrRefCount();
	  my_args.push(value_ptr);
          my_value_ptr = interp.list_obj_type.newListObj(my_args, 1);
          param_name_ptr.incrRefCount();
          ret = interp.variable_obj_type.setVariable(param_name_ptr, my_value_ptr);
	  value_ptr.decrRefCount();
        } else {
          my_args = new Array();
	  my_value_ptr = interp.string_obj_type.newStringObj("", -1);
	  my_args.push(my_value_ptr);
	  my_value_ptr.incrRefCount();
          my_value_ptr2 = interp.list_obj_type.newListObj(my_args, 1);
          var_name_ptr = interp.string_obj_type.newStringObj(param_name_ptr.getString(), -1);
          var_name_ptr.incrRefCount();
          ret = interp.variable_obj_type.setVariable(var_name_ptr, my_value_ptr2);
	  my_value_ptr.decrRefCount();
	}
      } else {
        if (args.length <= i + 1) {
          interp.setResultString("expandmacro not enough arguments!"+args.slice(1));
	  return interp.ERROR;
	}
        value_ptr = args[1 + i];
        var_name_ptr = interp.string_obj_type.newStringObj(param_name_ptr.getString(), -1);
        var_name_ptr.incrRefCount();
        ret = interp.variable_obj_type.setVariable(var_name_ptr, value_ptr);
      }
    }
    /* we don't substitute variables which are not arguments/parameters of the macro !!
     * that is forced by CALL_TYPE_MACROEXPAND;
     */
    ret = interp.script_obj_type.substObj(body, result_ptr, interp.FUNCTION_FLAGS_SUBST_NOESC);
................................................................................
      var cget_method_var = class_option_obj.cget_methodvar;
      if (cget_method_var == null) {
        /* just do "normal" cget */
        switch (class_ptr.class_type) {
        case interp.ITCL_TYPE_CLASS:
        case interp.ITCL_WIDGET:
        case interp.ITCL_WIDGETADAPTOR:
          name_ptr = interp.string_obj_type.newStringObj("options("+option_name.getString()+")", -1);
	  var var_ptr = new Array();
          obj_ptr = interp.variable_obj_type.getVariable(name_ptr, interp.FUNCTION_FLAGS_LEAVE_ERRMSG, var_ptr);
	  var_ptr = var_ptr[0];
//print("OP!"+option_name+"!"+name_ptr+"!"+obj_ptr.toDebugString()+"!"+var_ptr.toDebugString()+"!");
          break;
        case interp.ITCL_EXTENDEDCLASS:
        case interp.ITCL_CLASS:
          name_ptr = interp.string_obj_type.newStringObj("itcl_options("+option_name.getString()+")", -1);
          obj_ptr = interp.variable_obj_type.getVariable(name_ptr);
          break;
	}
	interp.setResult(obj_ptr);
      } else {
        /* get the method from the var */
// FIXME !!! need code here
      }
    } else {
      var cmd_obj = interp.string_obj_type.newStringObj(cget_method+" "+option_name, -1);
      cmd_obj.incrRefCount();
      var save_ns_ptr = interp.frame_ptr.ns_ptr;
      interp.frame_ptr.ns_ptr = class_ptr.ns_ptr;
      ret_code = interp.eval_statement.evalObj(cmd_obj);
      interp.frame_ptr.ns_ptr = save_ns_ptr;
      cmd_obj.decrRefCount();
    }
    return ret_code;
  });

  /* ==================== command ::itcl::internal::classconfigure ======================== */
  interp.registerCommand("::itcl::internal::classconfigure", function (interp, args) {
    var class_ptr = new Array();
................................................................................
//          configure_method_var = class_option_obj.configure_method_var;
	  if (configure_method_var == null) {
            /* just do "normal" configure */
            switch (class_ptr.class_type) {
            case interp.ITCL_TYPE_CLASS:
            case interp.ITCL_WIDGET:
            case interp.ITCL_WIDGETADAPTOR:
              name_ptr = interp.string_obj_type.newStringObj("options("+option_name.getString()+")", -1);
	      var var_ptr = new Array();
              obj_ptr = interp.variable_obj_type.getVariable(name_ptr, interp.FUNCTION_FLAGS_LEAVE_ERRMSG, var_ptr);
	      var_ptr = var_ptr[0];
//print("OP!"+option_name+"!"+name_ptr+"!"+obj_ptr.toDebugString()+"!"+var_ptr.toDebugString()+"!");
              break;
            case interp.ITCL_EXTENDEDCLASS:
            case interp.ITCL_CLASS:
              name_ptr = interp.string_obj_type.newStringObj("itcl_options("+option_name.getString()+")", -1);
              obj_ptr = interp.variable_obj_type.getVariable(name_ptr);
              break;
	    }
	    interp.setResult(obj_ptr);
            interp.frame_ptr.ns_ptr = save_ns_ptr;
	    return interp.OK;

................................................................................
              configure_method_var = class_option_obj.configure_method_var;
	      if (configure_method_var == null) {
                /* just do "normal" configure */
                switch (class_ptr.class_type) {
                case interp.ITCL_TYPE_CLASS:
                case interp.ITCL_WIDGET:
                case interp.ITCL_WIDGETADAPTOR:
                  name_ptr = interp.string_obj_type.newStringObj("options("+option_name.getString()+")", -1);
	          var var_ptr = new Array();
                  ret_code = interp.variable_obj_type.setVariable(name_ptr, option_val, var_ptr);
	          var_ptr = var_ptr[0];
                  break;
                case interp.ITCL_EXTENDEDCLASS:
                case interp.ITCL_CLASS:
	          var var_ptr = new Array();
                  name_ptr = interp.string_obj_type.newStringObj("itcl_options("+option_name.getString()+")", -1);
                  ret_code = interp.variable_obj_type.setVariable(name_ptr, option_val, var_ptr);
                  break;
	        }
              } else {
print("configure_method_var not yet implemented");
                /* get the method from the var */
// FIXME !!! need code here
................................................................................
    }
    lst_ptr = args[1];
    lgth = interp.list_obj_type.listLength(lst_ptr);
    if (lgth % 2) {
      interp.setResultString("must be an even number of elements in list");
      return interp.ERROR;
    }
    var name_ptr = interp.string_obj_type.newStringObj("::itcl::internal::classconfigure", -1);
    name_ptr.incrRefCount();
    var cmd_obj = interp.getCommand(name_ptr, interp.FUNCTION_FLAGS_NONE);
    if (cmd_obj == null) {
      interp.setResultString("no such command: \"::itcl::internal::classconfigure\"");
      return interp.ERROR;
    }
    for (i = 0; i < lgth; i++) {
      if (interp.list_obj_type.listIndex(lst_ptr, i, option_name) != interp.OK) {
................................................................................
      opt_val = option_val[0];
      var my_args = new Array();
      my_args.push(args[0]);
      my_args.push(opt_name);
      my_args.push(opt_val);
      ret_code = cmd_obj.call(interp, my_args);
    }
    name_ptr.decrRefCount();
    return ret_code;
  });

  /* ==================== command ::itcl::internal::classdestroy ======================== */
  interp.registerCommand("::itcl::internal::classdestroy", function (interp, args) {
print("WARNING! destroy not yet implemented!");
//interp.setResultString("WARNING! destroy not yet implemented!");
................................................................................
      }
    }
    if (typeof interp.classes[interp.escape_key(type_name)] == "undefined") {
      interp.setResultString("no such type: \""+object_type.getString()+"\"");
      return interp.ERROR;
    }
    type_class_ptr = interp.classes[interp.escape_key(type_name)];
    type_ptr = interp.string_obj_type.newStringObj(type_name, -1);
    my_args = new Array();
    my_args.push(type_ptr);
    my_args.push(object_name);
    for (i = 5; i < args.length; i++) {
      my_args.push(args[i]);
    }
    ret_code = interp.itcl_obj_type.classCommand(my_args);
................................................................................
    cmd += "body ::itcl::body "
    cmd += "class ::itcl::class "
    cmd += "type ::itcl::type "
    cmd += "extendedclass ::itcl::extendedclass "
    cmd += "widget ::itcl::widget "
    cmd += "widgetadaptor ::itcl::widgetadaptor "
    cmd += "] -command ::itcl";
    cmd_obj = itcl.interp.string_obj_type.newStringObj(cmd, -1);
    cmd_obj.incrRefCount();
    ret_code = itcl.interp.eval_statement.evalObj(cmd_obj);
    cmd_obj.decrRefCount();
    return ret_code;
  },

});

PkgItcl.prototype.constructor = PkgItcl;

R.PkgItcl = PkgItcl;

}, "0.0.1", {});







|


|

|


|

|

|
|

|







|
|







 







|







|









|
|




|







 







|







|







 







|







|







 







|
|







 







|







 







|







 







|
|

|










129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
...
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
...
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
...
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
...
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
...
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
...
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
      param_name_ptr = new Array();
      ret = interp.list_obj_type.listIndex(arglist, i, param_name_ptr, 0);
      param_name_ptr = param_name_ptr[0];
      if (param_name_ptr.getString() == "args") {
        if (args.length > i + 1) {
          value_ptr = args[1 + i];
          my_args = new Array();
	  value_ptr.incrRefCount("I_PKG_ITCLCMD_1");
	  my_args.push(value_ptr);
          my_value_ptr = interp.list_obj_type.newListObj(my_args, 1);
          param_name_ptr.incrRefCount("I_PKG_ITCLCMD_2");
          ret = interp.variable_obj_type.setVariable(param_name_ptr, my_value_ptr);
	  value_ptr.decrRefCount("D_PKG_ITCLCMD_1");
        } else {
          my_args = new Array();
	  my_value_ptr = interp.string_obj_type.newStringObj("", -1, "PKG_ITCLCMD_1");
	  my_args.push(my_value_ptr);
	  my_value_ptr.incrRefCount("I_PKG_ITCLCMD_3");
          my_value_ptr2 = interp.list_obj_type.newListObj(my_args, 1);
          var_name_ptr = interp.string_obj_type.newStringObj(param_name_ptr.getString(), -1, "PKG_ITCLCMD_2");
          var_name_ptr.incrRefCount("I_PKG_ITCLCMD_3");
          ret = interp.variable_obj_type.setVariable(var_name_ptr, my_value_ptr2);
	  my_value_ptr.decrRefCount("D_PKG_ITCLCMD_2");
	}
      } else {
        if (args.length <= i + 1) {
          interp.setResultString("expandmacro not enough arguments!"+args.slice(1));
	  return interp.ERROR;
	}
        value_ptr = args[1 + i];
        var_name_ptr = interp.string_obj_type.newStringObj(param_name_ptr.getString(), -1, "PKG_ITCLCMD_3");
        var_name_ptr.incrRefCount("I_PKG_ITCLCMD_4");
        ret = interp.variable_obj_type.setVariable(var_name_ptr, value_ptr);
      }
    }
    /* we don't substitute variables which are not arguments/parameters of the macro !!
     * that is forced by CALL_TYPE_MACROEXPAND;
     */
    ret = interp.script_obj_type.substObj(body, result_ptr, interp.FUNCTION_FLAGS_SUBST_NOESC);
................................................................................
      var cget_method_var = class_option_obj.cget_methodvar;
      if (cget_method_var == null) {
        /* just do "normal" cget */
        switch (class_ptr.class_type) {
        case interp.ITCL_TYPE_CLASS:
        case interp.ITCL_WIDGET:
        case interp.ITCL_WIDGETADAPTOR:
          name_ptr = interp.string_obj_type.newStringObj("options("+option_name.getString()+")", -1, "PKG_ITCLCMD_4");
	  var var_ptr = new Array();
          obj_ptr = interp.variable_obj_type.getVariable(name_ptr, interp.FUNCTION_FLAGS_LEAVE_ERRMSG, var_ptr);
	  var_ptr = var_ptr[0];
//print("OP!"+option_name+"!"+name_ptr+"!"+obj_ptr.toDebugString()+"!"+var_ptr.toDebugString()+"!");
          break;
        case interp.ITCL_EXTENDEDCLASS:
        case interp.ITCL_CLASS:
          name_ptr = interp.string_obj_type.newStringObj("itcl_options("+option_name.getString()+")", -1, "PKG_ITCLCMD_5");
          obj_ptr = interp.variable_obj_type.getVariable(name_ptr);
          break;
	}
	interp.setResult(obj_ptr);
      } else {
        /* get the method from the var */
// FIXME !!! need code here
      }
    } else {
      var cmd_obj = interp.string_obj_type.newStringObj(cget_method+" "+option_name, -1, "PKG_ITCLCMD_6");
      cmd_obj.incrRefCount("I_PKG_ITCLCMD_5");
      var save_ns_ptr = interp.frame_ptr.ns_ptr;
      interp.frame_ptr.ns_ptr = class_ptr.ns_ptr;
      ret_code = interp.eval_statement.evalObj(cmd_obj);
      interp.frame_ptr.ns_ptr = save_ns_ptr;
      cmd_obj.decrRefCount("D_PKG_ITCLCMD_3");
    }
    return ret_code;
  });

  /* ==================== command ::itcl::internal::classconfigure ======================== */
  interp.registerCommand("::itcl::internal::classconfigure", function (interp, args) {
    var class_ptr = new Array();
................................................................................
//          configure_method_var = class_option_obj.configure_method_var;
	  if (configure_method_var == null) {
            /* just do "normal" configure */
            switch (class_ptr.class_type) {
            case interp.ITCL_TYPE_CLASS:
            case interp.ITCL_WIDGET:
            case interp.ITCL_WIDGETADAPTOR:
              name_ptr = interp.string_obj_type.newStringObj("options("+option_name.getString()+")", -1, "PKG_ITCLCMD_7");
	      var var_ptr = new Array();
              obj_ptr = interp.variable_obj_type.getVariable(name_ptr, interp.FUNCTION_FLAGS_LEAVE_ERRMSG, var_ptr);
	      var_ptr = var_ptr[0];
//print("OP!"+option_name+"!"+name_ptr+"!"+obj_ptr.toDebugString()+"!"+var_ptr.toDebugString()+"!");
              break;
            case interp.ITCL_EXTENDEDCLASS:
            case interp.ITCL_CLASS:
              name_ptr = interp.string_obj_type.newStringObj("itcl_options("+option_name.getString()+")", -1, "PKG_ITCLCMD_8");
              obj_ptr = interp.variable_obj_type.getVariable(name_ptr);
              break;
	    }
	    interp.setResult(obj_ptr);
            interp.frame_ptr.ns_ptr = save_ns_ptr;
	    return interp.OK;

................................................................................
              configure_method_var = class_option_obj.configure_method_var;
	      if (configure_method_var == null) {
                /* just do "normal" configure */
                switch (class_ptr.class_type) {
                case interp.ITCL_TYPE_CLASS:
                case interp.ITCL_WIDGET:
                case interp.ITCL_WIDGETADAPTOR:
                  name_ptr = interp.string_obj_type.newStringObj("options("+option_name.getString()+")", -1, "PKG_ITCLCMD_9");
	          var var_ptr = new Array();
                  ret_code = interp.variable_obj_type.setVariable(name_ptr, option_val, var_ptr);
	          var_ptr = var_ptr[0];
                  break;
                case interp.ITCL_EXTENDEDCLASS:
                case interp.ITCL_CLASS:
	          var var_ptr = new Array();
                  name_ptr = interp.string_obj_type.newStringObj("itcl_options("+option_name.getString()+")", -1, "PKG_ITCLCMD_10");
                  ret_code = interp.variable_obj_type.setVariable(name_ptr, option_val, var_ptr);
                  break;
	        }
              } else {
print("configure_method_var not yet implemented");
                /* get the method from the var */
// FIXME !!! need code here
................................................................................
    }
    lst_ptr = args[1];
    lgth = interp.list_obj_type.listLength(lst_ptr);
    if (lgth % 2) {
      interp.setResultString("must be an even number of elements in list");
      return interp.ERROR;
    }
    var name_ptr = interp.string_obj_type.newStringObj("::itcl::internal::classconfigure", -1, "PKG_ITCLCMD_11");
    name_ptr.incrRefCount("I_PKG_ITCLCMD_6");
    var cmd_obj = interp.getCommand(name_ptr, interp.FUNCTION_FLAGS_NONE);
    if (cmd_obj == null) {
      interp.setResultString("no such command: \"::itcl::internal::classconfigure\"");
      return interp.ERROR;
    }
    for (i = 0; i < lgth; i++) {
      if (interp.list_obj_type.listIndex(lst_ptr, i, option_name) != interp.OK) {
................................................................................
      opt_val = option_val[0];
      var my_args = new Array();
      my_args.push(args[0]);
      my_args.push(opt_name);
      my_args.push(opt_val);
      ret_code = cmd_obj.call(interp, my_args);
    }
    name_ptr.decrRefCount("D_PKG_ITCLCMD_4");
    return ret_code;
  });

  /* ==================== command ::itcl::internal::classdestroy ======================== */
  interp.registerCommand("::itcl::internal::classdestroy", function (interp, args) {
print("WARNING! destroy not yet implemented!");
//interp.setResultString("WARNING! destroy not yet implemented!");
................................................................................
      }
    }
    if (typeof interp.classes[interp.escape_key(type_name)] == "undefined") {
      interp.setResultString("no such type: \""+object_type.getString()+"\"");
      return interp.ERROR;
    }
    type_class_ptr = interp.classes[interp.escape_key(type_name)];
    type_ptr = interp.string_obj_type.newStringObj(type_name, -1, "PKG_ITCLCMD_12");
    my_args = new Array();
    my_args.push(type_ptr);
    my_args.push(object_name);
    for (i = 5; i < args.length; i++) {
      my_args.push(args[i]);
    }
    ret_code = interp.itcl_obj_type.classCommand(my_args);
................................................................................
    cmd += "body ::itcl::body "
    cmd += "class ::itcl::class "
    cmd += "type ::itcl::type "
    cmd += "extendedclass ::itcl::extendedclass "
    cmd += "widget ::itcl::widget "
    cmd += "widgetadaptor ::itcl::widgetadaptor "
    cmd += "] -command ::itcl";
    cmd_obj = itcl.interp.string_obj_type.newStringObj(cmd, -1, "PKG_ITCLCMD_13");
    cmd_obj.incrRefCount("I_PKG_ITCLCMD_7");
    ret_code = itcl.interp.eval_statement.evalObj(cmd_obj);
    cmd_obj.decrRefCount("D_PKG_ITCLCMD_5");
    return ret_code;
  },

});

PkgItcl.prototype.constructor = PkgItcl;

R.PkgItcl = PkgItcl;

}, "0.0.1", {});

Changes to rapl_pkg_listcmd.js.

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
..
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
...
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
...
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
...
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
      interp.wrongNumArgs(1, args, "list ?varName ...?");
      return interp.ERROR;
    }
    list_copy_ptr = interp.list_obj_type.listCopy(args[1]);
    if (list_copy_ptr == null) {
	return interp.ERROR;
    }
    list_copy_ptr.incrRefCount();
    interp.list_obj_type.listGetElements(list_copy_ptr, list_objc, list_objv);
    list_objc = list_objc[0];
    list_objv = list_objv[0];
    while (code == interp.OK && objc > 0 && list_objc > 0) {
      if (interp.variable_obj_type.setVariable(args[idx + 2], list_objv[idx], interp.FUNCTION_FLAGS_LEAVE_ERR_MSG) == interp.ERROR) {
        code = interp.ERROR;
      }
................................................................................
      list_objc--;
      idx++;
    }
    if (code == interp.OK && objc > 0) {
      var empty_obj;

      empty_obj = interp.empty_obj;
      empty_obj.incrRefCount();
      while (code == interp.OK && objc-- > 0) {
        if (interp.variable_obj_type.setVariable(args[idx + 3], empty_obj, interp.FUNCTION_FLAGS_LEAVE_ERR_MSG) == interp.ERROR) {

          code = interp.ERROR;
        }
	idx++;
      }
      empty_obj.decrRefCount();
    }
    if (code == interp.OK && list_objc > 0) {
      interp.setResult(interp.list_obj_type.newListObj(list_objc, list_objv));
    }
    list_copy_ptr.decrRefCount();
    return code;
  });

  /* ==================== command lindex ===================================== */
  interp.registerCommand("::lindex", function (interp, args) {
    var objPtr;
    var list_obj_ptr;
................................................................................
    var idx = new Array();

    if (args.length < 3) {
      interp.wrongNumArgs(1, args, "list index ?...?");
      return interp.ERROR;
    }
    obj_ptr = args[1];
    obj_ptr.incrRefCount();
    for (i = 2; i < args.length; i++) {
      list_obj_ptr = obj_ptr;
      if (interp.index_obj_type.getIndex(args[i], idx) != interp.OK) {
        list_obj_ptr.decrRefCount();
        return interp.ERROR;
      }
      obj_ptr = new Array();
      /* force a list obj! */
      interp.list_obj_type.setFromAny(list_obj_ptr);
      len = list_obj_ptr.listValue.len();
      if (interp.list_obj_type.listIndex(list_obj_ptr, interp.relToAbsIndex(len, idx[0]), obj_ptr, interp.FUNCTION_FLAGS_NONE) != interp.OK) {
        /* Returns an empty object if the index
         * is out of range. 
	 */
        list_obj_ptr.decrRefCount();
        interp.setEmptyResult();
        return interp.OK;
      }
      obj_ptr = obj_ptr[0];
      obj_ptr.incrRefCount();
      list_obj_ptr.decrRefCount();
    }
    interp.setResult(obj_ptr);
    obj_ptr.decrRefCount();
    return interp.OK;
  });

  /* ==================== command list ===================================== */
  interp.registerCommand("::list", function (interp, args) {
    var list_obj_ptr;

................................................................................
        interp.setResultString("list doesn't contain element ", -1);
        interp.string_obj_type.appendObj(interp.getResult(), args[2]);
        return interp.ERROR;
      }
    }
    /* Add the first set of elements */
    new_list_obj = interp.list_obj_type.newListObj(list_obj.listValue.elem(), first);
    new_list_obj.incrRefCount();
    /* Add supplied elements */
    interp.list_obj_type._listInsertElements(new_list_obj, -1, args.length - 4, args.slice(4));
    /* Add the remaining elements */
    if (len - first - range_len > 0) {
      interp.list_obj_type._listInsertElements(new_list_obj, -1, len - first - range_len, list_obj.listValue.elem()[first + range_len]);
    }
    interp.setResult(new_list_obj);
    new_list_obj.decrRefCount();
    return interp.OK;
  });

  /* ==================== command lsearch ===================================== */
  interp.registerCommand("::lsearch", function (interp, args) {
    var usage = "lsearch ?options? list pattern";
    if (args.length < 2) {
................................................................................
    if (have_all_opt) {
      list_obj_ptr = interp.list_obj_type.newListObj(null, 0);
    }
    if (have_regexp_opt) {
      command_obj = interp.strng_obj_type.newStringObj("regexp", -1);
    }
    if (command_obj) {
      command_obj.incrRefCount();
    }
    list = args[list_start_idx];
    list_start_idx++;
    if (list_start_idx > args.length-1) {
      interp.wrongNumArgs(list_start_idx, args, usage);
      return interp.ERROR;
    }
................................................................................
        /* No match */
	if (!have_inline_opt) {
	  interp.setResultInt(-1);
	}
      }
    }
    if (command_obj) {
      command_obj.decrRefCount();
    }
    return rc;
  });

  /* ==================== command lset ===================================== */
  interp.registerCommand("::lset", function (interp, args) {
    interp.setResultString("lset not yet reimplemented");







|







 







|







|




|







 







|



|










|




|
|


|







 







|







|







 







|







 







|







73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
..
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
...
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
...
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
...
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
      interp.wrongNumArgs(1, args, "list ?varName ...?");
      return interp.ERROR;
    }
    list_copy_ptr = interp.list_obj_type.listCopy(args[1]);
    if (list_copy_ptr == null) {
	return interp.ERROR;
    }
    list_copy_ptr.incrRefCount("I_PKG_LISTCMD_1");
    interp.list_obj_type.listGetElements(list_copy_ptr, list_objc, list_objv);
    list_objc = list_objc[0];
    list_objv = list_objv[0];
    while (code == interp.OK && objc > 0 && list_objc > 0) {
      if (interp.variable_obj_type.setVariable(args[idx + 2], list_objv[idx], interp.FUNCTION_FLAGS_LEAVE_ERR_MSG) == interp.ERROR) {
        code = interp.ERROR;
      }
................................................................................
      list_objc--;
      idx++;
    }
    if (code == interp.OK && objc > 0) {
      var empty_obj;

      empty_obj = interp.empty_obj;
      empty_obj.incrRefCount("I_PKG_LISTCMD_2");
      while (code == interp.OK && objc-- > 0) {
        if (interp.variable_obj_type.setVariable(args[idx + 3], empty_obj, interp.FUNCTION_FLAGS_LEAVE_ERR_MSG) == interp.ERROR) {

          code = interp.ERROR;
        }
	idx++;
      }
      empty_obj.decrRefCount("D_PKG_LISTCMD_1");
    }
    if (code == interp.OK && list_objc > 0) {
      interp.setResult(interp.list_obj_type.newListObj(list_objc, list_objv));
    }
    list_copy_ptr.decrRefCount("D_PKG_LISTCMD_2");
    return code;
  });

  /* ==================== command lindex ===================================== */
  interp.registerCommand("::lindex", function (interp, args) {
    var objPtr;
    var list_obj_ptr;
................................................................................
    var idx = new Array();

    if (args.length < 3) {
      interp.wrongNumArgs(1, args, "list index ?...?");
      return interp.ERROR;
    }
    obj_ptr = args[1];
    obj_ptr.incrRefCount("I_PKG_LISTCMD_3");
    for (i = 2; i < args.length; i++) {
      list_obj_ptr = obj_ptr;
      if (interp.index_obj_type.getIndex(args[i], idx) != interp.OK) {
        list_obj_ptr.decrRefCount("D_PKG_LISTCMD_3");
        return interp.ERROR;
      }
      obj_ptr = new Array();
      /* force a list obj! */
      interp.list_obj_type.setFromAny(list_obj_ptr);
      len = list_obj_ptr.listValue.len();
      if (interp.list_obj_type.listIndex(list_obj_ptr, interp.relToAbsIndex(len, idx[0]), obj_ptr, interp.FUNCTION_FLAGS_NONE) != interp.OK) {
        /* Returns an empty object if the index
         * is out of range. 
	 */
        list_obj_ptr.decrRefCount("D_PKG_LISTCMD_4");
        interp.setEmptyResult();
        return interp.OK;
      }
      obj_ptr = obj_ptr[0];
      obj_ptr.incrRefCount("I_PKG_LISTCMD_4");
      list_obj_ptr.decrRefCount("D_PKG_LISTCMD_5");
    }
    interp.setResult(obj_ptr);
    obj_ptr.decrRefCount("D_PKG_LISTCMD_6");
    return interp.OK;
  });

  /* ==================== command list ===================================== */
  interp.registerCommand("::list", function (interp, args) {
    var list_obj_ptr;

................................................................................
        interp.setResultString("list doesn't contain element ", -1);
        interp.string_obj_type.appendObj(interp.getResult(), args[2]);
        return interp.ERROR;
      }
    }
    /* Add the first set of elements */
    new_list_obj = interp.list_obj_type.newListObj(list_obj.listValue.elem(), first);
    new_list_obj.incrRefCount("I_PKG_LISTCMD_5");
    /* Add supplied elements */
    interp.list_obj_type._listInsertElements(new_list_obj, -1, args.length - 4, args.slice(4));
    /* Add the remaining elements */
    if (len - first - range_len > 0) {
      interp.list_obj_type._listInsertElements(new_list_obj, -1, len - first - range_len, list_obj.listValue.elem()[first + range_len]);
    }
    interp.setResult(new_list_obj);
    new_list_obj.decrRefCount("D_PKG_LISTCMD_7");
    return interp.OK;
  });

  /* ==================== command lsearch ===================================== */
  interp.registerCommand("::lsearch", function (interp, args) {
    var usage = "lsearch ?options? list pattern";
    if (args.length < 2) {
................................................................................
    if (have_all_opt) {
      list_obj_ptr = interp.list_obj_type.newListObj(null, 0);
    }
    if (have_regexp_opt) {
      command_obj = interp.strng_obj_type.newStringObj("regexp", -1);
    }
    if (command_obj) {
      command_obj.incrRefCount("I_PKG_LISTCMD_6");
    }
    list = args[list_start_idx];
    list_start_idx++;
    if (list_start_idx > args.length-1) {
      interp.wrongNumArgs(list_start_idx, args, usage);
      return interp.ERROR;
    }
................................................................................
        /* No match */
	if (!have_inline_opt) {
	  interp.setResultInt(-1);
	}
      }
    }
    if (command_obj) {
      command_obj.decrRefCount("D_PKG_LISTCMD_8");
    }
    return rc;
  });

  /* ==================== command lset ===================================== */
  interp.registerCommand("::lset", function (interp, args) {
    interp.setResultString("lset not yet reimplemented");

Changes to rapl_pkg_namespacecmd.js.

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
...
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
...
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
...
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
     * "::" are treated as synonyms by the namespace code so that it is still
     * easy to do things like:
     *
     *    namespace [namespace current]::bar { ... }
     */
    curr_ns_ptr = interp.namespace_obj_type.getCurrentNamespace();
    if (curr_ns_ptr == interp.namespace_obj_type.getGlobalNamespace()) {
      interp.setResult(interp.string_obj_type.newStringObj("::", 2));
    } else {
      interp.setResult(interp.string_obj_type.newStringObj(curr_ns_ptr.full_name, -1));
    }
    return interp.OK;
  });

  /* ==================== command namespace delete ===================================== */
  interp.registerSubCommand("::namespace", "delete", function (interp, args) {
    interp.setResultString("namespace delete not yet implemented");
................................................................................
    if (subcommands.length == 0) {
      var ens = interp.registerSubCommand(command, null, function(interp, args) {
        args[0] = this.privdata;
	var cmd = this.privdata;
	for (var i = 1; i < args.length; i++) {
	  cmd = cmd+" {"+args[i]+"}";
	}
	var cmd_obj = interp.string_obj_type.newStringObj(cmd, -1);
	cmd_obj.incrRefCount();
        var result = interp.eval_statement.evalObj(cmd);
	cmd_obj.decrRefCount();
	return result;
      }, null);
    }
    for (var i = 0; i < subcommands.length; i++) {
      var sub_cmd = subcommands[i];
      var map_cmd = command+"::"+sub_cmd;
      if (map != null) {
................................................................................
      }
      var ens = interp.registerSubCommand(command, sub_cmd, function(interp, args) {
        args[0] = this.privdata;
	var cmd = this.privdata;
	for (var i = 1; i < args.length; i++) {
	  cmd = cmd+" {"+args[i]+"}";
	}
	var cmd_obj = interp.string_obj_type.newStringObj(cmd, -1);
        cmd_obj.incrRefCount();
        var result = interp.eval_statement.evalObj(cmd_obj);
        cmd_obj.decrRefCount();
	return result;
      }, map_cmd);
      ens["map"] = map;
      ens["parameters"] = parameters;
      ens["prefixes"] = prefixes;
      ens["subcommands"] = subcommands;
      ens["unknown"] = unknown;
................................................................................
    if (typeof options["-map"] != "undefined") {
      map = options["-map"] ;
      if (map == "") {
        result += sep+ens["map"];
        sep = " ";
      } else {
        var cmd = ensemble_name.toString();
	var my_obj = interp.string_obj_type.newStringObj(map, -1);
	interp.list_obj_type.setFromAny(my_obj);
        var len = new Array();
	var elems = new Array();
	interp.list_obj_type.listGetElements(my_obj, len, elems);
	len = len[0];
	elems = elems[0];
        if (len % 2 != 0) {
................................................................................
          var map_cmd = elems[i];
          var ens = interp.registerSubCommand(cmd, sub_cmd.getString(), function(interp, args) {
            args[0] = this.privdata;
            var cmd = this.privdata;
            for (var j = 1; j < args.length; j++) {
              cmd = cmd+" {"+args[j]+"}";
            }
            return interp.eval_statement.evalObj(interp.string_obj_type.newStringObj(cmd, -1));
          }, map_cmd);
          ens["map"] = map;
          ens["parameters"] = parameters;
          ens["prefixes"] = prefixes;
          ens["subcommands"] = subcommands;
          ens["unknown"] = unknown;
          ens["command"] = command;
................................................................................
      if (my_var_obj == null) {
        interp.varErrMsg(my_var, null, "create", err_msg_ptr, -1);
	interp.setErrorCode(["TCL", "LOOKUP", "VARNAME", my_var]);
	interp.code = Tcl.ERROR;
	return "";
      }
      if (other_var_obj == my_var_obj) {
        interp.setResult(interp.string_obj_type.newStringObj("can't upvar from variable to itself", -1));
	interp.setErrorCode(["TCL", "UPVAR", "SELF"]);
	interp.code = Tcl.ERROR;
	return "";
      }
      my_var_obj.linkVar(other_var_obj);
print("NSUPVAR OK!"+ns_name+"!"+other_var+"!"+my_var+"!");
    }







|

|







 







|
|

|







 







|
|

|







 







|







 







|







 







|







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
...
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
...
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
...
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
     * "::" are treated as synonyms by the namespace code so that it is still
     * easy to do things like:
     *
     *    namespace [namespace current]::bar { ... }
     */
    curr_ns_ptr = interp.namespace_obj_type.getCurrentNamespace();
    if (curr_ns_ptr == interp.namespace_obj_type.getGlobalNamespace()) {
      interp.setResult(interp.string_obj_type.newStringObj("::", 2, "PKG_NAMESPACECMD_1"));
    } else {
      interp.setResult(interp.string_obj_type.newStringObj(curr_ns_ptr.full_name, -1, "PKG_NAMESPACECMD_2"));
    }
    return interp.OK;
  });

  /* ==================== command namespace delete ===================================== */
  interp.registerSubCommand("::namespace", "delete", function (interp, args) {
    interp.setResultString("namespace delete not yet implemented");
................................................................................
    if (subcommands.length == 0) {
      var ens = interp.registerSubCommand(command, null, function(interp, args) {
        args[0] = this.privdata;
	var cmd = this.privdata;
	for (var i = 1; i < args.length; i++) {
	  cmd = cmd+" {"+args[i]+"}";
	}
	var cmd_obj = interp.string_obj_type.newStringObj(cmd, -1, "PKG_NAMESPACECMD_3");
	cmd_obj.incrRefCount("I_PKG_NAMESPACECMD_1");
        var result = interp.eval_statement.evalObj(cmd);
	cmd_obj.decrRefCount("D_PKG_NAMESPACECMD_1");
	return result;
      }, null);
    }
    for (var i = 0; i < subcommands.length; i++) {
      var sub_cmd = subcommands[i];
      var map_cmd = command+"::"+sub_cmd;
      if (map != null) {
................................................................................
      }
      var ens = interp.registerSubCommand(command, sub_cmd, function(interp, args) {
        args[0] = this.privdata;
	var cmd = this.privdata;
	for (var i = 1; i < args.length; i++) {
	  cmd = cmd+" {"+args[i]+"}";
	}
	var cmd_obj = interp.string_obj_type.newStringObj(cmd, -1, "PKG_NAMESPACECMD_4");
        cmd_obj.incrRefCount("I_PKG_NAMESPACECMD_2");
        var result = interp.eval_statement.evalObj(cmd_obj);
        cmd_obj.decrRefCount("D_PKG_NAMESPACECMD_2");
	return result;
      }, map_cmd);
      ens["map"] = map;
      ens["parameters"] = parameters;
      ens["prefixes"] = prefixes;
      ens["subcommands"] = subcommands;
      ens["unknown"] = unknown;
................................................................................
    if (typeof options["-map"] != "undefined") {
      map = options["-map"] ;
      if (map == "") {
        result += sep+ens["map"];
        sep = " ";
      } else {
        var cmd = ensemble_name.toString();
	var my_obj = interp.string_obj_type.newStringObj(map, -1, "PKG_NAMESPACECMD_5");
	interp.list_obj_type.setFromAny(my_obj);
        var len = new Array();
	var elems = new Array();
	interp.list_obj_type.listGetElements(my_obj, len, elems);
	len = len[0];
	elems = elems[0];
        if (len % 2 != 0) {
................................................................................
          var map_cmd = elems[i];
          var ens = interp.registerSubCommand(cmd, sub_cmd.getString(), function(interp, args) {
            args[0] = this.privdata;
            var cmd = this.privdata;
            for (var j = 1; j < args.length; j++) {
              cmd = cmd+" {"+args[j]+"}";
            }
            return interp.eval_statement.evalObj(interp.string_obj_type.newStringObj(cmd, -1, "PKG_NAMESPACECMD_6"));
          }, map_cmd);
          ens["map"] = map;
          ens["parameters"] = parameters;
          ens["prefixes"] = prefixes;
          ens["subcommands"] = subcommands;
          ens["unknown"] = unknown;
          ens["command"] = command;
................................................................................
      if (my_var_obj == null) {
        interp.varErrMsg(my_var, null, "create", err_msg_ptr, -1);
	interp.setErrorCode(["TCL", "LOOKUP", "VARNAME", my_var]);
	interp.code = Tcl.ERROR;
	return "";
      }
      if (other_var_obj == my_var_obj) {
        interp.setResult(interp.string_obj_type.newStringObj("can't upvar from variable to itself", -1, "PKG_NAMESPACECMD_7"));
	interp.setErrorCode(["TCL", "UPVAR", "SELF"]);
	interp.code = Tcl.ERROR;
	return "";
      }
      my_var_obj.linkVar(other_var_obj);
print("NSUPVAR OK!"+ns_name+"!"+other_var+"!"+my_var+"!");
    }

Changes to rapl_pkg_tcltestcmd.js.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
...
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
...
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
  var constructor = tcl_tst.constructor;
  PkgTclTest.superclass.constructor.apply(tcl_tst, arguments);

  R.Base.pkg_tcltest_oid++;
  tcl_tst.oid = R.Base.pkg_tcltest_oid;

  tcl_tst.interp = interp;
  tcl_tst.tcltest_name_ptr = interp.string_obj_type.newStringObj("::tcltest", -1);
  tcl_tst.tcltest_name_ptr.incrRefCount();
  tcl_tst.configure_name_ptr = interp.string_obj_type.newStringObj("configure", -1);
  tcl_tst.configure_name_ptr.incrRefCount();
  tcl_tst.test_name_ptr = interp.string_obj_type.newStringObj("test", -1);
  tcl_tst.test_name_ptr.incrRefCount();
  tcl_tst.run_all_tests_name_ptr = interp.string_obj_type.newStringObj("runAllTests", -1);
  tcl_tst.run_all_tests_name_ptr.incrRefCount();
  tcl_tst.tests_directory_name_ptr = interp.string_obj_type.newStringObj("testsDirectory", -1);
  tcl_tst.tests_directory_name_ptr.incrRefCount();
  tcl_tst.test_name_name_ptr = interp.string_obj_type.newStringObj("test_name", -1);
  tcl_tst.test_name_name_ptr.incrRefCount();
  tcl_tst.test_description_name_ptr = interp.string_obj_type.newStringObj("test_description", -1);
  tcl_tst.test_description_name_ptr.incrRefCount();

  /* ==================== command tcltest configure ============================== */
  interp.registerCommand("::tcltest::configure", function (interp, args) {
    var result;
    var my_args = new Array();
    var i = 1;

    tcl_tst.tcltest_name_ptr.incrRefCount();
    my_args.push(tcl_tst.tcltest_name_ptr);
    tcl_tst.configure_name_ptr.incrRefCount();
    my_args.push(tcl_tst.configure_name_ptr);
    for (; i < args.length; i++) {
      my_args.push(args[i]);
    }
    result = interp.eval_statement.evalObjVector(my_args.length, my_args);
    tcl_tst.tcltest_name_ptr.decrRefCount();
    tcl_tst.configure_name_ptr.decrRefCount();
    return result;
  });

  interp.registerSubCommand("::tcltest", "configure", function (interp, args) {
    var i = 2;
    var start_idx = 0;
    var usage = '?-option value ...?';
................................................................................

  /* ==================== command tcltest runAllTests ============================== */
  interp.registerCommand("::tcltest::runAllTests", function (interp, args) {
    var result;
    var my_args = new Array();
    var i = 1;

    tcl_tst.tcltest_name_ptr.incrRefCount();
    my_args.push(tcl_tst.tcltest_name_ptr);
    tcl_tst.run_all_tests_name_ptr.incrRefCount();
    my_args.push(tcl_tst.run_all_tests_name_ptr);
    for (; i < args.length; i++) {
      my_args.push(args[i]);
    }
    result = interp.eval_statement.evalObjVector(my_args.length, my_args);
    tcl_tst.tcltest_name_ptr.decrRefCount();
    tcl_tst.run_all_tests_name_ptr.decrRefCount();
    return result;
  });

  interp.registerSubCommand("::tcltest", "runAllTests", function (interp, args) {
    var ret_code;
    var tst_obj;
    var save_ns;
................................................................................
    var cmd;
    var cmd_obj;
    var tests_obj = interp.getTclTests();

if (false) {
    for (i = 1; i < 87; i++) {
      cmd = "source "+tests_obj.getProp("testdir")+"/t"+i+".test";
      cmd_obj = interp.string_obj_type.newStringObj(cmd, -1);
      cmd_obj.incrRefCount();
      save_ns = interp.frame_ptr.ns_ptr;
      interp.frame_ptr.ns_ptr = interp.global_ns_ptr;
      interp.eval_statement.evalObj(cmd_obj);
      interp.frame_ptr.ns_ptr = save_ns;
      cmd_obj.decrRefCount();
    }
}
    for (i = 0; i < tests_obj.tests.length; i++) {
      test_obj = tests_obj.tests[i];
      save_ns = interp.frame_ptr.ns_ptr;
      interp.frame_ptr.ns_ptr = interp.global_ns_ptr;
      ret_code = tests_obj.runTest(test_obj);
................................................................................

  /* ==================== command tcltest testsDirectory ============================== */
  interp.registerCommand("::tcltest::testsDirectory", function (interp, args) {
    var result;
    var my_args = new Array();
    var i = 1;

    tcl_tst.tcltest_name_ptr.incrRefCount();
    my_args.push(tcl_tst.tcltest_name_ptr);
    tcl_tst.test_directory_name_ptr.incrRefCount();
    my_args.push(tcl_tst.test_directory_name_ptr);
    for (; i < args.length; i++) {
      my_args.push(args[i]);
    }
    result = interp.eval_statement.evalObjVector(my_args.length, my_args);
    tcl_tst.tcltest_name_ptr.decrRefCount();
    -directorytcl_tst.run_test_ptr.decrRefCount();
    return result;
  });

  interp.registerSubCommand("::tcltest", "testsDirectory", function (interp, args) {
    args.shift();
    var test_dir = args.shift();
    var tests_obj = interp.getTclTests();
................................................................................

  /* ==================== command tcltest test ============================== */
  interp.registerCommand("::tcltest::test", function (interp, args) {
    var result;
    var my_args = new Array();
    var i = 1;

    tcl_tst.tcltest_name_ptr.incrRefCount();
    my_args.push(tcl_tst.tcltest_name_ptr);
    tcl_tst.test_name_ptr.incrRefCount();
    my_args.push(tcl_tst.test_name_ptr);
    for (; i < args.length; i++) {
      my_args.push(args[i]);
    }
    result = interp.eval_statement.evalObjVector(my_args.length, my_args);
    tcl_tst.tcltest_name_ptr.decrRefCount();
    tcl_tst.test_name_ptr.decrRefCount();
    return result;
  });

  interp.registerSubCommand("::tcltest", "test", function (interp, args) {
    var i = 2;
    var usage = 'test name description ?-option value ...?';
    var tcl_test_case;
................................................................................
    if (tcl_test_case.setTestProp(tcl_tst.test_description_name_ptr, description) != interp.OK) {
      interp.wrongNumArgs(2, args, usage);
      return interp.ERROR;
    }
    if (args.length == 6) {
      /* check for old style */
      if ((args[i].getString().charAt(0) != '-') && (args[i+1].getString().charAt(0) != '-')) {
	option_str = interp.string_obj_type.newStringObj("body", -1);
	option_str.incrRefCount();
        if (tcl_test_case.setTestProp(option_str, args[i++]) != interp.OK) {
	  option_str.decrRefCount();
	  return interp.ERROR;
        }
	option_str.decrRefCount();
	option_str = interp.string_obj_type.newStringObj("result", -1);
	option_str.incrRefCount();
        if (tcl_test_case.setTestProp(option_str, args[i++]) != interp.OK) {
	  option_str.decrRefCount();
	  return interp.ERROR;
        }
	option_str.decrRefCount();
      }
    }
    re = new RegExp("^[-].*");
    if (args.length - i  > 0) {
      for (start_idx = i; start_idx < args.length; start_idx++) {
        my_arg = args[start_idx].getString();
        if (my_arg.match(re)) {
................................................................................
	    start_idx++;
            break;
	  }
          if (start_idx > args.length - 2) {
            interp.wrongNumArgs(2, args, usage);
	    return interp.ERROR;
          }
	  option_str = interp.string_obj_type.newStringObj(my_arg.substring(1), -1);
          if (tcl_test_case.setTestProp(option_str, args[start_idx+1]) != interp.OK) {
	    return interp.ERROR;
          }
	  start_idx++;
        } else {
          break;
        }







|
|
|
|
|
|
|
|
|
|
|
|
|
|







|

|





|
|







 







|

|





|
|







 







|
|




|







 







|

|





|
|







 







|

|





|
|







 







|
|

|


|
|
|

|


|







 







|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
...
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
...
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
  var constructor = tcl_tst.constructor;
  PkgTclTest.superclass.constructor.apply(tcl_tst, arguments);

  R.Base.pkg_tcltest_oid++;
  tcl_tst.oid = R.Base.pkg_tcltest_oid;

  tcl_tst.interp = interp;
  tcl_tst.tcltest_name_ptr = interp.string_obj_type.newStringObj("::tcltest", -1, "PKG_TCLTESTCMD_1");
  tcl_tst.tcltest_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_1");
  tcl_tst.configure_name_ptr = interp.string_obj_type.newStringObj("configure", -1, "PKG_TCLTESTCMD_2");
  tcl_tst.configure_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_2");
  tcl_tst.test_name_ptr = interp.string_obj_type.newStringObj("test", -1, "PKG_TCLTESTCMD_3");
  tcl_tst.test_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_3");
  tcl_tst.run_all_tests_name_ptr = interp.string_obj_type.newStringObj("runAllTests", -1, "PKG_TCLTESTCMD_4");
  tcl_tst.run_all_tests_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_4");
  tcl_tst.tests_directory_name_ptr = interp.string_obj_type.newStringObj("testsDirectory", -1, "PKG_TCLTESTCMD_5");
  tcl_tst.tests_directory_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_5");
  tcl_tst.test_name_name_ptr = interp.string_obj_type.newStringObj("test_name", -1, "PKG_TCLTESTCMD_6");
  tcl_tst.test_name_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_6");
  tcl_tst.test_description_name_ptr = interp.string_obj_type.newStringObj("test_description", -1, "PKG_TCLTESTCMD_7");
  tcl_tst.test_description_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_7");

  /* ==================== command tcltest configure ============================== */
  interp.registerCommand("::tcltest::configure", function (interp, args) {
    var result;
    var my_args = new Array();
    var i = 1;

    tcl_tst.tcltest_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_8");
    my_args.push(tcl_tst.tcltest_name_ptr);
    tcl_tst.configure_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_9");
    my_args.push(tcl_tst.configure_name_ptr);
    for (; i < args.length; i++) {
      my_args.push(args[i]);
    }
    result = interp.eval_statement.evalObjVector(my_args.length, my_args);
    tcl_tst.tcltest_name_ptr.decrRefCount("D_PKG_TCLTESTCMD_1");
    tcl_tst.configure_name_ptr.decrRefCount("D_PKG_TCLTESTCMD_2");
    return result;
  });

  interp.registerSubCommand("::tcltest", "configure", function (interp, args) {
    var i = 2;
    var start_idx = 0;
    var usage = '?-option value ...?';
................................................................................

  /* ==================== command tcltest runAllTests ============================== */
  interp.registerCommand("::tcltest::runAllTests", function (interp, args) {
    var result;
    var my_args = new Array();
    var i = 1;

    tcl_tst.tcltest_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_10");
    my_args.push(tcl_tst.tcltest_name_ptr);
    tcl_tst.run_all_tests_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_11");
    my_args.push(tcl_tst.run_all_tests_name_ptr);
    for (; i < args.length; i++) {
      my_args.push(args[i]);
    }
    result = interp.eval_statement.evalObjVector(my_args.length, my_args);
    tcl_tst.tcltest_name_ptr.decrRefCount("D_PKG_TCLTESTCMD_3");
    tcl_tst.run_all_tests_name_ptr.decrRefCount("D_PKG_TCLTESTCMD_4");
    return result;
  });

  interp.registerSubCommand("::tcltest", "runAllTests", function (interp, args) {
    var ret_code;
    var tst_obj;
    var save_ns;
................................................................................
    var cmd;
    var cmd_obj;
    var tests_obj = interp.getTclTests();

if (false) {
    for (i = 1; i < 87; i++) {
      cmd = "source "+tests_obj.getProp("testdir")+"/t"+i+".test";
      cmd_obj = interp.string_obj_type.newStringObj(cmd, -1, "PKG_TCLTESTCMD_8");
      cmd_obj.incrRefCount("I_PKG_TCLTESTCMD_12");
      save_ns = interp.frame_ptr.ns_ptr;
      interp.frame_ptr.ns_ptr = interp.global_ns_ptr;
      interp.eval_statement.evalObj(cmd_obj);
      interp.frame_ptr.ns_ptr = save_ns;
      cmd_obj.decrRefCount("D_PKG_TCLTESTCMD_5");
    }
}
    for (i = 0; i < tests_obj.tests.length; i++) {
      test_obj = tests_obj.tests[i];
      save_ns = interp.frame_ptr.ns_ptr;
      interp.frame_ptr.ns_ptr = interp.global_ns_ptr;
      ret_code = tests_obj.runTest(test_obj);
................................................................................

  /* ==================== command tcltest testsDirectory ============================== */
  interp.registerCommand("::tcltest::testsDirectory", function (interp, args) {
    var result;
    var my_args = new Array();
    var i = 1;

    tcl_tst.tcltest_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_13");
    my_args.push(tcl_tst.tcltest_name_ptr);
    tcl_tst.test_directory_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_14");
    my_args.push(tcl_tst.test_directory_name_ptr);
    for (; i < args.length; i++) {
      my_args.push(args[i]);
    }
    result = interp.eval_statement.evalObjVector(my_args.length, my_args);
    tcl_tst.tcltest_name_ptr.decrRefCount("D_PKG_TCLTESTCMD_6");
    -directorytcl_tst.run_test_ptr.decrRefCount("D_PKG_TCLTESTCMD_7");
    return result;
  });

  interp.registerSubCommand("::tcltest", "testsDirectory", function (interp, args) {
    args.shift();
    var test_dir = args.shift();
    var tests_obj = interp.getTclTests();
................................................................................

  /* ==================== command tcltest test ============================== */
  interp.registerCommand("::tcltest::test", function (interp, args) {
    var result;
    var my_args = new Array();
    var i = 1;

    tcl_tst.tcltest_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_15");
    my_args.push(tcl_tst.tcltest_name_ptr);
    tcl_tst.test_name_ptr.incrRefCount("I_PKG_TCLTESTCMD_16");
    my_args.push(tcl_tst.test_name_ptr);
    for (; i < args.length; i++) {
      my_args.push(args[i]);
    }
    result = interp.eval_statement.evalObjVector(my_args.length, my_args);
    tcl_tst.tcltest_name_ptr.decrRefCount("D_PKG_TCLTESTCMD_8");
    tcl_tst.test_name_ptr.decrRefCount("D_PKG_TCLTESTCMD_9");
    return result;
  });

  interp.registerSubCommand("::tcltest", "test", function (interp, args) {
    var i = 2;
    var usage = 'test name description ?-option value ...?';
    var tcl_test_case;
................................................................................
    if (tcl_test_case.setTestProp(tcl_tst.test_description_name_ptr, description) != interp.OK) {
      interp.wrongNumArgs(2, args, usage);
      return interp.ERROR;
    }
    if (args.length == 6) {
      /* check for old style */
      if ((args[i].getString().charAt(0) != '-') && (args[i+1].getString().charAt(0) != '-')) {
	option_str = interp.string_obj_type.newStringObj("body", -1, "PKG_TCLTESTCMD_9");
	option_str.incrRefCount("I_PKG_TCLTESTCMD_17");
        if (tcl_test_case.setTestProp(option_str, args[i++]) != interp.OK) {
	  option_str.decrRefCount("D_PKG_TCLTESTCMD_10");
	  return interp.ERROR;
        }
	option_str.decrRefCount("D_PKG_TCLTESTCMD_11");
	option_str = interp.string_obj_type.newStringObj("result", -1, "PKG_TCLTESTCMD_10");
	option_str.incrRefCount("I_PKG_TCLTESTCMD_18");
        if (tcl_test_case.setTestProp(option_str, args[i++]) != interp.OK) {
	  option_str.decrRefCount("D_PKG_TCLTESTCMD_12");
	  return interp.ERROR;
        }
	option_str.decrRefCount("D_PKG_TCLTESTCMD_13");
      }
    }
    re = new RegExp("^[-].*");
    if (args.length - i  > 0) {
      for (start_idx = i; start_idx < args.length; start_idx++) {
        my_arg = args[start_idx].getString();
        if (my_arg.match(re)) {
................................................................................
	    start_idx++;
            break;
	  }
          if (start_idx > args.length - 2) {
            interp.wrongNumArgs(2, args, usage);
	    return interp.ERROR;
          }
	  option_str = interp.string_obj_type.newStringObj(my_arg.substring(1), -1, "PKG_TCLTESTCMD_11");
          if (tcl_test_case.setTestProp(option_str, args[start_idx+1]) != interp.OK) {
	    return interp.ERROR;
          }
	  start_idx++;
        } else {
          break;
        }

Changes to rapl_rh_start.js.

37
38
39
40
41
42
43

44

      var ret_code = intp.eval_statement.evalObj(script_obj_ptr);
      if (ret_code != intp.OK) {
        print(intp.getResultString(ret_code)+"!"+intp.result+"!");
      }
    }


print("END");







>

37
38
39
40
41
42
43
44
45

      var ret_code = intp.eval_statement.evalObj(script_obj_ptr);
      if (ret_code != intp.OK) {
        print(intp.getResultString(ret_code)+"!"+intp.result+"!");
      }
    }

//intp.default_obj.dumpObjLists();
print("END");

Changes to rapl_script.js.

84
85
86
87
88
89
90

91
92
93
94
95
96
97
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
...
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
...
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398

function RaplScript(interp) {
  R.log('constructor called', '2.life', 'RaplScript', true);
  // kweight
  var script = this;
  var constructor = script.constructor;
  RaplScript.superclass.constructor.apply(script, arguments);


  R.Base.script_oid++;
  script.oid = R.Base.script_oid;

  script.interp = interp;
  script.parse_token_list = null;
  script.result = null;
................................................................................
    file_name_obj: null,
    line: null                /* Line number of the first line */
   };

  R.log('constructor end', '2.life', 'RaplScript', true);
}

R.extend(RaplScript, R.RaplObject, {
  my_name: "RaplScript",

  /* ==================== TOKEN_IS_SEP ================================== */
  TOKEN_IS_SEP: function(token) {
    var script = this;
    return (token >= script.TOKEN_WORD_SEP && token <= script.TOKEN_EOF);
  },
................................................................................
      word_tokens = script.countWordTokens(token_list_idx);
      if (word_tokens == 0) {
        /* None, so at end of line */
        if (line_args) {
	  var my_token_info = script.script_object.tokens[line_first_idx];
          my_token_info.token = script.TOKEN_LINE;
	  my_token_info.obj_ptr = script.interp.script_line_obj_type.newScriptLineObject(line_args, line_no);
	  my_token_info.obj_ptr.incrRefCount();

	  /* Reset for new line */
	  line_args = 0;
	  line_first_idx = script.token_idx;
	  script.token_idx++;
	}
	token_list_idx++;
................................................................................
	continue;
      } else {
        if (word_tokens != 1) {
          /* More than 1, or {expand}, so insert a WORD token */
          token_info = script.script_object.tokens[script.token_idx];
	  token_info.token = script.TOKEN_WORD;
	  token_info.obj_ptr = script.interp.int_obj_type.newIntObj(word_tokens);
	  token_info.obj_ptr.incrRefCount();
	  script.token_idx++;
	  if (word_tokens < 0) {
            /* Skip the expand token */
	    token_list_idx++;
	    word_tokens = -word_tokens - 1;
	    line_args--;
	  }
................................................................................
	while (word_tokens--) {
          parse_token_info = script.parse_token_list[token_list_idx];
	  token_list_idx++;
	  token_info = script.script_object.tokens[script.token_idx];
	  token_info.token = parse_token_info.token;
	  /* put the token info into a new string obj in the bytes part */
	  token_info.obj_ptr = script.interp.script_obj_type.makeScriptObj(script.interp, parse_token_info, script.text);
	  token_info.obj_ptr.incrRefCount();

	  /* Every object is initially a string, but the
	   * internal type may be specialized during execution of the
	   * script.
	   * The bytes part still contains the token info!!
	   */
	  script.interp.source_obj_type.setSourceInfo(token_info.obj_ptr, script.script_object.file_name_obj, parse_token_info.line);
................................................................................

    while (token_list_idx < script.parse_token_list.length) {
      parse_token_info = script.parse_token_list[token_list_idx];
      token_list_idx++;
      token_info = script.script_object.tokens[script.token_idx];
      token_info.token = parse_token_info.token;
      token_info.obj_ptr = script.interp.script_obj_type.makeScriptObj(script.interp, parse_token_info, script.text);
      token_info.obj_ptr.incrRefCount();
      script.token_idx++;
    }
    script.len = script.token_idx;
    if (debug_script_tokens) {
print("substObjAddTokens!"+script.script_object.file_name_obj+"!");
      var fname = script.interp.string_obj_type.getString(script.script_object.file_name_obj);
      print("======== subst script ("+fname+") ======");







>







 







|







 







|







 







|







 







|







 







|







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
...
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
...
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399

function RaplScript(interp) {
  R.log('constructor called', '2.life', 'RaplScript', true);
  // kweight
  var script = this;
  var constructor = script.constructor;
  RaplScript.superclass.constructor.apply(script, arguments);
RaplScript.superclass.interp = interp;

  R.Base.script_oid++;
  script.oid = R.Base.script_oid;

  script.interp = interp;
  script.parse_token_list = null;
  script.result = null;
................................................................................
    file_name_obj: null,
    line: null                /* Line number of the first line */
   };

  R.log('constructor end', '2.life', 'RaplScript', true);
}

R.extend(RaplScript, R.Token, {
  my_name: "RaplScript",

  /* ==================== TOKEN_IS_SEP ================================== */
  TOKEN_IS_SEP: function(token) {
    var script = this;
    return (token >= script.TOKEN_WORD_SEP && token <= script.TOKEN_EOF);
  },
................................................................................
      word_tokens = script.countWordTokens(token_list_idx);
      if (word_tokens == 0) {
        /* None, so at end of line */
        if (line_args) {
	  var my_token_info = script.script_object.tokens[line_first_idx];
          my_token_info.token = script.TOKEN_LINE;
	  my_token_info.obj_ptr = script.interp.script_line_obj_type.newScriptLineObject(line_args, line_no);
	  my_token_info.obj_ptr.incrRefCount("I_SCRIPT_1");

	  /* Reset for new line */
	  line_args = 0;
	  line_first_idx = script.token_idx;
	  script.token_idx++;
	}
	token_list_idx++;
................................................................................
	continue;
      } else {
        if (word_tokens != 1) {
          /* More than 1, or {expand}, so insert a WORD token */
          token_info = script.script_object.tokens[script.token_idx];
	  token_info.token = script.TOKEN_WORD;
	  token_info.obj_ptr = script.interp.int_obj_type.newIntObj(word_tokens);
	  token_info.obj_ptr.incrRefCount("I_SCRIPT_2");
	  script.token_idx++;
	  if (word_tokens < 0) {
            /* Skip the expand token */
	    token_list_idx++;
	    word_tokens = -word_tokens - 1;
	    line_args--;
	  }
................................................................................
	while (word_tokens--) {
          parse_token_info = script.parse_token_list[token_list_idx];
	  token_list_idx++;
	  token_info = script.script_object.tokens[script.token_idx];
	  token_info.token = parse_token_info.token;
	  /* put the token info into a new string obj in the bytes part */
	  token_info.obj_ptr = script.interp.script_obj_type.makeScriptObj(script.interp, parse_token_info, script.text);
	  token_info.obj_ptr.incrRefCount("I_SCRIPT_3");

	  /* Every object is initially a string, but the
	   * internal type may be specialized during execution of the
	   * script.
	   * The bytes part still contains the token info!!
	   */
	  script.interp.source_obj_type.setSourceInfo(token_info.obj_ptr, script.script_object.file_name_obj, parse_token_info.line);
................................................................................

    while (token_list_idx < script.parse_token_list.length) {
      parse_token_info = script.parse_token_list[token_list_idx];
      token_list_idx++;
      token_info = script.script_object.tokens[script.token_idx];
      token_info.token = parse_token_info.token;
      token_info.obj_ptr = script.interp.script_obj_type.makeScriptObj(script.interp, parse_token_info, script.text);
      token_info.obj_ptr.incrRefCount("I_SCRIPT_4");
      script.token_idx++;
    }
    script.len = script.token_idx;
    if (debug_script_tokens) {
print("substObjAddTokens!"+script.script_object.file_name_obj+"!");
      var fname = script.interp.string_obj_type.getString(script.script_object.file_name_obj);
      print("======== subst script ("+fname+") ======");

Changes to rapl_script_line_obj_type.js.

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  newScriptLineObject: function(argc, line) {
    var obj = this;
    var debug_script = 1;
    var obj_ptr;

    if (debug_script) {
      var str = "line="+line+", argc="+argc;
      obj_ptr = obj.interp.string_obj_type.newStringObj(str, -1);
    } else {
      obj_ptr = obj.interp.string_obj_type.newEmtyStringObj();
    }
    obj_ptr.obj_type = obj;
    obj_ptr.scriptLineValue.argc(argc);
    obj_ptr.scriptLineValue.line(line);








|







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  newScriptLineObject: function(argc, line) {
    var obj = this;
    var debug_script = 1;
    var obj_ptr;

    if (debug_script) {
      var str = "line="+line+", argc="+argc;
      obj_ptr = obj.interp.string_obj_type.newStringObj(str, -1, "SCRIPT_LINE_OBJ_TYPE_1");
    } else {
      obj_ptr = obj.interp.string_obj_type.newEmtyStringObj();
    }
    obj_ptr.obj_type = obj;
    obj_ptr.scriptLineValue.argc(argc);
    obj_ptr.scriptLineValue.line(line);

Changes to rapl_script_obj_type.js.

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
    script.script_object.ref_count = 1;
    script.script_object.line = line;
    if (obj_ptr.obj_type != null && obj_ptr.obj_type.name == "source") {
      script.script_object.file_name_obj = obj_ptr.sourceValue.fileNameObj();
    } else {
      script.script_object.file_name_obj = script.interp.empty_string_obj;
    }
    script.script_object.file_name_obj.incrRefCount();
    script.scriptObjAddTokens();
    /* No longer need the token list */
    script.scriptTokenListFree();
    /* Free the old internal rep and set the new one. */
    obj_ptr.freeIntRep();
    obj_ptr.setIntRepPtr(script);
    obj_ptr.obj_type = this;
................................................................................
      /* Convert the backlash escapes . */
      var len = parse_token.len;
      var result_str = new Array();
      var str = text.substring(parse_token.start, parse_token.start + parse_token.len);
      //
      len = obj.escapeBackslash(result_str, str, len);
      str = result_str[0];
      obj_ptr = script_obj.interp.string_obj_type.newStringObjNoAlloc(str, len);
    } else {
      /* REVISIT: Strictly, TOKEN_STR should replace <backslash><newline><whitespace>
       *         with a single space. This is currently not done.
       */
      obj_ptr = interp.string_obj_type.newStringObj(text.substring(parse_token.start, parse_token.start + parse_token.len), parse_token.len);

    }
    return obj_ptr;
  },

  /* ==================== getScript ================================== */
  getScript: function(obj_ptr) {
................................................................................
    }


    /* Create the "real" subst/script tokens from the initial token list */
    script.script_object.ref_count = 1;
    script.script_object.subst_flags = flags;
    script.script_object.file_name_obj = script.interp.empty_string_obj;
    script.script_object.file_name_obj.incrRefCount();
    script.substObjAddTokens();

    /* No longer need the token list */
    script.scriptTokenListFree();

    /* Free the old internal rep and set the new one. */
    obj_ptr.freeIntRep();
................................................................................
   * storing the result object (with refcount 0) into
   * resObjPtrPtr. 
   */
  substObj: function(subst_obj_ptr, res_obj_ptr_ptr, flags) {
    var subst_obj = this;
    var script = subst_obj.getSubst(subst_obj_ptr, flags);

    subst_obj_ptr.incrRefCount();      /* Make sure it's shared. */
    /* In order to preserve the internal rep, we increment the
     * ref_count field of the script internal rep structure. 
     */
    script.ref_count++;
    res_obj_ptr_ptr[0] = subst_obj.interp.eval_statement.interpolateTokens(script, 0, script.len, flags);
    script.ref_count--;
    subst_obj_ptr.decrRefCount();
    if (res_obj_ptr_ptr[0] == null) {
      return subst_obj.ERROR;
    }
    return subst_obj.OK;
  },

});

ScriptObjType.prototype.constructor = ScriptObjType;

R.ScriptObjType = ScriptObjType;

}, "0.0.1", {});







|







 







|




|







 







|







 







|






|













68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
    script.script_object.ref_count = 1;
    script.script_object.line = line;
    if (obj_ptr.obj_type != null && obj_ptr.obj_type.name == "source") {
      script.script_object.file_name_obj = obj_ptr.sourceValue.fileNameObj();
    } else {
      script.script_object.file_name_obj = script.interp.empty_string_obj;
    }
    script.script_object.file_name_obj.incrRefCount("I_SCRIPT_OBJ_TYPE_1");
    script.scriptObjAddTokens();
    /* No longer need the token list */
    script.scriptTokenListFree();
    /* Free the old internal rep and set the new one. */
    obj_ptr.freeIntRep();
    obj_ptr.setIntRepPtr(script);
    obj_ptr.obj_type = this;
................................................................................
      /* Convert the backlash escapes . */
      var len = parse_token.len;
      var result_str = new Array();
      var str = text.substring(parse_token.start, parse_token.start + parse_token.len);
      //
      len = obj.escapeBackslash(result_str, str, len);
      str = result_str[0];
      obj_ptr = script_obj.interp.string_obj_type.newStringObjNoAlloc(str, len, "SCRIPT_OBJ_TYPE_1");
    } else {
      /* REVISIT: Strictly, TOKEN_STR should replace <backslash><newline><whitespace>
       *         with a single space. This is currently not done.
       */
      obj_ptr = interp.string_obj_type.newStringObj(text.substring(parse_token.start, parse_token.start + parse_token.len), parse_token.len, "SCRIPT_OBJ_TYPE_2");

    }
    return obj_ptr;
  },

  /* ==================== getScript ================================== */
  getScript: function(obj_ptr) {
................................................................................
    }


    /* Create the "real" subst/script tokens from the initial token list */
    script.script_object.ref_count = 1;
    script.script_object.subst_flags = flags;
    script.script_object.file_name_obj = script.interp.empty_string_obj;
    script.script_object.file_name_obj.incrRefCount("I_SCRIPT_OBJ_TYPE_2");
    script.substObjAddTokens();

    /* No longer need the token list */
    script.scriptTokenListFree();

    /* Free the old internal rep and set the new one. */
    obj_ptr.freeIntRep();
................................................................................
   * storing the result object (with refcount 0) into
   * resObjPtrPtr. 
   */
  substObj: function(subst_obj_ptr, res_obj_ptr_ptr, flags) {
    var subst_obj = this;
    var script = subst_obj.getSubst(subst_obj_ptr, flags);

    subst_obj_ptr.incrRefCount("I_SCRIPT_OBJ_TYPE_3");      /* Make sure it's shared. */
    /* In order to preserve the internal rep, we increment the
     * ref_count field of the script internal rep structure. 
     */
    script.ref_count++;
    res_obj_ptr_ptr[0] = subst_obj.interp.eval_statement.interpolateTokens(script, 0, script.len, flags);
    script.ref_count--;
    subst_obj_ptr.decrRefCount("D_SCRIPT_OBJ_TYPE_1");
    if (res_obj_ptr_ptr[0] == null) {
      return subst_obj.ERROR;
    }
    return subst_obj.OK;
  },

});

ScriptObjType.prototype.constructor = ScriptObjType;

R.ScriptObjType = ScriptObjType;

}, "0.0.1", {});

Changes to rapl_source_obj_type.js.

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  /* ==================== setFromAny ================================== */
  setFromAny: function(obj_ptr) {
    print("source setFromAny not yet implemented");
  },

  /* ==================== freeInternalRep ===================================== */
  freeInternalRep: function(obj_ptr) {
    obj_ptr.sourceValue.file_name_obj().decrRefCount();
  },

  /* ==================== dupInternalRep ===================================== */
  dupInternalRep: function(src_ptr, dup_ptr) {
    dup_ptr.internalRep.value1 = src_ptr.internalRep.value1;
    dup_ptr.internalRep.value2 = src_ptr.internalRep.value2;
    dup_ptr.internalRep.value3 = src_ptr.internalRep.value3;
    dup_ptr.sourceValue.fileNameObj().incrRefCount();
  },

  /* ==================== setSourceInfo ================================== */
  setSourceInfo: function(obj_ptr, file_name_ptr, line_number) {
    var obj = this;
    obj_ptr.panic(obj_ptr.isShared(), "setSourceInfo called with shared object")
    obj_ptr.panic(obj_ptr.obj_type != null, "setSourceInfo called with typePtr != null");
    file_name_ptr.incrRefCount();
    obj_ptr.sourceValue.fileNameObj(file_name_ptr);
    obj_ptr.sourceValue.lineNumber(line_number);
    obj_ptr.obj_type = obj;
  },


});

SourceObjType.prototype.constructor = SourceObjType;

R.SourceObjType = SourceObjType;

}, "0.0.1", {});







|







|







|













34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  /* ==================== setFromAny ================================== */
  setFromAny: function(obj_ptr) {
    print("source setFromAny not yet implemented");
  },

  /* ==================== freeInternalRep ===================================== */
  freeInternalRep: function(obj_ptr) {
    obj_ptr.sourceValue.file_name_obj().decrRefCount("D_SOURCE_OBJ_TYPE_1");
  },

  /* ==================== dupInternalRep ===================================== */
  dupInternalRep: function(src_ptr, dup_ptr) {
    dup_ptr.internalRep.value1 = src_ptr.internalRep.value1;
    dup_ptr.internalRep.value2 = src_ptr.internalRep.value2;
    dup_ptr.internalRep.value3 = src_ptr.internalRep.value3;
    dup_ptr.sourceValue.fileNameObj().incrRefCount("I_SOURCE_OBJ_TYPE_1");
  },

  /* ==================== setSourceInfo ================================== */
  setSourceInfo: function(obj_ptr, file_name_ptr, line_number) {
    var obj = this;
    obj_ptr.panic(obj_ptr.isShared(), "setSourceInfo called with shared object")
    obj_ptr.panic(obj_ptr.obj_type != null, "setSourceInfo called with typePtr != null");
    file_name_ptr.incrRefCount("I_SOURCE_OBJ_TYPE_2");
    obj_ptr.sourceValue.fileNameObj(file_name_ptr);
    obj_ptr.sourceValue.lineNumber(line_number);
    obj_ptr.obj_type = obj;
  },


});

SourceObjType.prototype.constructor = SourceObjType;

R.SourceObjType = SourceObjType;

}, "0.0.1", {});

Changes to rapl_string_obj_type.js.

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82




83
84
85
86
87
88
89
90
91
92
93
94
95
...
100
101
102
103
104
105
106




107
108
109
110
111
112
113
114





115
116
117
118
119
120
121
...
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
...
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
...
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
...
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405

  /* ==================== getStringLength ================================== */
  getStringLength: function(obj_ptr) {
    return obj_ptr.len;
  },

  /* ==================== newStringObjNoAlloc ================================== */
  newStringObjNoAlloc: function(str, len) {
    var obj = this.interp.default_obj;
    var obj_ptr = obj.newRaplObject();
    if (len == -1) {
      len = str.length;
    }
    obj_ptr.setStringRep(obj_ptr, str, len);
    obj_ptr.obj_type = null;




    return obj_ptr;
  },

  /* ==================== newStringObj ================================== */
  /* len is in bytes -- see also newStringObjUtf8() */
  newStringObj: function(str, len) {
    var obj = this.interp.default_obj;
    var obj_ptr = obj.newRaplObject();

    str = str+"";  /* force conversion to string */
    /* Need to find out how many bytes the string requires */
    if (len == -1) {
      len = str.length;
................................................................................
    } else {
      obj_ptr.bytes = str.substring(0, len)+"\0";
      obj_ptr.len = len;
    }

    /* No obj_type field for the vanilla string object. */
    obj_ptr.obj_type = null;




    return obj_ptr;
  },

  /* ==================== newEmptyStringObj ================================== */
  newEmptyStringObj: function() {
    var obj = this;

    return obj.newStringObj("", 0);





  },

  /* ==================== appendString ================================== */
  /* Low-level string append. Use it only against objects
   * of type "string". 
   */
  appendString: function(obj_ptr, str, len) {
................................................................................
    if (num_maps % 2) {
      obj.interp.setResultString("list must contain an even number of elements");
      return null;
    }
    str = obj_ptr.getString();
    str_len = obj_ptr.utf8_length(obj_ptr);
    /* Map it */
    result_obj_ptr = obj.interp.string_obj_type.newStringObj("", 0);
    while (str_len) {
      for (i = 0; i < num_maps; i += 2) {
        var my_obj_ptr = new Array();
        var k;
        var kl;

        obj.interp.list_obj_type.listIndex(map_list_obj_ptr, i, my_obj_ptr, obj.interp.FUNCTION_FLAGS_NONE);
................................................................................
      trim_chars = trim_chars_obj_ptr.getString();
      trim_chars_len = trim_chars_obj_ptr.getStringLength();
    }
    new_str = obj.findTrimLeft(str, len, trim_chars, trim_chars_len);
    if (new_str == str) {
      return str_obj_ptr;
    }
    return obj.newStringObj(new_str, -1);
  },

  /* ==================== stringTrimRight ================================== */
  stringTrimRight: function(str_obj_ptr, trim_chars_obj_ptr) {
    var obj = this;
    var len;
    var trim_chars = obj.default_trim_chars;
................................................................................
      /* All trim, so return a zero-length string */
      return obj.newEmptyStringObj();
    }
    if (nontrim == str_obj_ptr.bytes.substring(0, len)) {
      return str_obj_ptr;
    }
    if (str_obj_ptr.isShared()) {
        str_obj_ptr = obj.newStringObj(str_obj_ptr.bytes, nontrim.length);
    } else {
      /* Can modify this string in place */
      str_obj_ptr.bytes[nontrim.length] = '\0';
      str_obj_ptr.len = nontrim.length;
    }
    return str_obj_ptr;
  },
................................................................................
    
    /* First trim left. */
    obj_ptr = obj.stringTrimLeft(str_obj_ptr, trim_chars_obj_ptr);
    /* Now trim right */
    str_obj_ptr = obj.stringTrimRight(obj_ptr, trim_chars_obj_ptr);
    if (obj_ptr != str_obj_ptr) {
      /* Note that we don't want this object to be leaked */
      obj_ptr.incrRefCount();
      obj_ptr.decrRefCount();
    }
    return str_obj_ptr;
  },

});

StringObjType.prototype.constructor = StringObjType;

R.StringObjType = StringObjType;

}, "0.0.1", {});







|







>
>
>
>





|







 







>
>
>
>




|


|
>
>
>
>
>







 







|







 







|







 







|







 







|
|











68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
...
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
...
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
...
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418

  /* ==================== getStringLength ================================== */
  getStringLength: function(obj_ptr) {
    return obj_ptr.len;
  },

  /* ==================== newStringObjNoAlloc ================================== */
  newStringObjNoAlloc: function(str, len, where) {
    var obj = this.interp.default_obj;
    var obj_ptr = obj.newRaplObject();
    if (len == -1) {
      len = str.length;
    }
    obj_ptr.setStringRep(obj_ptr, str, len);
    obj_ptr.obj_type = null;
    if (typeof where != "undefined") {
       obj_ptr.allocated = where;
       obj_ptr.freed = null;
    }
    return obj_ptr;
  },

  /* ==================== newStringObj ================================== */
  /* len is in bytes -- see also newStringObjUtf8() */
  newStringObj: function(str, len, where) {
    var obj = this.interp.default_obj;
    var obj_ptr = obj.newRaplObject();

    str = str+"";  /* force conversion to string */
    /* Need to find out how many bytes the string requires */
    if (len == -1) {
      len = str.length;
................................................................................
    } else {
      obj_ptr.bytes = str.substring(0, len)+"\0";
      obj_ptr.len = len;
    }

    /* No obj_type field for the vanilla string object. */
    obj_ptr.obj_type = null;
    if (typeof where != "undefined") {
       obj_ptr.allocated = where;
       obj_ptr.freed = null;
    }
    return obj_ptr;
  },

  /* ==================== newEmptyStringObj ================================== */
  newEmptyStringObj: function(where) {
    var obj = this;

    var obj_ptr = obj.newStringObj("", 0);
    if (typeof where != "undefined") {
       obj_ptr.allocated = where;
       obj_ptr.freed = null;
    }
    return obj_ptr;
  },

  /* ==================== appendString ================================== */
  /* Low-level string append. Use it only against objects
   * of type "string". 
   */
  appendString: function(obj_ptr, str, len) {
................................................................................
    if (num_maps % 2) {
      obj.interp.setResultString("list must contain an even number of elements");
      return null;
    }
    str = obj_ptr.getString();
    str_len = obj_ptr.utf8_length(obj_ptr);
    /* Map it */
    result_obj_ptr = obj.interp.string_obj_type.newStringObj("", 0, "STRING_OBJ_TYPE_1");
    while (str_len) {
      for (i = 0; i < num_maps; i += 2) {
        var my_obj_ptr = new Array();
        var k;
        var kl;

        obj.interp.list_obj_type.listIndex(map_list_obj_ptr, i, my_obj_ptr, obj.interp.FUNCTION_FLAGS_NONE);
................................................................................
      trim_chars = trim_chars_obj_ptr.getString();
      trim_chars_len = trim_chars_obj_ptr.getStringLength();
    }
    new_str = obj.findTrimLeft(str, len, trim_chars, trim_chars_len);
    if (new_str == str) {
      return str_obj_ptr;
    }
    return obj.newStringObj(new_str, -1, "STRING_OBJ_TYPE_2");
  },

  /* ==================== stringTrimRight ================================== */
  stringTrimRight: function(str_obj_ptr, trim_chars_obj_ptr) {
    var obj = this;
    var len;
    var trim_chars = obj.default_trim_chars;
................................................................................
      /* All trim, so return a zero-length string */
      return obj.newEmptyStringObj();
    }
    if (nontrim == str_obj_ptr.bytes.substring(0, len)) {
      return str_obj_ptr;
    }
    if (str_obj_ptr.isShared()) {
        str_obj_ptr = obj.newStringObj(str_obj_ptr.bytes, nontrim.length, "STRING_OBJ_TYPE_3");
    } else {
      /* Can modify this string in place */
      str_obj_ptr.bytes[nontrim.length] = '\0';
      str_obj_ptr.len = nontrim.length;
    }
    return str_obj_ptr;
  },
................................................................................
    
    /* First trim left. */
    obj_ptr = obj.stringTrimLeft(str_obj_ptr, trim_chars_obj_ptr);
    /* Now trim right */
    str_obj_ptr = obj.stringTrimRight(obj_ptr, trim_chars_obj_ptr);
    if (obj_ptr != str_obj_ptr) {
      /* Note that we don't want this object to be leaked */
      obj_ptr.incrRefCount("I_STRING_OBJ_TYPE_1");
      obj_ptr.decrRefCount("D_STRING_OBJ_TYPE_1");
    }
    return str_obj_ptr;
  },

});

StringObjType.prototype.constructor = StringObjType;

R.StringObjType = StringObjType;

}, "0.0.1", {});

Changes to rapl_tcltest.js.

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240


241
242
243
244
245
246
247
  getProps: function() {
    var tcl_tst = this;
    var props = new Array();
    var result;

    for (var z in tcl_tst.configure_options) {
      if (tcl_tst.configure_options[z] != "undefined") {
        props.push(tcl_tst.interp.string_obj_type.newStringObj("-"+z, -1));
      }
    }
    result = tcl_tst.interp.list_obj_type.newListObj(props, props.length);
    tcl_tst.interp.setResult(result);
    return tcl_tst.OK;
  },

................................................................................
    /* Destroy the call frame */
    result = tcl_tst.interp.namespace_obj_type.popStackFrame();

    result = tcl_tst.interp.getResult();
    /* check the result against the expected result */
    var expected_result = test_obj.test_prop["result"];
    if (expected_result == null) {
      expected_result = tcl_tst.interp.string_obj_type.newStringObj("", -1);
    }
    /* if we have a match configure option use that for comparing  */
    var match_script = tcl_tst.configure_options["match"];
    if (match_script == "*") {
      if ((ret_code != tcl_tst.OK && ret_code != tcl_tst.RETURN) || (result != null && result.getString() != expected_result.getString())) {
print("FAILED  "+test_name+"!"+test_description+"!"+tcl_tst.getResultString(ret_code)+"!");
print("__result: "+result.getString()+"!");
print("expected: "+(expected_result == null ? "null" : expected_result.getString())+"!");
        tcl_tst.failed_tests.push(new R.TestResult(tcl_tst.interp, test_name, test_description, expected_result, result));
	return tcl_tst.ERROR;
      } else {
print("SUCCESS "+test_name+"!"+test_description+"!");
        tcl_tst.success_tests.push(new R.TestResult(tcl_tst.interp, test_name, test_description, expected_result, result));
	return tcl_tst.OK;
      }


    } else {
      tcl_tst.interp.setResultString("runTest match script not yet implemented");
      return tcl_tst.ERROR;
    }
    return tcl_tst.OK;
  },








|







 







|









<



<

>
>







160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234

235
236
237

238
239
240
241
242
243
244
245
246
247
  getProps: function() {
    var tcl_tst = this;
    var props = new Array();
    var result;

    for (var z in tcl_tst.configure_options) {
      if (tcl_tst.configure_options[z] != "undefined") {
        props.push(tcl_tst.interp.string_obj_type.newStringObj("-"+z, -1, "TCLTEST_1"));
      }
    }
    result = tcl_tst.interp.list_obj_type.newListObj(props, props.length);
    tcl_tst.interp.setResult(result);
    return tcl_tst.OK;
  },

................................................................................
    /* Destroy the call frame */
    result = tcl_tst.interp.namespace_obj_type.popStackFrame();

    result = tcl_tst.interp.getResult();
    /* check the result against the expected result */
    var expected_result = test_obj.test_prop["result"];
    if (expected_result == null) {
      expected_result = tcl_tst.interp.string_obj_type.newStringObj("", -1, "TCLTEST_2");
    }
    /* if we have a match configure option use that for comparing  */
    var match_script = tcl_tst.configure_options["match"];
    if (match_script == "*") {
      if ((ret_code != tcl_tst.OK && ret_code != tcl_tst.RETURN) || (result != null && result.getString() != expected_result.getString())) {
print("FAILED  "+test_name+"!"+test_description+"!"+tcl_tst.getResultString(ret_code)+"!");
print("__result: "+result.getString()+"!");
print("expected: "+(expected_result == null ? "null" : expected_result.getString())+"!");
        tcl_tst.failed_tests.push(new R.TestResult(tcl_tst.interp, test_name, test_description, expected_result, result));

      } else {
print("SUCCESS "+test_name+"!"+test_description+"!");
        tcl_tst.success_tests.push(new R.TestResult(tcl_tst.interp, test_name, test_description, expected_result, result));

      }
	/* the calling of the test was ok so return OK and not the ret_code of the test !! */
      return tcl_tst.OK;
    } else {
      tcl_tst.interp.setResultString("runTest match script not yet implemented");
      return tcl_tst.ERROR;
    }
    return tcl_tst.OK;
  },

Changes to rapl_variable_obj_type.js.

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
...
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
...
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
...
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
...
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
...
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
...
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
...
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
...
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
...
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
....
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
....
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
....
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
....
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
....
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
....
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
....
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
....
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
....
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
....
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
    }
    /* Get the string representation */
    var_name = obj_ptr.getString();
    /* Make sure it's not an array name (syntax glue to get/set dict). */
    if (varbl.interp.nameIsArrayName(var_name, varbl.interp.string_obj_type.getStringLength(obj_ptr))) {
      return varbl.TOKEN_VAR_ARRAY_NAME;
    }
    var part1_ptr = varbl.interp.string_obj_type.newStringObj(var_name, -1);
    part1_ptr.incrRefCount();
    var err_msg_ptr = new Array();
    var index_ptr = new Array();
    var_obj_ptr = varbl.lookupSimpleVar(part1_ptr, varbl.FUNCTION_FLAGS_LEAVE_ERR_MSG, /* create_part1 */ 0, err_msg_ptr, index_ptr);
    part1_ptr.decrRefCount();
    if (var_obj_ptr == null) {
      if (typeof err_msg_ptr_ptr != "undefined") {
        err_msg_ptr_ptr[0] = err_msg_ptr[0];
      }
      return varbl.ERROR;
    }
    /* Free the old internal repr and set the new one. */
................................................................................
      }
      var_ptr = frame_ptr.getVariable(name, create);
//print("SEV!"+name+"!"+frame_ptr.variables[name]+"!"+intp.var_frame_ptr.variables[name]+"!"+frame_ptr.toDebugString()+"!"+intp.var_frame_ptr.toDebugString()+"!");
      if (typeof result_var_ptr != "undefined") {
        result_var_ptr[0] = var_ptr;
      }
      var_ptr.obj_ptr = val_obj_ptr;
      val_obj_ptr.incrRefCount();
      var_ptr.link_frame_ptr = null;
      /* Make the object int rep a variable */
      name_obj_ptr.freeIntRep();
      name_obj_ptr.obj_type = intp.variable_obj_type;
      name_obj_ptr.varValue.namespace(frame_ptr.ns_ptr);
      name_obj_ptr.varValue.varPtr(var_ptr);
      if (var_ptr.type & varbl.VAR_UNDEFINED) {
................................................................................
      varbl.handleVariableTrace(name_obj_ptr, null, varbl.TRACE_OP_WRITE, "write");
    } else {
      var_ptr = name_obj_ptr.varValue.varPtr();
      if (var_ptr.type & varbl.VAR_UNDEFINED) {
        var_ptr.type &= ~varbl.VAR_UNDEFINED;
      }
      if (var_ptr.link_frame_ptr == null) {
        val_obj_ptr.incrRefCount();
//print("VA!"+var_ptr+"!"+var_ptr.obj_ptr+"!");
// FIXME that is only the case when we create a namespace variable with the variable command
// using lookupSimpleVar. That should be changed!!!
if (var_ptr.obj_ptr != null) {
//print("setVariable FIXME passed");
  var_ptr.obj_ptr.decrRefCount();
}
        var_ptr.obj_ptr = val_obj_ptr;
//print("set!"+val_obj_ptr+"!");
      } else {                  /* Else handle the link */
        var saved_call_frame;

        savedCallFrame = intp.frame_ptr;
................................................................................
  setVariableStr: function(name, obj_ptr) {
    var varbl = this;
    var intp = varbl.interp;
    var obj = intp.default_obj;
    var name_obj_ptr;
    var result;

    name_obj_ptr = intp.var_obj_type.newStringObj(name, -1);
    name_obj_ptr.incrRefCount();
    result = varbl.setVariable(name_obj_ptr, obj_ptr);
    name_obj_ptr.decrRefCount();
    return result;
  },

  /* ==================== setGlobalVariableStr ================================== */
  setGlobalVariableStr: function(name, obj_ptr) {
    var varbl = this;
    var intp = varbl.interp;
................................................................................
    var varbl = this;
    var intp = varbl.interp;
    var obj = intp.default_obj;
    var name_obj_ptr;
    var val_obj_ptr;
    var result;

    name_obj_ptr = intp.string_obj_type.newStringObj(name, -1);
    val_obj_ptr = intp.string_obj_type.newStringObj(val, -1);
    name_obj_ptr.incrRefCount();
    val_obj_ptr.incrRefCount();
    result = varbl.setVariable(name_obj_ptr, val_obj_ptr);
    name_obj_ptr.decrRefCount();
    val_obj_ptr.decrRefCount();
    return result;
  },

  /* ==================== setVariableLink ================================== */
  setVariableLink: function(name_obj_ptr, target_name_obj_ptr, target_call_frame) {
    var varbl = this;
    var var_name;
................................................................................
  getVariableStr: function(name, flags) {
    var varbl = this;
    var intp = varbl.interp;
    var obj = intp.default_obj;
    var name_obj_ptr;
    var var_obj_ptr;

    name_obj_ptr = intp.string_obj_type.newStringObj(name, -1);
    name_obj_ptr.incrRefCount();
    var_obj_ptr = varbl.getVariable(name_obj_ptr, flags);
    name_obj_ptr.decrRefCount();
    return var_obj_ptr;
  },

  /* ==================== setVarNamespaceVar ================================== */
  setVarNamespaceVar: function(var_ptr) {
    var varbl = this;

................................................................................
        var_ptr.obj_ptr = null;
      }
      if (flags & (varbl.APPEND_VALUE|varbl.LIST_ELEMENT)) {
	if (flags & varbl.LIST_ELEMENT) {               /* Append list element. */
          if (old_value_ptr == null) {
	    old_value_ptr = varbl.interp.default_obj.newObj();
	    var_ptr.obj_ptr = old_value_ptr;
	    old_value_ptr.incrRefCount();    /* Since var is referenced. */
          } else {
            if (old_value_ptr.isShared()) {
	      var_ptr.obj_ptr = old_value_ptr.duplicateObj();
	      old_value_ptr.decrRefCount();
	      old_value_ptr = var_ptr.obj_ptr;
              old_value_ptr.incrRefCount();             /* Since var is referenced. */
            }
          }
          result = varbl.interp.list_obj_type.listObjAppendElement(old_value_ptr, new_value_ptr);
	  if (result != varbl.OK) {
            earlyError = true;
	  }
	} else {				/* Append string. */
	  /*
	   * We append newValuePtr's bytes but don't change its ref count.
	   */
	  if (old_value_ptr == null) {
	    var_ptr.obj_ptr = new_value_ptr;
	    new_value_ptr.incrRefCount();
	  } else {
	    if (old_value_ptr.isShared()) {      /* Append to copy. */
	      var_ptr.obj_ptr = old_value_ptr.duplicateObj();
	      varbl.continuationsCopy(var_ptr.obj_ptr, old_value_ptr);
	      old_value_ptr.decrRefCount();
	      old_value_ptr = var_ptr.obj_ptr;
	      old_value_ptr.incrRefCount();      /* Since var is ref */
	    }
            varbl.interp.string_obj_type.appendObjToObj(old_value_ptr, new_value_ptr);
	  }
	}
      } else {
        if (new_value_ptr != old_value_ptr) {
	  /*
................................................................................
	   * more than swap the objects.
	   */
          if (old_value_ptr == null) {
            /* unset the VAR_UNDEFINED flag */
            var_ptr.type &= ~varbl.VAR_UNDEFINED;
	  }
	  var_ptr.obj_ptr = new_value_ptr;
	  new_value_ptr.incrRefCount();         /* Var is another ref. */
	  if (old_value_ptr != null) {
	    old_value_ptr.decrRefCount();       /* Discard old value. */
	  }
        }
      }
    }
    /*
     * Invoke any write traces for the variable.
     */
................................................................................
      /*
       * If the variable doesn't exist anymore and no-one's using it, then free
       * up the relevant structures and hash table entries.
       */
    }
    if (early_error) {
      if (cleanup_on_early_error) {
        new_value_ptr.decrRefCount();
      }
    }
    if (result_ptr == null) {
      varbl.interp.setErrorCode(["TCL", "WRITE", "VARNAME"]);
    }
    if (varbl.isVarUndefined(var_ptr)) {
      varbl.cleanupVar(var_ptr, array_ptr);
................................................................................
   */
  ptrMakeUpvar: function(other_ptr, my_name, my_flags, index) {
    var varbl = this;
    var my_name_ptr;
    var result;

    if (my_name) {
      my_name_ptr = varbl.interp.string_ob_type.newStringObj(my_name, -1);
      my_name_ptr.incrRefCount();
    } else {
      myNamePtr = null;
    }
    result = varbl.ptrObjMakeUpvar(other_ptr, my_name_ptr, my_flags, index);
    if (my_name_ptr) {
      my_name_ptr.decrRefCount();
    }
    return result;
  },

  /* ==================== ptrObjMakeUpvar ===================================== */
  ptrObjMakeUpvar: function(other_ptr, my_name_ptr, my_flags, index) {
    var varbl = this;
................................................................................
      my_name = my_name_ptr.getString();
      p = my_name.match("[(]");
      if (p >= 0) {
        if (my_name.charAt(my_name.length - 1) == ')') {
	  /*
	   * myName looks like an array reference.
	   */
	  varbl.interp.setResult(varbl.interp.string_obj_type.newStringObj("bad variable name \""+myName+"\": upvar won't create a scalar variable that looks like an array element", -1));
	  varbl.interp.setErrorCode(["TCL", "UPVAR", "LOCAL_ELEMENT"]);
	  return varbl.ERROR;
        }
      }
      /*
       * Lookup and eventually create the new variable. Set the flag bit
       * VAR_LOOKUP_AVOID_RESOLVERS to indicate the special resolution rules for upvar
................................................................................
      if (var_ptr == null) {
        varbl.interp.objVarErrMsg(my_name_ptr, null, "create", err_msg[0], -1);
        varbl.interp.setErrorCode(["TCL", "LOOKUP", "VARNAME", my_name_ptr.getString()]);
        return varbl.ERROR;
      }
    }
    if (var_ptr == other_ptr) {
      varbl.interp.setResult(varbl.interp.string_obj_type.newStringObj("can't upvar from variable to itself", -1));
      varbl.interp.setErrorCode(["TCL", "UPVAR", "SELF"]);
      return varbl.ERROR;
    }
    if (varbl.isVarTraced(var_ptr)) {
      varbl.interp.setResult(varbl.interp.string_obj_type.newStringObj("variable \""+my_name+"\" has traces: can't use for upvar", -1));
      varbl.interp.setErrorCode(["TCL", "UPVAR", "TRACED"]);
      return varbl.ERROR;
    } else {
      if (!varbl.isVarUndefined(var_ptr)) {
        var link_ptr;
        /*
         * The variable already existed. Make sure this variable "varPtr"
         * isn't the same as "otherPtr" (avoid circular links). Also, if it's
	 * not an upvar then it's an error. If it is an upvar, then just
	 * disconnect it from the thing it currently refers to.
	 */
	if (!varbl.isVarLink(var_ptr)) {
	  varbl.interp.setResult(varbl.interp.string_obj_type.newStringObj("variable \""+my_name+"\" already exists", -1));
	  varbl.interp.setErrorCode(["TCL", "UPVAR", "EXISTS"]);
	  return varbl.ERROR;
	}
	link_ptr = var_ptr.link;
	if (link_ptr == other_ptr) {
          return varbl.OK;
	}
................................................................................
      if (!(array_ptr != null
          ? (varbl.isVarInHash(array_ptr) && varbl.getVarNsPtr(array_ptr))
          : (varbl.isVarInHash(other_ptr) && varbl.getVarNsPtr(other_ptr)))
	  && ((my_flags & (varbl.NAMESPACE_LOOKUP_GLOBAL_ONLY | varbl.NAMESPACE_LOOKUP_NAMESPACE_ONLY))
	    || (var_frame_ptr == null)
	    || !var_frame_ptr.hasLocalVars()
	    || (my_name_ptr.getString().search("::") >= 0))) {
          varbl.interp.setResult(varbl.interp.string_obj_type.newStringObj("bad variable name \""+my_name_ptr.getString()+ "\": upvar won't create namespace variable that refers to procedure variable", -1));
          varbl.interp.setErrorCode(["TCL", "UPVAR", "INVERTED"]);
          return varbl.ERROR;
	}
    }
    return varbl.ptrObjMakeUpvar(other_ptr, my_name_ptr, my_flags, index);
  },

................................................................................
print("QUALNS!"+(ns_ptr1 == null ? "<null>" : ns_ptr1.full_name)+"!");
if (ns_ptr1 != null) {
for (var z in ns_ptr1.variables) {
print("z!"+z+"!");
}
}
}
        simple_name_ptr = varbl.interp.string_obj_type.newStringObj(simple_name, -1);
        simple_name_ptr.incrRefCount();
      }
    } else {
      simple_name_ptr = name_ptr;
    }
    if ((var_ptr == null) && (ns_ptr1 != null) && (simple_name != null)) {
      if (typeof ns_ptr1.variables[simple_name] != "undefined") {
        var_ptr = ns_ptr1.variables[simple_name];
................................................................................
    }
    if ((var_ptr == null) && (ns_ptr2 != null) && (simple_name != null)) {
      if (typeof ns_ptr2.variables[simple_name] != "undefined") {
        var_ptr = ns_ptr2.variables[simple_name];
      }
    }
    if (simple_name != name && simple_name != null) {
      simple_name_ptr.decrRefCount();
    }
    if ((var_ptr == null) && (flags & varbl.FUNCTION_FLAGS_LEAVE_ERR_MSG)) {
      varbl.interp.setResult("unknown variable \""+name+"\"");
      varbl.interp.setErrorCode(["RAPL", "LOOKUP", "VARIABLE", name]);
    }
    return var_ptr;
  },

  /* ==================== findNamespaceVar ===================================== */
  findNamespaceVar: function(name, context_ns_ptr, flags) {
    var varbl = this;
    var name_ptr = varbl.interp.string_obj_type.newStringObj(name, -1);
    var var_obj;

    name_ptr.incrRefCount();
    var_obj = varbl.objFindNamespaceVar(name_ptr, context_ns_ptr, flags);
    name_ptr.decrRefCount();
    return var_obj;
  },

  /* ==================== findNamespace ===================================== */
  /*
   *----------------------------------------------------------------------
   *
................................................................................
if (varbl.variable_debug) {
print("lookupSimpleVar ret4!"+var_name+"!");
}
	      return null;
	    }
	  }
	  if (tail != var_name) {
	    tail_ptr = varbl.interp.string_obj_type.newStringObj(tail, -1);
	  } else {
            tail_ptr = var_name_ptr;
	  }
          var_ns_ptr.variables[tail] = new R.Variable(varbl.interp, tail, "VAR_NAMESPACE_VAR VAR_UNDEFINED", varbl.interp.var_frame_ptr, null);
	  var_ptr = var_ns_ptr.variables[tail];
	  var_ptr.namespace = var_ns_ptr;
	  if (look_global) {
................................................................................
	        varbl.setErrorCode(["TCL", "VALUE", "VARNAME"]);
	      }
	      return null;
            }
            part2 = part1_ptr.twoPtrValue.ptr2();
            new_part2 = part2
            if (new_part2) {
              part2_Ptr = varbl.interp.default_obj.string_obj_type.newStringObj(new_Part2, -1);
              part2_ptr.incrRefCount();
            }
            part1_ptr = part1_ptr.twoPtrValue.ptr1();
            obj_type = part1_ptr.obj_type;
            if (obj_type == varbl.interp.local_var_name_obj_type) {
              local_var_name_type_handling = true;
            }
          }
................................................................................
             * name to a new string part2.
             */
            part2 = part1 + i + 1;
            len2 = len1 - i - 2;
            len1 = i;
            new_part2 = part2;
            part2 = new_part2;
            part2_ptr = varbl.interp.string_obj_type.newStringObj(new_part2, -1);
            part2_ptr.incrRefCount();
            /*
             * Free the internal rep of the original part1Ptr, now renamed
             * objPtr, and set it to tclParsedVarNameType.
             */
            obj_ptr = part1_ptr;
            obj_ptr.freeIntRep();
            obj_ptr.obj_type = varbl.interp.parse_var_name_obj_type;
            /*
             * Define a new string object to hold the new part1_ptr, i.e.,
             * the array name. Set the internal rep of obj_ptr, reset
             * obj_type and part1 to contain the references to the array
             * name.
             */
            part1_ptr = varbl.interp.string_obj_type.newStringObj(part1, len1);
            part1_ptr.incrRefCount();
            obj_ptr.twoPtrValue.ptr1(part1_ptr);
            obj_ptr.twoPtrValue.ptr2(part2);
            obj_type = part1_ptr.obj_type;
            part1 = part1_ptr.getString();
            break;
          }
        }
................................................................................
      var_ptr = varbl.lookupSimpleVar(part1_ptr, flags, create_part1, err_msg, index);
      if (var_ptr == null) {
	if ((err_msg != null) && (flags & varbl.FUNCTION_FLAGS_LEAVE_ERR_MSG)) {
          varbl.interp.objVarErrMsg(part1_ptr, part2_ptr, msg, err_msg[0], -1);
          varbl.interp.setErrorCode(["TCL", "LOOKUP", "VARNAME", part1_ptr.getString()]);
	}
	if (new_part2) {
          part2_ptr.decrRefCount();
	}
	return null;
      }
      /*
       * Cache the newly found variable if possible.
       */
      if (index >= 0) {
................................................................................
      if (part2_ptr != null) {
        /*
         * Array element sought: look it up.
         */
        array_ptr[0] = var_ptr;
        var_ptr = lookupArrayElement(part1_ptr, part2_ptr, flags, msg, create_part1, create_part2, var_ptr, -1);
        if (new_part2) {
          part2_ptr.decrRefCount();
        }
      }
    }
    return var_ptr;
  },

  /* ==================== objLookupVar ================================== */
................................................................................
   */
  objLookupVar: function(part1_ptr, part2, flags, msg, create_part1, create_part2, array_ptr) {
    var varbl = this;
    var part2_ptr;
    var res_ptr;

    if (part2) {
      part2_ptr = varbl.interp.string_obj_type.newStringObj(part2, -1);
      part2_ptr.incrRefCount();
    } else {
      part2_ptr = null;
    }
    res_ptr = varbl.objLookupVarEx(part1_ptr, part2_ptr, flags, msg, create_part1, create_part2, array_ptr);
    if (part2_ptr) {
      part2_ptr.decrRefCount();
    }
    return res_ptr;
  },

  /* ==================== unsetVariable ================================== */
  /* Unset a variable.
   * Note: On success unset invalidates all the variable objects created
................................................................................
          }
	  var var_name = varbl.interp.frame_ptr.ns_ptr.full_name+name_obj_ptr.getString();
	  if (varbl.interp.frame_ptr.ns_ptr.full_name == "::") {
	    if ((name_obj_ptr.getString().charAt(0) == ":") && (name_obj_ptr.getString().charAt(1) == ":")) {
              var_name = name_obj_ptr.getString();
	    }
	  }
	  var code_ptr = trace_obj.interp.string_obj_type.newStringObj(trace_obj.getCommand()+" "+var_name+" "+my_part+" "+op_str, -1);
          code_ptr.incrRefCount();
          try {
            varbl.no_trace = true;		    
            var rc = varbl.interp.eval_statement.evalObj(code_ptr);
            varbl.no_trace = false;		    
          } catch(e) {
            trace_obj.interp.setResultString("error in executing "+op_str+" trace: "+code_ptr+"!"+e+"!");
            varbl.no_trace = save_no_trace;
	    return trace_obj.ERROR;
          }
          code_ptr.decrRefCount();
          varbl.no_trace = save_no_trace;
        }
      }
    }
    return rc;
  },

................................................................................
      return varbl.interp.array_obj_type.arraySet(name_obj_ptr, null);
    } else {
      if (retval == varbl.OK) {
        var_ptr = name_obj_ptr.varValue.varPtr();
var my_ptr = varbl.getVariable(name_obj_ptr, 0);
if (my_ptr != null) {
// FIXME temporary !! for unsetting!!
var my_obj = varbl.interp.string_obj_type.newStringObj("", 0);
varbl.setVariable(name_obj_ptr, my_obj);
}
        /* If it's a link call UnsetVariable recursively */
        if (var_ptr.linkFramePtr) {
          var saved_call_frame;

          saved_call_frame = varbl.interp.frame_ptr;







|
|



|







 







|







 







|





|







 







|
|

|







 







|
|
|
|

|
|







 







|
|

|







 







|



|

|












|




|

|







 







|

|







 







|







 







|
|





|







 







|







 







|




|












|







 







|







 







|
|







 







|











|


|

|







 







|







 







|
|







 







|
|













|
|







 







|







 







|







 







|
|





|







 







|
|









|







 







|







93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
...
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
...
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
...
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
...
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
...
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
...
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
...
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
...
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
...
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
....
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
....
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
....
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
....
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
....
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
....
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
....
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
....
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
....
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
....
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
    }
    /* Get the string representation */
    var_name = obj_ptr.getString();
    /* Make sure it's not an array name (syntax glue to get/set dict). */
    if (varbl.interp.nameIsArrayName(var_name, varbl.interp.string_obj_type.getStringLength(obj_ptr))) {
      return varbl.TOKEN_VAR_ARRAY_NAME;
    }
    var part1_ptr = varbl.interp.string_obj_type.newStringObj(var_name, -1, "VARIABLE_OBJ_TYPE_1");
    part1_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_1");
    var err_msg_ptr = new Array();
    var index_ptr = new Array();
    var_obj_ptr = varbl.lookupSimpleVar(part1_ptr, varbl.FUNCTION_FLAGS_LEAVE_ERR_MSG, /* create_part1 */ 0, err_msg_ptr, index_ptr);
    part1_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_1");
    if (var_obj_ptr == null) {
      if (typeof err_msg_ptr_ptr != "undefined") {
        err_msg_ptr_ptr[0] = err_msg_ptr[0];
      }
      return varbl.ERROR;
    }
    /* Free the old internal repr and set the new one. */
................................................................................
      }
      var_ptr = frame_ptr.getVariable(name, create);
//print("SEV!"+name+"!"+frame_ptr.variables[name]+"!"+intp.var_frame_ptr.variables[name]+"!"+frame_ptr.toDebugString()+"!"+intp.var_frame_ptr.toDebugString()+"!");
      if (typeof result_var_ptr != "undefined") {
        result_var_ptr[0] = var_ptr;
      }
      var_ptr.obj_ptr = val_obj_ptr;
      val_obj_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_2");
      var_ptr.link_frame_ptr = null;
      /* Make the object int rep a variable */
      name_obj_ptr.freeIntRep();
      name_obj_ptr.obj_type = intp.variable_obj_type;
      name_obj_ptr.varValue.namespace(frame_ptr.ns_ptr);
      name_obj_ptr.varValue.varPtr(var_ptr);
      if (var_ptr.type & varbl.VAR_UNDEFINED) {
................................................................................
      varbl.handleVariableTrace(name_obj_ptr, null, varbl.TRACE_OP_WRITE, "write");
    } else {
      var_ptr = name_obj_ptr.varValue.varPtr();
      if (var_ptr.type & varbl.VAR_UNDEFINED) {
        var_ptr.type &= ~varbl.VAR_UNDEFINED;
      }
      if (var_ptr.link_frame_ptr == null) {
        val_obj_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_3");
//print("VA!"+var_ptr+"!"+var_ptr.obj_ptr+"!");
// FIXME that is only the case when we create a namespace variable with the variable command
// using lookupSimpleVar. That should be changed!!!
if (var_ptr.obj_ptr != null) {
//print("setVariable FIXME passed");
  var_ptr.obj_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_2");
}
        var_ptr.obj_ptr = val_obj_ptr;
//print("set!"+val_obj_ptr+"!");
      } else {                  /* Else handle the link */
        var saved_call_frame;

        savedCallFrame = intp.frame_ptr;
................................................................................
  setVariableStr: function(name, obj_ptr) {
    var varbl = this;
    var intp = varbl.interp;
    var obj = intp.default_obj;
    var name_obj_ptr;
    var result;

    name_obj_ptr = intp.var_obj_type.newStringObj(name, -1, "VARIABLE_OBJ_TYPE_2");
    name_obj_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_4");
    result = varbl.setVariable(name_obj_ptr, obj_ptr);
    name_obj_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_3");
    return result;
  },

  /* ==================== setGlobalVariableStr ================================== */
  setGlobalVariableStr: function(name, obj_ptr) {
    var varbl = this;
    var intp = varbl.interp;
................................................................................
    var varbl = this;
    var intp = varbl.interp;
    var obj = intp.default_obj;
    var name_obj_ptr;
    var val_obj_ptr;
    var result;

    name_obj_ptr = intp.string_obj_type.newStringObj(name, -1, "VARIABLE_OBJ_TYPE_3");
    val_obj_ptr = intp.string_obj_type.newStringObj(val, -1, "VARIABLE_OBJ_TYPE_4");
    name_obj_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_5");
    val_obj_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_6");
    result = varbl.setVariable(name_obj_ptr, val_obj_ptr);
    name_obj_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_4");
    val_obj_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_5");
    return result;
  },

  /* ==================== setVariableLink ================================== */
  setVariableLink: function(name_obj_ptr, target_name_obj_ptr, target_call_frame) {
    var varbl = this;
    var var_name;
................................................................................
  getVariableStr: function(name, flags) {
    var varbl = this;
    var intp = varbl.interp;
    var obj = intp.default_obj;
    var name_obj_ptr;
    var var_obj_ptr;

    name_obj_ptr = intp.string_obj_type.newStringObj(name, -1, "VARIABLE_OBJ_TYPE_5");
    name_obj_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_7");
    var_obj_ptr = varbl.getVariable(name_obj_ptr, flags);
    name_obj_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_6");
    return var_obj_ptr;
  },

  /* ==================== setVarNamespaceVar ================================== */
  setVarNamespaceVar: function(var_ptr) {
    var varbl = this;

................................................................................
        var_ptr.obj_ptr = null;
      }
      if (flags & (varbl.APPEND_VALUE|varbl.LIST_ELEMENT)) {
	if (flags & varbl.LIST_ELEMENT) {               /* Append list element. */
          if (old_value_ptr == null) {
	    old_value_ptr = varbl.interp.default_obj.newObj();
	    var_ptr.obj_ptr = old_value_ptr;
	    old_value_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_8");    /* Since var is referenced. */
          } else {
            if (old_value_ptr.isShared()) {
	      var_ptr.obj_ptr = old_value_ptr.duplicateObj();
	      old_value_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_7");
	      old_value_ptr = var_ptr.obj_ptr;
              old_value_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_9");             /* Since var is referenced. */
            }
          }
          result = varbl.interp.list_obj_type.listObjAppendElement(old_value_ptr, new_value_ptr);
	  if (result != varbl.OK) {
            earlyError = true;
	  }
	} else {				/* Append string. */
	  /*
	   * We append newValuePtr's bytes but don't change its ref count.
	   */
	  if (old_value_ptr == null) {
	    var_ptr.obj_ptr = new_value_ptr;
	    new_value_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_10");
	  } else {
	    if (old_value_ptr.isShared()) {      /* Append to copy. */
	      var_ptr.obj_ptr = old_value_ptr.duplicateObj();
	      varbl.continuationsCopy(var_ptr.obj_ptr, old_value_ptr);
	      old_value_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_8");
	      old_value_ptr = var_ptr.obj_ptr;
	      old_value_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_11");      /* Since var is ref */
	    }
            varbl.interp.string_obj_type.appendObjToObj(old_value_ptr, new_value_ptr);
	  }
	}
      } else {
        if (new_value_ptr != old_value_ptr) {
	  /*
................................................................................
	   * more than swap the objects.
	   */
          if (old_value_ptr == null) {
            /* unset the VAR_UNDEFINED flag */
            var_ptr.type &= ~varbl.VAR_UNDEFINED;
	  }
	  var_ptr.obj_ptr = new_value_ptr;
	  new_value_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_12");         /* Var is another ref. */
	  if (old_value_ptr != null) {
	    old_value_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_9");       /* Discard old value. */
	  }
        }
      }
    }
    /*
     * Invoke any write traces for the variable.
     */
................................................................................
      /*
       * If the variable doesn't exist anymore and no-one's using it, then free
       * up the relevant structures and hash table entries.
       */
    }
    if (early_error) {
      if (cleanup_on_early_error) {
        new_value_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_10");
      }
    }
    if (result_ptr == null) {
      varbl.interp.setErrorCode(["TCL", "WRITE", "VARNAME"]);
    }
    if (varbl.isVarUndefined(var_ptr)) {
      varbl.cleanupVar(var_ptr, array_ptr);
................................................................................
   */
  ptrMakeUpvar: function(other_ptr, my_name, my_flags, index) {
    var varbl = this;
    var my_name_ptr;
    var result;

    if (my_name) {
      my_name_ptr = varbl.interp.string_ob_type.newStringObj(my_name, -1, "VARIABLE_OBJ_TYPE_6");
      my_name_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_13");
    } else {
      myNamePtr = null;
    }
    result = varbl.ptrObjMakeUpvar(other_ptr, my_name_ptr, my_flags, index);
    if (my_name_ptr) {
      my_name_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_11");
    }
    return result;
  },

  /* ==================== ptrObjMakeUpvar ===================================== */
  ptrObjMakeUpvar: function(other_ptr, my_name_ptr, my_flags, index) {
    var varbl = this;
................................................................................
      my_name = my_name_ptr.getString();
      p = my_name.match("[(]");
      if (p >= 0) {
        if (my_name.charAt(my_name.length - 1) == ')') {
	  /*
	   * myName looks like an array reference.
	   */
	  varbl.interp.setResult(varbl.interp.string_obj_type.newStringObj("bad variable name \""+myName+"\": upvar won't create a scalar variable that looks like an array element", -1, "VARIABLE_OBJ_TYPE_7"));
	  varbl.interp.setErrorCode(["TCL", "UPVAR", "LOCAL_ELEMENT"]);
	  return varbl.ERROR;
        }
      }
      /*
       * Lookup and eventually create the new variable. Set the flag bit
       * VAR_LOOKUP_AVOID_RESOLVERS to indicate the special resolution rules for upvar
................................................................................
      if (var_ptr == null) {
        varbl.interp.objVarErrMsg(my_name_ptr, null, "create", err_msg[0], -1);
        varbl.interp.setErrorCode(["TCL", "LOOKUP", "VARNAME", my_name_ptr.getString()]);
        return varbl.ERROR;
      }
    }
    if (var_ptr == other_ptr) {
      varbl.interp.setResult(varbl.interp.string_obj_type.newStringObj("can't upvar from variable to itself", -1, "VARIABLE_OBJ_TYPE_8"));
      varbl.interp.setErrorCode(["TCL", "UPVAR", "SELF"]);
      return varbl.ERROR;
    }
    if (varbl.isVarTraced(var_ptr)) {
      varbl.interp.setResult(varbl.interp.string_obj_type.newStringObj("variable \""+my_name+"\" has traces: can't use for upvar", -1, "VARIABLE_OBJ_TYPE_9"));
      varbl.interp.setErrorCode(["TCL", "UPVAR", "TRACED"]);
      return varbl.ERROR;
    } else {
      if (!varbl.isVarUndefined(var_ptr)) {
        var link_ptr;
        /*
         * The variable already existed. Make sure this variable "varPtr"
         * isn't the same as "otherPtr" (avoid circular links). Also, if it's
	 * not an upvar then it's an error. If it is an upvar, then just
	 * disconnect it from the thing it currently refers to.
	 */
	if (!varbl.isVarLink(var_ptr)) {
	  varbl.interp.setResult(varbl.interp.string_obj_type.newStringObj("variable \""+my_name+"\" already exists", -1, "VARIABLE_OBJ_TYPE_10"));
	  varbl.interp.setErrorCode(["TCL", "UPVAR", "EXISTS"]);
	  return varbl.ERROR;
	}
	link_ptr = var_ptr.link;
	if (link_ptr == other_ptr) {
          return varbl.OK;
	}
................................................................................
      if (!(array_ptr != null
          ? (varbl.isVarInHash(array_ptr) && varbl.getVarNsPtr(array_ptr))
          : (varbl.isVarInHash(other_ptr) && varbl.getVarNsPtr(other_ptr)))
	  && ((my_flags & (varbl.NAMESPACE_LOOKUP_GLOBAL_ONLY | varbl.NAMESPACE_LOOKUP_NAMESPACE_ONLY))
	    || (var_frame_ptr == null)
	    || !var_frame_ptr.hasLocalVars()
	    || (my_name_ptr.getString().search("::") >= 0))) {
          varbl.interp.setResult(varbl.interp.string_obj_type.newStringObj("bad variable name \""+my_name_ptr.getString()+ "\": upvar won't create namespace variable that refers to procedure variable", -1, "VARIABLE_OBJ_TYPE_11"));
          varbl.interp.setErrorCode(["TCL", "UPVAR", "INVERTED"]);
          return varbl.ERROR;
	}
    }
    return varbl.ptrObjMakeUpvar(other_ptr, my_name_ptr, my_flags, index);
  },

................................................................................
print("QUALNS!"+(ns_ptr1 == null ? "<null>" : ns_ptr1.full_name)+"!");
if (ns_ptr1 != null) {
for (var z in ns_ptr1.variables) {
print("z!"+z+"!");
}
}
}
        simple_name_ptr = varbl.interp.string_obj_type.newStringObj(simple_name, -1, "VARIABLE_OBJ_TYPE_12");
        simple_name_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_14");
      }
    } else {
      simple_name_ptr = name_ptr;
    }
    if ((var_ptr == null) && (ns_ptr1 != null) && (simple_name != null)) {
      if (typeof ns_ptr1.variables[simple_name] != "undefined") {
        var_ptr = ns_ptr1.variables[simple_name];
................................................................................
    }
    if ((var_ptr == null) && (ns_ptr2 != null) && (simple_name != null)) {
      if (typeof ns_ptr2.variables[simple_name] != "undefined") {
        var_ptr = ns_ptr2.variables[simple_name];
      }
    }
    if (simple_name != name && simple_name != null) {
      simple_name_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_12");
    }
    if ((var_ptr == null) && (flags & varbl.FUNCTION_FLAGS_LEAVE_ERR_MSG)) {
      varbl.interp.setResult("unknown variable \""+name+"\"");
      varbl.interp.setErrorCode(["RAPL", "LOOKUP", "VARIABLE", name]);
    }
    return var_ptr;
  },

  /* ==================== findNamespaceVar ===================================== */
  findNamespaceVar: function(name, context_ns_ptr, flags) {
    var varbl = this;
    var name_ptr = varbl.interp.string_obj_type.newStringObj(name, -1, "VARIABLE_OBJ_TYPE_12");
    var var_obj;

    name_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_15");
    var_obj = varbl.objFindNamespaceVar(name_ptr, context_ns_ptr, flags);
    name_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_13");
    return var_obj;
  },

  /* ==================== findNamespace ===================================== */
  /*
   *----------------------------------------------------------------------
   *
................................................................................
if (varbl.variable_debug) {
print("lookupSimpleVar ret4!"+var_name+"!");
}
	      return null;
	    }
	  }
	  if (tail != var_name) {
	    tail_ptr = varbl.interp.string_obj_type.newStringObj(tail, -1, "VARIABLE_OBJ_TYPE_13");
	  } else {
            tail_ptr = var_name_ptr;
	  }
          var_ns_ptr.variables[tail] = new R.Variable(varbl.interp, tail, "VAR_NAMESPACE_VAR VAR_UNDEFINED", varbl.interp.var_frame_ptr, null);
	  var_ptr = var_ns_ptr.variables[tail];
	  var_ptr.namespace = var_ns_ptr;
	  if (look_global) {
................................................................................
	        varbl.setErrorCode(["TCL", "VALUE", "VARNAME"]);
	      }
	      return null;
            }
            part2 = part1_ptr.twoPtrValue.ptr2();
            new_part2 = part2
            if (new_part2) {
              part2_Ptr = varbl.interp.default_obj.string_obj_type.newStringObj(new_Part2, -1, "VARIABLE_OBJ_TYPE_14");
              part2_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_16");
            }
            part1_ptr = part1_ptr.twoPtrValue.ptr1();
            obj_type = part1_ptr.obj_type;
            if (obj_type == varbl.interp.local_var_name_obj_type) {
              local_var_name_type_handling = true;
            }
          }
................................................................................
             * name to a new string part2.
             */
            part2 = part1 + i + 1;
            len2 = len1 - i - 2;
            len1 = i;
            new_part2 = part2;
            part2 = new_part2;
            part2_ptr = varbl.interp.string_obj_type.newStringObj(new_part2, -1, "VARIABLE_OBJ_TYPE_15");
            part2_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_17");
            /*
             * Free the internal rep of the original part1Ptr, now renamed
             * objPtr, and set it to tclParsedVarNameType.
             */
            obj_ptr = part1_ptr;
            obj_ptr.freeIntRep();
            obj_ptr.obj_type = varbl.interp.parse_var_name_obj_type;
            /*
             * Define a new string object to hold the new part1_ptr, i.e.,
             * the array name. Set the internal rep of obj_ptr, reset
             * obj_type and part1 to contain the references to the array
             * name.
             */
            part1_ptr = varbl.interp.string_obj_type.newStringObj(part1, len1, "VARIABLE_OBJ_TYPE_16");
            part1_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_18");
            obj_ptr.twoPtrValue.ptr1(part1_ptr);
            obj_ptr.twoPtrValue.ptr2(part2);
            obj_type = part1_ptr.obj_type;
            part1 = part1_ptr.getString();
            break;
          }
        }
................................................................................
      var_ptr = varbl.lookupSimpleVar(part1_ptr, flags, create_part1, err_msg, index);
      if (var_ptr == null) {
	if ((err_msg != null) && (flags & varbl.FUNCTION_FLAGS_LEAVE_ERR_MSG)) {
          varbl.interp.objVarErrMsg(part1_ptr, part2_ptr, msg, err_msg[0], -1);
          varbl.interp.setErrorCode(["TCL", "LOOKUP", "VARNAME", part1_ptr.getString()]);
	}
	if (new_part2) {
          part2_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_14");
	}
	return null;
      }
      /*
       * Cache the newly found variable if possible.
       */
      if (index >= 0) {
................................................................................
      if (part2_ptr != null) {
        /*
         * Array element sought: look it up.
         */
        array_ptr[0] = var_ptr;
        var_ptr = lookupArrayElement(part1_ptr, part2_ptr, flags, msg, create_part1, create_part2, var_ptr, -1);
        if (new_part2) {
          part2_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_15");
        }
      }
    }
    return var_ptr;
  },

  /* ==================== objLookupVar ================================== */
................................................................................
   */
  objLookupVar: function(part1_ptr, part2, flags, msg, create_part1, create_part2, array_ptr) {
    var varbl = this;
    var part2_ptr;
    var res_ptr;

    if (part2) {
      part2_ptr = varbl.interp.string_obj_type.newStringObj(part2, -1, "VARIABLE_OBJ_TYPE_17");
      part2_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_19");
    } else {
      part2_ptr = null;
    }
    res_ptr = varbl.objLookupVarEx(part1_ptr, part2_ptr, flags, msg, create_part1, create_part2, array_ptr);
    if (part2_ptr) {
      part2_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_16");
    }
    return res_ptr;
  },

  /* ==================== unsetVariable ================================== */
  /* Unset a variable.
   * Note: On success unset invalidates all the variable objects created
................................................................................
          }
	  var var_name = varbl.interp.frame_ptr.ns_ptr.full_name+name_obj_ptr.getString();
	  if (varbl.interp.frame_ptr.ns_ptr.full_name == "::") {
	    if ((name_obj_ptr.getString().charAt(0) == ":") && (name_obj_ptr.getString().charAt(1) == ":")) {
              var_name = name_obj_ptr.getString();
	    }
	  }
	  var code_ptr = trace_obj.interp.string_obj_type.newStringObj(trace_obj.getCommand()+" "+var_name+" "+my_part+" "+op_str, -1, "VARIABLE_OBJ_TYPE_18");
          code_ptr.incrRefCount("I_VARIABLE_OBJ_TYPE_20");
          try {
            varbl.no_trace = true;		    
            var rc = varbl.interp.eval_statement.evalObj(code_ptr);
            varbl.no_trace = false;		    
          } catch(e) {
            trace_obj.interp.setResultString("error in executing "+op_str+" trace: "+code_ptr+"!"+e+"!");
            varbl.no_trace = save_no_trace;
	    return trace_obj.ERROR;
          }
          code_ptr.decrRefCount("D_VARIABLE_OBJ_TYPE_17");
          varbl.no_trace = save_no_trace;
        }
      }
    }
    return rc;
  },

................................................................................
      return varbl.interp.array_obj_type.arraySet(name_obj_ptr, null);
    } else {
      if (retval == varbl.OK) {
        var_ptr = name_obj_ptr.varValue.varPtr();
var my_ptr = varbl.getVariable(name_obj_ptr, 0);
if (my_ptr != null) {
// FIXME temporary !! for unsetting!!
var my_obj = varbl.interp.string_obj_type.newStringObj("", 0, "VARIABLE_OBJ_TYPE_19");
varbl.setVariable(name_obj_ptr, my_obj);
}
        /* If it's a link call UnsetVariable recursively */
        if (var_ptr.linkFramePtr) {
          var saved_call_frame;

          saved_call_frame = varbl.interp.frame_ptr;

Changes to simple_tests/t26.test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
tcltest::test simple-26.0 "t26.tcl" -body {
set ::result [list]
set __rootNamespace ::itcl
namespace eval ::itcl {
    proc object {args} {lappend ::result "object called!$args!" }
    proc body {args} {lappend ::result "body called!$args!" }
namespace ensemble create
}
namespace ensemble configure $__rootNamespace -map [list \
    object ${__rootNamespace}::object \
    body ${__rootNamespace}::body \
]

::itcl object xx
::itcl body yy
return $::result
} -result {{object called!xx!} {body called!yy!}}





|




|



|

|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
tcltest::test simple-26.0 "t26.tcl" -body {
set ::result [list]
set __rootNamespace ::itcl
namespace eval ::itcl {
    proc object {args} {lappend ::result "object called!$args!" }
    proc my_body {args} {lappend ::result "my_body called!$args!" }
namespace ensemble create
}
namespace ensemble configure $__rootNamespace -map [list \
    object ${__rootNamespace}::object \
    my_body ${__rootNamespace}::my_body \
]

::itcl object xx
::itcl my_body yy
return $::result
} -result {{object called!xx!} {my_body called!yy!}}