APWTCL Arnulf's Preferred Web Tcl

Check-in [168f592e8c]
Login

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

Overview
Comment:fixes for making first steps with gles20 package commands.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:168f592e8c48ba266e30fd7173ffbca817a44f78
User & Date: arnulf 2014-02-07 20:56:22
Context
2014-02-08
15:41
commented out debug stuff check-in: 2c65d2f052 user: arnulf tags: trunk
2014-02-07
20:56
fixes for making first steps with gles20 package commands. check-in: 168f592e8c user: arnulf tags: trunk
2014-02-06
19:57
fixes for makeing loading of gles20 PackageCommand possible. Support of some OBJ_TYPE_DOUBLE functions. check-in: b6251dec71 user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/org/apwtcl/lang/CoreCommandPackages.java.

228
229
230
231
232
233
234

235
236
237
238
239
240
241
    sub_cmds.add(interp.string_obj_type.newStringObj("LinsertCommand ::linsert", -1, "CORE_COMMAND_PACKAGES_49"));
    cmds.put("linsert", sub_cmds);
    
//print("core!"+cmds.keySet()+"!");    
    packages.put("core", cmds);
    package_names.add("core");
    package_infos.put("core", this);

  }

  /* ==================== mySelf ================================== */
  public String mySelf() {
    String str = "CoreCommandPackages!"+id+"!";
    return str;
  } 







>







228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
    sub_cmds.add(interp.string_obj_type.newStringObj("LinsertCommand ::linsert", -1, "CORE_COMMAND_PACKAGES_49"));
    cmds.put("linsert", sub_cmds);
    
//print("core!"+cmds.keySet()+"!");    
    packages.put("core", cmds);
    package_names.add("core");
    package_infos.put("core", this);
    package_namespaces.put("core", interp.global_ns_ptr);
  }

  /* ==================== mySelf ================================== */
  public String mySelf() {
    String str = "CoreCommandPackages!"+id+"!";
    return str;
  } 

Changes to src/org/apwtcl/lang/EvalStatement.java.

