HACKING 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. -*-text-*-
  2. Guile Hacking Guide
  3. Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2008 Free software Foundation, Inc.
  4. Permission is granted to anyone to make or distribute verbatim copies
  5. of this document as received, in any medium, provided that the
  6. copyright notice and permission notice are preserved,
  7. and that the distributor grants the recipient permission
  8. for further redistribution as permitted by this notice.
  9. Permission is granted to distribute modified versions
  10. of this document, or of portions of it,
  11. under the above conditions, provided also that they
  12. carry prominent notices stating who last changed them,
  13. and that any new or changed statements about the activities
  14. of the Free Software Foundation are approved by the Foundation.
  15. What to Hack =========================================================
  16. You can hack whatever you want, thank GNU.
  17. However, to see what others have indicated as their interest (and avoid
  18. potential wasteful duplication of effort), see file TODO. Note that
  19. the version you find may be out of date; a CVS checkout is recommended:
  20. see below for details (see also the files ANON-CVS and SNAPSHOTS).
  21. It's also a good idea to join the guile-devel@gnu.org mailing list.
  22. See http://www.gnu.org/software/guile/mail/mail.html for more info.
  23. Hacking It Yourself ==================================================
  24. When Guile is obtained from Git, a few extra steps must be taken
  25. before the usual configure, make, make install. You will need to have
  26. up-to-date versions of the tools as listed below, correctly installed.
  27. Sometimes older or newer versions will work. (See below for versions
  28. to avoid.)
  29. Then you must run the autogen.sh script, as described below.
  30. The same procedure can be used to regenerate the files in released
  31. versions of Guile. In that case the headers of the original generated
  32. files (e.g., configure, Makefile.in, ltmain.sh) can be used to
  33. identify which tool versions may be required.
  34. Autoconf --- a system for automatically generating `configure'
  35. scripts from templates which list the non-portable features a
  36. program would like to use. Available in
  37. "ftp://ftp.gnu.org/pub/gnu/autoconf"
  38. Automake --- a system for automatically generating Makefiles that
  39. conform to the (rather Byzantine) GNU coding standards. The
  40. nice thing is that it takes care of hairy targets like 'make
  41. dist' and 'make distclean', and automatically generates
  42. Makefile dependencies. Automake is available in
  43. "ftp://ftp.gnu.org/pub/gnu/automake"
  44. libtool --- a system for managing the zillion hairy options needed
  45. on various systems to produce shared libraries. Available in
  46. "ftp://ftp.gnu.org/pub/gnu/libtool". Version 1.5.26 (or
  47. later) is needed for correct AIX support.
  48. gettext --- a system for rigging a program so that it can output its
  49. messages in the local tongue. Guile presently only exports
  50. the gettext functionality to Scheme, it does not use it
  51. itself.
  52. flex --- a scanner generator. It's probably not essential to have the
  53. latest version.
  54. One false move and you will be lost in a little maze of automatically
  55. generated files, all different.
  56. Here is the authoritative list of tool/version/platform tuples that
  57. have been known to cause problems, and a short description of the problem.
  58. - automake 1.4 adds extraneous rules to the top-level Makefile if
  59. you specify specific Makefiles to rebuild on the command line.
  60. - automake 1.4-p4 (debian "1:1.4-p4-1.1") all platforms
  61. automake "include" facility does not recognize filenames w/ "-".
  62. - libtool 1.4 uses acconfig.h, which is deprecated by newest autoconf
  63. (which constructs the equivalent through 3rd arg of AC_DEFINE forms).
  64. - autoreconf from autoconf prior to 2.59 will run gettextize, which
  65. will mess up the Guile tree.
  66. - (add here.)
  67. Sample GDB Initialization File=========================================
  68. Here is a sample .gdbinit posted by Bill Schottstaedt (modified to
  69. use `set' instead of `call' in some places):
  70. define gp
  71. set gdb_print($arg0)
  72. print gdb_output
  73. end
  74. document gp
  75. Executes (object->string arg)
  76. end
  77. define ge
  78. call gdb_read($arg0)
  79. call gdb_eval(gdb_result)
  80. set gdb_print(gdb_result)
  81. print gdb_output
  82. end
  83. document ge
  84. Executes (print (eval (read arg))): ge "(+ 1 2)" => 3
  85. end
  86. define gh
  87. call g_help(scm_str2symbol($arg0), 20)
  88. set gdb_print($1)
  89. print gdb_output
  90. end
  91. document gh
  92. Prints help string for arg: gh "enved-target"
  93. end
  94. Bill further writes:
  95. so in gdb if you see something useless like:
  96. #32 0x081ae8f4 in scm_primitive_load (filename=1112137128) at load.c:129
  97. You can get the file name with gp:
  98. (gdb) gp 1112137128
  99. $1 = 0x40853fac "\"/home/bil/test/share/guile/1.5.0/ice-9/session.scm\""
  100. Contributing Your Changes ============================================
  101. - If you have put together a change that meets the coding standards
  102. described below, we encourage you to submit it to Guile. Post your
  103. patch to guile-devel@gnu.org.
  104. - We prefer patches generated using 'git format-patch'.
  105. - Provide a description in the commit message, like so:
  106. 1-line description of change
  107. More extensive discussion of your change. Document why you are
  108. changing things.
  109. * filename (function name): file specific change comments.
  110. - For proper credit, also make sure you update the AUTHORS file
  111. (for new files for which you've assigned copyright to the FSF), or
  112. the THANKS file (for everything else).
  113. Coding standards =====================================================
  114. - As for any part of Project GNU, changes to Guile should follow the
  115. GNU coding standards. The standards are available via anonymous FTP
  116. from prep.ai.mit.edu, as /pub/gnu/standards/standards.texi and
  117. make-stds.texi.
  118. - The Guile tree should compile without warnings under the following
  119. GCC switches, which are the default in the current configure script:
  120. -O2 -Wall -Wpointer-arith -Wmissing-prototypes
  121. To make sure of this, you can use the --enable-error-on-warning option
  122. to configure. This option will make GCC fail if it hits a warning.
  123. Note that the warnings generated vary from one version of GCC to the
  124. next, and from one architecture to the next (apparently). To provide
  125. a concrete common standard, Guile should compile without warnings from
  126. GCC 2.7.2.3 in a Red Hat 5.2 i386 Linux machine. Furthermore, each
  127. developer should pursue any additional warnings noted by on their
  128. compiler. This means that people using more stringent compilers will
  129. have more work to do, and assures that everyone won't switch to the
  130. most lenient compiler they can find. :)
  131. - If you add code which uses functions or other features that are not
  132. entirely portable, please make sure the rest of Guile will still
  133. function properly on systems where they are missing. This usually
  134. entails adding a test to configure.in, and then adding #ifdefs to your
  135. code to disable it if the system's features are missing.
  136. - The normal way of removing a function, macro or variable is to mark
  137. it as "deprecated", keep it for a while, and remove it in a later
  138. release. If a function or macro is marked as "deprecated" it
  139. indicates that people shouldn't use it in new programs, and should try
  140. to remove it in old. Make sure that an alternative exists unless it
  141. is our purpose to remove functionality. Don't deprecate definitions
  142. if it is unclear when they will be removed. (This is to ensure that a
  143. valid way of implementing some functionality always exists.)
  144. When deprecating a definition, always follow this procedure:
  145. 1. Mark the definition using
  146. #if (SCM_DEBUG_DEPRECATED == 0)
  147. ...
  148. #endif
  149. or, for Scheme code, wrap it using
  150. (begin-deprecated
  151. ...)
  152. 2. Make the deprecated code issue a warning when it is used, by using
  153. scm_c_issue_deprecation_warning (in C) or issue-deprecation-warning
  154. (in Scheme).
  155. 3. Write a comment at the definition explaining how a programmer can
  156. manage without the deprecated definition.
  157. 4. Add an entry that the definition has been deprecated in NEWS and
  158. explain what do do instead.
  159. 5. In file TODO, there is a list of releases with reminders about what
  160. to do at each release. Add a reminder about the removal of the
  161. deprecated defintion at the appropriate release.
  162. - Write commit messages for functions written in C using the
  163. functions' C names, and write entries for functions written in Scheme
  164. using the functions' Scheme names. For example,
  165. * foo.c: Moved scm_procedure_documentation from eval.c.
  166. is preferred over
  167. * foo.c: Moved procedure-documentation from eval.c.
  168. Changes like adding this line are special:
  169. SCM_PROC (s_map_in_order, "map-in-order", 2, 0, 1, scm_map);
  170. Since the change here is about the name itself --- we're adding a new
  171. alias for scm_map that guarantees the order in which we process list
  172. elements, but we're not changing scm_map at all --- it's appropriate
  173. to use the Scheme name in the commit message.
  174. - Make sure you have papers from people before integrating their
  175. changes or contributions. This is very frustrating, but very
  176. important to do right. From maintain.texi, "Information for
  177. Maintainers of GNU Software":
  178. When incorporating changes from other people, make sure to follow the
  179. correct procedures. Doing this ensures that the FSF has the legal
  180. right to distribute and defend GNU software.
  181. For the sake of registering the copyright on later versions ofthe
  182. software you need to keep track of each person who makes significant
  183. changes. A change of ten lines or so, or a few such changes, in a
  184. large program is not significant.
  185. *Before* incorporating significant changes, make sure that the person
  186. has signed copyright papers, and that the Free Software Foundation has
  187. received them.
  188. If you receive contributions you want to use from someone, let me know
  189. and I'll take care of the administrivia. Put the contributions aside
  190. until we have the necessary papers.
  191. Once you accept a contribution, be sure to keep the files AUTHORS and
  192. THANKS uptodate.
  193. - When you make substantial changes to a file, add the current year to
  194. the list of years in the copyright notice at the top of the file.
  195. - When you get bug reports or patches from people, be sure to list
  196. them in THANKS.
  197. Naming conventions =================================================
  198. We use certain naming conventions to structure the considerable number
  199. of global identifiers. All identifiers should be either all lower
  200. case or all upper case. Syllables are separated by underscores `_'.
  201. All non-static identifiers should start with scm_ or SCM_. Then might
  202. follow zero or more syllables giving the category of the identifier.
  203. The currently used category identifiers are
  204. t - type name
  205. c,C - something with a interface suited for C use. This is used
  206. to name functions that behave like Scheme primitives but
  207. have a more C friendly calling convention.
  208. i,I - internal to libguile. It is global, but not considered part
  209. of the libguile API.
  210. f - a SCM variable pointing to a Scheme function object.
  211. F - a bit mask for a flag.
  212. m - a macro transformer procedure
  213. n,N - a count of something
  214. s - a constant C string
  215. k - a SCM variable pointing to a keyword.
  216. sym - a SCM variable pointing to a symbol.
  217. var - a SCM variable pointing to a variable object.
  218. The follwing syllables also have a technical meaning:
  219. str - this denotes a zero terminated C string
  220. mem - a C string with an explicit count
  221. See also the file `devel/names.text'.
  222. Helpful hints ========================================================
  223. - [From Mikael Djurfeldt] When working on the Guile internals, it is
  224. quite often practical to implement a scheme-level procedure which
  225. helps you examine the feature you're working on.
  226. Examples of such procedures are: pt-size, debug-hand and
  227. current-pstate.
  228. I've now put #ifdef GUILE_DEBUG around all such procedures, so that
  229. they are not compiled into the "normal" Guile library. Please do the
  230. same when you add new procedures/C functions for debugging purpose.
  231. You can define the GUILE_DEBUG flag by passing --enable-guile-debug to
  232. the configure script.
  233. Jim Blandy, and others