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


Il giorno Sun, 16 Mar 2014 23:26:08 -0700
Per Bothner <per@bothner.com> ha scritto:

> > 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.):
> 
> That doesn't sound right.  How would you decide which kind of key you
> have until you expand it?  In general you may not know until you do
> type-inference/-propagation, which happens in the (awkwardly-named)
> InlineCalls phase.

Ok, so now I'm wondering if it is possible to use the same concepts
described in "Rapid case dispatch in Scheme" in the compile method of
CaseExp. That is, to use dispatch on the type and index/clause mapping
in Java to generate optimized bytecode.

> 
> > Then we need a CaseExp in gnu.expr to perform the actual compilation
> > using gnu.bytecode.SwitchState:
> 
> Right - though an alternative may be to do similar to what we do
> for TypeSwitch: Represent each case branch as a LambdaExp - which
> then gets inlined.  This avoids creating a new Expression type, but
> it is more complicated and slightly harder to understand.  However,
> the TypeSwitch approach may mesh better with the pattern-matching
> framework I'm working on.
> 
> Perhaps best to focus on implementing a CaseExpr class; we can look
> at the TypeSwitch-like LambdaExp approach later.

I agree.

> 
> > An other thing I didn't understand yet is where and how this two
> > classes should be used in the rest of the code.
> 
> You don't actually need a Case Syntax class.  You can create the
> CaseExp object directly using Scheme code.  Look at how try-finally
> (in syntax,scm) creates a TryExp, or how if (in prim_syntax.scm)
> creates an IfExp.

I came to this:

>public class CaseExp extends Expression {
>	
>	public CaseExp(Expression key, Expression clauses) {
>		System.out.print("Case Expression\n");
>	}
>
>	public CaseExp(Expression key, Expression clauses, 
>			Expression elseClause , Boolean isLambdaForm) {
>		System.out.print("Case Expression with else
>	clause"+...));
>	}

>(define-rewrite-syntax case
>  (lambda (x)
>    (syntax-case x (else =>)
>       ((_ case-key case-clause ... (else => case-else-lambda))
>       (make <it.polimi.kawacase.CaseExp>
>         (syntax->expression (syntax case-key))
>         (syntax->expression (syntax (case-clause ...)))
>         (syntax->expression (syntax case-else-lambda))
>         #t))
>      ((_ case-key case-clause ... (else case-else))
>       (make <it.polimi.kawacase.CaseExp>
>         (syntax->expression (syntax case-key))
>         (syntax->expression (syntax (case-clause ...)))
>         (syntax->expression (syntax case-else))
>         #f))
>      ((_ case-key case-clause ...)
>       (make <it.polimi.kawacase.CaseExp>
>         (syntax->expression (syntax case-key))
>         (syntax->expression (syntax (case-clause ...))))))))

So if i compile this sample code:

>(case 'sym
>  ((sym) (display 1))
>  ((boo) (display 2))
>  (else => (lambda (x)
>             (display 3))))

Kawa prints:

> Case Expression with else clause in lambda form

Am I on the right track? Now I have to study how to generate the
bytecode, obviously at the current state the generated code does
nothing.

Thank you very much for all your answers.

Andrea


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