673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
if (eval_stmt_debug > -2) {
print("callProcedure end retcode and level!"+getReturnCodeString(retcode)+"!"+eval_level+"!");
if (retcode != OK) {
print("result!"+interp.getResult().getString()+"!");
}
}
            } else {
              /* Check if there are too nested calls */
//print("FR!"+interp.frame_ptr.toDebugString()+"!"+interp.max_nesting_depth+"!");
              interp.cmd_priv_data = cmd.native_fcn.privdata;
if (eval_stmt_debug > -2) {
print("pp!"+eval_level+"!"+cmd+"!"+my_args+"!");
}
              Object ret2 = cmd.call(interp, my_args, /* ensemble_expand */ true);
              retcode = (Integer)ret2;







|







673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
if (eval_stmt_debug > -2) {
print("callProcedure end retcode and level!"+getReturnCodeString(retcode)+"!"+eval_level+"!");
if (retcode != OK) {
print("result!"+interp.getResult().getString()+"!");
}
}
            } else {
              /* Check if there are too many nested calls */
//print("FR!"+interp.frame_ptr.toDebugString()+"!"+interp.max_nesting_depth+"!");
              interp.cmd_priv_data = cmd.native_fcn.privdata;
if (eval_stmt_debug > -2) {
print("pp!"+eval_level+"!"+cmd+"!"+my_args+"!");
}
              Object ret2 = cmd.call(interp, my_args, /* ensemble_expand */ true);
              retcode = (Integer)ret2;

Changes to src/org/apwtcl/lang/Namespace.java.

15
16
17
18
19
20
21


22
23
24
25
26
27
28
...
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
...
407
408
409
410
411
412
413

414
415
416













417
418
419
420
421
422
423
...
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611

package org.apwtcl.lang;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;



public class Namespace extends Token implements Debug {
  private static int oid = 0;
  private static int variable_debug = 0;
  public static final String msg_bad_namespace = "parent namespace doesn't exist";
  public static final String msg_no_such_var = "no such variable";
  public static final String msg_missing_name = "missing variable name";
................................................................................
   *
   * Side effects:
   *      None.
   *
   *----------------------------------------------------------------------
   */
  public Command findCommand(String cmd_name, Namespace context_ns_ptr, int flags) {
//print("FINDCOMMAND!"+cmd_name+"!"+(context_ns_ptr  != null ? context_ns_ptr.toDebugString() : "null")+"!");
    Namespace cxt_ns_ptr = null;
    Namespace path_ns;
    Namespace real_ns;
    ArrayList<Object> cmd_ptr = new ArrayList<Object>();
    ArrayList<Object> macro_ptr = new ArrayList<Object>();
    Command cmd = null;
    HashMap<String, Command> commands;
................................................................................
    /*
     * If this namespace has a command resolver, then give it first crack at
     * the command resolution. If the interpreter has any command resolvers,
     * consult them next. The command resolver functions may return a
     * Command value, they may signal to continue onward, or they may
     * signal an error.
     */

    if (((flags & NAMESPACE_LOOKUP_GLOBAL_ONLY) != 0) || ((cmd_name.charAt(0) ==':') && (cmd_name.charAt(1) == ':'))) {
      cxt_ns_ptr = interp.getGlobalNamespace();
    } else {













      if (context_ns_ptr != null) {
        cxt_ns_ptr = context_ns_ptr;
      } else {
        cxt_ns_ptr = interp.frame_ptr.ns_ptr;
      }
    }
    if (cxt_ns_ptr.macro_resolver != null) {
................................................................................
      simple_name = simple_name_ptr.get(0);
      simple_name = escapeKey(simple_name);
      /* FIXME!!! only temporary !! for ::itcl::type avoid using the class namespace here !!
       * if there exists a global command with the same name
       */
      if (ns1 != null && ns1.class_type == ITCL_TYPE_CLASS && ns2 != null && ns2 == interp.global_ns_ptr) {
        /* load the core command if possible first */
        if (interp.command_obj_type.canLoadCommand(simple_name)) {
          interp.command_obj_type.loadCommandIfPossible(simple_name);
        }
        if (interp.global_ns_ptr.cmd_procs.get(escapeKey(simple_name)) != null) {
          ns1 = null;
        }
      }
      /*
       * Look for the command in the command table of its namespace. Be sure
................................................................................
      }
    }
    if (cmd != null) {
//print("FIND2!"+cmd.toDebugString()+"!");
      return cmd;
    }

//print("findCommand not found!"+cmd_name+"!"+simple_name+"!");
    cmd = interp.command_obj_type.loadCommandIfPossible(unescapeKey(simple_name));
//print("cmd!"+cmd+"!");
    if (cmd != null) {
	  return cmd;
    }
//print("FIND3!"+cmd_ptr+"!");
    if ((flags & FUNCTION_FLAGS_LEAVE_ERR_MSG) != 0) {
      interp.resetResult();







>
>







 







|







 







>
|


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







 







|
|







 







|
|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
...
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
...
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
...
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627

package org.apwtcl.lang;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class Namespace extends Token implements Debug {
  private static int oid = 0;
  private static int variable_debug = 0;
  public static final String msg_bad_namespace = "parent namespace doesn't exist";
  public static final String msg_no_such_var = "no such variable";
  public static final String msg_missing_name = "missing variable name";
................................................................................
   *
   * Side effects:
   *      None.
   *
   *----------------------------------------------------------------------
   */
  public Command findCommand(String cmd_name, Namespace context_ns_ptr, int flags) {
print("FINDCOMMAND!"+cmd_name+"!"+(context_ns_ptr  != null ? context_ns_ptr.toDebugString() : "null")+"!");
    Namespace cxt_ns_ptr = null;
    Namespace path_ns;
    Namespace real_ns;
    ArrayList<Object> cmd_ptr = new ArrayList<Object>();
    ArrayList<Object> macro_ptr = new ArrayList<Object>();
    Command cmd = null;
    HashMap<String, Command> commands;
................................................................................
    /*
     * If this namespace has a command resolver, then give it first crack at
     * the command resolution. If the interpreter has any command resolvers,
     * consult them next. The command resolver functions may return a
     * Command value, they may signal to continue onward, or they may
     * signal an error.
     */
//System.out.println("context_ns: "+interp.frame_ptr.ns_ptr+"!");    
    if (((flags & NAMESPACE_LOOKUP_GLOBAL_ONLY) != 0)) {
      cxt_ns_ptr = interp.getGlobalNamespace();
    } else {
      if ((cmd_name.charAt(0) ==':') && (cmd_name.charAt(1) == ':')) {
        String[] strs = cmd_name.split(":+");
        if (strs.length > 2) {
          String ns_name = cmd_name.substring(0, cmd_name.lastIndexOf(':') - 1);
          cxt_ns_ptr = getNamespace(ns_name);
          if (cxt_ns_ptr == null) {
            cxt_ns_ptr = interp.namespace_obj_type.createNamespace(ns_name);
            context_ns_ptr = cxt_ns_ptr;
          }
    	} else {
            cxt_ns_ptr = interp.getGlobalNamespace();          		
    	}
      }
      if (context_ns_ptr != null) {
        cxt_ns_ptr = context_ns_ptr;
      } else {
        cxt_ns_ptr = interp.frame_ptr.ns_ptr;
      }
    }
    if (cxt_ns_ptr.macro_resolver != null) {
................................................................................
      simple_name = simple_name_ptr.get(0);
      simple_name = escapeKey(simple_name);
      /* FIXME!!! only temporary !! for ::itcl::type avoid using the class namespace here !!
       * if there exists a global command with the same name
       */
      if (ns1 != null && ns1.class_type == ITCL_TYPE_CLASS && ns2 != null && ns2 == interp.global_ns_ptr) {
        /* load the core command if possible first */
        if (interp.command_obj_type.canLoadCommand(simple_name, cxt_ns_ptr)) {
          interp.command_obj_type.loadCommandIfPossible(simple_name, cxt_ns_ptr);
        }
        if (interp.global_ns_ptr.cmd_procs.get(escapeKey(simple_name)) != null) {
          ns1 = null;
        }
      }
      /*
       * Look for the command in the command table of its namespace. Be sure
................................................................................
      }
    }
    if (cmd != null) {
//print("FIND2!"+cmd.toDebugString()+"!");
      return cmd;
    }

//print("findCommand not found!"+cmd_name+"!"+simple_name+"!"+cxt_ns_ptr+"!");
    cmd = interp.command_obj_type.loadCommandIfPossible(unescapeKey(simple_name), cxt_ns_ptr);
//print("cmd!"+cmd+"!");
    if (cmd != null) {
	  return cmd;
    }
//print("FIND3!"+cmd_ptr+"!");
    if ((flags & FUNCTION_FLAGS_LEAVE_ERR_MSG) != 0) {
      interp.resetResult();

Changes to src/org/apwtcl/lang/PackageCommandInfo.java.

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
51
52
53
54
55
56
57


58
59
60
61
62
63
64
65
66
..
79
80
81
82
83
84
85
86
  private static int oid = 0;

  private int id;

  public static HashMap<String, HashMap<String, ArrayList<ApwtclObj>>> packages = new HashMap<String, HashMap<String, ArrayList<ApwtclObj>>>();
  public static ArrayList<String> package_names = new ArrayList<String>();
  public static HashMap<String, PackageCommandInfo> package_infos = new HashMap<String, PackageCommandInfo>();
  

  /* ==================== PackageCommandInfo ================================== */
  public PackageCommandInfo() {
    oid++;
    id = oid;
  }

................................................................................
    return str.toString();
  }

  /* ==================== hasCommand ===================================== */
  public boolean hasCommand(String package_name, String cmd_name) {
	HashMap<String, ArrayList<ApwtclObj>> package_commands;
	package_commands = packages.get(package_name);


//print("hasCommand!"+cmd_name+"!"+package_name+"!"+package_commands+"!"+package_commands.get(cmd_name)+"!");
print("hasCommand!"+cmd_name+"!"+package_name+"!"+package_commands.get(cmd_name)+"!");
	if (package_commands == null) {
		/* package is not yet implemented */
		return false;
	}
	if (package_commands.get(cmd_name) == null) {
      return false;
    }
................................................................................
	if (cmd_infos == null) {
      return null;	
	}
	return cmd_infos.get(0);
  }

}








|







 







>
>

|







 







<
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
..
81
82
83
84
85
86
87

  private static int oid = 0;

  private int id;

  public static HashMap<String, HashMap<String, ArrayList<ApwtclObj>>> packages = new HashMap<String, HashMap<String, ArrayList<ApwtclObj>>>();
  public static ArrayList<String> package_names = new ArrayList<String>();
  public static HashMap<String, PackageCommandInfo> package_infos = new HashMap<String, PackageCommandInfo>();
  public static HashMap<String, Namespace> package_namespaces = new HashMap<String, Namespace>();  

  /* ==================== PackageCommandInfo ================================== */
  public PackageCommandInfo() {
    oid++;
    id = oid;
  }

................................................................................
    return str.toString();
  }

  /* ==================== hasCommand ===================================== */
  public boolean hasCommand(String package_name, String cmd_name) {
	HashMap<String, ArrayList<ApwtclObj>> package_commands;
	package_commands = packages.get(package_name);
	// Namespace ns_ptr = package_namespaces.get(package_name);
	
//print("hasCommand!"+cmd_name+"!"+package_name+"!"+package_commands+"!"+package_commands.get(cmd_name)+"!");
//print("hasCommand!"+cmd_name+"!"+package_name+"!"+package_commands.get(cmd_name)+"!");
	if (package_commands == null) {
		/* package is not yet implemented */
		return false;
	}
	if (package_commands.get(cmd_name) == null) {
      return false;
    }
................................................................................
	if (cmd_infos == null) {
      return null;	
	}
	return cmd_infos.get(0);
  }

}

Changes to src/org/apwtcl/lang/Token.java.

408
409
410
411
412
413
414
415


416

417
418
419
420
421
422
423
  public static boolean isNested(String str) {
    Matcher matcher = patternIsNested.matcher(str);
    return matcher.matches();
  }

  /* ==================== hasNamespacePart ================================ */
  public static boolean hasNamespacePart(String str) {
    Matcher matcher = patternHasNamespacePart.matcher(str);


    return matcher.matches();

  }

  /* ==================== getNamespaceSeparator ========================== */
  public static boolean getNamespaceSeparator(String str) {
    Matcher matcher = patternGetNamespaceSeparator.matcher(str);
    return matcher.matches();
  }







|
>
>
|
>







408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
  public static boolean isNested(String str) {
    Matcher matcher = patternIsNested.matcher(str);
    return matcher.matches();
  }

  /* ==================== hasNamespacePart ================================ */
  public static boolean hasNamespacePart(String str) {
    //Matcher matcher = patternHasNamespacePart.matcher(str);
    boolean mtch = str.indexOf("::")>=0;    
//System.out.println("HAS: "+str+"!"+matcher.matches()+"!"+mtch+"!");    
//    return matcher.matches();
	  return mtch;
  }

  /* ==================== getNamespaceSeparator ========================== */
  public static boolean getNamespaceSeparator(String str) {
    Matcher matcher = patternGetNamespaceSeparator.matcher(str);
    return matcher.matches();
  }

Changes to src/org/apwtcl/lang/objtype/CommandObjType.java.

20
21
22
23
24
25
26

27
28
29
30
31
32
33

34
35
36
37
38
39
40
...
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
...
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
...
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
...
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
...
826
827
828
829
830
831
832
833
834


835
836
837
838
839
840
841
842
...
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
...
906
907
908
909
910
911
912
913
914
915
import java.util.HashMap;

import org.apwtcl.lang.ApwtclClassLoader;
import org.apwtcl.lang.ApwtclObj;
import org.apwtcl.lang.CallFrame;
import org.apwtcl.lang.Command;
import org.apwtcl.lang.CoreCommandPackages;

import org.apwtcl.lang.Debug;
import org.apwtcl.lang.FunctionArgList;
import org.apwtcl.lang.Interp;
import org.apwtcl.lang.Namespace;
import org.apwtcl.lang.ResolvedCmdName;
import org.apwtcl.lang.Token;
import org.apwtcl.lang.Variable;


public class CommandObjType extends Token implements Debug {
  private static int oid = 0;

  private int id;
  private Interp interp;
  private ApwtclClassLoader native_command_class_loader;
................................................................................
      }
    }
    return err;
  }

  /* ==================== registerNativeCommand ===================================== */
  public Command registerNativeCommand(String cmd_name, String class_name, boolean register_in_namespace) {
//print("REGI!"+cmd_name+"!"+class_name+"!");
    ArrayList<Namespace> ns_ptr_ptr1 = new ArrayList<Namespace>();
    ArrayList<Namespace> ns_ptr_ptr2 = new ArrayList<Namespace>();
    ArrayList<Namespace> ctx_ns_ptr_ptr = new ArrayList<Namespace>();
    ArrayList<String> simple_name_ptr = new ArrayList<String>();
    String simple_name;
    String method_name;
    Namespace ns_ptr = interp.global_ns_ptr;
................................................................................
    Object cmd_instance = null;
    Class<?> cmd_class = null;
    
    interp.variable_obj_type.getNamespaceForQualName(cmd_name, interp.frame_ptr.ns_ptr, 
            NAMESPACE_CREATE_IF_UNKNOWN, ns_ptr_ptr1, ns_ptr_ptr2, ctx_ns_ptr_ptr, simple_name_ptr);
    simple_name = simple_name_ptr.get(0);
    ns_ptr = ns_ptr_ptr1.get(0);
//print("RGI!"+cmd_name+"!"+ns_ptr+"!");
    
    cmd_instance = interp.loaded_class_info.getLoadedClassInstance(class_name);
//print("simple_name!"+cmd_name+"!"+simple_name+"!"+class_name+"!"+cmd_instance+"!");
    cmd_class = native_command_class_loader.myFindClass(class_name);
//print("registerNativeCommand cmd_class!"+cmd_class+"!");
    method_name = simple_name+"Cmd";
    try {
................................................................................
      }

    } catch(Exception e) {
print("registerNativeCommand Exception!"+e.getMessage()+"!");
e.printStackTrace();
      return null;
    }
