1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
-
+
-
+
+
+
+
+
+
+
+
-
+
+
+
|
/*====================================================
* rapl_register_cmd.js "A Tcl like language implementation in Javascript named WebRAPL
* (Web Rapid Application Programming Language)"
*
* registration of base built in commands for RAPL
* registration of core built in commands for RAPL
*
* Released under the same terms as Tcl itself.
* (BSD license found at <http://www.tcl.tk/software/tcltk/license.html>)
*
* Based on Picol by Salvatore Sanfilippo (<http://antirez.com/page/picol>)
* (c) Stéphane Arnold 2007
* Richard Suchenwirth 2007: cleanup, additions
* Arnulf Wiedemann 2011: a lot of additions for Tcl 8.6 commands
*/
RP.add("rapl-register-cmd", function(R, name) {
RP.add("rapl-pkg-core", function(R, name) {
function PkgCore(interp) {
R.log('constructor called', '2.life', 'PkgCore', true);
// kweight
var pkg_core = this;
pkg_core.interp = interp;
var constructor = pkg_core.constructor;
PkgCore.superclass.constructor.apply(pkg_core, arguments);
function registerCmds(interp) {
R.Base.pkg_core_oid++;
pkg_core.oid = R.Base.pkg_core_oid;
//---------------------------------- Commands in alphabetical order
/* ==================== command append ===================================== */
interp.registerCommand("::append", function (interp, args) {
args.shift();
this.requireMinArgc(args, 1, "append", "");
var var_name = args.shift().toString();
|
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
|
-
+
|
if (args.length != 4 && args.length != 5) {
interp.wrongNumArgs(1, args, "name arglist ?statics? body");
return interp.ERROR;
}
if (args.length == 4) {
return interp.command_obj_type.createProcedure(args[1], args[2], null, args[3]);
} else {
return interp.command_obj_type.createProcedure(args[1], args[2], args[3], argvs[4]);
return interp.command_obj_type.createProcedure(args[1], args[2], args[3], argv[4]);
}
});
/* ==================== command regexp ===================================== */
interp.registerCommand("::regexp", function (interp, args) {
var regcomp_flags = 0;
var regexp;
|
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
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
627
628
629
630
631
632
633
634
635
636
637
638
|
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
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
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
|
+
+
+
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
|
interp.registerCommand("::rename", function (interp, args) {
this.requireExactArgc(args, 3, "rename", "");
interp.renameCommand(args[1], args[2]);
});
/* ==================== command return ===================================== */
interp.registerCommand("::return", function (interp, args) {
var core_cmd = interp.core_pkg;
var errorcode = null;
var errorinfo = null;
var level = 1;
var return_code = interp.OK;
var options = null;
var stack_trace_obj = null;
var error_code_obj = null;
var allowed_codes = new Object();
var allowed_options = new Object();
var num_option_fields = new Array();
var num_options = new Array();
var result = new Array();
var result = new Array();
var r = "";
var option_flags = new Array();
var options = new Array();
var error_msg = new Array();
var processed_args = new Array();
allowed_codes["ok"] = 0;
allowed_codes["error"] = 1;
allowed_codes["return"] = 2;
allowed_codes["break"] = 3;
allowed_codes["continue"] = 4;
allowed_codes["0"] = 0;
allowed_codes["1"] = 1;
allowed_codes["2"] = 2;
allowed_codes["3"] = 3;
allowed_codes["4"] = 4;
allowed_options["-code"] = 1;
allowed_options["-errorcode"] = 1;
allowed_options["-errorinfo"] = 1;
allowed_options["-level"] = 1;
allowed_options["-options"] = 1;
interp.eval_statement.code = interp.RETURN;
var r = "";
if (args.length == 1) {
/* seems to be a return value only */
r = args.shift();
}
var options = interp.getOptions(allowed_options, "::return", args.slice(1), num_option_fields, num_options);
num_option_fields = num_option_fields[0];
num_options = num_options[0];
if (args.length - num_option_fields > 2) {
throw "usage: return ?option value ...? ?result?"
if (interp.getCallOptions(core_cmd.return_options, args.slice(1), "return", option_flags, options, error_msg, processed_args) != interp.OK) {
interp.setResultString(error_msg[0]);
return interp.ERROR;
}
processed_args = processed_args[0];
option_flags = option_flags[0];
options = options[0];
if (args.length - processed_args > 2) {
interp.setResultString("usage: return ?option value ...? ?result?");
return interp.ERROR;
}
/* take care of command as args[0] */
if (typeof options["-errorcode"] != "undefined") {
errorcode = options["-errorcode"] ;
if (processed_args > 0) {
processed_args++;
}
if (option_flags & core_cmd.return_options.RETURN_OPT_ERRORCODE) {
error_code_obj = options["-errorcode"] ;
throw "return -errorcode not yet implemented"
}
if (typeof options["-code"] != "undefined") {
if (option_flags & core_cmd.return_options.RETURN_OPT_CODE) {
code = options["-code"];
if (interp.return_code_obj_type.getReturnCode(code, result) == interp.ERROR) {
return interp.ERROR;
}
return_code = result[0];
}
if (typeof options["-errorinfo"] != "undefined") {
errorinfo = options["-errorinfo"] ;
if (option_flags & core_cmd.return_options.RETURN_OPT_ERRORINFO) {
error_info_obj = options["-errorinfo"] ;
throw "return -errorinfo not yet implemented"
}
if (typeof options["-level"] != "undefined") {
level = options["-level"];
throw "return -level not yet implemented"
}
if (typeof options["-options"] != "undefined") {
if (option_flags & core_cmd.return_options.RETURN_OPT_LEVEL) {
var level_obj = options["-level"];
level = new Array();
if (interp.int_obj_type.getLong(level_obj, level) != interp.OK || level[0] < 0) {
interp.setResultFormatted("bad level \"%#s\"", level_obj);
return interp.ERROR;
}
}
if (option_flags & core_cmd.return_options.RETURN_OPT_OPTIONS) {
options = options["-options"];
throw "return -options not yet implemented"
interp.setResultString("return -options not yet implemented");
return interp.ERROR;
}
if (args.length - num_option_fields > 1) {
// if (processed_args != args.length - 1 && processed_args != args.length) {
r = args[num_option_fields + 1];
interp.setResult(r);
// interp.wrongNumArgs(1, args, "?-code code? ?-errorinfo stacktrace? ?-level level? ?result?");
// return interp.ERROR;
// }
/* If a stack trace is supplied and code is error, set the stack trace */
if (stack_trace_obj && return_code == interp.ERROR) {
interp.setStackTrace(stack_trace_obj);
}
/* If an error code list is supplied, set the global $errorCode */
if (error_code_obj && return_code == interp.ERROR) {
interp.variable_obj_type.setGlobalVariableStr("errorCode", error_code_obj);
}
interp.return_code = return_code;
interp.return_level = level;
if (processed_args == args.length - 1) {
interp.setResult(args[processed_args]);
}
return interp.RETURN;
});
/* ==================== command scan ===================================== */
interp.registerCommand("::scan", function (interp, args) {
this.requireMinArgc(args, 2, "scan", "");
throw "scan not yet implemented";
|
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
|
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
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
|
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
txt = args.shift();
}
for (var i = interp.eval_statement.level-1; i >= 0; i--) {
print("LEVEL_INFO!"+i+"!"+txt+"!"+interp.level_infos[i]+"!");
}
});
R.log('constructor end', '2.life', 'PkgCore', true);
}
var RETURN_OPT_CODE = 1;
var RETURN_OPT_ERRORCODE = 2;
var RETURN_OPT_ERRORINFO = 4;
var RETURN_OPT_LEVEL = 8;
var RETURN_OPT_OPTIONS = 16;
R.registerCmds = registerCmds;
R.extend(PkgCore, R.Token, {
my_name: "PkgCore",
return_options: {
RETURN_OPT_CODE: 1,
"1": "-code",
"-code": {
opt_name: "-code",
opt_code: RETURN_OPT_CODE,
opt_val: 1,
},
RETURN_OPT_ERRORCODE: 2,
"2": "-errorcode",
"-errorcode": {
opt_name: "-errorcode",
opt_code: RETURN_OPT_ERRORCODE,
opt_val: 1,
},
RETURN_OPT_ERRORINFO: 4,
"4": "-errorinfo",
"-errorinfo": {
opt_name: "-errorinfo",
opt_code: RETURN_OPT_ERRORINFO,
opt_val: 1,
},
RETURN_OPT_LEVEL: 8,
"8": "-level",
"-level": {
opt_name: "-level",
opt_code: RETURN_OPT_LEVEL,
opt_val: 1,
},
RETURN_OPT_OPTIONS: 16,
"16": "-options",
"-options": {
opt_name: "-options",
opt_code: RETURN_OPT_OPTIONS,
opt_val: 1,
},
},
});
PkgCore.prototype.constructor = PkgCore;
R.PkgCore = PkgCore;
}, "0.0.1", {});
|