public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Jamison Hope <jrh@theptrgroup.com>
To: "kawa@sourceware.org list" <kawa@sourceware.org>
Subject: strange int->boolean behavior
Date: Thu, 18 Dec 2014 18:19:00 -0000	[thread overview]
Message-ID: <72768B2F-733F-4F37-BB02-880E16C2E855@theptrgroup.com> (raw)

Sometimes, a primitive 0 is false:

#|kawa:1|# (->boolean (->int 3))
Exception in thread "main" java.lang.Error: unsupported CodeAttr.emitConvert
	at gnu.bytecode.CodeAttr.emitConvert(CodeAttr.java:2006)
	[...]

#|kawa:1|# (if (->int 3) "YES" "NO")
YES
#|kawa:2|# (if (->int 0) "YES" "NO")
YES
#|kawa:3|# (define (f x::int) ::string (if x "YES" "NO"))
#|kawa:4|# (f 3)
YES
#|kawa:5|# (f 0)
NO
#|kawa:6|# (disassemble f)
In class atInteractiveLevel$3

Method name:"f" public static Signature: (int)java.lang.CharSequence
Attribute "Code", length:70, max_stack:1, max_locals:1, code_length:14
  0: iload_0
  1: ifeq 10
  4: getstatic <Field atInteractiveLevel$3.Lit0 java.lang.String>
  7: goto 13
 10: getstatic <Field atInteractiveLevel$3.Lit1 java.lang.String>
 13: areturn

I get similar results with the other primitive types.  If I'm following things correctly, it's ConditionalTarget#compileFromStack which is treating zero as false?

--
Jamison Hope
The PTR Group
www.theptrgroup.com



             reply	other threads:[~2014-12-18 18:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-18 18:19 Jamison Hope [this message]
2015-02-19 23:06 ` Per Bothner
2015-02-20  0:39   ` Jamison Hope

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=72768B2F-733F-4F37-BB02-880E16C2E855@theptrgroup.com \
    --to=jrh@theptrgroup.com \
    --cc=kawa@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).