//print("registerNativeCommand DONE");
    Command cmd_obj = new Command(interp, cmd_name);
    cmd_obj.setNativeInfo(cmd_class, cmd_method, cmd_instance, ns_ptr);
    if (register_in_namespace) {
//      interp.global_ns_ptr.registerCommand(simple_name, cmd_obj, "NAMESPACE", "NAMESPACE_PROC");
      ns_ptr.registerCommand(simple_name, cmd_obj, "NAMESPACE", "NAMESPACE_PROC");
    }
    if (interp.loaded_class_info.instanceIsInitted(class_name) == null) {
................................................................................
    cmd_name_ptr.incrRefCount("COMMAND_OBJ_TYPE_3");
    cmd_obj = getCommand(cmd_name_ptr, FUNCTION_FLAGS_NONE);
    cmd_name_ptr.decrRefCount("COMMAND_OBJ_TYPE_4");
    native_cmd_name = new StringBuffer(simple_name);
    ensemble_cmd_name = new StringBuffer(simple_name);
//print("REGI_SUB!"+simple_name+"!"+cmd_obj+"!");
    if (cmd_obj == null) {
      cmd_obj = loadCommandIfPossible(simple_name);
      if (cmd_obj == null) {
        interp.setResultString("cannot register subcommand: "+cmd_name+" "+sub_cmd);
        return null;
      }
    }
    if (cmd_obj.command_type != COMMAND_ENSEMBLE) {
      cmd_obj.command_type = COMMAND_ENSEMBLE;
................................................................................
    }
    my_cmd_obj.name = ensemble_cmd_name.toString();
    ensemble_cmd.put(sub_cmd, my_cmd_obj);
    return cmd_obj;
  }

  /* ==================== loadCommandIfPossible ===================================== */
  public Command loadCommandIfPossible(String cmd_name) {
//print("loadCommandIfPossible!");


    if (canLoadCommand(cmd_name)) {
//print("loadCommandIfPossible1!");
      ApwtclObj cmd_info = getCommandInfo(cmd_name);
      /* force conversion to list!! */
      interp.list_obj_type.listLength(cmd_info);
      ArrayList<ApwtclObj> class_obj_ptr = new ArrayList<ApwtclObj>();
      interp.list_obj_type.listIndex(cmd_info, 0, class_obj_ptr, 0);
      ApwtclObj class_obj = class_obj_ptr.get(0);
................................................................................
//print("loadCommandIfPossible 2 cmd!"+cmd+"!"+interp.frame_ptr.ns_ptr.toDebugString()+"!");
      return cmd;
    }
    return null;
  }
  
  /* ==================== canLoadCommand ===================================== */
  public boolean canLoadCommand(String cmd_name) {
//print("canLoadCommand!"+cmd_name+"!"+core_command_packages.hasCommand("core", cmd_name));
    if (core_command_packages.hasCommand("core", cmd_name)) {










      /* avoid reloading the command otherwise there are problems !! */
      if (interp.global_ns_ptr.cmd_procs.get(escapeKey(cmd_name)) == null) {

        return true;
      }
    }

    return false;
  }
  
  /* ==================== getCommandInfo ===================================== */
  public ApwtclObj getCommandInfo(String cmd_name) {
    return core_command_packages.getCommandInfo("core", cmd_name);











  }
  
  /* ==================== getSubCommands ===================================== */
  public ApwtclObj getSubCommands(ApwtclObj sub_cmd_ptr) {
print("getSubCommands!"+sub_cmd_ptr.getString()+"!");
    ArrayList<ApwtclObj> obj_ptr_ptr;
    Command cmd_obj = null;
    String sub_cmd = null;
    HashMap<String, Command> ensemble = null;
    
    obj_ptr_ptr = new ArrayList<ApwtclObj>();
    int len = interp.list_obj_type.listLength(sub_cmd_ptr);
................................................................................
      sep = " ";
    }
    ApwtclObj result_obj = interp.string_obj_type.newStringObj(str.toString(), -1, "COMMAND_OBJ_TYPE_5");
    /* force a list */
    interp.list_obj_type.listLength(result_obj);
    return result_obj;
  }
  
  
}







