This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

define-namespace patch


I use define-namespace extensively and have a few patches to extend its
functionality.  This first one adds two features:

1.  Extend the syntax to allow class names to be of the form
    <some.class.Name> in addition to the traditional "class:..."

2. Add a procedure define-private-namespace that creates a namespace but
   doesn't export the name out of the current module.

Regards,
Chris Dean


Index: gnu/expr/Interpreter.java
===================================================================
RCS file: /cvs/kawa/kawa/gnu/expr/Interpreter.java,v
retrieving revision 1.58
diff -u -w -r1.58 Interpreter.java
--- gnu/expr/Interpreter.java	9 Mar 2004 07:16:36 -0000	1.58
+++ gnu/expr/Interpreter.java	16 Jul 2004 06:23:43 -0000
@@ -449,10 +449,10 @@
 	Object val = Environment.getCurrent().get(name);
 	if (val instanceof Type)
 	  return (Type) val;
-        int len = name.length();
-        if (len > 2 && name.charAt(0) == '<'
-            && name.charAt(len-1) == '>')
-          return getTypeFor(name.substring(1, len-1));
+
+        String typeString = classNameFromTypeString(name);
+        if (typeString != null)
+          return getTypeFor(typeString);
       }
     else if (exp instanceof ClassExp)
       {
@@ -664,6 +664,19 @@
     return (Procedure) val;
   }
 
+  public static String classNameFromTypeString(Object obj)
+  {
+    if (obj == null || ! (obj instanceof String))
+      return null;
+    
+    String name = (String) obj;
+    int len = name.length();
+    if (len > 2 && name.charAt(0) == '<' && name.charAt(len-1) == '>')
+        return name.substring(1, len-1);
+    else
+      return null;
+  }
+  
   // The compiler finds registerEnvironment by using reflection.
   //
   // public static void registerEnvironment()
Index: ChangeLog
===================================================================
RCS file: /cvs/kawa/kawa/ChangeLog,v
retrieving revision 1.422
diff -u -w -r1.422 ChangeLog
--- ChangeLog	22 Jun 2004 00:29:43 -0000	1.422
+++ ChangeLog	16 Jul 2004 06:23:44 -0000
@@ -1,3 +1,7 @@
+2004-07-15  Chris Dean  <ctdean@sokitomi.com>
+
+	* kawa/standard/Scheme.java (LispInterpreter): define-private-namespace
+
 2004-06-21  Per Bothner  <per@bothner.com>
 
 	* kawa/standard/object.java (throwsKeyword):  New constant.
