HACKING 13 KB

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