>







>







 







|







 







|







 







|







 







|







 







|
|
>
>
|







 







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





<
>
>
>
>
>
>
>
>
>
>
>




|







 








|
<
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
...
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
...
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
...
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
...
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
...
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
...
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
...
932
933
934
935
936
937
938
939
940

import java.util.HashMap;

import org.apwtcl.lang.ApwtclClassLoader;
import org.apwtcl.lang.ApwtclObj;
import org.apwtcl.lang.CallFrame;
import org.apwtcl.lang.Command;
import org.apwtcl.lang.CoreCommandPackages;
import org.apwtcl.lang.PackageCommandInfo;
import org.apwtcl.lang.Debug;
import org.apwtcl.lang.FunctionArgList;
import org.apwtcl.lang.Interp;
import org.apwtcl.lang.Namespace;
import org.apwtcl.lang.ResolvedCmdName;
import org.apwtcl.lang.Token;
import org.apwtcl.lang.Variable;
import org.apwtcl.lang.PackageCommandInfo.*;

public class CommandObjType extends Token implements Debug {
  private static int oid = 0;

  private int id;
  private Interp interp;
  private ApwtclClassLoader native_command_class_loader;
................................................................................
      }
    }
    return err;
  }

  /* ==================== registerNativeCommand ===================================== */
  public Command registerNativeCommand(String cmd_name, String class_name, boolean register_in_namespace) {
//System.out.println("REGI!"+cmd_name+"!"+class_name+"!");
    ArrayList<Namespace> ns_ptr_ptr1 = new ArrayList<Namespace>();
    ArrayList<Namespace> ns_ptr_ptr2 = new ArrayList<Namespace>();
    ArrayList<Namespace> ctx_ns_ptr_ptr = new ArrayList<Namespace>();
    ArrayList<String> simple_name_ptr = new ArrayList<String>();
    String simple_name;
    String method_name;
    Namespace ns_ptr = interp.global_ns_ptr;
................................................................................
    Object cmd_instance = null;
    Class<?> cmd_class = null;
    
    interp.variable_obj_type.getNamespaceForQualName(cmd_name, interp.frame_ptr.ns_ptr, 
            NAMESPACE_CREATE_IF_UNKNOWN, ns_ptr_ptr1, ns_ptr_ptr2, ctx_ns_ptr_ptr, simple_name_ptr);
    simple_name = simple_name_ptr.get(0);
    ns_ptr = ns_ptr_ptr1.get(0);
//System.out.println("REGI!"+cmd_name+"!ns!"+ns_ptr.toString()+"!");
    
    cmd_instance = interp.loaded_class_info.getLoadedClassInstance(class_name);
//print("simple_name!"+cmd_name+"!"+simple_name+"!"+class_name+"!"+cmd_instance+"!");
    cmd_class = native_command_class_loader.myFindClass(class_name);
//print("registerNativeCommand cmd_class!"+cmd_class+"!");
    method_name = simple_name+"Cmd";
    try {
................................................................................
      }

    } catch(Exception e) {
print("registerNativeCommand Exception!"+e.getMessage()+"!");
e.printStackTrace();
      return null;
    }
