RAPL

Diff
Login

Diff

Differences From Artifact [deb6fa4e5a]:

To Artifact [41ac670b41]:


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



747
748
749
750
751


752
753
754


755
756
757
758



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
797

798
799
800
801
802
803
804
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
747
748
749


750
751
752


753
754
755



756
757
758
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

797
798
799
800
801
802
803
804







-
-
+
+

-
-
+
+

-
-
-
-
+
+
+
+


-
-
+
+

-
-
+
+

-
-
-
+
+
+



-
-
+
+

-
-
+
+

-
-
-
+
+
+



-
-
+
+




-
-
+
+


-
+




-
-
+
+



-
-
+
+


-
+




-
-
-
+
+
+

-
+

-
+







    var re = new RegExp("^[-].*");
    if (args.length > 3) {
      for (body_start_idx = 1; body_start_idx < args.length; body_start_idx++) {
        my_arg = args[body_start_idx].toString();
        if (my_arg.match(re)) {
          if (my_arg == "-exact") {
            if (have_exact_opt != 0) {
	      throw 'bad option "-exact": -exact option already found'
	    }
              throw 'bad option "-exact": -exact option already found'
            }
            if (have_glob_opt != 0) {
	      throw 'bad option "-exact": -glob option already found'
	    }
              throw 'bad option "-exact": -glob option already found'
            }
            if (have_regexp_opt != 0) {
	      throw 'bad option "-exact": -regexp option already found'
	    }
	    have_exact_opt = 1;
	  }
              throw 'bad option "-exact": -regexp option already found'
            }
            have_exact_opt = 1;
          }
          if (my_arg == "-glob") {
            if (have_exact_opt != 0) {
	      throw 'bad option "-glob": -exact option already found'
	    }
              throw 'bad option "-glob": -exact option already found'
            }
            if (have_regexp_opt != 0) {
	      throw 'bad option "-glob": -regexp option already found'
	    }
              throw 'bad option "-glob": -regexp option already found'
            }
            if (have_glob_opt != 0) {
	      throw 'bad option "-glob": -glob option already found'
	    }
	    have_glob_opt = 1;
                throw 'bad option "-glob": -glob option already found'
            }
            have_glob_opt = 1;
          }
          if (my_arg == "-regexp") {
            if (have_regexp_opt != 0) {
	      throw 'bad option "-regexp": -regexp option already found'
	    }
              throw 'bad option "-regexp": -regexp option already found'
            }
            if (have_exact_opt != 0) {
	      throw 'bad option "-regexp": -exact option already found'
	    }
              throw 'bad option "-regexp": -exact option already found'
            }
            if (have_glob_opt != 0) {
	      throw 'bad option "-regexp": -glob option already found'
	    }
	    have_regexp_opt = 1;
              throw 'bad option "-regexp": -glob option already found'
            }
            have_regexp_opt = 1;
          }
          if (my_arg == "-nocase") {
            if (have_nocase_opt != 0) {
	      throw 'bad option "-nocase": -nocase option already found'
	    }
              throw 'bad option "-nocase": -nocase option already found'
            }
            have_nocase_opt = 1;
          }
          if (my_arg == "-matchvar") {
            if (have_matchvar_opt != 0) {
	      throw 'bad option "-matchvar": -matchvar option already found'
	    }
              throw 'bad option "-matchvar": -matchvar option already found'
            }
            if (have_regexp_opt == 0) {
              throw '-matchvar option requires -regexp option'
	    }
            }
            have_matchvar_opt = 1;
            if (body_start_idx > args.length-1) {
              throw usage;
            }
	    body_start_idx++;
	    matchvar = args[body_start_idx].toString();
            body_start_idx++;
            matchvar = args[body_start_idx].toString();
          }
          if (my_arg == "-indexvar") {
            if (have_indexvar_opt != 0) {
	      throw 'bad option "-indexvar": -indexvar option already found'
	    }
              throw 'bad option "-indexvar": -indexvar option already found'
            }
            if (have_regexp_opt == 0) {
              throw '-indexvar option requires -regexp option'
	    }
            }
            have_indexvar_opt = 1;
            if (body_start_idx > args.length-1) {
              throw usage;
            }
	    body_start_idx++;
	    indexvar = args[body_start_idx].toString();
	  }
            body_start_idx++;
            indexvar = args[body_start_idx].toString();
          }
          if (my_arg == "--") {
	    body_start_idx++;
            body_start_idx++;
            break;
	  }
          }
        } else {
          break;
        }
      }
      if (body_start_idx == args.length-1) {
        throw usage;
      }
