This is the mail archive of the kawa@sourceware.org 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]

Question regarding procedure compilation


I've been using kawa-1.7 for a while it was working well.  I recently
tried to upgrade to 1.8 and received an error during procedure
compilation.  I believe this is due to the updated code in LambdaExp
which makes a call to compileWithPosition.  Essentially, my case is that
I have a string in memory that I wish to compile into a Procedure.  The
compileWithPosition eventually makes a call to getLine() and then tries
to modify the source file.  Since in my case I have no source file, this
throws an NPE.  I have attached a sample piece of code to re-create my
issue and the stack trace that results.  If there is a flag I should be
setting so that it calls compile instead of compileWithPosition, please
let me know.


Thanks,
Mayer


==============================================

Sample code:

import gnu.expr.Compilation;
import gnu.expr.Language;
import gnu.expr.ModuleExp;
import gnu.mapping.CharArrayInPort;
import gnu.mapping.InPort;
import gnu.mapping.Procedure;
import gnu.text.SourceMessages;
import kawa.standard.Scheme;

public class KawaCompileTest {
    /**
     * A helper method to compile a String rule into a Procedure.
     * 
     * @param rule      The string representation of the rule
     */
    static final Procedure compileRule(String rule, String ruleName)
            throws Exception {
        Scheme scheme = Scheme.getInstance();
        InPort port = new InPort(new CharArrayInPort(rule));
        SourceMessages messages = new SourceMessages();
        Compilation comp = scheme.parse(port, messages,
                Language.PARSE_IMMEDIATE | Language.PARSE_ONE_LINE);
        comp.getModule().setName(ruleName);
        Class cl = ModuleExp.evalToClass(comp);

        if (messages.getErrorCount() > 0) {
            StringBuffer sb = new StringBuffer();
            sb.append("Failed compiling: ");
            sb.append(messages.toString(messages.getErrorCount()));
            throw new Exception(sb.toString());
        }

        Procedure p = null;
        try {
            p = (Procedure) cl.newInstance();
        }
        catch (Exception e) {
            throw new Exception("Could not create new instance of rule:
"
                    + rule);
        }

        return p;
    }

    public static void main(String[] args) {
        try {
            String schemeStr = "(equal? 1 2)";
            Procedure proc = compileRule(schemeStr, "test");
        }
        catch (Throwable t) {
            t.printStackTrace();
        }
    }
}


========================================

Stack trace:

<unknown>: internal compile error - caught
java.lang.NullPointerException
java.lang.NullPointerException
	at
gnu.bytecode.SourceFileAttr.fixSourceFile(SourceFileAttr.java:31)
	at gnu.bytecode.ClassType.setSourceFile(ClassType.java:138)
	at gnu.bytecode.CodeAttr.putLineNumber(CodeAttr.java:278)
	at gnu.expr.Expression.compileWithPosition(Expression.java:112)
	at gnu.expr.LambdaExp.compileBody(LambdaExp.java:1456)
	at gnu.expr.Compilation.addClass(Compilation.java:1896)
	at gnu.expr.Compilation.compile(Compilation.java:917)
	at gnu.expr.ModuleExp.evalToClass(ModuleExp.java:61)
	at KawaCompileTest.compileRule(KawaCompileTest.java:24)
	at KawaCompileTest.main(KawaCompileTest.java:48)


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