dotfiles / emacs.d / slime-2012-01-20 / contrib /

;; swank-larceny.scm --- Swank server for Ikarus
;; License: Public Domain
;; Author: Helmut Eller
;; In a shell execute:
;;   ikarus
;; and then `M-x slime-connect' in Emacs.

(library (swank os)
    (export getpid make-server-socket accept local-port close-socket)
    (import (rnrs)
	    (only (ikarus foreign) make-c-callout dlsym dlopen
		  pointer-set-c-long! pointer-ref-c-unsigned-short
		  malloc free pointer-size)
	    (rename (only (ikarus ipc) tcp-server-socket accept-connection
		    (tcp-server-socket make-server-socket)
		    (close-tcp-server-socket close-socket))
	    (only (ikarus)

 (define libc (dlopen))
 (define (cfun name return-type arg-types)
   ((make-c-callout return-type arg-types) (dlsym libc name)))

 (define getpid (cfun "getpid" 'signed-int '()))

 (define (accept socket codec)
   (let-values (((in out) (accept-connection socket)))
     (values (transcoded-port in (make-transcoder codec))
	     (transcoded-port out (make-transcoder codec)))))

 (define (socket-fd socket)
   (let ((rtd (struct-type-descriptor socket)))
     (do ((i 0 (+ i 1))
	  (names (struct-type-field-names rtd) (cdr names)))
	 ((eq? (car names) 'fd) ((struct-field-accessor rtd i) socket)))))

 (define sockaddr_in/size 16)
 (define sockaddr_in/sin_family 0)
 (define sockaddr_in/sin_port 2)
 (define sockaddr_in/sin_addr 4)

 (define (local-port socket)
   (let* ((fd (socket-fd socket))
	  (addr (malloc sockaddr_in/size))
	  (size (malloc (pointer-size))))
     (pointer-set-c-long! size 0 sockaddr_in/size)
     (let ((code (getsockname fd addr size))
	   (port (ntohs (pointer-ref-c-unsigned-short 
			 addr sockaddr_in/sin_port))))
       (free addr)
       (free size)
       (cond ((= code -1) (error "getsockname failed"))
	     (#t port)))))

 (define getsockname 
   (cfun "getsockname" 'signed-int '(signed-int pointer pointer)))

 (define ntohs (cfun "ntohs" 'unsigned-short '(unsigned-short)))


(library (swank sys)
    (export implementation-name eval-in-interaction-environment)
    (import (rnrs) 
	    (rnrs eval)
	    (only (ikarus) interaction-environment))

 (define (implementation-name) "ikarus")

 (define (eval-in-interaction-environment form)
   (eval form (interaction-environment)))


(import (only (ikarus) load))
(load "swank-r6rs.scm")
(import (swank))
(start-server #f)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.