From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Rottmann Newsgroups: gmane.lisp.guile.devel Subject: Re: thoughts on native code Date: Thu, 15 Nov 2012 23:44:46 +0100 Message-ID: <876256eba9.fsf@delenn.home.rotty.xx.vu> References: <50A4C19A.3030907@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1353019516 20684 80.91.229.3 (15 Nov 2012 22:45:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 15 Nov 2012 22:45:16 +0000 (UTC) Cc: guile-devel@gnu.org To: Sjoerd van Leent =?utf-8?Q?Priv=C3=A9?= Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Nov 15 23:45:23 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TZ8BW-0004JM-QZ for guile-devel@m.gmane.org; Thu, 15 Nov 2012 23:45:23 +0100 Original-Received: from localhost ([::1]:34674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZ8BM-0004Gv-V7 for guile-devel@m.gmane.org; Thu, 15 Nov 2012 17:45:12 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:59763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZ8BG-0004Dl-JH for guile-devel@gnu.org; Thu, 15 Nov 2012 17:45:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TZ8BD-0003fw-F9 for guile-devel@gnu.org; Thu, 15 Nov 2012 17:45:06 -0500 Original-Received: from mailout-de.gmx.net ([213.165.64.23]:55518) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1TZ8BD-0003eG-5c for guile-devel@gnu.org; Thu, 15 Nov 2012 17:45:03 -0500 Original-Received: (qmail invoked by alias); 15 Nov 2012 22:45:01 -0000 Original-Received: from 85-127-117-38.dynamic.xdsl-line.inode.at (EHLO cubox.home.rotty.xx.vu) [85.127.117.38] by mail.gmx.net (mp035) with SMTP; 15 Nov 2012 23:45:01 +0100 X-Authenticated: #3102804 X-Provags-ID: V01U2FsdGVkX1/FSwEA8LDFj9ow9EAPqGK/on4NPIXPsfwtqs7lyA 8e0de+KVstX19U Original-Received: from delenn.home.rotty.xx.vu (delenn.home.rotty.xx.vu [IPv6:fdfb:599d:f328:2::6e]) by cubox.home.rotty.xx.vu (Postfix) with ESMTP id C65E916008C; Thu, 15 Nov 2012 23:44:47 +0100 (CET) Original-Received: by delenn.home.rotty.xx.vu (Postfix, from userid 1000) id 13C6A32002C; Thu, 15 Nov 2012 23:44:47 +0100 (CET) In-Reply-To: <50A4C19A.3030907@gmail.com> ("Sjoerd van Leent =?utf-8?Q?Pri?= =?utf-8?Q?v=C3=A9=22's?= message of "Thu, 15 Nov 2012 11:19:06 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 213.165.64.23 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:15176 Archived-At: Sjoerd van Leent Priv=C3=A9 writes: > Hi Stefan, > > Just my idea about an assembler in Scheme. Sounds interesting. If it's > done properly, it can be very promising to use scheme itself to > directly emit machine instructions. This would also be interesting for > meta compilation in the future (think of aiding GCC). > > So you are thinking about an assembler for x86? Perhaps I can help out > on this one. I would like to do this part, as I haven't been able to > aid on other parts besides voicing my ideas (anyways, I am on embedded > development these days.) > > The only discussion is the syntax I believe, I mean, should it be AT&T > like, Intel like, or leave this domain and do something new. I would > go for instructions like this (using macros): > > (let ((target :x686)) > (assemble target > ((mov long 100 EAX) > (mov long 200 EBX) > (add long EBX EAX)))) > > Giving back the native machine code instructions. Perhaps special > constructions can be made to return partially complete instructions > (such as missing labels or calls to guile procedures...) > Regarding the assembler: I have a working AVR assembler [0] in my "avrth" AVR Forth implementation [1]. That assembler also employs this "partially complete instructions" idea you mentioned, having a symbol resolution step. It also supports a simple evaluator for Assembly-time expressions. Maybe you find it interesting :-). Here's an example snippet, from the Forth implementation's runtime: (define-primitive-vocable vocabulary:primitive "1ms" (vm) (scheme (sleep-seconds 0.001)) (assembly (ldi zl (lo8 (/ cpu-frequency 4000))) (ldi zh (hi8 (/ cpu-frequency 4000))) (sbiw zl 42) ;internal plus forth kernel overhead PFA_1MS1 (sbiw zl 1) (brne PFA_1MS1))) The assembler code is the `(assembly ...)' part, but above that you can see the runable documentation, written in Scheme ;-). You may also have noticed the expressions used, i.e. `(lo8 ...)' and `(hi8 ...)' -- these are evaluated at assembly-time by the `assembler-eval' as found in [0]. While I'm probably too time-starved to really help with Guile's assembler, I'd be interested in having, and maybe working on (if time permits), a Scheme-based assembler targeting ARM platforms, so I might chime in this area at some point. It should be fine to use my code (from a copyright view angle) as a basis something to be incorporated into Guile (even though that file is marked GPLv2, not GPLv2+), as long as you take care to eliminate the actual AVR instruction generation code. This part (i.e., the section marked "Code emitters") is mostly originally transcribed from the assembler [2] written in Forth included in AmForth [3], which is GPLv2 (only, unfortunatly). However, I'm not even sure if the AmForth copyright is still applicable to that part of my code, as the code has been transformed substantially by transcription. That might well be a moot point, we probably don't want to target 8-bit microcontrollers as Guile platforms anyway ;-). [0] http://rotty.xx.vu/gitweb/?p=3Dscheme/avrth.git;a=3Dblob;f=3Dassembler.= sls;hb=3DHEAD [1] http://rotty.xx.vu/gitweb/?p=3Dscheme/avrth.git;a=3Dsummary [2] http://amforth.svn.sourceforge.net/viewvc/amforth/trunk/lib/assembler.f= rt?revision=3D1301&view=3Dmarkup [3] http://amforth.sourceforge.net/ Regards, Rotty --=20 Andreas Rottmann --