//System.out.println("registerNativeCommand DONE: ns: "+ns_ptr.toString());
    Command cmd_obj = new Command(interp, cmd_name);
    cmd_obj.setNativeInfo(cmd_class, cmd_method, cmd_instance, ns_ptr);
    if (register_in_namespace) {
//      interp.global_ns_ptr.registerCommand(simple_name, cmd_obj, "NAMESPACE", "NAMESPACE_PROC");
      ns_ptr.registerCommand(simple_name, cmd_obj, "NAMESPACE", "NAMESPACE_PROC");
    }
    if (interp.loaded_class_info.instanceIsInitted(class_name) == null) {
................................................................................
    cmd_name_ptr.incrRefCount("COMMAND_OBJ_TYPE_3");
    cmd_obj = getCommand(cmd_name_ptr, FUNCTION_FLAGS_NONE);
    cmd_name_ptr.decrRefCount("COMMAND_OBJ_TYPE_4");
    native_cmd_name = new StringBuffer(simple_name);
    ensemble_cmd_name = new StringBuffer(simple_name);
//print("REGI_SUB!"+simple_name+"!"+cmd_obj+"!");
    if (cmd_obj == null) {
      cmd_obj = loadCommandIfPossible(simple_name, ctx_ns_ptr_ptr.get(0));
      if (cmd_obj == null) {
        interp.setResultString("cannot register subcommand: "+cmd_name+" "+sub_cmd);
        return null;
      }
    }
    if (cmd_obj.command_type != COMMAND_ENSEMBLE) {
      cmd_obj.command_type = COMMAND_ENSEMBLE;
................................................................................
    }
    my_cmd_obj.name = ensemble_cmd_name.toString();
    ensemble_cmd.put(sub_cmd, my_cmd_obj);
    return cmd_obj;
  }

  /* ==================== loadCommandIfPossible ===================================== */
  public Command loadCommandIfPossible(String cmd_name, Namespace ns_ptr) {
//System.out.println("loadCommandIfPossible!"+cmd_name+"!"+ns_ptr+"!");
    StringBuffer my_name = new StringBuffer(cmd_name);
    
    if (canLoadCommand(my_name.toString(), ns_ptr)) {
//print("loadCommandIfPossible1!");
      ApwtclObj cmd_info = getCommandInfo(cmd_name);
      /* force conversion to list!! */
      interp.list_obj_type.listLength(cmd_info);
      ArrayList<ApwtclObj> class_obj_ptr = new ArrayList<ApwtclObj>();
      interp.list_obj_type.listIndex(cmd_info, 0, class_obj_ptr, 0);
      ApwtclObj class_obj = class_obj_ptr.get(0);
................................................................................
//print("loadCommandIfPossible 2 cmd!"+cmd+"!"+interp.frame_ptr.ns_ptr.toDebugString()+"!");
      return cmd;
    }
    return null;
  }
  
  /* ==================== canLoadCommand ===================================== */
  public boolean canLoadCommand(String cmd_name, Namespace ns_ptr) {
//print("canLoadCommand1!"+cmd_name+"!"+core_command_packages.hasCommand("core", cmd_name));
    int i;
    StringBuffer my_name = new StringBuffer();
    
    for (i = 0; i < PackageCommandInfo.package_names.size(); i++) {
    	String pkg_name = PackageCommandInfo.package_names.get(i);
    	Namespace pkg_ns_ptr = PackageCommandInfo.package_namespaces.get(pkg_name);
        PackageCommandInfo pci = PackageCommandInfo.package_infos.get(pkg_name);
        my_name.delete(0, my_name.length());
        my_name.append(cmd_name);
System.out.println("pkg_name: "+pkg_name+"!"+my_name.toString()+"!");
        if (pci.hasCommand(pkg_name, my_name.toString())) {
          /* avoid reloading the command otherwise there are problems !! */
          if (interp.global_ns_ptr.cmd_procs.get(escapeKey(cmd_name)) == null) {
 System.out.println("found pkg_name: "+pkg_name+"!"+my_name.toString()+"!");
            return true;
          }
        }
     }
    return false;
  }
  
  /* ==================== getCommandInfo ===================================== */
  public ApwtclObj getCommandInfo(String cmd_name) {

    int i;
    for (i = 0; i < PackageCommandInfo.package_names.size(); i++) {
      String pkg_name = PackageCommandInfo.package_names.get(i);
//System.out.println("pkg_name: "+pkg_name);
      PackageCommandInfo pci = PackageCommandInfo.package_infos.get(pkg_name);
      ApwtclObj obj = pci.getCommandInfo(pkg_name, cmd_name);
      if (obj != null) {
          return obj;
      }
    }
    return null;
  }
  
  /* ==================== getSubCommands ===================================== */
  public ApwtclObj getSubCommands(ApwtclObj sub_cmd_ptr) {
//print("getSubCommands!"+sub_cmd_ptr.getString()+"!");
    ArrayList<ApwtclObj> obj_ptr_ptr;
    Command cmd_obj = null;
    String sub_cmd = null;
    HashMap<String, Command> ensemble = null;
    
    obj_ptr_ptr = new ArrayList<ApwtclObj>();
    int len = interp.list_obj_type.listLength(sub_cmd_ptr);
................................................................................
      sep = " ";
    }
    ApwtclObj result_obj = interp.string_obj_type.newStringObj(str.toString(), -1, "COMMAND_OBJ_TYPE_5");
    /* force a list */
    interp.list_obj_type.listLength(result_obj);
    return result_obj;
  }
  
}