818
819
820
821
822
823
824
825

826
827
828


829
830
831

832
833
834

835
836
837
838
839
840
841



842
843

844
845
846
847
848
849
850
851
852
853
854
855
856
857


858
859
860
861
862
863
864


865
866
867
868
869
870
871
872
873
874
875
876
877

878
879
880
881
882
883
884
885
886
887
888
889
890
891


892
893
894


895
896
897
898

899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915


916
917
918
919



920
921
922
923
924
925
926


927
928
929
930
931
932
933
934
935







936
937
938
939
940
941


942
943
944
945
946
947
948



949
950
951
952
953
954
955
818
819
820
821
822
823
824

825
826


827
828
829
830

831
832
833

834
835
836
837
838
839


840
841
842
843

844
845
846
847
848
849
850
851
852
853
854
855
856


857
858
859
860
861
862
863


864
865
866
867
868
869
870
871
872
873
874
875
876
877

878
879
880
881
882
883
884
885
886
887
888
889
890


891
892
893


894
895
896
897
898

899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914


915
916
917



918
919
920
921
922
923
924
925


926
927
928
929
930
931





932
933
934
935
936
937
938
939
940
941
942


943
944
945
946
947
948
949


950
951
952
953
954
955
956
957
958
959







-
+

-
-
+
+


-
+


-
+





-
-
+
+
+

-
+












-
-
+
+





-
-
+
+












-
+












-
-
+
+

-
-
+
+



-
+















-
-
+
+

-
-
-
+
+
+





-
-
+
+




-
-
-
-
-
+
+
+
+
+
+
+




-
-
+
+





-
-
+
+
+







      parser = new R.Parser(args[args.length-1].toString());
      body = new Array();
      while (parser.type != interp.TOKEN_EOF) {
        token = parser.getToken();
        if (parser.type == interp.TOKEN_EOF) {
          break;
        }
	if ((parser.type == interp.TOKEN_EOL) || (parser.type == interp.TOKEN_WORD_SEP)) {
        if ((parser.type == interp.TOKEN_EOL) || (parser.type == interp.TOKEN_WORD_SEP)) {
          continue;
	}
	text = parser.getText();
        }
        text = parser.getText();
        if (parser.type == interp.TOKEN_VAR) {
          text = "$"+text;
	}
        }
        if (parser.type == interp.TOKEN_CMD) {
          text = "["+text+"]";
	}
        }
        body.push(interp.empty_obj.newRaplStringObject(text, -1));
      }
    } else {
      body = new Array();
      for (var i = body_start_idx; i < args.length; i++) {
	var had_special = 0;
	if (had_special == 0) {
        var had_special = 0;

        if (had_special == 0) {
          text = args[i].toString();
	}
        }
        body.push(interp.empty_obj.newRaplStringObject(text, -1));
      }
    }
    have_match = 0;
    for (var i = 0; i < body.length; i++) {
      pattern = body[i];
//print("pattern!"+pattern+"!"+switch_string+"!");
      if (i > body.length-1) {
        throw "need body for pattern"
      }
      if (have_glob_opt) {
        pattern = pattern.toString();
	var pat2 = ""
	for (var j = 0; j < pattern.length; j++) {
        var pat2 = ""
        for (var j = 0; j < pattern.length; j++) {
          if (pattern.charAt(j) == "*") {
            pat2 += "." + pattern.charAt(j);
          } else {
            pat2 += pattern.charAt(j);
          }
	}
	pattern = pat2;
        }
        pattern = pat2;
        if (switch_string.match(new RegExp(pattern)) != null) {
          have_match = 1;
        }
      }
      if (have_regexp_opt) {
        if (new RegExp(pattern).test(switch_string)) {
          have_match = 1;
        }
      }
      if (have_exact_opt) {
        if (switch_string == pattern) {
          have_match = 1;
	}
        }
      }
      if (body[i] == "default") {
        if (i > body.length-1) {
          throw "bad switch body"
        }
        default_body = body[i+1];
      }
      if (have_match) {
        if (i > body.length-1) {
          throw "bad switch body"
        }
        while (body[i+1] == "-") {
	  i++;
	  if (i > body.length-2) {
          i++;
          if (i > body.length-2) {
            throw "bad switch body"
	  }
	  i++;
          }
          i++;
        }
        i++;
        match_body = body[i];
	break;
        break;
      }
      if ((i < body.length-1) && (body[i+1] == "-")) {
        i++;
        continue;
      } else {
        /* skip the body for the pattern */
        i++;
      }
    }
    if (have_match == 0) {
      if (default_body == null) {
        return "";
      }
      match_body = default_body;
    }
