dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]Java compiler , more news


From: Gopal V
Subject: Re: [DotGNU]Java compiler , more news
Date: Sat, 26 Apr 2003 12:15:19 +0530
User-agent: Mutt/1.2.5i

If memory serves me right, Jeroen Frijters wrote:

(replying to the two threads at once)

Here's how the java.lang.Object system works now ....

My compiler allows the user defined conversion operators to
work , mainly to allow C# code to be used well here ... But
it turned out to be the best thing I ever did (by mistake 
of course).

public class ObjectWrapper: System.Object
{
        private bool isWrapper=false;
        private System.Object value__;
        public ObjectWrapper()
        {
        }
        internal System.Object GetWrappedObject()
        {
                if(!isWrapper)
                {
                        throw new JavaWrapperException(this.ToString()+
                                                " is not a wrapped object");
                }
                return this.value__;
        }

        internal static java.lang.Object WrapObject(System.Object obj)
        {
                java.lang.Object retval = new java.lang.Object();
                retval.value__=obj;
                retval.isWrapper=true;
                return retval;
        }

And java.lang.Object inherits from ObjectWrapper ... So let's see 
how the Exception stuff is handled.

public class ExceptionWrapper
{
        public static implicit operator java.lang.Object(System.Exception obj)
        {
                return ObjectWrapper.WrapObject(obj);
        }               
        public static implicit operator ExceptionWrapper (java.lang.Object obj)
        {
                return (ExceptionWrapper) obj.GetWrappedObject();
        }
}

So in Action ...

                try
                {
                        Object b=new MyException();
                        throw (MyException)b;
                }

.....
        .try {
        newobj  instance void 'MyException'::'.ctor'()
        call    class ['java.lang']'java.lang'.'Object' 
['java.lang']'dotgnu.javawrappers'.'ExceptionWrapper'::'op_Implicit'(class 
['mscorlib']'System'.'Exception')
        stloc.0
        ldloc.0
        call    class ['java.lang']'dotgnu.javawrappers'.'ExceptionWrapper' 
['java.lang']'dotgnu.javawrappers'.'ExceptionWrapper'::'op_Implicit'(class 
['java.lang']'java.lang'.'Object')
        throw
        }

> This doesn't work well. For example, CLI arrays and strings need to be
> assignable to java.lang.Object, but they (obviously) aren't derived from
> it. 

So here's the answer to this comment ... I can assign strings to java.lang.
Object ... Need to work on the array part. (implict conversion to 
System.Array ?)

Btw, java.lang.String <-> System.String is also an implicit conversion in
both directions.

> I chose to make java.lang.Throwable an alias for System.Exception and do
> some exception substitution in Java exception handlers (e.g.
> System.NullReferenceException -> java.lang.NullPointerException). This
> also requires playing some tricks with the virtual methods in Throwable.

I think the compiler will be able to make the switch ... but the behavior
might be modified beyond scope ... I'm trying to get the library to be 
as similar to the Classpath as possible.

> they had a huge hole in the type system (an unsafe method that could
> cast any System.Object to a java.lang.Object, not a smart thing to do

Unsafe method ... IMHO my wrapped objects make more sense  ...

> System.Object). In the release version they map java.lang.Object to
> System.Object, java.lang.Throwable extends System.Exception and
> java.lang.String maps to System.String.

Btw, I have made my system so that libraries written in Java can be 
pushed into C# ... ie cross inheriting stuff...

Gopal
-- 
The difference between insanity and genius is measured by success


reply via email to

[Prev in Thread] Current Thread [Next in Thread]