This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
strange int->boolean behavior
- From: Jamison Hope <jrh at theptrgroup dot com>
- To: "kawa at sourceware dot org list" <kawa at sourceware dot org>
- Date: Thu, 18 Dec 2014 13:19:14 -0500
- Subject: strange int->boolean behavior
- Authentication-results: sourceware.org; auth=none
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