3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
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.
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.
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
21 (define-module (language bytecode)
22 #:use-module (ice-9 match)
23 #:use-module ((srfi srfi-1) #:select (fold))
24 #:export (instruction-list
29 (load-extension (string-append "libguile-" (effective-version))
30 "scm_init_instructions")
31 (load-extension (string-append "libguile-" (effective-version))
32 "scm_init_vm_builtins")
34 (define (compute-instruction-arity name args)
35 (define (first-word-arity word)
43 (define (tail-word-arity word)
67 (fold (lambda (arg arity)
68 (+ (tail-word-arity arg) arity))
69 (first-word-arity arg0)
72 (define *macro-instruction-arities*
73 '((cache-current-module! . (0 . 2))
74 (cached-toplevel-box . (1 . 3))
75 (cached-module-box . (1 . 4))))
77 (define (compute-instruction-arities)
78 (let ((table (make-hash-table)))
81 ;; Put special cases here.
83 (hashq-set! table name
84 (cons 0 (compute-instruction-arity name args))))
86 (hashq-set! table name
87 (cons 1 (1- (compute-instruction-arity name args))))))
89 (for-each (match-lambda
91 (hashq-set! table name arity)))
92 *macro-instruction-arities*)
95 (define *instruction-arities* (delay (compute-instruction-arities)))
97 (define (instruction-arity name)
98 (hashq-ref (force *instruction-arities*) name))