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


On 03/15/2014 05:20 PM, Andrea Bernardini wrote:
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.

Right.

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.

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.

What the rewrite method is supposed to do?

It converts the S-Expression (list) case expression into a CaseExp object.

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.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


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