RAPL

Diff
Login

Diff

Differences From Artifact [27f64b1050]:

To Artifact [5a91eaf6f4]:


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
  var sqrt = "";
  sqrt = Math.sqrt; // "publish" other Math.* functions as needed

  /* ==================== command expr ===================================== */
  interp.registerCommand("::expr", function (interp, args) {
    var result = null;
    var retcode;
print("::expr!"+args+"!");
    if (args.length == 2) {
      result = new Array();
      /* seems to be a braced expression argument */
      retcode = interp.eval_expression.evalExpression(args[1], result);
print("::expr retcode!"+retcode+"!"+result[0]+"!");
      // for being compatible with Tcl we need to return 0 or 1 instead of true or false!!

      if (result == "true") {
        return interp.objectify("1");
      }
      if (result == "false") {
        return interp.objectify("0");


      }


      return result;
    }
    var str = args.splice(0, args.length).join(' ');
    retcode = interp.eval_expression.evalExpression(args[1], result);
    // for being compatible with Tcl we need to return 0 or 1 instead of true or false!!
    if (result == "true") {
      return interp.objectify("1");
    }
    if (result == "false") {
      return interp.objectify("0");


    }


    return result
  });

  /* ==================== command file join ===================================== */
  interp.registerSubCommand("::file", "join", function (interp, args) {
    args.shift();
    this.requireMinArgc(args, 1, "file join", "");
    var path = args.shift();







<




<

>
|
|
|
|
|
>
>
|
>
>
|





|
|
|
|
>
>
|
>
>
|







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
  var sqrt = "";
  sqrt = Math.sqrt; // "publish" other Math.* functions as needed

  /* ==================== command expr ===================================== */
  interp.registerCommand("::expr", function (interp, args) {
    var result = null;
    var retcode;

    if (args.length == 2) {
      result = new Array();
      /* seems to be a braced expression argument */
      retcode = interp.eval_expression.evalExpression(args[1], result);

      // for being compatible with Tcl we need to return 0 or 1 instead of true or false!!
      result = result[0];
      if (result.toString() == "true") {
        result = interp.objectify("1");
      } else {
        if (result.toString() == "false") {
          result = interp.objectify("0");
        } else {
          result = interp.objectify(result);
	}
      }
      interp.default_obj.setResult(result);
      return retcode;
    }
    var str = args.splice(0, args.length).join(' ');
    retcode = interp.eval_expression.evalExpression(args[1], result);
    // for being compatible with Tcl we need to return 0 or 1 instead of true or false!!
    if (result == "true") {
      result = interp.objectify("1");
    } else {
      if (result == "false") {
        result = interp.objectify("0");
      } else {
        result = interp.objectify(result);
      }
    }
    interp.default_obj.setResult(result);
    return retcode;
  });

  /* ==================== command file join ===================================== */
  interp.registerSubCommand("::file", "join", function (interp, args) {
    args.shift();
    this.requireMinArgc(args, 1, "file join", "");
    var path = args.shift();
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
      interp.setVar(args[2],interp.statement_parser.objectify(reply));
      return reply.length;
    } else return reply;
  });

  /* ==================== command if ===================================== */
  interp.registerCommand("::if", function (interp, args) {
    args.shift();
    this.requireMinArgc(args, 2, "if", "");

    var cond = args.shift();
    var body = args.shift();
    cond = cond.toExprTree();

    var res = interp.eval_statement.evalExprSubTree(cond, null, 0);




    res = res.toBoolean();
    if (res) {

      var result = interp.eval_statement.eval(body);
      return result;
    }






    if (args.length == 0) {
      return;
    }


    for (var i = 0; i < args.length; ) {



      switch (args[i].toString()) {

      case "else":





        this.requireExactArgc(args, i + 2, "if", "");





        return interp.eval_statement.eval(args[i+1]);
      case "elseif":
        this.requireMinArgc(args, i + 3, "if", "");
        test = interp.statement_parser.objectify(interp.eval_statement.eval("::set _ "+args[i+1].toString()));






        if (test.toBoolean()) {



          return interp.eval_statement.eval(args[i+2].toString());
        }


        i += 3;
        break;
      default:
        throw "Expected 'else' or 'elseif', got "+ args[i];
      }
    }


  });

  /* ==================== command incr ===================================== */
  interp.registerCommand("::incr", function (interp, args) {
    args.shift();
    this.requireArgcRange(args, 1, 2, "incr", "");
    var name = args.shift();







|
|
>
|
|
|
>
|
>
>
>
>
|
|
>
|
|
|
>
>
>
>
>
>
|
|
|
>
>
|
>
>
>
|
>
|
>
>
>
>
>
|
>
>
>
>
>
|
|
|
<
>
>
>
>
>
>
|
>
>
>
|
|
>
>
|
|
<
<


>
>







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
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
323
324
325
326


327
328
329
330
331
332
333
334
335
336
337
      interp.setVar(args[2],interp.statement_parser.objectify(reply));
      return reply.length;
    } else return reply;
  });

  /* ==================== command if ===================================== */
  interp.registerCommand("::if", function (interp, args) {
    var idx = 1;
    var bool = new Array();
    var retcode;
    var current = 1;
    var falsebody = 0;
    var err = false;
    var argc = args.length;

    if (args.length >= 3) {
      while (1) {
        /* Far not enough arguments given! */
        if (current >= argc) {
          err = true;
          break;
        }
        if ((retval = interp.eval_expression.getBoolFromExpr(args[current++], bool)) != interp.OK) {
          return retval;
	}
	bool = bool[0];
        /* There lacks something, isn't it? */
        if (current >= argc) {
          err = true;
	  break;
        }
        if (args[current] == "then") {
          current++;
	}
        /* Tsk tsk, no then-clause? */
        if (current >= argc) {
          err = true;
	  break;
	}
        if (bool) {
          return interp.eval_statement.evalObj(args[current]);
	}
        /* Ok: no else-clause follows */
        if (++current >= argc) {
          interp.default_obj.setResult(intp.string_obj_type.newEmptyStringObj());
          return interp.OK;
        }
        falsebody = current++;
        if (args[falsebody] == "else") {
          /* IIICKS - else-clause isn't last cmd? */
          if (current != argc - 1) {
            err = true;
	    break
	  }
          return interp.eval_statement.evalObj(args[current]);
        } else {
          if (args[falsebody] == "elseif") {

            /* Ok: elseif follows meaning all the stuff
             * again (how boring...) 
	     */
            continue;
	  } else {
            /* OOPS - else-clause is not last cmd? */
            if (falsebody != argc - 1) {
              err = true;
	      break;
	    }
            return interp.eval_statement.evalObj(args[falsebody]);
	  }
	}
      }
      if (!err) {
        return interp.OK;


      }
    }
    interp.wrongNumArgs(1, args, "condition ?then? trueBody ?elseif ...? ?else? falseBody");
    return interp.ERROR;
  });

  /* ==================== command incr ===================================== */
  interp.registerCommand("::incr", function (interp, args) {
    args.shift();
    this.requireArgcRange(args, 1, 2, "incr", "");
    var name = args.shift();
445
446
447
448
449
450
451
452

453
454
455
456
457
458
459
460
461
462
463
464
    args.shift();
    var result = eval(args[0].toString());
    return result;
  });

  /* ==================== command puts ===================================== */
  interp.registerCommand("::puts", function (interp, args) {
    args.shift();

    this.requireMinArgc(args, 1, "puts", "");
    if ((args[0] == "stderr") || (args[0] == "stdout")) {
      args.shift();
    }
    var val = args.shift();
    print(val);
    var result = interp.objectify("");
    return result;
  });

  /* ==================== command proc ===================================== */
  interp.registerCommand("::proc", function (interp, args) {







|
>

|
|

|







491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
    args.shift();
    var result = eval(args[0].toString());
    return result;
  });

  /* ==================== command puts ===================================== */
  interp.registerCommand("::puts", function (interp, args) {
print("::puts!"+args+"!");
    var idx = 1;
    this.requireMinArgc(args, 1, "puts", "");
    if ((args[1] == "stderr") || (args[1] == "stdout")) {
      idx++;
    }
    var val = args[idx];
    print(val);
    var result = interp.objectify("");
    return result;
  });

  /* ==================== command proc ===================================== */
  interp.registerCommand("::proc", function (interp, args) {