*** empty log message ***
[bpt/guile.git] / module / system / repl / common.scm
CommitLineData
ea9c5dab 1;;; Repl common routines
17e90c5e
KN
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 repl common)
23 :use-module (oop goops)
24 :use-syntax (system base syntax)
17e90c5e
KN
25 :use-module (system base language)
26 :use-module (system vm core)
46cd9a34 27 :use-module (system vm trace)
17e90c5e
KN
28 :export (make-repl repl-welcome repl-prompt repl-read repl-compile
29 repl-eval repl-print repl-compile-file repl-load-file))
30
31\f
32;;;
33;;; Repl
34;;;
35
36(define-vm-class <repl> ()
37 vm language module value-count value-history tm-stats vm-stats gc-stats)
38
39(define (make-repl lang)
40 (let ((vm (make-vm)))
41 (make <repl>
42 :vm vm
43 :language (lookup-language lang)
9419ff9a 44 :module #f ;; (global-ref 'user)
17e90c5e
KN
45 :value-count 0
46; :value-history (make-vmodule)
47 :tm-stats (times)
48 :vm-stats (vm-stats vm)
49 :gc-stats (gc-stats))))
50
51(define (repl-welcome repl)
52 (format #t "~A interpreter ~A on Guile ~A\n"
53 repl.language.title repl.language.version (version))
54 (display "Copyright (C) 2001 Free Software Foundation, Inc.\n\n")
55 (display "Enter `,help' for help.\n"))
56
57(define (repl-prompt repl)
9419ff9a
KN
58 (format #t "~A@~A> " repl.language.name 'guile)
59 ;; (env-identifier repl.module))
17e90c5e
KN
60 (force-output))
61
62(define (repl-read repl . args)
63 (apply read-in repl.language args))
64
65(define (repl-compile repl form . opts)
66 (let ((bytes (apply compile-in form repl.module repl.language opts)))
46cd9a34 67 (if (or (memq :c opts) (memq :l opts) (memq :t opts) (memq :e opts))
17e90c5e
KN
68 bytes
69 (vm-load repl.vm bytes))))
70
71(define (repl-eval repl form)
72 (let ((evaler repl.language.evaler))
73 (if evaler
74 (evaler form repl.module)
75 (repl.vm (repl-compile repl form)))))
76
77(define (repl-print repl val)
78 (if (not (eq? val *unspecified*))
79 (let* ((num (1+ repl.value-count))
80 (sym (string->symbol (format #f "$~A" num))))
81; (vmodule-define repl.value-history sym val)
82 (format #t "~A = " sym)
83 (print-in val repl.language)
84 (newline)
85 (set! repl.value-count num))))
86
87(define (repl-compile-file repl form . opts)
88 (apply compile-file-in form repl.module repl.language opts))
89
90(define (repl-load-file repl file . opts)
91 (let ((bytes (apply load-file-in file repl.module repl.language opts)))
46cd9a34
KN
92 (if (memq #:t opts) (vm-trace-start! repl.vm #:a))
93 (repl.vm (vm-load repl.vm bytes))
94 (if (memq #:t opts) (vm-trace-end! repl.vm #:a))))