/*====================================================
 * rapl_pkg_itclcmd.js "A Tcl like language implementation in Javascript named WebRAPL 
 * (Web Rapid Application Programming Language)"
 *
 * RAPL itcl commands implementation
 *
 * Released under BSD license.
 * (BSD license found at <http://www.tcl.tk/software/tcltk/license.html>)
 *
 * Arnulf Wiedemann    2011
 */

RP.add("rapl-pkg-itcl", function(R, name) {

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

  R.Base.pkg_itcl_oid++;
  itcl.oid = R.Base.pkg_itcl_oid;

  /* ==================== command itcl class ===================================== */
  interp.registerCommand("::itcl::class", function (interp, args) {
    var ret_code;

//print("itcl class!"+args+"!");
    if (args.length != 3) {
      interp.wrongNumArgs(1, args, "className classdef");
      return interp.ERROR;
    }
    interp.itcl_obj_type.class_type = interp.ITCL_CLASS;
    interp.itcl_obj_type.class_name = args[1];
    ret_code = interp.itcl_obj_type.setFromAny(args[2]);
    return ret_code;
  });

  /* ==================== command itcl body ===================================== */
  interp.registerSubCommand("::itcl", "body", function (interp, args) {
    if (args.length != 3) {
      interp.wrongNumArgs(1, args, "body ");
      return interp.ERROR;
    }
    var class_name = args[1];
    interp.setResultString("itcl body not yet implemented");
    return interp.ERROR;
  });

  /* ==================== command itcl extendedclass ===================================== */
  interp.registerCommand("::itcl::extendedclass", function (interp, args) {
    var ret_code;

    if (args.length != 3) {
      interp.wrongNumArgs(1, args, "className classdef");
      return interp.ERROR;
    }
    interp.itcl_obj_type.class_type = interp.ITCL_EXTENDED_CLASS;
    interp.itcl_obj_type.class_name = args[1];
    ret_code = interp.itcl_obj_type.setFromAny(args[2]);
    return ret_code;
  });

  /* ==================== command itcl type ===================================== */
  interp.registerCommand("::itcl::mk_member", function (interp, args) {
    var ret_code;
    var protection = null;
    var protection_val;
    var kind;

//print("mk_member!"+args+"!");
    if (args.length < 3) {
      interp.wrongNumArgs(1, args, "className classdef");
      return interp.ERROR;
    }
    if (interp.frame_ptr.parent_call_frame.argv != null) {
      protection = interp.frame_ptr.parent_call_frame.argv[0];
    }
    kind = args[1].getString();
    protection_val = interp.getProtectionValFromString(protection);
    protection_val = parseInt(protection_val);
    switch (protection_val) {
    case interp.PROTECTION_PUBLIC:
      break;
    case interp.PROTECTION_PROTECTED:
      break;
    case interp.PROTECTION_PRIVATE:
      break;
    default:
      switch(kind) {
      case "variable":
      case "common":
        protection_val = interp.PROTECTION_PROTECTED;
	break;
      default:
        protection_val = interp.PROTECTION_PUBLIC;
	break;
      }
      break;
    }
    return itcl.interp.itcl_obj_type.mkMember(protection_val, kind, args.slice(2));
  });

  /* ==================== command itcl type ===================================== */
  interp.registerSubCommand("::itcl", "type", function (interp, args) {
    var ret_code;

    if (args.length != 3) {
      interp.wrongNumArgs(1, args, "className classdef");
      return interp.ERROR;
    }
    interp.class_type = interp.ITCL_TYPE_CLASS;
    interp.itcl_obj_type.class_name = args[1];
    ret_code = interp.itcl_obj_type.setFromAny(args[2]);
    return ret_code;
  });


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

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


});

PkgItcl.prototype.constructor = PkgItcl;

R.PkgItcl = PkgItcl;

}, "0.0.1", {});
