* standalone/test-bad-identifiers: New test.
[bpt/guile.git] / HACKING
CommitLineData
a84251b0
LC
1-*-text-*-
2Guile Hacking Guide
3Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free software Foundation, Inc.
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
19What to Hack =========================================================
20
21You can hack whatever you want, thank GNU.
22
23However, to see what others have indicated as their interest (and avoid
24potential wasteful duplication of effort), see file TODO. Note that
25the version you find may be out of date; a CVS checkout is recommended:
26see below for details (see also the files ANON-CVS and SNAPSHOTS).
27
28It's also a good idea to join the guile-devel@gnu.org mailing list.
29See http://www.gnu.org/software/guile/mail/mail.html for more info.
30
31
32Hacking It Yourself ==================================================
33
34When Guile is obtained from CVS, a few extra steps must be taken
35before the usual configure, make, make install. You will need to have
36up-to-date versions of the tools listed below, correctly installed.
37i.e., they must be found in the current PATH and not shadowed or
38otherwise broken by files left behind from other versions.
39
40"up-to-date" means the latest released versions at the time that Guile
41was obtained from CVS. Sometimes older or newer versions will work.
42(See below for versions to avoid.)
43
44Then you must run the autogen.sh script, as described below.
45
46In case of problems, it may be worth getting a fresh copy of Guile
47from CVS: synchronisation problems have been known to occur
48occasionally.
49
50The same procedure can be used to regenerate the files in released
51versions of Guile. In that case the headers of the original generated
52files (e.g., configure, Makefile.in, ltmain.sh) can be used to
53identify which tool versions may be required.
54
55Autoconf --- 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
60Automake --- 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
67libtool --- a system for managing the zillion hairy options needed
68 on various systems to produce shared libraries. Available in
69 "ftp://ftp.gnu.org/pub/gnu/libtool"
70
71gettext --- a system for rigging a program so that it can output its
72 messages in the local tongue. Guile presently only exports
73 the gettext functionality to Scheme, it does not use it
74 itself.
75
76flex --- a scanner generator. It's probably not essential to have the
77 latest version.
78
79One false move and you will be lost in a little maze of automatically
80generated files, all different.
81
82Here is the authoritative list of tool/version/platform tuples that
83have been known to cause problems, and a short description of the problem.
84
85- automake 1.4 adds extraneous rules to the top-level Makefile if
86 you specify specific Makefiles to rebuild on the command line.
87
88- automake 1.4-p4 (debian "1:1.4-p4-1.1") all platforms
89 automake "include" facility does not recognize filenames w/ "-".
90
91- libtool 1.4 uses acconfig.h, which is deprecated by newest autoconf
92 (which constructs the equivalent through 3rd arg of AC_DEFINE forms).
93
94- autoreconf from autoconf prior to 2.59 will run gettextize, which
95 will mess up the Guile tree.
96
97- (add here.)
98
99
100Sample GDB Initialization File=========================================
101
102Here is a sample .gdbinit posted by Bill Schottstaedt (modified to
103use `set' instead of `call' in some places):
104
105 define gp
106 set gdb_print($arg0)
107 print gdb_output
108 end
109 document gp
110 Executes (object->string arg)
111 end
112
113 define ge
114 call gdb_read($arg0)
115 call gdb_eval(gdb_result)
116 set gdb_print(gdb_result)
117 print gdb_output
118 end
119 document ge
120 Executes (print (eval (read arg))): ge "(+ 1 2)" => 3
121 end
122
123 define gh
124 call g_help(scm_str2symbol($arg0), 20)
125 set gdb_print($1)
126 print gdb_output
127 end
128 document gh
129 Prints help string for arg: gh "enved-target"
130 end
131
132Bill further writes:
133
134 so in gdb if you see something useless like:
135
136 #32 0x081ae8f4 in scm_primitive_load (filename=1112137128) at load.c:129
137
138 You can get the file name with gp:
139
140 (gdb) gp 1112137128
141 $1 = 0x40853fac "\"/home/bil/test/share/guile/1.5.0/ice-9/session.scm\""
142
143
144Contributing Your Changes ============================================
145
146- If you have put together a change that meets the coding standards
147described below, we encourage you to submit it to Guile. The best
148place to post it is guile-devel@gnu.org. Please don't send it
149directly to me; I often don't have time to look things over. If you
150have tested your change, then you don't need to be shy.
151
152- Please submit patches using either context or unified diffs (diff -c
153or diff -u). Don't include a patch for ChangeLog; such patches don't
154apply cleanly, since we've probably changed the top of ChangeLog too.
155Instead, provide the unaltered text at the top of your patch.
156
157- For proper credit, also make sure you update the AUTHORS file
158(for new files for which you've assigned copyright to the FSF), or
159the THANKS file (for everything else).
160
161Please don't include patches for generated files like configure,
162aclocal.m4, or any Makefile.in. Such patches are often large, and
163we're just going to regenerate those files anyway.
164
165
166CVS conventions ======================================================
167
168- We use CVS to manage the Guile sources. The repository lives on
169subversions.gnu.org, in /cvs; you will need an
170account on that machine to access the repository. Also, for security
171reasons, subversions presently only supports CVS connections via the SSH
172protocol, so you must first install the SSH client. Then, you should
173set your CVS_RSH environment variable to ssh, and use the following as
174your CVS root:
175
176 :ext:USER@subversions.gnu.org:/cvs
177
178Either set your CVSROOT environment variable to that, or give it as
179the value of the global -d option to CVS when you check out a working
180directory.
181
182For more information on SSH, see http://www.openssh.com.
183
184The Guile sources live in several modules:
185
186 - guile-core --- the interpreter, QuickThreads, and ice-9
187 - guile-tcltk --- the Guile/Tk interface
188 - guile-tk --- the new Guile/Tk interface, based on STk's modified Tk
189 - guile-rgx-ctax --- the Guile/Rx interface, and the ctax implementation
190 - guile-scsh --- the port of SCSH to guile, talk to Gary Houston
191 - guile-www --- A Guile module for making HTTP requests.
192 - guile-statprof --- an experimental statistical profiler.
193
194There is a mailing list for CVS commit messages; see README for details.
195
196- The guile-core tree is now versioned similarly to the Linux kernel.
197Guile now always uses three numbers to represent the version,
198i.e. "1.6.5". The first number, 1, is the major version number, the
199second number, 6, is the minor version number, and the third number,
2005, is the micro version number. Changes in major version number
201indicate major changes in Guile.
202
203Minor version numbers that are even denote stable releases, and odd
204minor version numbers denote development versions (which may be
205unstable). The micro version number indicates a minor sub-revision of
206a given MAJOR.MINOR release.
207
208- A default CVS checkout will get the current unstable development
209tree. However, for each stable release, a CVS branch is created so
210that release (and ongoing maintenance) of the stable version can
211proceed independent of the development of the next unstable version.
212To check out a particular stable branch, you just need to specify "-r
213branch_release-X-Y" to your CVS checkout command (or to any update).
214For example, if you wanted to check out the 1.6 stable branch, you
215would specify "-r branch_release-1-6".
216
217So, for example, during a normal development cycle, work will proceed
218on an unstable version, say 1.5.X, until it is decided that it's time
219for a stable release. At that point, a branch named
220branch_release-1-6 will be created, and the version numbers on the
221HEAD of the CVS tree (the trunk, i.e. what you get by default), will
222be changed to reflect the new unstable version 1.7.X. Then unstable
223development will proceed on the unstable version, while the stable
2241.5.X branch is fixed up for the eventual 1.6.0 release.
225
226Anytime you want to yank an existing checked out tree to the stable
227branch, you can run a command like this:
228
229 cvs -z3 update -r branch_release-1-6 -Pd
230
231This will yank the working directory over on to the stable release
232branch. Note that this directory will track that branch from then on
233unless you do something to yank it back to the main (unstable) trunk.
234
235To go back to the unstable branch, you can use
236
237 cvs -z3 update -A -Pd
238
239Note that in either case, you should probably make sure you've
240commited or removed all local changes before running the commands or
241you're likely to have some unexpected results.
242
243Finally note that one approach, should you need to work on both
244branches, is to keep two trees checked out, one stable, the other
245unstable and you can work in whichever is appropriate.
246
247To save some initial bandwidth, you can check out either the stable
248tree or the unstable tree, and then do something like this:
249
250 cp -a core-unstable core-1.5
251 cd core-1.5
252 cvs -z3 update -r branch_release-1-6 -Pd
253
254- The stable and unstable CVS trees are distinct, and no changes will
255automatically propagate between them. If you make changes that need
256to show up both places, you'll need to apply the changes both places.
257You *might* be able to do this with a cvs command, but often you'll
258probably need to apply the changes by hand or risk migrating
259superfluous modifications between the two versions. This is
260particularly important when moving a change from the unstable branch
261to the stable branch.
262
263- In general, please don't be adventurous with the stable branch. We
264mostly want bugfixes, documentation improvements, build improvements,
265etc., though exceptions will doubtless exist.
266
267- There are a few CVS tagging conventions which follow the Scheme
268convention that dashes are used to separate words within a single
269symbol, and so dashes bind more tightly than underscores. This means
270that foo-bar_baz-bax indicates that foo-bar is somehow separate from
271baz-bax. The conventions are as follows:
272
273 Branch root tags:
274 -----------------
275 anytime just before you create a branch it's a good
276 idea to create a normal tag so that you can refer to the branch point
277 on the main trunk as well as on the branch. So please use a tag of
278 the form
279
280 branch-root-release-1-X
281
282 or more generally, for other non-release branches:
283
284 branch-root_FOO
285
286 Branch tags:
287 ------------
288 for the branch tag itself please use
289
290 branch_release-1-6
291
292 or more generally, for other non-release branches:
293
294 branch_FOO
295
296 Merge tags:
297 -----------
298 Whenever you're merging a branch back into the trunk (or into another
299 branch repeatedly) you need to tag the branch each time you merge. If
300 you don't do that, you won't be able to merge repeatedly without
301 possibly tedious conflicts. For those tags, we suggest:
302
303 branch-merge_SOME-FOO_to_SOME-BAR_1
304 branch-merge_SOME-FOO_to_SOME-BAR_2
305 ..
306
307 As an example, SOME-BAR might be trunk, or even perhaps another branch
308 like branch-mvo-super-fixes :>
309
310 More mundanely, you might have
311
312 branch-merge_release-1-6_to_trunk_1
313
314 (Merging the stable branch to the trunk like this
315 will probably be much more common, when it happens, than the
316 reverse for the reasons mentioned above.
317
318 Release tags:
319 -------------
320 When releasing a new version of guile, please use:
321
322 release_X-Y-Z
323
324 i.e.
325
326 release_1-6-0
327
328- If you hack on a stable branch, please apply any relevant patches or
329fixes to the current unstable version (the main CVS trunk) as well.
330Similarly, please back-port any important fixes to the unstable CVS
331tree to the current stable branch.
332
333- We check Makefile.am and configure.in files into CVS, but the
334"autogen.sh" script must be run from the top-level to generate the
335actual "configure" script that then must be run to create the various
336Makefile-s to build guile. The general rule is that you should be able
337to check out a working directory of Guile from CVS, and then type
338"./autogen.sh", then "configure", and finally "make". No
339automatically generated files should be checked into the CVS
340repository.
341
342- The .cvsignore file is contained in the repository, to provide a
343reasonable list of auto-generated files that should not be checked in.
344This, however, prohibits one from having local additions to the
345.cvsignore file (yes, you can modify it and never check it in, but
346that doesn't seem to be a good solution to me). To get around this
347problem, you might want to patch your cvs program so that it uses a
348.cvsignore-local file (say) instead of the one from the repository. A
349patch for this can be found at the very end of this file.
350
351- (Automake 1.4 only) Be sure to run automake at the top of the tree
352with no arguments. Do not use `automake Makefile' to regenerate
353specific Makefile.in files, and do not trust the Makefile rules to
354rebuild them when they are out of date. Automake 1.4 will add
355extraneous rules to the top-level Makefile if you specify specific
356Makefiles to rebuild on the command line. Running the command
357`autoreconf --force' should take care of everything correctly.
358
359- Make sure your changes compile and work, at least on your own
360machine, before checking them into the main branch of the Guile
361repository. A good way for testing this is to run "make distcheck".
362If you really need to check in untested changes, make a branch.
363
364- Include each log entry in both the ChangeLog and in the CVS logs.
365If you're using Emacs, the pcl-cvs interface to CVS has features to
366make this easier; it checks the ChangeLog, and generates good default
367CVS log entries from that.
368
369
370Coding standards =====================================================
371
372- Before contributing larger amounts of code to Guile, please read the
373documents in `guile-core/devel/policy' in the CVS source tree.
374
375- As for any part of Project GNU, changes to Guile should follow the
376GNU coding standards. The standards are available via anonymous FTP
377from prep.ai.mit.edu, as /pub/gnu/standards/standards.texi and
378make-stds.texi.
379
380- The Guile tree should compile without warnings under the following
381GCC switches, which are the default in the current configure script:
382
383 -O2 -Wall -Wpointer-arith -Wmissing-prototypes
384
385To make sure of this, you can use the --enable-error-on-warning option
386to configure. This option will make GCC fail if it hits a warning.
387
388Note that the warnings generated vary from one version of GCC to the
389next, and from one architecture to the next (apparently). To provide
390a concrete common standard, Guile should compile without warnings from
391GCC 2.7.2.3 in a Red Hat 5.2 i386 Linux machine. Furthermore, each
392developer should pursue any additional warnings noted by on their
393compiler. This means that people using more stringent compilers will
394have more work to do, and assures that everyone won't switch to the
395most lenient compiler they can find. :)
396
397Note also that EGCS (as of November 3 1998) doesn't handle the
398`noreturn' attribute properly, so it doesn't understand that functions
399like scm_error won't return. This may lead to some silly warnings
400about uninitialized variables. You should look into these warnings to
401make sure they are indeed spurious, but you needn't correct warnings
402caused by this EGCS bug.
403
404- If you add code which uses functions or other features that are not
405entirely portable, please make sure the rest of Guile will still
406function properly on systems where they are missing. This usually
407entails adding a test to configure.in, and then adding #ifdefs to your
408code to disable it if the system's features are missing.
409
410- The normal way of removing a function, macro or variable is to mark
411it as "deprecated", keep it for a while, and remove it in a later
412release. If a function or macro is marked as "deprecated" it
413indicates that people shouldn't use it in new programs, and should try
414to remove it in old. Make sure that an alternative exists unless it
415is our purpose to remove functionality. Don't deprecate definitions
416if it is unclear when they will be removed. (This is to ensure that a
417valid way of implementing some functionality always exists.)
418
419When deprecating a definition, always follow this procedure:
420
4211. Mark the definition using
422
423 #if (SCM_DEBUG_DEPRECATED == 0)
424 ...
425 #endif
426
427 or, for Scheme code, wrap it using
428
429 (begin-deprecated
430 ...)
431
4322. Make the deprecated code issue a warning when it is used, by using
433 scm_c_issue_deprecation_warning (in C) or issue-deprecation-warning
434 (in Scheme).
435
4363. Write a comment at the definition explaining how a programmer can
437 manage without the deprecated definition.
438
4394. Add an entry that the definition has been deprecated in NEWS and
440 explain what do do instead.
441
4425. In file TODO, there is a list of releases with reminders about what
443 to do at each release. Add a reminder about the removal of the
444 deprecated defintion at the appropriate release.
445
446- Please write log entries for functions written in C under the
447functions' C names, and write log entries for functions written in
448Scheme under the functions' Scheme names. Please don't do this:
449
450 * procs.c, procs.h (procedure-documentation): Moved from eval.c.
451
452Entries like this make it harder to search the ChangeLogs, because you
453can never tell which name the entry will refer to. Instead, write this:
454
455 * procs.c, procs.h (scm_procedure_documentation): Moved from eval.c.
456
457Changes like adding this line are special:
458
459 SCM_PROC (s_map_in_order, "map-in-order", 2, 0, 1, scm_map);
460
461Since the change here is about the name itself --- we're adding a new
462alias for scm_map that guarantees the order in which we process list
463elements, but we're not changing scm_map at all --- it's appropriate
464to use the Scheme name in the log entry.
465
466- There's no need to keep a change log for a ChangeLog file. For any
467other kind of file (including documentation, since our documentation
468is indeed precisely engineered -- we surpass GNU standards here), add
469an appropriate ChangeLog entry when you change it. Simple!
470
471- Make sure you have papers from people before integrating their
472changes or contributions. This is very frustrating, but very
473important to do right. From maintain.texi, "Information for
474Maintainers of GNU Software":
475
476 When incorporating changes from other people, make sure to follow the
477 correct procedures. Doing this ensures that the FSF has the legal
478 right to distribute and defend GNU software.
479
480 For the sake of registering the copyright on later versions ofthe
481 software you need to keep track of each person who makes significant
482 changes. A change of ten lines or so, or a few such changes, in a
483 large program is not significant.
484
485 *Before* incorporating significant changes, make sure that the person
486 has signed copyright papers, and that the Free Software Foundation has
487 received them.
488
489If you receive contributions you want to use from someone, let me know
490and I'll take care of the administrivia. Put the contributions aside
491until we have the necessary papers.
492
493Once you accept a contribution, be sure to keep the files AUTHORS and
494THANKS uptodate.
495
496- When you make substantial changes to a file, add the current year to
497the list of years in the copyright notice at the top of the file.
498
499- When you get bug reports or patches from people, be sure to list
500them in THANKS.
501
502
503Naming conventions =================================================
504
505We use certain naming conventions to structure the considerable number
506of global identifiers. All identifiers should be either all lower
507case or all upper case. Syllables are separated by underscores `_'.
508All non-static identifiers should start with scm_ or SCM_. Then might
509follow zero or more syllables giving the category of the identifier.
510The currently used category identifiers are
511
512 t - type name
513
514 c,C - something with a interface suited for C use. This is used
515 to name functions that behave like Scheme primitives but
516 have a more C friendly calling convention.
517
518 i,I - internal to libguile. It is global, but not considered part
519 of the libguile API.
520
521 f - a SCM variable pointing to a Scheme function object.
522
523 F - a bit mask for a flag.
524
525 m - a macro transformer procedure
526
527 n,N - a count of something
528
529 s - a constant C string
530
531 k - a SCM variable pointing to a keyword.
532
533 sym - a SCM variable pointing to a symbol.
534
535 var - a SCM variable pointing to a variable object.
536
537The follwing syllables also have a technical meaning:
538
539 str - this denotes a zero terminated C string
540
541 mem - a C string with an explicit count
542
543
544See also the file `devel/names.text'.
545
546
547Helpful hints ========================================================
548
549- [From Mikael Djurfeldt] When working on the Guile internals, it is
550quite often practical to implement a scheme-level procedure which
551helps you examine the feature you're working on.
552
553Examples of such procedures are: pt-size, debug-hand and
554current-pstate.
555
556I've now put #ifdef GUILE_DEBUG around all such procedures, so that
557they are not compiled into the "normal" Guile library. Please do the
558same when you add new procedures/C functions for debugging purpose.
559
560You can define the GUILE_DEBUG flag by passing --enable-guile-debug to
561the configure script.
562
563- You'll see uses of the macro SCM_P scattered throughout the code;
564those are vestiges of a time when Guile was meant to compile on
565pre-ANSI compilers. Guile now requires ANSI C, so when you write new
566functions, feel free to use ANSI declarations, and please provide
567prototypes for everything. You don't need to use SCM_P in new code.
568
569
570Jim Blandy, and others
571
572
573Patches ===========================================================
574
575This one makes cvs-1.10 consider the file $CVSDOTIGNORE instead of
576.cvsignore when that environment variable is set.
577
578=== patch start ===
579diff -r -u cvs-1.10/src/cvs.h cvs-1.10.ignore-hack/src/cvs.h
580--- cvs-1.10/src/cvs.h Mon Jul 27 04:54:11 1998
581+++ cvs-1.10.ignore-hack/src/cvs.h Sun Jan 23 12:58:09 2000
582@@ -516,7 +516,7 @@
583
584 extern int ign_name PROTO ((char *name));
585 void ign_add PROTO((char *ign, int hold));
586-void ign_add_file PROTO((char *file, int hold));
587+int ign_add_file PROTO((char *file, int hold));
588 void ign_setup PROTO((void));
589 void ign_dir_add PROTO((char *name));
590 int ignore_directory PROTO((char *name));
591diff -r -u cvs-1.10/src/ignore.c cvs-1.10.ignore-hack/src/ignore.c
592--- cvs-1.10/src/ignore.c Mon Sep 8 01:04:15 1997
593+++ cvs-1.10.ignore-hack/src/ignore.c Sun Jan 23 12:57:50 2000
594@@ -99,9 +99,9 @@
595 /*
596 * Open a file and read lines, feeding each line to a line parser. Arrange
597 * for keeping a temporary list of wildcards at the end, if the "hold"
598- * argument is set.
599+ * argument is set. Return true when the file exists and has been handled.
600 */
601-void
602+int
603 ign_add_file (file, hold)
604 char *file;
605 int hold;
606@@ -149,8 +149,8 @@
607 if (fp == NULL)
608 {
609 if (! existence_error (errno))
610- error (0, errno, "cannot open %s", file);
611- return;
612+ error (0, errno, "cannot open %s", file);
613+ return 0;
614 }
615 while (getline (&line, &line_allocated, fp) >= 0)
616 ign_add (line, hold);
617@@ -159,6 +159,7 @@
618 if (fclose (fp) < 0)
619 error (0, errno, "cannot close %s", file);
620 free (line);
621+ return 1;
622 }
623
624 /* Parse a line of space-separated wildcards and add them to the list. */
625@@ -375,6 +376,7 @@
626 struct stat sb;
627 char *file;
628 char *xdir;
629+ char *cvsdotignore;
630
631 /* Set SUBDIRS if we have subdirectory information in ENTRIES. */
632 if (entries == NULL)
633@@ -397,7 +399,10 @@
634 if (dirp == NULL)
635 return;
636
637- ign_add_file (CVSDOTIGNORE, 1);
638+ cvsdotignore = getenv("CVSDOTIGNORE");
639+ if (cvsdotignore == NULL || !ign_add_file (cvsdotignore, 1))
640+ ign_add_file (CVSDOTIGNORE, 1);
641+
642 wrap_add_file (CVSDOTWRAPPER, 1);
643
644 while ((dp = readdir (dirp)) != NULL)
645=== patch end ===
646
647This one is for pcl-cvs-2.9.2, so that `i' adds to the local
648.cvsignore file.
649
650=== patch start ===
651--- pcl-cvs.el~ Mon Nov 1 12:33:46 1999
652+++ pcl-cvs.el Tue Jan 25 21:46:27 2000
653@@ -1177,7 +1177,10 @@
654 "Append the file in FILEINFO to the .cvsignore file.
655 Can only be used in the *cvs* buffer."
656 (save-window-excursion
657- (set-buffer (find-file-noselect (expand-file-name ".cvsignore" dir)))
658+ (set-buffer (find-file-noselect
659+ (expand-file-name (or (getenv "CVSDOTIGNORE")
660+ ".cvsignore")
661+ dir)))
662 (goto-char (point-max))
663 (unless (zerop (current-column)) (insert "\n"))
664 (insert str "\n")
665=== patch end ===