[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell
Subject:    RE: Haskell -> Java bytecode?
From:       "Erik Meijer" <erik () microsoft-lab ! org>
Date:       2000-05-26 9:39:41
Message-ID: NCEFIJLCGKAMNBLGANCCEEOCCFAA.erik () microsoft-lab ! org
[Download RAW message or body]

> Any particular reason for generating Java rather than JVM bytecode?
> Does it make a difference?

Yes, we make *heavy* use of innerclasses and exceptions. So we are more than
happy to leave the dirty work to the Java compiler. (We are however
currently working on an "inner classes lifter" so that we can spit out flat
Java or even byte code directly.)

For example, the following program

main = do {
  url <- new_URL "http://www.mondrian-script.org";
  protocol <- (url # getProtocol) ();
  putStr ("protocol = "); putStr (protocol);
  host <- (url # getHost) ();
  putStr ("host = "); putStr (host);
};

is compiled into the following piece of Java (the current compiler actually
does a much better job when compiling monadic code like this, this gives a
fair impression of the kind of Java we generate. The great thing is that
even the code below runs pretty fast)

package demo.net.url;
public class main extends Object implements Code {
    public Object ENTER () {
        VM.PUSH(new Thunk(new Code(){
            public Object ENTER () {
                VM.COLLECT(1, this);
                final Object url = VM.POP();
                VM.PUSH(new Thunk(new Code(){
                    public Object ENTER () {
                        VM.COLLECT(1, this);
                        final Object protocol = VM.POP();
                        VM.PUSH(new Thunk(new Code(){
                            public Object ENTER () {
                                VM.COLLECT(1, this);
                                final Object dummy$1 = VM.POP();
                                VM.PUSH(new Thunk(new Code(){
                                    public Object ENTER () {
                                        VM.COLLECT(1, this);
                                        final Object dummy$2 = VM.POP();
                                        VM.PUSH(new Thunk(new Code(){
                                            public Object ENTER () {
                                                VM.COLLECT(1, this);
                                                final Object host =
VM.POP();
                                                VM.PUSH(new Thunk(new
Code(){
                                                    public Object ENTER () {
                                                        VM.COLLECT(1, this);
                                                        final Object dummy$3
= VM.POP();
                                                        VM.PUSH(host);
                                                        return new putStr();
                                                    }
                                                }));
                                                VM.PUSH(new Thunk(new
Code(){
                                                    public Object ENTER () {
                                                        VM.PUSH(new
Nullary("host = "));
                                                        return new putStr();
                                                    }
                                                }));
                                                return new bind();
                                            }
                                        }));
                                        VM.PUSH(new Thunk(new Code(){
                                            public Object ENTER () {
                                                VM.PUSH(new Thunk(new
Code(){
                                                    public Object ENTER () {
                                                        return new Code[]{};
                                                    }
                                                }));
                                                VM.PUSH(new getHost());
                                                VM.PUSH(url);
                                                return new _35();
                                            }
                                        }));
                                        return new bind();
                                    }
                                }));
                                VM.PUSH(new Thunk(new Code(){
                                    public Object ENTER () {
                                        VM.PUSH(protocol);
                                        return new putStr();
                                    }
                                }));
                                return new bind();
                            }
                        }));
                        VM.PUSH(new Thunk(new Code(){
                            public Object ENTER () {
                                VM.PUSH(new Nullary("protocol = "));
                                return new putStr();
                            }
                        }));
                        return new bind();
                    }
                }));
                VM.PUSH(new Thunk(new Code(){
                    public Object ENTER () {
                        VM.PUSH(new Thunk(new Code(){
                            public Object ENTER () {
                                return new Code[]{};
                            }
                        }));
                        VM.PUSH(new getProtocol());
                        VM.PUSH(url);
                        return new _35();
                    }
                }));
                return new bind();
            }
        }));
        VM.PUSH(new Thunk(new Code(){
            public Object ENTER () {
                VM.PUSH(new Nullary("http://www.mondrian-script.org"));
                return new new_URL();
            }
        }));
        return new bind();
    }
}




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic