This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: bug/patch for kawa/standard/object.java
- From: Per Bothner <per at bothner dot com>
- To: Vladimir Tsichevski <wowa at jet dot msk dot su>
- Cc: Kawa List <kawa at sources dot redhat dot com>
- Date: Mon, 24 Mar 2003 10:46:41 -0800
- Subject: Re: bug/patch for kawa/standard/object.java
- References: <3E7F40D4.6090403@jet.msk.su>
Vladimir Tsichevski wrote:
Hi,
object with methods cannot currently be declared with define-syntax
mechanism. You get "missing method name"
error message if you try to.
Below is the patch which (hopefully) cures this problem.
Good job getting this far. The patch is basically correct,
but it doesn't go far enough.
Co-incidentally (?), I was looking the bug Chris Dean
reported, and I came up with the attached patch.
--
--Per Bothner
per at bothner dot com http://per.bothner.com/
Index: kawa/standard/define_class.java
===================================================================
RCS file: /cvs/kawa/kawa/kawa/standard/define_class.java,v
retrieving revision 1.8
diff -u -r1.8 define_class.java
--- kawa/standard/define_class.java 15 Nov 2002 20:40:36 -0000 1.8
+++ kawa/standard/define_class.java 24 Mar 2003 18:42:51 -0000
@@ -2,6 +2,7 @@
import kawa.lang.*;
import gnu.lists.*;
import gnu.expr.*;
+import gnu.mapping.Symbol;
public class define_class extends Syntax
{
@@ -18,10 +19,11 @@
ScopeExp defs, Translator tr)
{
Pair p;
+ Object name;
if (! (st.cdr instanceof Pair)
- || ! ((p = (Pair) st.cdr).car instanceof String))
+ || ! ((name = (p = (Pair) st.cdr).car) instanceof String
+ || name instanceof Symbol))
return super.scanForDefinitions(st, forms, defs, tr);
- String name = (String) p.car;
Declaration decl = new Declaration(name);
ClassExp oexp = new ClassExp();
decl.noteValue(oexp);
@@ -51,21 +53,23 @@
public Expression rewriteForm (Pair form, Translator tr)
{
//FIXME needs work
- String name = null;
+ Object symbol = null;
Declaration decl = null;
if (form.cdr instanceof Pair)
{
form = (Pair) form.cdr;
- if (form.car instanceof String)
- name = (String) form.car;
+ if (form.car instanceof String || form.car instanceof Symbol)
+ symbol = form.car;
else if (form.car instanceof Declaration)
{
decl = (Declaration) form.car;
- name = decl.getName();
+ symbol = decl.getName();
}
}
- if (name == null)
+ if (symbol == null)
return tr.syntaxError("missing class name in "+this.getName());
+ String name = symbol instanceof Symbol ? ((Symbol) symbol).getName()
+ : symbol.toString();
//LambdaExp lexp = new LambdaExp();
//lexp.setName(name);
// tr.push(lexp);
@@ -80,7 +84,7 @@
Expression oe = objectSyntax.rewriteClassDef((Pair) form.cdr, oexp, tr);
// lexp.body = oe;
// tr.pop(lexp);
- SetExp sexp = new SetExp (name, oe);
+ SetExp sexp = new SetExp (symbol, oe);
sexp.binding = decl;
sexp.setDefining (true);
// sexp.binding = decl;
Index: kawa/standard/object.java
===================================================================
RCS file: /cvs/kawa/kawa/kawa/standard/object.java,v
retrieving revision 1.13
diff -u -r1.13 object.java
--- kawa/standard/object.java 25 Aug 2001 00:20:04 -0000 1.13
+++ kawa/standard/object.java 24 Mar 2003 18:42:51 -0000
@@ -4,6 +4,7 @@
import gnu.lists.*;
import gnu.bytecode.*;
import java.util.Vector;
+import gnu.mapping.Symbol;
public class object extends Syntax
{
@@ -69,10 +70,10 @@
return tr.syntaxError("object member not a list");
obj = pair.cdr; // Next member.
pair = (Pair) pair.car;
- if (pair.car instanceof String)
+ if (pair.car instanceof String || pair.car instanceof Symbol)
{ // Field declaration.
Pair typePair = null;
- String sname = (String) pair.car;
+ Object sname = pair.car;
Declaration decl = oexp.addDeclaration(sname);
decl.setSimple(false);
int nKeywords = 0;
@@ -112,7 +113,8 @@
{
if (! (value instanceof Keyword))
tr.error('e', "invalid 'init-keyword' - not a keyword");
- else if (((Keyword) value).getName() != sname)
+ else if (((Keyword) value).getName()
+ != sname.toString())
tr.error('w', "init-keyword option ignored");
}
else
@@ -157,9 +159,10 @@
else if (pair.car instanceof Pair)
{ // Method declaration.
Pair mpair = (Pair) pair.car;
- if (! (mpair.car instanceof String))
+ Object mname = mpair.car;
+ if (! (mname instanceof String)
+ && ! (mname instanceof Symbol))
return tr.syntaxError("missing method name");
- String mname = (String) mpair.car;
Declaration decl = oexp.addDeclaration(mname);
LambdaExp lexp = new LambdaExp();
lexp.setClassMethod(true);
@@ -189,7 +192,7 @@
{
obj = pair.cdr; // Next member.
pair = (Pair) pair.car;
- if (pair.car instanceof String)
+ if (pair.car instanceof String || pair.car instanceof Symbol)
{ // Field declaration.
Object type = null;
int nKeywords = 0;
Index: kawa/lang/Translator.java
===================================================================
RCS file: /cvs/kawa/kawa/kawa/lang/Translator.java,v
retrieving revision 1.73
diff -u -r1.73 Translator.java
--- kawa/lang/Translator.java 23 Nov 2002 20:12:05 -0000 1.73
+++ kawa/lang/Translator.java 24 Mar 2003 18:42:52 -0000
@@ -206,7 +206,8 @@
return obj;
if (obj instanceof Declaration)
{
- Expression dval = ((Declaration) obj).getValue();
+ Expression dval
+ = Declaration.followAliases((Declaration) obj).getValue();
if (dval instanceof QuoteExp)
return ((QuoteExp) dval).getValue();
}