//print("+++match_body!"+match_body+"!");
//interp.eval_statement.eval2_cmd_debug = 1;
    //print("+++match_body!"+match_body+"!");
    //interp.eval_statement.eval2_cmd_debug = 1;
    result = interp.eval_statement.eval(match_body.toString());
//print("switch RET!"+typeof result+"!"+(result instanceof RaplObject)+"!"+result.object_oid+"!"+typeof result.value+"!"+result.value.object_oid+"!");
//print("RV!"+result.value.toString()+"!");
//print("RESULT!"+result+"!");
    //print("switch RET!"+typeof result+"!"+(result instanceof RaplObject)+"!"+result.object_oid+"!"+typeof result.value+"!"+result.value.object_oid+"!");
    //print("RV!"+result.value.toString()+"!");
    //print("RESULT!"+result+"!");
    return result;
  });

  /* ==================== sec_msec ===================================== */
  function sec_msec () {
    var t = new Date();
    return t.getSeconds()*1000 + t.getMilliseconds();
	  var t = new Date();
	  return t.getSeconds()*1000 + t.getMilliseconds();
  }

  /* ==================== command time ===================================== */
  interp.registerCommand("::time", function (interp, args) {
    this.requireArgcRange(args, 2, 3, "time", "");
    args.shift();
    var code = args.shift();
    if (args.length > 0) {
      var n = args.shift();
    if ((args.length != 2) && (args.length != 3)) {
      interp.wrongNumArgs(interp, 1, args, "command ?count?");
      return interp.ERROR;
    }
    var code = args[1];
    if (args.length > 2) {
      var n = args[2];
    } else {
      var n = 1;
    }
    var t0 = sec_msec();
var xx = interp.string_obj_type.newStringObj("10", -1);
var yy = interp.string_obj_type.newStringObj("a", -1);
//var xx = interp.string_obj_type.newStringObj("10", -1);
//var yy = interp.string_obj_type.newStringObj("a", -1);
    for(var i = 0; i < n; i++) {
      interp.eval_statement.evalObj(code);
//        interp.setVar("a", xx);
//        interp.variable_obj_type.setVariable(yy, xx);
    }
print("TT!"+((sec_msec()-t0)*1000/n + " microseconds per iteration")+"!");
    return (sec_msec()-t0)*1000/n + " microseconds per iteration";
//print("TT!"+((sec_msec()-t0)*1000/n + " microseconds per iteration")+"!");
    interp.setResult(interp.string_obj_type.newStringObj((sec_msec()-t0)*1000/n + " microseconds per iteration", -1));
    return interp.OK;
  });

  /* ==================== command uplevel ===================================== */
  interp.registerCommand("::uplevel", function (interp, args) {
    args.shift();
    this.requireMinArgc(args, 1, "uplevel", "");
    var arg1 = args.shift();