Index: gnu/kawa/xml/DefineNamespace.java
===================================================================
RCS file: /cvs/kawa/kawa/gnu/kawa/xml/DefineNamespace.java,v
retrieving revision 1.6
diff -u -w -r1.6 DefineNamespace.java
--- gnu/kawa/xml/DefineNamespace.java	16 Feb 2004 04:42:28 -0000	1.6
+++ gnu/kawa/xml/DefineNamespace.java	16 Jul 2004 06:23:44 -0000
@@ -7,6 +7,18 @@
 
 public class DefineNamespace extends Syntax
 {
+  private boolean makePrivate = false;
+  
+  public DefineNamespace()
+  {
+    this.makePrivate = false;
+  }
+
+  public DefineNamespace(boolean makePrivate)
+  {
+    this.makePrivate = makePrivate;
+  }
+  
   public boolean scanForDefinitions (Pair st, java.util.Vector forms,
                                      ScopeExp defs, Translator tr)
   {
@@ -25,9 +37,28 @@
     decl.setType(gnu.bytecode.Type.tostring_type);
     tr.push(decl);
     decl.setFlag(Declaration.IS_CONSTANT);
-    if (defs instanceof ModuleExp)
+    if (makePrivate)
+      {
+        decl.setFlag(Declaration.PRIVATE_SPECIFIED);
+        decl.setPrivate(true);
+      }
+    else if (defs instanceof ModuleExp)
+      {
       decl.setCanRead(true);
+      }
+    
     Translator.setLine(decl, p1);
+
+    String className = Interpreter.classNameFromTypeString(p2.car);
+    if (className != null)
+      {
+        FString alias = new FString("class:" + className);
+        if (p2 instanceof PairWithPosition)
+          p2 = new PairWithPosition((PairWithPosition) p2, alias, LList.Empty);
+        else
+          p2 = new Pair(alias, LList.Empty);
+      }
+    
     Expression value = tr.rewrite_car (p2, false);
     SetExp sexp = new SetExp (name, value);
     sexp.setDefining (true);
Index: gnu/kawa/xml/ChangeLog
===================================================================
RCS file: /cvs/kawa/kawa/gnu/kawa/xml/ChangeLog,v
retrieving revision 1.81
diff -u -w -r1.81 ChangeLog
--- gnu/kawa/xml/ChangeLog	22 Jun 2004 19:53:37 -0000	1.81
+++ gnu/kawa/xml/ChangeLog	16 Jul 2004 06:23:44 -0000
@@ -1,3 +1,7 @@
+2004-07-15  Chris Dean  <ctdean@sokitomi.com>
+
+	* DefineNamespace.java: private namespaces and ClassType names
+
 2004-06-22  Per Bothner  <per@bothner.com>
 
 	* KAttr.java (getObjectValue):  New method.
Index: kawa/standard/Scheme.java
===================================================================
RCS file: /cvs/kawa/kawa/kawa/standard/Scheme.java,v
retrieving revision 1.150
diff -u -w -r1.150 Scheme.java
--- kawa/standard/Scheme.java	18 Apr 2004 01:40:02 -0000	1.150
+++ kawa/standard/Scheme.java	16 Jul 2004 06:23:44 -0000
@@ -528,6 +528,8 @@
       define_proc ("make-quantity", "kawa.standard.make_quantity");
       define_syntax ("define-unit", new kawa.standard.define_unit(false));
       define_syntax ("define-namespace", "gnu.kawa.xml.DefineNamespace");
+      define_syntax ("define-private-namespace", 
+                     new gnu.kawa.xml.DefineNamespace(true));
       define_syntax ("define-base-unit", new kawa.standard.define_unit(true));
 
       define_proc ("gentemp", "kawa.lib.syntax");
Index: doc/kawa.texi
===================================================================
RCS file: /cvs/kawa/kawa/doc/kawa.texi,v
retrieving revision 1.149
diff -u -w -r1.149 kawa.texi
--- doc/kawa.texi	27 Jun 2004 19:47:36 -0000	1.149
+++ doc/kawa.texi	16 Jul 2004 06:23:45 -0000
@@ -3895,12 +3895,18 @@
 The most convenient way to do it is to
 use @code{define-namespace} to define an alias for a Java class:
 @example
+(define-namespace Int32 <java.lang.Integer>)
+@end example
+or
+@example
 (define-namespace Int32 "class:java.lang.Integer")
 @end example
+
 In this example the name @code{Int32} is a @dfn{namespace alias}
 for the namespace whose full name is @code{"class:java.lang.Integer"}.
 The full name should be the 6 characters @code{"class:"} followed
 by the fully-qualified name of a Java class.
+Alternately, you can just use the form @code{<java.lang.Integer>}.
 You can name a method using a @dfn{qualified name} containing a colon.
 The part of the name before the colon is a namespace alias (in
 this case @code{Int32}), and the part of the name after the colon is the
@@ -4466,6 +4472,10 @@
 
 @end deffn
 
+@deffn Syntax define-private-namespace name namespace-uri
+Same as @code{define-namespace}, except that @code{name} is not exported.
+@end deffn
+
 @subsection How a module becomes a class
 
 If you want to just use a Scheme module as a module (i.e. @code{load}
Index: doc/ChangeLog
===================================================================
RCS file: /cvs/kawa/kawa/doc/ChangeLog,v
retrieving revision 1.119
diff -u -w -r1.119 ChangeLog
--- doc/ChangeLog	27 Jun 2004 19:47:36 -0000	1.119
+++ doc/ChangeLog	16 Jul 2004 06:23:45 -0000
@@ -1,3 +1,7 @@
+2004-07-15  Chris Dean  <ctdean@sokitomi.com>
+
+	* kawa.texi: define-private-namespace and (define-namespace foo <Foo>) 
+
 2004-06-27  Per Bothner  <per@bothner.com>
 
 	* kawa.texi (Defining new classes):  Document new throws: specifier.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]