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