From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 75362 invoked by alias); 22 Sep 2017 22:18:51 -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 75352 invoked by uid 89); 22 Sep 2017 22:18:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=sk:www.the, sk:wwwthe, HX-HELO:sk:mail.th, H*r:sk:mail.th X-HELO: mail.theptrgroup.com Received: from mail.theptrgroup.com (HELO mail.theptrgroup.com) (71.178.251.9) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 22 Sep 2017 22:18:49 +0000 Received: from [10.11.21.6] (unknown [10.11.21.6]) by mail.theptrgroup.com (Postfix) with ESMTPS id 14C4D40324 for ; Fri, 22 Sep 2017 18:18:48 -0400 (EDT) From: Jamison Hope Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: no class-of ? Date: Fri, 22 Sep 2017 22:18:00 -0000 References: <425B3BC8-31F3-4299-ADB1-9E064C1E8D3E@theptrgroup.com> <51a642b1-f20d-9f32-645d-ea96b935e3c2@bothner.com> To: Kawa mailing list In-Reply-To: <51a642b1-f20d-9f32-645d-ea96b935e3c2@bothner.com> Message-Id: X-IsSubscribed: yes X-SW-Source: 2017-q3/txt/msg00077.txt.bz2 OK, so if I understand correctly, I can't use a macro for this, but what I can do instead is write a function that always gets inlined. The function itself doesn't really have to do anything, because the real work will be done in the validate-apply handler that rewrites the procedure application to a new Expression. And there, I can decide what kind of Expression to construct based upon the Type of the argument expression. I think that should work for what I'm trying to accomplish, thanks! -J On Sep 22, 2017, at 3:21 PM, Per Bothner wrote: >=20 > On 09/22/2017 11:28 AM, Jamison Hope wrote: >> On a somewhat related note, is there a way to define a macro that can >> determine the type of an expression at macro expansion time, without >> actually evaluating the expression? >=20 > Note that expressions do not have types at macro-expansion time - that ha= ppens > at a later stage. >=20 > What you can do is write a procedure and associate either a 'validate' > or a 'compile' property with it. >=20 > There are lots of examples in kawa/lib. Look for the search string 'vali= date-apply:'. > For example in characters.scm: >=20 > (define (char->integer ch::character) ::int > validate-apply: "kawa.lib.compile_misc:charToIntegerValidateApply" > (as int ch)) >=20 > You'll find charToIntegerValidateApply in compile-misc.scm: >=20 > (define-validate charToIntegerValidateApply (exp required proc) > ((exp:isSimple 1 1) > (let ((e0 (visit-exp (exp:getArg 0) character))) > (apply-exp as int > (apply-exp gnu.kawa.functions.Convert:cast character e0)))= )) >=20 > This mean is exp is a simple application (no splices or keywords) with on= e argument, > then apply the following transformation. This is evaluated during the > InlineCall phase of the compilation. >=20 > When it comes to charToIntegerValidateApply it first "validates" argument= 0 > in the context of the "required type" character (which is a 32-bit "primi= tive" > character type). It then wraps the result in a call to the low-lever Con= vert:cast > procedure. Assuming the types are correct, this will be a no-op. > Then that result is cast to an int. >=20 > If all goes well and the incoming value is a 32-bit unboxed character or = a 16-bit unboxed char, > no code actually needs to be generated - which is the reason > for using the charToIntegerValidateApply transformer in the first place. = Otherwise, > you either get a compile-time error of the appropriate run-time conversio= n. >=20 > You can use (exp:getType) to get the type of the expression. >=20 > There is also the compile-apply property: >=20 > (define (values #!rest (args :: )) > validate-apply: "kawa.lib.compile_misc:valuesValidateApply" > compile-apply: "kawa.lib.compile_misc:valuesCompile" > (invoke-static 'make args)) >=20 > This causes the valuesCompile method in class kawa.lib.compile_misc > to be called at code-generation time. This is more low-level, > and most of the code-generation are actually written in Java to > generate custom byte-code depending on the argument expressions > and their types. >=20 > (If I wanted to get the type of a standalone expression, I'd > look at the implementation of eval (see kawa/lang/Eval.java), and do the = same, > but stop before code-generation. Specifically,you would probably want to= do > compilation.process(Compilation.WALKED). Then you'd do something like > compilation.getModule().body.getType(). >=20 > However, that doesn't give you the type on an expression *in a lexical co= ntext*.) > --=20 > --Per Bothner > per@bothner.com http://per.bothner.com/ -- Jamison Hope The PTR Group www.theptrgroup.com