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]

Compiling procedures questions


I'm relatively new to kawa (and scheme for that matter) and have a question
about compiling procedures into bytecode and using them in a java program.
The scenario I am coding is as follows:

-  I have created three procedures (which extend Procedure0) and they all
return Boolean.TRUE or Boolean.FALSE.
-  I have written a rule of the following form:  (or proc1? (or proc2?
proc3?))
-  I compile the rule into a procedure using the following code:

    /**
     * A helper method to compile a String rule into a Procedure.
     *
     * @param rule The string representation of the rule
     */
    private static final Procedure compileRule( String rule ) throws
Exception {
            Scheme scheme = new Scheme( Scheme.builtin() );
            scheme.eval( "(load \" + MyProcs.class.getName() + ".class\")"
);

            InPort port = new InPort( new CharArrayInPort( rule ) );
            SourceMessages messages = new SourceMessages();
            Compilation comp = scheme.parseFile( port, true, messages );

            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;
    }


- The compilation succeeds and is cached.
- I evaluate the rule using the following code:

	return ((Boolean)rule.apply0()).booleanValue();


The evaluation throws a ClassCastException reporting that I am attempting to
cast my proc1 class to a Boolean.  Did I miss something in the compilation
step?  How do a compile the procedure (and any references it may have to
other procedures) such that after compilation I can call an apply() method
and retrieve the final boolean result?


Thanks,
Mayer Crystal



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