spec.scm 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ;;; Bytecode
  2. ;; Copyright (C) 2013 Free Software Foundation, Inc.
  3. ;;;; This library is free software; you can redistribute it and/or
  4. ;;;; modify it under the terms of the GNU Lesser General Public
  5. ;;;; License as published by the Free Software Foundation; either
  6. ;;;; version 3 of the License, or (at your option) any later version.
  7. ;;;;
  8. ;;;; This library is distributed in the hope that it will be useful,
  9. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. ;;;; Lesser General Public License for more details.
  12. ;;;;
  13. ;;;; You should have received a copy of the GNU Lesser General Public
  14. ;;;; License along with this library; if not, write to the Free Software
  15. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. ;;; Code:
  17. (define-module (language bytecode spec)
  18. #:use-module (system base language)
  19. #:use-module (system vm loader)
  20. #:use-module (ice-9 binary-ports)
  21. #:export (bytecode))
  22. (define (bytecode->value x e opts)
  23. (let ((thunk (load-thunk-from-memory x)))
  24. (if (eq? e (current-module))
  25. ;; save a cons in this case
  26. (values (thunk) e e)
  27. (save-module-excursion
  28. (lambda ()
  29. (set-current-module e)
  30. (values (thunk) e e))))))
  31. (define-language bytecode
  32. #:title "Bytecode"
  33. #:compilers `((value . ,bytecode->value))
  34. #:printer (lambda (x port)
  35. (put-bytevector port (car x)))
  36. #:reader get-bytevector-all
  37. #:for-humans? #f)