Changes to src/org/apwtcl/lang/objtype/DoubleObjType.java.

20
21
22
23
24
25
26

27
28
29
30
31
32
33
..
97
98
99
100
101
102
103













104
105
106







107
108
109
110
111
112
113
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import org.apwtcl.lang.ApwtclObj;
import org.apwtcl.lang.Token;

import java.util.ArrayList;

public class DoubleObjType extends Token implements Debug {
  private static int oid = 0;


  public int id;
  private Interp interp;

  /* ==================== DoubleObjType ================================== */
  public DoubleObjType(Interp interp) {
    oid++;
................................................................................
        obj_ptr.freeIntRep();
//     }
    obj_ptr.obj_type = OBJ_TYPE_DOUBLE;
    obj_ptr.doubleValue_SetValue(doubleValue.doubleValue());
    return OK;
  }














  /* ==================== updateString ===================================== */
  public void updateString(ApwtclObj obj_ptr) {
    print("double updateString not yet implemented");







  }

  /* ==================== getDouble ================================== */
  public int getDouble(ApwtclObj obj_ptr, ArrayList<Double> double_ptr) {
    if (obj_ptr.obj_type == OBJ_TYPE_COERCED_DOUBLE) {
//        *doublePtr = JimWideValue(objPtr);
//        return Defines.OK;
................................................................................

    if (obj_ptr.obj_type == OBJ_TYPE_COERCED_DOUBLE) {
//        double_ptr.set(0, WideValue(obj_ptr);
        print("double getDouble for CORECED_DOUBLE not yet implemented");
        return ERROR;
    }
    else {
        double_ptr.set(0, new Double(obj_ptr.doubleValue_GetValue()));
    }
    return OK;
  }

  /* ==================== newDoubleObj ================================== */
  public ApwtclObj newDoubleObj(double val) {
    ApwtclObj obj_ptr;







>







 







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


<
>
>
>
>
>
>
>







 







|







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
98
99
100
101
102
103
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
...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import org.apwtcl.lang.ApwtclObj;
import org.apwtcl.lang.Token;

import java.util.ArrayList;

public class DoubleObjType extends Token implements Debug {
  private static int oid = 0;
  private final static int DOUBLE_SPACE = 30;

  public int id;
  private Interp interp;

  /* ==================== DoubleObjType ================================== */
  public DoubleObjType(Interp interp) {
    oid++;
................................................................................
        obj_ptr.freeIntRep();
//     }
    obj_ptr.obj_type = OBJ_TYPE_DOUBLE;
    obj_ptr.doubleValue_SetValue(doubleValue.doubleValue());
    return OK;
  }

  /* ==================== DoubleToString ===================================== */
  int DoubleToString(StringBuffer buf, Double double_value) {
    if (double_value.isNaN()) {
      buf.append("Nan");
      return buf.length();
    }
    if (double_value.isInfinite()) {
      buf.append("Inf");
      return buf.length();
    }
    buf.append(double_value.toString());
    return buf.length();
  }
  /* ==================== updateString ===================================== */
  public void updateString(ApwtclObj obj_ptr) {

    int len;
    StringBuffer buf = new StringBuffer(DOUBLE_SPACE + 1);
    // Double double_value = new Double();

    len = DoubleToString(buf, Double.valueOf(obj_ptr.doubleValue_GetValue()));
    obj_ptr.bytes = buf;
    obj_ptr.len = len;
  }

  /* ==================== getDouble ================================== */
  public int getDouble(ApwtclObj obj_ptr, ArrayList<Double> double_ptr) {
    if (obj_ptr.obj_type == OBJ_TYPE_COERCED_DOUBLE) {
//        *doublePtr = JimWideValue(objPtr);
//        return Defines.OK;
................................................................................

    if (obj_ptr.obj_type == OBJ_TYPE_COERCED_DOUBLE) {
//        double_ptr.set(0, WideValue(obj_ptr);
        print("double getDouble for CORECED_DOUBLE not yet implemented");
        return ERROR;
    }
    else {
        double_ptr.add(Double.valueOf(obj_ptr.doubleValue_GetValue()));
    }
    return OK;
  }

  /* ==================== newDoubleObj ================================== */
  public ApwtclObj newDoubleObj(double val) {
    ApwtclObj obj_ptr;

Changes to src/org/apwtcl/lang/objtype/NamespaceObjType.java.

688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
    ArrayList<String> parts = nsGetParts(name);
    Namespace parent_ns = interp.global_ns_ptr;
    for (int i = 0; i < parts.size(); i++) {
      String part = parts.get(i);
      children = parent_ns.children;
      found = 0;
      Set<String> key_set = children.keySet();
      Iterator<String> iter = key_set.iterator();
      while (iter.hasNext()) {
        String child = iter.next();
//print("GETNS!"+child.full_name+"!"+part+"!");
        if (child == part) {
          parent_ns = children.get(child);
          found = 1;
          break;
        }
      }
      if (found == 0 && (i < parts.size() - 2)) {
        return null;







|


|
<







688
689
690
691
692
693
694
695
696
697
698

699
700
701
702
703
704
705
    ArrayList<String> parts = nsGetParts(name);
    Namespace parent_ns = interp.global_ns_ptr;
    for (int i = 0; i < parts.size(); i++) {
      String part = parts.get(i);
      children = parent_ns.children;
      found = 0;
      Set<String> key_set = children.keySet();
      Iterator<String> iter = key_set.iterator();      
      while (iter.hasNext()) {
        String child = iter.next();
        if (child.matches(part.toString())) {

          parent_ns = children.get(child);
          found = 1;
          break;
        }
      }
      if (found == 0 && (i < parts.size() - 2)) {
        return null;

Changes to src/org/apwtcl/lang/objtype/ObjTypeBase.java.

45
46
47
48
49
50
51


52
53
54
55
56
57
58
..
63
64
65
66
67
68
69



70
71
72
73
74
75
76
      return true;
    case OBJ_TYPE_INT:
      return true;
    case OBJ_TYPE_LIST:
      return true;
    case OBJ_TYPE_DICT:
      return true;


    }
    return false;
  }

  /* ==================== callUpdateString ===================================== */
  public int callUpdateString(int obj_type, ApwtclObj obj_ptr) {
    switch (obj_type) {
................................................................................
      return OK;
    case OBJ_TYPE_LIST:
      interp.list_obj_type.updateString(obj_ptr);
      return OK;
    case OBJ_TYPE_DICT:
        interp.dict_obj_type.updateString(obj_ptr);
        return OK;



    }
print("callUpdateString missing case for obj_type!"+getObjTypeString(obj_type)+"!");
    return OK;
  }

  /* ==================== haveDupInternalRep ===================================== */
  public boolean haveDupInternalRep(int obj_type) {







>
>







 







>
>
>







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
      return true;
    case OBJ_TYPE_INT:
      return true;
    case OBJ_TYPE_LIST:
      return true;
    case OBJ_TYPE_DICT:
      return true;
    case OBJ_TYPE_DOUBLE:
        return true;
    }
    return false;
  }

  /* ==================== callUpdateString ===================================== */
  public int callUpdateString(int obj_type, ApwtclObj obj_ptr) {
    switch (obj_type) {
................................................................................
      return OK;
    case OBJ_TYPE_LIST:
      interp.list_obj_type.updateString(obj_ptr);
      return OK;
    case OBJ_TYPE_DICT:
        interp.dict_obj_type.updateString(obj_ptr);
        return OK;
    case OBJ_TYPE_DOUBLE:
        interp.double_obj_type.updateString(obj_ptr);
        return OK;
    }
print("callUpdateString missing case for obj_type!"+getObjTypeString(obj_type)+"!");
    return OK;
  }

  /* ==================== haveDupInternalRep ===================================== */
  public boolean haveDupInternalRep(int obj_type) {