This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Google Summer of Code
- From: Andrea Bernardini <andrebask at gmail dot com>
- To: kawa at sourceware dot org
- Date: Sun, 16 Mar 2014 01:20:26 +0100
- Subject: Re: Google Summer of Code
- Authentication-results: sourceware.org; auth=none
- References: <20140305094242 dot 349492d0 at debian-andrebask> <5316F956 dot 8040303 at gmail dot com> <20140305132208 dot 3081f8dc at debian-andrebask> <m2lhwo48vi dot fsf at gmail dot com> <5319088C dot 5060401 at bothner dot com> <7B118191-4144-4937-B679-89392D5463EE at theptrgroup dot com>
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