Commit | Line | Data |
---|---|---|
d4ae3ae6 KN |
1 | ;;; Guile VM compiling loader |
2 | ||
3 | ;; Copyright (C) 2001 Free Software Foundation, Inc. | |
4 | ||
5 | ;; This program is free software; you can redistribute it and/or modify | |
6 | ;; it under the terms of the GNU General Public License as published by | |
7 | ;; the Free Software Foundation; either version 2, or (at your option) | |
8 | ;; any later version. | |
9 | ;; | |
10 | ;; This program 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 | |
13 | ;; GNU General Public License for more details. | |
14 | ;; | |
15 | ;; You should have received a copy of the GNU General Public License | |
16 | ;; along with this program; see the file COPYING. If not, write to | |
17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
18 | ;; Boston, MA 02111-1307, USA. | |
19 | ||
20 | ;;; Code: | |
21 | ||
22 | (define-module (system vm load) | |
23 | :use-module (system vm core) | |
d4ae3ae6 KN |
24 | :autoload (system base language) (compile-file-in lookup-language) |
25 | :use-module (ice-9 regex) | |
26 | :export (load/compile)) | |
27 | ||
d4ae3ae6 KN |
28 | (define (load/compile file) |
29 | (let* ((file (file-name-full-name file)) | |
30 | (compiled (object-file-name file))) | |
31 | (if (or (not (file-exists? compiled)) | |
32 | (> (stat:mtime (stat file)) (stat:mtime (stat compiled)))) | |
0b5437c9 | 33 | (compile-file-in file #f (lookup-language 'gscheme) #:O)) |
d4ae3ae6 KN |
34 | (let ((bytes (make-uniform-vector (stat:size (stat compiled)) #\a))) |
35 | (call-with-input-file compiled | |
36 | (lambda (p) (uniform-vector-read! bytes p))) | |
499a4c07 | 37 | (vm-load (the-vm) bytes)))) |
d4ae3ae6 KN |
38 | |
39 | (define (file-name-full-name filename) | |
40 | (let ((oldname (and (current-load-port) | |
41 | (port-filename (current-load-port))))) | |
42 | (if (and oldname | |
43 | (> (string-length filename) 0) | |
44 | (not (char=? (string-ref filename 0) #\/)) | |
45 | (not (string=? (dirname oldname) "."))) | |
46 | (string-append (dirname oldname) "/" filename) | |
47 | filename))) | |
48 | ||
49 | (define (object-file-name file) | |
50 | (let ((m (string-match "\\.[^.]*$" file))) | |
51 | (string-append (if m (match:prefix m) file) ".go"))) |