From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.devel Subject: rtl meta information Date: Sat, 1 Dec 2012 00:39:31 +0100 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7bdc12725158a004cfbee9a6 X-Trace: ger.gmane.org 1354318779 23668 80.91.229.3 (30 Nov 2012 23:39:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 30 Nov 2012 23:39:39 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Dec 01 00:39:52 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 1TeaBT-0003Oc-Dq for guile-devel@m.gmane.org; Sat, 01 Dec 2012 00:39:51 +0100 Original-Received: from localhost ([::1]:41428 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeaBH-00075B-Kv for guile-devel@m.gmane.org; Fri, 30 Nov 2012 18:39:39 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:52740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeaBD-00074u-3m for guile-devel@gnu.org; Fri, 30 Nov 2012 18:39:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TeaBB-0006Dg-Dr for guile-devel@gnu.org; Fri, 30 Nov 2012 18:39:35 -0500 Original-Received: from mail-qc0-f169.google.com ([209.85.216.169]:54117) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeaBB-0006DU-84 for guile-devel@gnu.org; Fri, 30 Nov 2012 18:39:33 -0500 Original-Received: by mail-qc0-f169.google.com with SMTP id t2so627617qcq.0 for ; Fri, 30 Nov 2012 15:39:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=xLP8bMyuuQvgA1APluuLfhwhFdB2wKeutsFpAOVjEIA=; b=TctLDHfCE0GEDsArDnoX9EMaVl/rwV0nFBGRAA5QSybmlNSCw0T/8ZT+jA1CJTR9pz 4aGsm9/+h6o2Be6Q1x22VDr9KP4HFNzedN1upraxWVIMgSbqDQsUrQGvtCq373ieljFs gGKu+gDp2L1kdQAiV7LsdMaIn5ZiJmAzbZ6nCpFzMpGB+cry2B/60eQxTlAufLOaJv4P /b52sC78z0LvOBuoNyUwXS/f8pI15iYkZfCf0CwrSUpWFLk8tUVVDD0vFVAoUDDhC4Q7 Yyiwfl8XVAIYmigM7r6DZ6uidSPeHTmB1tOutVZjMXSy0mevWItIERmYtC2Xg88aq451 aYkQ== Original-Received: by 10.49.74.10 with SMTP id p10mr5063636qev.35.1354318772000; Fri, 30 Nov 2012 15:39:32 -0800 (PST) Original-Received: by 10.49.28.135 with HTTP; Fri, 30 Nov 2012 15:39:31 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.216.169 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:15287 Archived-At: --047d7bdc12725158a004cfbee9a6 Content-Type: text/plain; charset=ISO-8859-1 Hi all, I have kept pondering the rtl code-base and it's pretty cool work wingo has put up. I can't say that I fully grasp his intentions for the code base but I do have added some useful infrastructure in order to be able smooth the experience of this exploration. One of the main drawback of the current wip-rtl version is that there is no support for toplevel forms yet. Here is how I added this feature, it's possible to add 'macros' to the rtl-assembler via define-macro-assembler, so here is the toplevel one, (define-macro-assembler (toplevel asm dst sym) (let ((s (emit-non-immediate asm sym)) (d (emit-non-immediate asm (current-module))) (v (intern-constant asm 0 #:slot #t))) (emit-toplevel-ref asm dst v d s))) emit-non-immediate will return a label to an allocated constant object sym and (current-module) (I needed to add to the codebase the possibility of constant modules) intern-constant is similar in nature, but using the #:slot key will force it to allocate a SCM slot and return a label to a slot initialized to #f (for a place to put the ref to a toplevel box used to cache the lookup of the toplevel) . This feature was also added by me, it's a bit unclean because this slot is not a constant and we might want to separate regions of writable memory and non writable memory. Anyway this works for now. Another hack was to add a header to the begin-program code. I (define-macro-assembler (begin-program asm label . f-meta) (emit-label asm label) (let ((meta (make-meta label #f (asm-start asm) #f))) (set-asm-meta! asm (cons meta (asm-meta asm))) (emit asm 0) (emit asm 0) (emit asm 0) ;;Mark that we have a meta prefix (reset-asm-start! asm) (let* ((i (asm-start asm)) (a (asm-cur asm))) (meta-fend-set! meta (lambda (n) (u32-set! a i n)))) (emit asm 0) (reset-asm-start! asm) (emit-load-constant asm 0 f-meta))) I allowed an argument f-meta e.g. function meta data like function signature data structure. that could be added in some way reachable from the header of the code, I do not know yet if there already are present some meta information, wingo's disassemble routine would indicate that the meta structure above was stored and locals, in a header but I'm not clear if that was implemented. I also needed to get the actual code into a bytevector in order to use wingo's dissasemble routine that was already in rtl.scm. To do this I needed the size of the program. Also I wan't to execute native code, and this code need to be hooked into the header, so I ended up doing. u32 HEADER: 0 | If nonzero there is native code that can be executed 0 | ------- 0 | If this u32 is zero then there is metadata, if nonzero then program starts here -------- u32 | Size of the program --------- u32 | Instruction that represent a fetch of the meta constant u32 | --------- Program starts here + some extra hackity hack and I can now do, As usual c compiles a lambda of the argument code which is evaluated and then f will be the lambda inside (c ...) (define f ((c (lambda (x) (pk 1)))) Disassemble rtl functions works somewhat, scheme@(guile-user)> ,x f ((assert-nargs-ee/locals 1 1) (make-short-immediate 0 6) (toplevel-ref 1 4294967275 4294967273 4294967257) (tail-call 1 1)) And a little more information for when printing them notice the (x) scheme@(guile-user)> f $1 = # Finally toplevel ref work by executing the function scheme@(guile-user)> (f 1) ;;; (1) $3 = 1 Fun fun indeed. There are many tangents to take here, one would be to add more metadata like source information, the assembler can be improved where one lookup constants and presents them nicer function names as meta information, variable names and more meta information in the assembler would also be good to have in order to get better disassemble printouts. Anyway Happy Friday/Saturday to you all! /Stefan --047d7bdc12725158a004cfbee9a6 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi all,

I have kept pondering the rtl code-base and it's pretty = cool work wingo has put up. I can't say that I fully grasp
his inten= tions for the code base but I do have added some useful infrastructure in o= rder to be able smooth the
experience of this exploration.

One of the main drawback of the curr= ent wip-rtl version is that there is no support for toplevel forms yet.
=
Here is how I added this feature,

it's possible to add '= macros' to the rtl-assembler via define-macro-assembler, so here is the= toplevel one,

(define-macro-assembler (toplevel asm dst sym)
=A0 (let ((s (emit-no= n-immediate asm sym))
=A0=A0=A0=A0=A0=A0=A0 (d (emit-non-immediate asm (= current-module)))
=A0=A0=A0=A0=A0=A0=A0 (v (intern-constant asm 0 #:slot= #t)))
=A0=A0=A0 (emit-toplevel-ref asm dst v d s)))

emit-non-immediate will return a label to an allocated constant object = sym and (current-module)
(I needed to add to the codebase the possibilit= y of constant modules)

intern-constant is similar in nature, but usi= ng the #:slot key will force it to allocate a SCM slot and
return a label to a slot initialized to #f (for a place to put the ref to a= toplevel box used to cache the lookup of the toplevel) .
This feature = was also added by me, it's a bit unclean because this slot is not a con= stant and we might want to
separate regions of writable memory and non writable memory. Anyway this wo= rks for now.


Another hack was to add a header to the begin-progr= am code. I
(define-macro-assembler (begin-program asm label . f-meta)= =A0=A0=A0
=A0 (emit-label asm label)
=A0 (let ((meta (make-meta label #f (asm-sta= rt asm) #f)))
=A0=A0=A0 (set-asm-meta! asm (cons meta (asm-meta asm)))=A0=A0=A0 (emit asm 0)
=A0=A0=A0 (emit asm 0)
=A0=A0=A0 (emit asm 0= ) ;;Mark that we have a meta prefix
=A0=A0=A0 (reset-asm-start! asm)
=A0=A0=A0 (let* ((i (asm-start asm))=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (a (asm-cur=A0=A0 asm)))
=A0=A0=A0=A0=A0= (meta-fend-set! meta (lambda (n) (u32-set! a i n))))=A0=A0=A0=A0=A0
= =A0=A0=A0 (emit asm 0)
=A0=A0=A0 (reset-asm-start! asm)
=A0=A0=A0 (em= it-load-constant asm 0 f-meta)))

I allowed an argument f-meta e.g. function meta data like function sign= ature data structure.
that could be added in some way reachable from the= header of the code, I do not know yet
if there already are present some= meta information, wingo's disassemble routine would indicate
that the meta structure above was stored and locals, in a header but I'= m not clear if that was
implemented.

I also needed to get the ac= tual code into a bytevector in order to use wingo's dissasemble routine=
that was already in rtl.scm. To do this I needed the size of the program.
Also I wan't to execute native code, and this code need to be hoo= ked into the header, so I ended up doing.

u32 HEADER:
0=A0=A0=A0 = | If nonzero there is native code that can be executed
0=A0=A0=A0 |
-------
0=A0=A0=A0 | If this u32 is zero then there is = metadata, if nonzero then program starts here
--------
u32 | Size of = the program
---------
u32 | Instruction that represent a fetch of the= meta constant
u32 |
---------
Program starts here

+ some extra hackity hack = and I can now do,

As usual c compiles a lambda of the argument code = which is evaluated and then f will be the lambda inside (c ...)
(define = f ((c (lambda (x) (pk 1))))

Disassemble rtl functions works somewhat,
scheme@(guile-user)> ,x= f
((assert-nargs-ee/locals 1 1)
=A0(make-short-immediate 0 6)
=A0= (toplevel-ref 1 4294967275 4294967273 4294967257)
=A0(tail-call 1 1))
And a little more information for when printing them notice the (x)
sche= me@(guile-user)> f
$1 =3D #<rtl-program 158f240 1373314 (x)>

Finally toplevel ref work by executing the function

scheme@= (guile-user)> (f 1)
;;; (1)
$3 =3D 1

Fun fun indeed. There are many tangents to take = here, one would be to add more metadata like
source information, the ass= embler can be improved where one lookup constants and presents them nicer function names as meta information, variable names and more meta informatio= n in the assembler would also
be good to have in order to get better dis= assemble printouts.


Anyway Happy Friday/Saturday to you all!

/Stefan
--047d7bdc12725158a004cfbee9a6--