Klimi's new dotfiles with stow.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

86 líneas
2.4 KiB

hace 5 años
  1. ;; swank-larceny.scm --- Swank server for Ikarus
  2. ;;
  3. ;; License: Public Domain
  4. ;; Author: Helmut Eller
  5. ;;
  6. ;; In a shell execute:
  7. ;; ikarus swank-ikarus.ss
  8. ;; and then `M-x slime-connect' in Emacs.
  9. ;;
  10. (library (swank os)
  11. (export getpid make-server-socket accept local-port close-socket)
  12. (import (rnrs)
  13. (only (ikarus foreign) make-c-callout dlsym dlopen
  14. pointer-set-c-long! pointer-ref-c-unsigned-short
  15. malloc free pointer-size)
  16. (rename (only (ikarus ipc) tcp-server-socket accept-connection
  17. close-tcp-server-socket)
  18. (tcp-server-socket make-server-socket)
  19. (close-tcp-server-socket close-socket))
  20. (only (ikarus)
  21. struct-type-descriptor
  22. struct-type-field-names
  23. struct-field-accessor)
  24. )
  25. (define libc (dlopen))
  26. (define (cfun name return-type arg-types)
  27. ((make-c-callout return-type arg-types) (dlsym libc name)))
  28. (define getpid (cfun "getpid" 'signed-int '()))
  29. (define (accept socket codec)
  30. (let-values (((in out) (accept-connection socket)))
  31. (values (transcoded-port in (make-transcoder codec))
  32. (transcoded-port out (make-transcoder codec)))))
  33. (define (socket-fd socket)
  34. (let ((rtd (struct-type-descriptor socket)))
  35. (do ((i 0 (+ i 1))
  36. (names (struct-type-field-names rtd) (cdr names)))
  37. ((eq? (car names) 'fd) ((struct-field-accessor rtd i) socket)))))
  38. (define sockaddr_in/size 16)
  39. (define sockaddr_in/sin_family 0)
  40. (define sockaddr_in/sin_port 2)
  41. (define sockaddr_in/sin_addr 4)
  42. (define (local-port socket)
  43. (let* ((fd (socket-fd socket))
  44. (addr (malloc sockaddr_in/size))
  45. (size (malloc (pointer-size))))
  46. (pointer-set-c-long! size 0 sockaddr_in/size)
  47. (let ((code (getsockname fd addr size))
  48. (port (ntohs (pointer-ref-c-unsigned-short
  49. addr sockaddr_in/sin_port))))
  50. (free addr)
  51. (free size)
  52. (cond ((= code -1) (error "getsockname failed"))
  53. (#t port)))))
  54. (define getsockname
  55. (cfun "getsockname" 'signed-int '(signed-int pointer pointer)))
  56. (define ntohs (cfun "ntohs" 'unsigned-short '(unsigned-short)))
  57. )
  58. (library (swank sys)
  59. (export implementation-name eval-in-interaction-environment)
  60. (import (rnrs)
  61. (rnrs eval)
  62. (only (ikarus) interaction-environment))
  63. (define (implementation-name) "ikarus")
  64. (define (eval-in-interaction-environment form)
  65. (eval form (interaction-environment)))
  66. )
  67. (import (only (ikarus) load))
  68. (load "swank-r6rs.scm")
  69. (import (swank))
  70. (start-server #f)