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 Thu, 20 Mar 2014 19:56:31 -0700
Per Bothner <per@bothner.com> ha scritto:

> On 03/20/2014 12:48 PM, Andrea Bernardini wrote:
> > Il giorno Sun, 16 Mar 2014 23:26:08 -0700
> > Per Bothner <per@bothner.com> ha scritto:
> 
> It is certainly possible, but using a type-specific Case Syntax class
> doesn't seem practical.  

Ok. I'm not using the Case Syntax class any more.

> That's the right basic idea.  However, 'clauses' is not an expression;
> it's not a set of expressions.  Perhaps best to try something similar
> to how TryExpr contains a set of CatchClauses.

Right, that implementation was wrong, as a clause is of the form
((datum*) exp+). 
Now I'm able to create a CaseExp in the Scheme code, containing an
array of CaseClause. Each case clause contains an array of Object
(the datum*) and an Expression (the clause body). 

I also tried to implement the compile method in CaseExp, but i got this
error:

java.lang.Error: popType called with empty stack
at gnu.bytecode.CodeAttr.popType(CodeAttr.java:442)
at gnu.bytecode.SwitchState.switchValuePushed(SwitchState.java:76)
at gnu.bytecode.CodeAttr.startSwitch(CodeAttr.java:2505)

Code:

>public void compile(Compilation comp, Target target) {
>	System.out.print("Compiling CaseExp\n");
>	
>	CodeAttr code = comp.getCode();
>	key.compile(comp, target);
>	SwitchState sw = code.startSwitch();
>	
>	for (int i = 0; i < clauses.length; i++) {
>		clauses[i].compile(sw, comp,
>	target);			
>}
>	if (elseClause != null)
>		elseClause.compile(sw, comp, target);
>}

I think the problem is that the key Expression is not found on the
stack when startSwitch is called. How can I push the key on the stack?
Looking at the IfExp.compile implementation I found a similar code:

>ConditionalTarget ctarget
>      = new ConditionalTarget(trueLabel, falseLabel, language);
>test.compile(comp, ctarget);
>code.emitIfThen(); 

Do I have to create a particular Target to compile the case key?

> 
> If CaseClause extends LetExp in the same way as CatchClause, then
> you can translate '=> expression' as something like
>    '(let ((dummy (match ...))) (expression dummy))'

I choose not to use a LetExp as we have no bindings in the case clauses.

To avoid writing a lot of code here, I published the git repository:

bit.ly/1g0ajsl 

Andrea




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