Commit | Line | Data |
---|---|---|
a84251b0 LC |
1 | -*-text-*- |
2 | Guile Hacking Guide | |
b226295a | 3 | Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2008 Free software Foundation, Inc. |
a84251b0 LC |
4 | |
5 | Permission is granted to anyone to make or distribute verbatim copies | |
6 | of this document as received, in any medium, provided that the | |
7 | copyright notice and permission notice are preserved, | |
8 | and that the distributor grants the recipient permission | |
9 | for further redistribution as permitted by this notice. | |
10 | ||
11 | Permission is granted to distribute modified versions | |
12 | of this document, or of portions of it, | |
13 | under the above conditions, provided also that they | |
14 | carry prominent notices stating who last changed them, | |
15 | and that any new or changed statements about the activities | |
16 | of the Free Software Foundation are approved by the Foundation. | |
17 | ||
18 | ||
19 | What to Hack ========================================================= | |
20 | ||
21 | You can hack whatever you want, thank GNU. | |
22 | ||
23 | However, to see what others have indicated as their interest (and avoid | |
24 | potential wasteful duplication of effort), see file TODO. Note that | |
25 | the version you find may be out of date; a CVS checkout is recommended: | |
26 | see below for details (see also the files ANON-CVS and SNAPSHOTS). | |
27 | ||
28 | It's also a good idea to join the guile-devel@gnu.org mailing list. | |
29 | See http://www.gnu.org/software/guile/mail/mail.html for more info. | |
30 | ||
31 | ||
32 | Hacking It Yourself ================================================== | |
33 | ||
34 | When Guile is obtained from CVS, a few extra steps must be taken | |
35 | before the usual configure, make, make install. You will need to have | |
36 | up-to-date versions of the tools listed below, correctly installed. | |
37 | i.e., they must be found in the current PATH and not shadowed or | |
38 | otherwise broken by files left behind from other versions. | |
39 | ||
40 | "up-to-date" means the latest released versions at the time that Guile | |
41 | was obtained from CVS. Sometimes older or newer versions will work. | |
42 | (See below for versions to avoid.) | |
43 | ||
44 | Then you must run the autogen.sh script, as described below. | |
45 | ||
46 | In case of problems, it may be worth getting a fresh copy of Guile | |
47 | from CVS: synchronisation problems have been known to occur | |
48 | occasionally. | |
49 | ||
50 | The same procedure can be used to regenerate the files in released | |
51 | versions of Guile. In that case the headers of the original generated | |
52 | files (e.g., configure, Makefile.in, ltmain.sh) can be used to | |
53 | identify which tool versions may be required. | |
54 | ||
55 | Autoconf --- a system for automatically generating `configure' | |
56 | scripts from templates which list the non-portable features a | |
57 | program would like to use. Available in | |
58 | "ftp://ftp.gnu.org/pub/gnu/autoconf" | |
59 | ||
60 | Automake --- a system for automatically generating Makefiles that | |
61 | conform to the (rather Byzantine) GNU coding standards. The | |
62 | nice thing is that it takes care of hairy targets like 'make | |
63 | dist' and 'make distclean', and automatically generates | |
64 | Makefile dependencies. Automake is available in | |
65 | "ftp://ftp.gnu.org/pub/gnu/automake" | |
66 | ||
67 | libtool --- a system for managing the zillion hairy options needed | |
68 | on various systems to produce shared libraries. Available in | |
d4a00708 NJ |
69 | "ftp://ftp.gnu.org/pub/gnu/libtool". Version 1.5.26 (or |
70 | later) is needed for correct AIX support. | |
a84251b0 LC |
71 | |
72 | gettext --- a system for rigging a program so that it can output its | |
73 | messages in the local tongue. Guile presently only exports | |
74 | the gettext functionality to Scheme, it does not use it | |
75 | itself. | |
76 | ||
77 | flex --- a scanner generator. It's probably not essential to have the | |
78 | latest version. | |
79 | ||
80 | One false move and you will be lost in a little maze of automatically | |
81 | generated files, all different. | |
82 | ||
83 | Here is the authoritative list of tool/version/platform tuples that | |
84 | have been known to cause problems, and a short description of the problem. | |
85 | ||
86 | - automake 1.4 adds extraneous rules to the top-level Makefile if | |
87 | you specify specific Makefiles to rebuild on the command line. | |
88 | ||
89 | - automake 1.4-p4 (debian "1:1.4-p4-1.1") all platforms | |
90 | automake "include" facility does not recognize filenames w/ "-". | |
91 | ||
92 | - libtool 1.4 uses acconfig.h, which is deprecated by newest autoconf | |
93 | (which constructs the equivalent through 3rd arg of AC_DEFINE forms). | |
94 | ||
95 | - autoreconf from autoconf prior to 2.59 will run gettextize, which | |
96 | will mess up the Guile tree. | |
97 | ||
98 | - (add here.) | |
99 | ||
100 | ||
101 | Sample GDB Initialization File========================================= | |
102 | ||
103 | Here is a sample .gdbinit posted by Bill Schottstaedt (modified to | |
104 | use `set' instead of `call' in some places): | |
105 | ||
106 | define gp | |
107 | set gdb_print($arg0) | |
108 | print gdb_output | |
109 | end | |
110 | document gp | |
111 | Executes (object->string arg) | |
112 | end | |
113 | ||
114 | define ge | |
115 | call gdb_read($arg0) | |
116 | call gdb_eval(gdb_result) | |
117 | set gdb_print(gdb_result) | |
118 | print gdb_output | |
119 | end | |
120 | document ge | |
121 | Executes (print (eval (read arg))): ge "(+ 1 2)" => 3 | |
122 | end | |
123 | ||
124 | define gh | |
125 | call g_help(scm_str2symbol($arg0), 20) | |
126 | set gdb_print($1) | |
127 | print gdb_output | |
128 | end | |
129 | document gh | |
130 | Prints help string for arg: gh "enved-target" | |
131 | end | |
132 | ||
133 | Bill further writes: | |
134 | ||
135 | so in gdb if you see something useless like: | |
136 | ||
137 | #32 0x081ae8f4 in scm_primitive_load (filename=1112137128) at load.c:129 | |
138 | ||
139 | You can get the file name with gp: | |
140 | ||
141 | (gdb) gp 1112137128 | |
142 | $1 = 0x40853fac "\"/home/bil/test/share/guile/1.5.0/ice-9/session.scm\"" | |
143 | ||
144 | ||
145 | Contributing Your Changes ============================================ | |
146 | ||
147 | - If you have put together a change that meets the coding standards | |
148 | described below, we encourage you to submit it to Guile. The best | |
149 | place to post it is guile-devel@gnu.org. Please don't send it | |
150 | directly to me; I often don't have time to look things over. If you | |
151 | have tested your change, then you don't need to be shy. | |
152 | ||
153 | - Please submit patches using either context or unified diffs (diff -c | |
154 | or diff -u). Don't include a patch for ChangeLog; such patches don't | |
155 | apply cleanly, since we've probably changed the top of ChangeLog too. | |
156 | Instead, provide the unaltered text at the top of your patch. | |
157 | ||
158 | - For proper credit, also make sure you update the AUTHORS file | |
159 | (for new files for which you've assigned copyright to the FSF), or | |
160 | the THANKS file (for everything else). | |
161 | ||
162 | Please don't include patches for generated files like configure, | |
163 | aclocal.m4, or any Makefile.in. Such patches are often large, and | |
164 | we're just going to regenerate those files anyway. | |
165 | ||
166 | ||
a84251b0 LC |
167 | Coding standards ===================================================== |
168 | ||
169 | - Before contributing larger amounts of code to Guile, please read the | |
170 | documents in `guile-core/devel/policy' in the CVS source tree. | |
171 | ||
172 | - As for any part of Project GNU, changes to Guile should follow the | |
173 | GNU coding standards. The standards are available via anonymous FTP | |
174 | from prep.ai.mit.edu, as /pub/gnu/standards/standards.texi and | |
175 | make-stds.texi. | |
176 | ||
177 | - The Guile tree should compile without warnings under the following | |
178 | GCC switches, which are the default in the current configure script: | |
179 | ||
180 | -O2 -Wall -Wpointer-arith -Wmissing-prototypes | |
181 | ||
182 | To make sure of this, you can use the --enable-error-on-warning option | |
183 | to configure. This option will make GCC fail if it hits a warning. | |
184 | ||
185 | Note that the warnings generated vary from one version of GCC to the | |
186 | next, and from one architecture to the next (apparently). To provide | |
187 | a concrete common standard, Guile should compile without warnings from | |
188 | GCC 2.7.2.3 in a Red Hat 5.2 i386 Linux machine. Furthermore, each | |
189 | developer should pursue any additional warnings noted by on their | |
190 | compiler. This means that people using more stringent compilers will | |
191 | have more work to do, and assures that everyone won't switch to the | |
192 | most lenient compiler they can find. :) | |
193 | ||
194 | Note also that EGCS (as of November 3 1998) doesn't handle the | |
195 | `noreturn' attribute properly, so it doesn't understand that functions | |
196 | like scm_error won't return. This may lead to some silly warnings | |
197 | about uninitialized variables. You should look into these warnings to | |
198 | make sure they are indeed spurious, but you needn't correct warnings | |
199 | caused by this EGCS bug. | |
200 | ||
201 | - If you add code which uses functions or other features that are not | |
202 | entirely portable, please make sure the rest of Guile will still | |
203 | function properly on systems where they are missing. This usually | |
204 | entails adding a test to configure.in, and then adding #ifdefs to your | |
205 | code to disable it if the system's features are missing. | |
206 | ||
207 | - The normal way of removing a function, macro or variable is to mark | |
208 | it as "deprecated", keep it for a while, and remove it in a later | |
209 | release. If a function or macro is marked as "deprecated" it | |
210 | indicates that people shouldn't use it in new programs, and should try | |
211 | to remove it in old. Make sure that an alternative exists unless it | |
212 | is our purpose to remove functionality. Don't deprecate definitions | |
213 | if it is unclear when they will be removed. (This is to ensure that a | |
214 | valid way of implementing some functionality always exists.) | |
215 | ||
216 | When deprecating a definition, always follow this procedure: | |
217 | ||
218 | 1. Mark the definition using | |
219 | ||
220 | #if (SCM_DEBUG_DEPRECATED == 0) | |
221 | ... | |
222 | #endif | |
223 | ||
224 | or, for Scheme code, wrap it using | |
225 | ||
226 | (begin-deprecated | |
227 | ...) | |
228 | ||
229 | 2. Make the deprecated code issue a warning when it is used, by using | |
230 | scm_c_issue_deprecation_warning (in C) or issue-deprecation-warning | |
231 | (in Scheme). | |
232 | ||
233 | 3. Write a comment at the definition explaining how a programmer can | |
234 | manage without the deprecated definition. | |
235 | ||
236 | 4. Add an entry that the definition has been deprecated in NEWS and | |
237 | explain what do do instead. | |
238 | ||
239 | 5. In file TODO, there is a list of releases with reminders about what | |
240 | to do at each release. Add a reminder about the removal of the | |
241 | deprecated defintion at the appropriate release. | |
242 | ||
243 | - Please write log entries for functions written in C under the | |
244 | functions' C names, and write log entries for functions written in | |
245 | Scheme under the functions' Scheme names. Please don't do this: | |
246 | ||
247 | * procs.c, procs.h (procedure-documentation): Moved from eval.c. | |
248 | ||
249 | Entries like this make it harder to search the ChangeLogs, because you | |
250 | can never tell which name the entry will refer to. Instead, write this: | |
251 | ||
252 | * procs.c, procs.h (scm_procedure_documentation): Moved from eval.c. | |
253 | ||
254 | Changes like adding this line are special: | |
255 | ||
256 | SCM_PROC (s_map_in_order, "map-in-order", 2, 0, 1, scm_map); | |
257 | ||
258 | Since the change here is about the name itself --- we're adding a new | |
259 | alias for scm_map that guarantees the order in which we process list | |
260 | elements, but we're not changing scm_map at all --- it's appropriate | |
261 | to use the Scheme name in the log entry. | |
262 | ||
263 | - There's no need to keep a change log for a ChangeLog file. For any | |
264 | other kind of file (including documentation, since our documentation | |
265 | is indeed precisely engineered -- we surpass GNU standards here), add | |
266 | an appropriate ChangeLog entry when you change it. Simple! | |
267 | ||
268 | - Make sure you have papers from people before integrating their | |
269 | changes or contributions. This is very frustrating, but very | |
270 | important to do right. From maintain.texi, "Information for | |
271 | Maintainers of GNU Software": | |
272 | ||
273 | When incorporating changes from other people, make sure to follow the | |
274 | correct procedures. Doing this ensures that the FSF has the legal | |
275 | right to distribute and defend GNU software. | |
276 | ||
277 | For the sake of registering the copyright on later versions ofthe | |
278 | software you need to keep track of each person who makes significant | |
279 | changes. A change of ten lines or so, or a few such changes, in a | |
280 | large program is not significant. | |
281 | ||
282 | *Before* incorporating significant changes, make sure that the person | |
283 | has signed copyright papers, and that the Free Software Foundation has | |
284 | received them. | |
285 | ||
286 | If you receive contributions you want to use from someone, let me know | |
287 | and I'll take care of the administrivia. Put the contributions aside | |
288 | until we have the necessary papers. | |
289 | ||
290 | Once you accept a contribution, be sure to keep the files AUTHORS and | |
291 | THANKS uptodate. | |
292 | ||
293 | - When you make substantial changes to a file, add the current year to | |
294 | the list of years in the copyright notice at the top of the file. | |
295 | ||
296 | - When you get bug reports or patches from people, be sure to list | |
297 | them in THANKS. | |
298 | ||
299 | ||
300 | Naming conventions ================================================= | |
301 | ||
302 | We use certain naming conventions to structure the considerable number | |
303 | of global identifiers. All identifiers should be either all lower | |
304 | case or all upper case. Syllables are separated by underscores `_'. | |
305 | All non-static identifiers should start with scm_ or SCM_. Then might | |
306 | follow zero or more syllables giving the category of the identifier. | |
307 | The currently used category identifiers are | |
308 | ||
309 | t - type name | |
310 | ||
311 | c,C - something with a interface suited for C use. This is used | |
312 | to name functions that behave like Scheme primitives but | |
313 | have a more C friendly calling convention. | |
314 | ||
315 | i,I - internal to libguile. It is global, but not considered part | |
316 | of the libguile API. | |
317 | ||
318 | f - a SCM variable pointing to a Scheme function object. | |
319 | ||
320 | F - a bit mask for a flag. | |
321 | ||
322 | m - a macro transformer procedure | |
323 | ||
324 | n,N - a count of something | |
325 | ||
326 | s - a constant C string | |
327 | ||
328 | k - a SCM variable pointing to a keyword. | |
329 | ||
330 | sym - a SCM variable pointing to a symbol. | |
331 | ||
332 | var - a SCM variable pointing to a variable object. | |
333 | ||
334 | The follwing syllables also have a technical meaning: | |
335 | ||
336 | str - this denotes a zero terminated C string | |
337 | ||
338 | mem - a C string with an explicit count | |
339 | ||
340 | ||
341 | See also the file `devel/names.text'. | |
342 | ||
343 | ||
344 | Helpful hints ======================================================== | |
345 | ||
346 | - [From Mikael Djurfeldt] When working on the Guile internals, it is | |
347 | quite often practical to implement a scheme-level procedure which | |
348 | helps you examine the feature you're working on. | |
349 | ||
350 | Examples of such procedures are: pt-size, debug-hand and | |
351 | current-pstate. | |
352 | ||
353 | I've now put #ifdef GUILE_DEBUG around all such procedures, so that | |
354 | they are not compiled into the "normal" Guile library. Please do the | |
355 | same when you add new procedures/C functions for debugging purpose. | |
356 | ||
357 | You can define the GUILE_DEBUG flag by passing --enable-guile-debug to | |
358 | the configure script. | |
359 | ||
360 | - You'll see uses of the macro SCM_P scattered throughout the code; | |
361 | those are vestiges of a time when Guile was meant to compile on | |
362 | pre-ANSI compilers. Guile now requires ANSI C, so when you write new | |
363 | functions, feel free to use ANSI declarations, and please provide | |
364 | prototypes for everything. You don't need to use SCM_P in new code. | |
365 | ||
366 | ||
367 | Jim Blandy, and others | |
368 | ||
369 | ||
370 | Patches =========================================================== | |
371 | ||
372 | This one makes cvs-1.10 consider the file $CVSDOTIGNORE instead of | |
373 | .cvsignore when that environment variable is set. | |
374 | ||
375 | === patch start === | |
376 | diff -r -u cvs-1.10/src/cvs.h cvs-1.10.ignore-hack/src/cvs.h | |
377 | --- cvs-1.10/src/cvs.h Mon Jul 27 04:54:11 1998 | |
378 | +++ cvs-1.10.ignore-hack/src/cvs.h Sun Jan 23 12:58:09 2000 | |
379 | @@ -516,7 +516,7 @@ | |
380 | ||
381 | extern int ign_name PROTO ((char *name)); | |
382 | void ign_add PROTO((char *ign, int hold)); | |
383 | -void ign_add_file PROTO((char *file, int hold)); | |
384 | +int ign_add_file PROTO((char *file, int hold)); | |
385 | void ign_setup PROTO((void)); | |
386 | void ign_dir_add PROTO((char *name)); | |
387 | int ignore_directory PROTO((char *name)); | |
388 | diff -r -u cvs-1.10/src/ignore.c cvs-1.10.ignore-hack/src/ignore.c | |
389 | --- cvs-1.10/src/ignore.c Mon Sep 8 01:04:15 1997 | |
390 | +++ cvs-1.10.ignore-hack/src/ignore.c Sun Jan 23 12:57:50 2000 | |
391 | @@ -99,9 +99,9 @@ | |
392 | /* | |
393 | * Open a file and read lines, feeding each line to a line parser. Arrange | |
394 | * for keeping a temporary list of wildcards at the end, if the "hold" | |
395 | - * argument is set. | |
396 | + * argument is set. Return true when the file exists and has been handled. | |
397 | */ | |
398 | -void | |
399 | +int | |
400 | ign_add_file (file, hold) | |
401 | char *file; | |
402 | int hold; | |
403 | @@ -149,8 +149,8 @@ | |
404 | if (fp == NULL) | |
405 | { | |
406 | if (! existence_error (errno)) | |
407 | - error (0, errno, "cannot open %s", file); | |
408 | - return; | |
409 | + error (0, errno, "cannot open %s", file); | |
410 | + return 0; | |
411 | } | |
412 | while (getline (&line, &line_allocated, fp) >= 0) | |
413 | ign_add (line, hold); | |
414 | @@ -159,6 +159,7 @@ | |
415 | if (fclose (fp) < 0) | |
416 | error (0, errno, "cannot close %s", file); | |
417 | free (line); | |
418 | + return 1; | |
419 | } | |
420 | ||
421 | /* Parse a line of space-separated wildcards and add them to the list. */ | |
422 | @@ -375,6 +376,7 @@ | |
423 | struct stat sb; | |
424 | char *file; | |
425 | char *xdir; | |
426 | + char *cvsdotignore; | |
427 | ||
428 | /* Set SUBDIRS if we have subdirectory information in ENTRIES. */ | |
429 | if (entries == NULL) | |
430 | @@ -397,7 +399,10 @@ | |
431 | if (dirp == NULL) | |
432 | return; | |
433 | ||
434 | - ign_add_file (CVSDOTIGNORE, 1); | |
435 | + cvsdotignore = getenv("CVSDOTIGNORE"); | |
436 | + if (cvsdotignore == NULL || !ign_add_file (cvsdotignore, 1)) | |
437 | + ign_add_file (CVSDOTIGNORE, 1); | |
438 | + | |
439 | wrap_add_file (CVSDOTWRAPPER, 1); | |
440 | ||
441 | while ((dp = readdir (dirp)) != NULL) | |
442 | === patch end === | |
443 | ||
444 | This one is for pcl-cvs-2.9.2, so that `i' adds to the local | |
445 | .cvsignore file. | |
446 | ||
447 | === patch start === | |
448 | --- pcl-cvs.el~ Mon Nov 1 12:33:46 1999 | |
449 | +++ pcl-cvs.el Tue Jan 25 21:46:27 2000 | |
450 | @@ -1177,7 +1177,10 @@ | |
451 | "Append the file in FILEINFO to the .cvsignore file. | |
452 | Can only be used in the *cvs* buffer." | |
453 | (save-window-excursion | |
454 | - (set-buffer (find-file-noselect (expand-file-name ".cvsignore" dir))) | |
455 | + (set-buffer (find-file-noselect | |
456 | + (expand-file-name (or (getenv "CVSDOTIGNORE") | |
457 | + ".cvsignore") | |
458 | + dir))) | |
459 | (goto-char (point-max)) | |
460 | (unless (zerop (current-column)) (insert "\n")) | |
461 | (insert str "\n") | |
462 | === patch end === |