Commit | Line | Data |
---|---|---|
4ee5686f KN |
1 | Installation |
2 | ------------ | |
3 | ||
0b5437c9 KN |
4 | 1. Install the latest Guile from CVS. |
5 | ||
6 | 2. Install slib. | |
7 | ||
8 | 3. Install Guile VM: | |
9 | ||
4ee5686f | 10 | % configure |
0b5437c9 KN |
11 | % make install |
12 | % ln -s module/{system,language} /usr/local/share/guile/site/ | |
4ee5686f | 13 | |
0b5437c9 | 14 | 4. Add the following lines to your ~/.guile: |
4ee5686f | 15 | |
0b5437c9 KN |
16 | (cond ((string=? (car (command-line)) "guile-vm") |
17 | (use-modules (system repl repl)) | |
18 | (start-repl 'gscheme) | |
19 | (quit))) | |
4ee5686f KN |
20 | |
21 | Example Session | |
22 | --------------- | |
23 | ||
24 | % guile-vm | |
0b5437c9 | 25 | Guile Scheme interpreter 0.4 on Guile 1.4.1 |
4ee5686f KN |
26 | Copyright (C) 2001 Free Software Foundation, Inc. |
27 | ||
28 | Enter `,help' for help. | |
0b5437c9 | 29 | gscheme@guile> (+ 1 2) |
4ee5686f | 30 | $1 = 3 |
0b5437c9 | 31 | gscheme@guile> ,c -c (+ 1 2) ;; Compile into GLIL |
4ee5686f KN |
32 | (@asm (0 0 0 0) |
33 | (const 1) | |
34 | (const 2) | |
0b5437c9 KN |
35 | (add 2) |
36 | (return 0)) | |
37 | gscheme@guile> ,c (+ 1 2) ;; Compile into bootcode | |
38 | Disassembly of bootcode: | |
4ee5686f | 39 | |
0b5437c9 | 40 | Compiled for Guile VM 0.4 |
4ee5686f | 41 | |
0b5437c9 | 42 | nlocs = 0 nexts = 0 |
4ee5686f | 43 | |
0b5437c9 KN |
44 | 0 make-int8:1 ;; 1 |
45 | 1 make-int8 2 ;; 2 | |
4ee5686f KN |
46 | 3 add |
47 | 4 return | |
48 | ||
0b5437c9 KN |
49 | gscheme@guile> |
50 | gscheme@guile> (add 1 2) | |
4ee5686f | 51 | $2 = 3 |
0b5437c9 KN |
52 | gscheme@guile> ,x add ;; Disassemble |
53 | Disassembly of #<program add>: | |
4ee5686f | 54 | |
0b5437c9 | 55 | nargs = 2 nrest = 0 nlocs = 0 nexts = 0 |
4ee5686f KN |
56 | |
57 | Bytecode: | |
58 | ||
0b5437c9 KN |
59 | 0 local-ref 0 |
60 | 2 local-ref 1 | |
61 | 4 add | |
62 | 5 return | |
4ee5686f | 63 | |
0b5437c9 | 64 | gscheme@guile> |
4ee5686f KN |
65 | |
66 | Write Modules | |
67 | ------------- | |
68 | ||
69 | ---- fib.scm --------------------------- | |
70 | (define-module (fib) | |
71 | :use-module (system vm load) | |
72 | :export (fib)) | |
73 | ||
0b5437c9 | 74 | (load/compile "fib.gs") |
4ee5686f KN |
75 | ---------------------------------------- |
76 | ||
0b5437c9 | 77 | ---- fib.gs ---------------------------- |
4ee5686f KN |
78 | (define (fib n) |
79 | (if (< n 2) | |
80 | 1 | |
81 | (+ (fib (- n 1)) (fib (- n 2))))) | |
82 | ---------------------------------------- | |
83 | ||
84 | Now, expressions in fib.gsm are automatically compiled and | |
85 | executed by the Guile VM: | |
86 | ||
87 | % guile | |
88 | guile> (use-modules (fib)) | |
89 | guile> (time (fib 30)) | |
90 | clock utime stime cutime cstime gctime | |
0b5437c9 | 91 | 2.80 2.79 0.00 0.00 0.00 0.00 |
4ee5686f KN |
92 | $1 = 1346269 |
93 | guile> (define (fib n) (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2))))) | |
94 | guile> (time (fib 30)) | |
95 | clock utime stime cutime cstime gctime | |
96 | 26.05 25.01 0.17 0.00 0.00 14.33 | |
97 | $2 = 1346269 | |
98 | ||
99 | If you don't want to compile your code (e.g., for debugging purpose), | |
100 | just change `load/compile' to `load'. |