public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* define-simple-class fields with ConstantValue attribute?
@ 2020-06-01 18:16 Jamison Hope
  2020-06-02  5:10 ` Per Bothner
  0 siblings, 1 reply; 2+ messages in thread
From: Jamison Hope @ 2020-06-01 18:16 UTC (permalink / raw)
  To: kawa

Is there a field initialization syntax for define-simple-class which
will cause the field to have a ConstantValue attribute set?

For example, if Test.java contains:

public class Test {
  public static final int X = 3;
}

then Test.class will have:

Field name: X public static final Signature: int
Attribute "ConstantValue", length:2, value: Integer 3

However, the equivalent (I believe) Kawa:

(define-simple-class Test () (X ::int allocation: 'static access:
'final init-form: 3))

produces:

Field name: X public static final Signature: int

without the ConstantValue attribute, and instead fills in the value
via code in clinit:

Method name:"<clinit>" public static Signature: ()void
Attribute "Code", length:29, max_stack:1, max_locals:0, code_length:5
  0: iconst_3
  1: putstatic <Field Test.X int>
  4: return

I also tried init: and init-value: and they didn't make a difference.

Thanks,

-- 
Jamison Hope

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: define-simple-class fields with ConstantValue attribute?
  2020-06-01 18:16 define-simple-class fields with ConstantValue attribute? Jamison Hope
@ 2020-06-02  5:10 ` Per Bothner
  0 siblings, 0 replies; 2+ messages in thread
From: Per Bothner @ 2020-06-02  5:10 UTC (permalink / raw)
  To: Jamison Hope, kawa

On 6/1/20 11:16 AM, Jamison Hope wrote:
> Is there a field initialization syntax for define-simple-class which
> will cause the field to have a ConstantValue attribute set?

I got this sort-of-working (with some testsuite failures,
that are probably fixable), by hacking object.java (which is used
to "syntax-expand" define-simple-class).

However, I think it might be more general and less fragile
to change this at bytecode-generating time, in SetExp.java.
(A minor downside is you might get a useless empty <clinit>
method, but that's acceptable, I think.)

I'll look into this approach shortly, perhaps in the morning.

-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-02  5:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-01 18:16 define-simple-class fields with ConstantValue attribute? Jamison Hope
2020-06-02  5:10 ` Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).