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]

Re: Google Summer of Code


After reading the documentation, I started to inspect the code. Looking
at the implementation of other types of expressions I began to outline
some code, so I would like to ask some questions to know if I am on the
right track. If I understand correctly the problem, we now have case
constructs implemented as Scheme macros in kawa/lib/std_syntax.scm and
we would like to implement them at a lower level (i.e. using Java
bytecode), to make optimizations.

I created a Case class in kawa.lang. It is an abstract class, so we can
generate a specialized matchKey method for each type of key (String,
Enums, etc.):

> public abstract class Case extends Syntax {
> 	
> 	public Pair[] clauses;
> 	
> 	public Object matchKey(Object key) {
> 		return matchKey(key, key.getClass().getName());
> 	}
> 	
> 	/* Check if one of the clauses is equal to the key, 
> 	 * returning the corresponding expression
> 	*/
> 	public abstract Expression matchKey(Object key, String type);
> 	
> 	@Override
> 	public Expression rewrite(Object obj, Translator tr) {//TODO}
> }

Then we need a CaseExp in gnu.expr to perform the actual compilation
using gnu.bytecode.SwitchState:

> public class CaseExp extends Expression {
> 
> 	@Override
> 	protected boolean mustCompile() {return false;}
> 
> 	@Override
> 	public void print(OutPort ps) {//TODO}
> 
> 	@Override
> 	public void compile(Compilation comp, Target target) {//TODO}
> 
> }

Does this make any sense?

What the rewrite method is supposed to do?

An other thing I didn't understand yet is where and how this two classes
should be used in the rest of the code.

Thanks,

Andrea Bernardini


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