Quick documentation.
[bpt/guile.git] / README
1 Installation
2 ------------
3
4 % ./autogen.sh
5 % configure
6 % make
7 % su
8 # make install
9 # ln -s module/{system,language} /usr/local/share/guile/site/
10
11 Add the following lines to your ~/.guile:
12
13 (if (string=? (car (command-line)) "guile-vm")
14 (begin
15 (use-modules (system repl repl))
16 (start-repl 'r5rs)
17 (quit)))
18
19 Example Session
20 ---------------
21
22 % guile-vm
23 Standard Scheme (R5RS + syntax-case) interpreter 0.3 on Guile 1.4.1
24 Copyright (C) 2001 Free Software Foundation, Inc.
25
26 Enter `,help' for help.
27 r5rs@guile> (+ 1 2)
28 $1 = 3
29 r5rs@guile> ,c -c (+ 1 2) ;; Compile into GLIL
30 (@asm (0 0 0 0)
31 (const 1)
32 (const 2)
33 (add)
34 (return))
35 r5rs@guile> ,c -l (+ 1 2) ;; Compile into loadable code
36 0 make-int8:0 ;; 0
37 1 load-program #0
38 8 return
39
40 Bytecode #0:
41
42 0 make-int8:1 ;; 1
43 1 make-int8 2 ;; 2
44 3 add
45 4 return
46
47 r5rs@guile> ,c (+ 1 2) ;; Compile and disassemble
48 Disassembly of #<program 0x810f75b>:
49
50 args = 0 rest = 0 locals = 0
51
52 Bytecode:
53
54 0 make-int8:1 ;; 1
55 1 make-int8 2 ;; 2
56 3 add
57 4 return
58
59 r5rs@guile> (define (add x y) (+ x y))
60 r5rs@guile> (add 1 2)
61 $2 = 3
62 r5rs@guile> ,x add ;; Disassemble
63 Disassembly of #<program 0x8125f70>:
64
65 args = 2 rest = 0 locals = 0
66
67 Bytecode:
68
69 0 local-ref 1
70 2 local-ref:0
71 3 add
72 4 return
73
74 r5rs@guile>
75
76 Write Modules
77 -------------
78
79 ---- fib.scm ---------------------------
80 (define-module (fib)
81 :use-module (system vm load)
82 :export (fib))
83
84 (load/compile "fib.gsm")
85 ----------------------------------------
86
87 ---- fib.gsm ---------------------------
88 (define (fib n)
89 (if (< n 2)
90 1
91 (+ (fib (- n 1)) (fib (- n 2)))))
92 ----------------------------------------
93
94 Now, expressions in fib.gsm are automatically compiled and
95 executed by the Guile VM:
96
97 % guile
98 guile> (use-modules (fib))
99 guile> (time (fib 30))
100 clock utime stime cutime cstime gctime
101 2.89 2.88 0.00 0.00 0.00 0.00
102 $1 = 1346269
103 guile> (define (fib n) (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2)))))
104 guile> (time (fib 30))
105 clock utime stime cutime cstime gctime
106 26.05 25.01 0.17 0.00 0.00 14.33
107 $2 = 1346269
108
109 If you don't want to compile your code (e.g., for debugging purpose),
110 just change `load/compile' to `load'.