HACKING 13 KB

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