Adding implementation specific extensions

Asked by Arthur Smyles

I'm currently using the gambit-c scheme compiler. I'd like to add libraries for some it's apis (threading, ffi, and io). I'd like your advice on the best way to update your system so that I can create r6rs libraries with these builtin extensions. I like the approach you take on setting up the r6rs libraries and would like to achieve something similar.

Question information

Language:
English Edit question
Status:
Answered
For:
r6rs-libraries Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Abdulaziz Ghuloum (aghuloum) said :
#1

Greetings,

I have added a file to the repository explaining how one might
go about adding additional libraries and exports. The
contents of that file are included at the end of this message.
Now this addresses how to add "primitives" only. Additional
syntactic forms such as implementation-specific ffi syntax are
not addressed. Right now, you can hack onto the source of the
expander to add additional forma, but I would like to explore
how one might go about doing so without having to modify the
distribution files themselves (you don't want to add your
extensions again everytime I push a new revision, right?).

So, for now, you can add the gambit and any other procedures
that you define outside of the r6rs system. For FFI, give me
some time to think it over.

Thanks for your interest.

Aziz,,,

********************************************************************

For this exercise, we would like to:

 1. create a library for an implementation, say (gambit).
 2. add some exports that the implementation provides to the
 library, say object->serial-number and serial-number->object.

We will limit the added exports to primitives which require
no special syntax. In later series, we'll see how those can
be added.

Steps:

1. Modify psyntax-buildscript.ss as follows:

 a. Add the library to the set of libraries:

  (define library-legend
    ;; abbr. name visible? required?
    '((interaction (ikarus interaction) #t #f)
      (ne (psyntax null-environment-5) #t #f)
      (se (psyntax scheme-report-environment-5) #t #f)
      ...
      (gambit (gambit) #t #f)
      ))

 b. Add a bunch of exported primitives to the library:
  (define identifier->library-map
    '(
      ;;;
      (lambda r ba se ne)
      (and r ba se ne)
      ...
      ;;; gambit-specific exports
      (object->serial-number gambit)
      (serial-number->object gambit)
      ))

2. Rebuild the expanded psyntax code by running:

   $ make psyntax-gambit.pp

   This produces psyntax-gambit.pp which has the new library
   and exports.

3. Write a small script (call it gambit-test.ss) which contains:

   (import (rnrs) (gambit))
   (write (object->serial-number 'foo))
   (newline)
   (write (eq? 'foo
                (serial-number->object
                  (object->serial-number 'foo))))
   (newline)

   *** I added gambit-test.ss to the examples.

4. Run the script:

   $ ./gsi.r6rs.ss gambit-test.ss
   r6rs psyntax ready
   2
   #t

If you have a list of all of your implementation's primitives,
please email it to me and I'll integrate them with the
standard distribution so that you won't have to do that every
time I make a change.

TODO: (gambit) should not be visible unless we're in gambit,
but to do so requires determining which host we're running
under. I might simply just add a (implementation-name)
procedure that returns the name of the implementation, and
set that primitive in the implementation-specific startup
file.

Revision history for this message
leppie (leppie) said :
#2

Thanks for the info. I too have a need to have something similar to the ffi macro. Unfortunately, I couldnt get it to work. I did however find an easy hack for now, and thought I might share it.

1. Add your macro as a function to a library as per the explanation above. In my case 'clr-call-internal'
2. Create a macro in a library that 'calls' the macro above. For example:

(library (ironscheme clr)
  (export
    clr-call)
  (import
    (rnrs)
    (ironscheme clr internal))

  (define-syntax clr-call
    (lambda (e)
      (syntax-case e ()
        [(_ target:member instance args ...)
         #'(clr-call-internal 'target:member instance args ...)])))
)

Simply quote the datum you dont want to be 'gensym'd'. Now in your implementation macro you would have to remove that quote again, and you should have what you are looking for. This way at least you dont have to mess with the psyntax files, except for the build-script as per above.

Can you help with this problem?

Provide an answer of your own, or ask Arthur Smyles for more information if necessary.

To post a message you must log in.