This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Google Summer of Code
- From: Per Bothner <per at bothner dot com>
- To: Andrea Bernardini <andrebask at gmail dot com>, kawa at sourceware dot org
- Date: Sun, 16 Mar 2014 23:26:08 -0700
- 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> <20140316012026 dot 4e0ebfef at debian-andrebask>
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/