From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68533 invoked by alias); 20 Jan 2020 15:13:42 -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 68261 invoked by uid 89); 20 Jan 2020 15:13:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,KAM_SHORT,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:4.86_2, welcome! 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 ESMTP; Mon, 20 Jan 2020 15:13:29 +0000 Received: from [10.9.9.203] (helo=mailfront21.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1itYk1-0004CE-Mf; Mon, 20 Jan 2020 16:13:25 +0100 Received: by mailfront21.runbox with esmtpsa [Authenticated alias (524175)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1itYji-0003yX-Kr; Mon, 20 Jan 2020 16:13:07 +0100 Subject: Re: Porting SLAYER to Android To: Panicz Maciej Godek , kawa@sourceware.org References: From: Per Bothner Message-ID: Date: Mon, 20 Jan 2020 15:13:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2020-q1/txt/msg00013.txt On 1/19/20 1:43 AM, Panicz Maciej Godek wrote: > Now, I've been thinking about porting this project to the Android platform. > But I know very little about Java, and even less about Android. Welcome! I did port Kawa to Android years ago, but I generally don't do much if any Android programming. I know very little about the state of Android programming, but I believe there are people on this list who know more. > - is there some class that could be used to represent the Kawa closures in > Java that could be stored in an array and invoked from Java? If you eval Scheme lambda (as a string or an s-expression) the result is a Java object - specifically an instance of the class gnu.mapping.Procedure. You can definitely store that in an array and invoke it from Java. > In the documentation, I have found this: > https://www.gnu.org/software/kawa/Evaluating-Scheme-expressions-from-Java.html > > but the question is whether the Scheme.eval method compiles the expression > (if it's, say, a function) or only interprets it? The terms "compiling" and "interpreting" are vague and have various gray areas. Kawa on normal platforms (i.e. not Android/Dalvik) doesn't really distinguish: When a Scheme form it evaluated (as in the eval function/method or a REPL), it is parsed, compiled to a bytecode class, and then a method in that class is called. Then the bytecode is thrown away. However, if the eval result is a function (or an object like a list that contains a function), then of course the function is preserved as long as there is a reference to it, which means that the bytecode is preserved and reused each time the function is called. So yes, the evaluating a function compiles it to bytecode only once, and reuses the bytecode each time it is called. On Android the situation is different. It used its own non-standard bytecode and virtual machine "Dalvik". Generating "Dalvik" bytecode is not supported by Kawa, so instead Kawa just generates its internal "AST" data type (the Expression class) and then evaluates it. It should be possible to generate regular JVM bytercode and then convert them as needed to Dalvik using dx.jar. However, I haven't tried that - someone else may have. The Dalvik VM is discontinued, but Dalvik bytecode is still used for distribution. I don't know what tools are used these days to generate code on-the-fly on Android. > - given some text file, is there any way to obtain some representations of > the subsequent s-expressions from that file? If you literally means the s-expressions, that is what the standard Scheme read procedure does. If you mean the Kawa AST, I don't think there is a official documented way to do that, but it is of course possible and probably simple. The --debug-print-final-expr will print out the resulting (pre-bytecode-generation) Expression in human-readable form, but it is purely for debugging, and is not meant to be parseable. > Does the above idea have any chance to work, or is there some other way you > would recommend? Well, it's pretty vague, but it can definitely be made to work. If performance of the Scheme code is an issue, you will need to find a way to compile Kawa to Android internal format. -- --Per Bothner per@bothner.com http://per.bothner.com/