From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29815 invoked by alias); 19 Feb 2015 23:06:34 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 29802 invoked by uid 89); 19 Feb 2015 23:06:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: aibo.runbox.com Received: from aibo.runbox.com (HELO aibo.runbox.com) (91.220.196.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 19 Feb 2015 23:06:32 +0000 Received: from [10.9.9.206] (helo=mailfront02.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1YOaAu-0003gF-3v; Fri, 20 Feb 2015 00:06:28 +0100 Received: from 70-36-239-115.dsl.dynamic.fusionbroadband.com ([70.36.239.115] helo=toshie.bothner.com) by mailfront02.runbox.com with esmtpsa (uid:757155 ) (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) id 1YOa8M-0002L4-2p; Fri, 20 Feb 2015 00:03:50 +0100 Message-ID: <54E66BD2.1060903@bothner.com> Date: Thu, 19 Feb 2015 23:06:00 -0000 From: Per Bothner User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Jamison Hope , "kawa@sourceware.org list" Subject: Re: strange int->boolean behavior References: <72768B2F-733F-4F37-BB02-880E16C2E855@theptrgroup.com> In-Reply-To: <72768B2F-733F-4F37-BB02-880E16C2E855@theptrgroup.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-q1/txt/msg00046.txt.bz2 On 12/18/2014 10:19 AM, Jamison Hope wrote: > 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 > 7: goto 13 > 10: getstatic > 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? Yes. I checked in a fix for this. The change in ConditionalTarget depends on the language; specifically whether language.isTrue(Integer.valueOf(0)). If so, we an just emitGoto the true label. I forgot about or overlooking this message, but found it while searching for another discussion (which turn out to be "proposed changes to handling of false and end-of-list"). (I'm looking into doing at least part of that previous proposal - specifically treating #!null as false.) -- --Per Bothner per@bothner.com http://per.bothner.com/