Mercurial > hg > xemacs-beta
comparison man/emodules.texi @ 442:abe6d1db359e r21-2-36
Import from CVS: tag r21-2-36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:35:02 +0200 |
parents | 8de8e3f6228a |
children | 98528da0b7fc |
comparison
equal
deleted
inserted
replaced
441:72a7cfa4a488 | 442:abe6d1db359e |
---|---|
115 @node Top, Introduction, (dir), (dir) | 115 @node Top, Introduction, (dir), (dir) |
116 This Info file contains v1.0 of the @value{emacs} dynamic loadable module | 116 This Info file contains v1.0 of the @value{emacs} dynamic loadable module |
117 support documentation. | 117 support documentation. |
118 @menu | 118 @menu |
119 * Introduction:: Introducing Emacs Modules | 119 * Introduction:: Introducing Emacs Modules |
120 * Annatomy of a Module:: Basic module layout and technology | 120 * Anatomy of a Module:: Basic module layout and technology |
121 * Using ellcc:: How to use the module compiler | 121 * Using ellcc:: How to use the module compiler |
122 * Defining Functions:: Creating new Lisp primitives | 122 * Defining Functions:: Creating new Lisp primitives |
123 * Defining Variables:: Creating new Lisp variables | 123 * Defining Variables:: Creating new Lisp variables |
124 * Index:: Concept Index | 124 * Index:: Concept Index |
125 | 125 |
126 --- The Detailed Node Listing --- | 126 --- The Detailed Node Listing --- |
127 | 127 |
128 Annatomy of a Module | 128 Anatomy of a Module |
129 | 129 |
130 * Required Header File:: Always include <emodules.h> | 130 * Required Header File:: Always include <emodules.h> |
131 * Required Functions:: Functions you must always provide | 131 * Required Functions:: Functions you must always provide |
132 * Required Variables:: Variables whose values you must provide | 132 * Required Variables:: Variables whose values you must provide |
133 * Loading other Modules:: How to load dependant modules | 133 * Loading other Modules:: How to load dependent modules |
134 | 134 |
135 Using @code{ellcc} | 135 Using @code{ellcc} |
136 | 136 |
137 * Compile Mode:: Compiling modules using ellcc | 137 * Compile Mode:: Compiling modules using ellcc |
138 * Initialization Mode:: Generating documentation and variables | 138 * Initialization Mode:: Generating documentation and variables |
146 * Declaring Functions:: Declaring functions to the Lisp reader | 146 * Declaring Functions:: Declaring functions to the Lisp reader |
147 @end menu | 147 @end menu |
148 | 148 |
149 @end ifinfo | 149 @end ifinfo |
150 | 150 |
151 @node Introduction, Annatomy of a Module, Top, Top | 151 @node Introduction, Anatomy of a Module, Top, Top |
152 @chapter Introduction | 152 @chapter Introduction |
153 | 153 |
154 @value{emacs} is a powerful, extensible editor. The traditional way of | 154 @value{emacs} is a powerful, extensible editor. The traditional way of |
155 extending the functionality of @value{emacs} is to use its built-in Lisp | 155 extending the functionality of @value{emacs} is to use its built-in Lisp |
156 language (called Emacs Lisp, or Elisp for short). However, while Elisp | 156 language (called Emacs Lisp, or Elisp for short). However, while Elisp |
159 | 159 |
160 Firstly, Elisp is an interpreted language, and this has serious speed | 160 Firstly, Elisp is an interpreted language, and this has serious speed |
161 implications. Like all other interpreted languages (like Java), Elisp | 161 implications. Like all other interpreted languages (like Java), Elisp |
162 is often suitable only for certain types of application or extension. | 162 is often suitable only for certain types of application or extension. |
163 So although Elisp is a general purpose language, and very high level, | 163 So although Elisp is a general purpose language, and very high level, |
164 there are times when it is desirable to descend to a lower level compiled | 164 there are times when it is desirable to descend to a lower level compiled |
165 language for speed purposes. | 165 language for speed purposes. |
166 | 166 |
167 Secondly, Elisp (or Lisp in general) is not a very common language any | 167 Secondly, Elisp (or Lisp in general) is not a very common language any |
168 more, except for certain circles in the computer industry. C is a far | 168 more, except for certain circles in the computer industry. C is a far |
169 more commonly known language, and because it is compiled, more suited to | 169 more commonly known language, and because it is compiled, more suited to |
170 a wider range of applications, especially those that require low level | 170 a wider range of applications, especially those that require low level |
171 access to a system or need to be as quick as possible. | 171 access to a system or need to be as quick as possible. |
172 | 172 |
173 @cindex Emacs Modules | 173 @cindex Emacs Modules |
174 @cindex DLL | 174 @cindex DLL |
175 @cindex DSO | 175 @cindex DSO |
176 @cindex shared object | 176 @cindex shared object |
177 This manual describes a new way of extending @value{emacs}, by using dynamic | 177 This manual describes a new way of extending @value{emacs}, by using dynamic |
178 loadable modules (also knows as dynamicaly loadable libraries (DLLs), | 178 loadable modules (also known as dynamically loadable libraries (DLLs), |
179 dynamic shared objects (DSOs) or just simply shared objectcs), which can | 179 dynamic shared objects (DSOs) or just simply shared objects), which can |
180 be written in C or C++ and loaded into @value{emacs} at any time. I sometimes | 180 be written in C or C++ and loaded into @value{emacs} at any time. I sometimes |
181 refer to this technology as @dfn{CEmacs}, which is short for @dfn{C | 181 refer to this technology as @dfn{CEmacs}, which is short for @dfn{C |
182 Extensible Emacs}. | 182 Extensible Emacs}. |
183 | 183 |
184 @value{emacs} modules are configured into and installed with @value{emacs} by | 184 @value{emacs} modules are configured into and installed with @value{emacs} by |
197 created during compile time, and is intended to abstract compiler | 197 created during compile time, and is intended to abstract compiler |
198 specific characteristics from the developer. This program is called to | 198 specific characteristics from the developer. This program is called to |
199 compile and link all objects that will make up the final shared object, | 199 compile and link all objects that will make up the final shared object, |
200 and accepts all common C compiler flags. @code{ellcc} also sets up the | 200 and accepts all common C compiler flags. @code{ellcc} also sets up the |
201 correct environment for compiling modules by enabling any special | 201 correct environment for compiling modules by enabling any special |
202 compiler modes (such as PIC mode), setting the correct include paths for | 202 compiler modes (such as PIC mode), setting the correct include paths for |
203 the location of @value{emacs} internal header files etc. The program will also | 203 the location of @value{emacs} internal header files etc. The program will also |
204 invoke the linker correctly to created the final shared object which is | 204 invoke the linker correctly to created the final shared object which is |
205 loaded into @value{emacs}. | 205 loaded into @value{emacs}. |
206 | 206 |
207 @item | 207 @item |
208 @cindex header files | 208 @cindex header files |
209 CEmacs also makes all of the relevant @value{emacs} internal header files | 209 CEmacs also makes all of the relevant @value{emacs} internal header files |
210 availible for module authors to use. This is often required to get data | 210 available for module authors to use. This is often required to get data |
211 structure definitions and external variable declarations. The header | 211 structure definitions and external variable declarations. The header |
212 files installed include the module specific header file | 212 files installed include the module specific header file |
213 @file{emodules.h}. Due to the nature of dynamic modules, most of the | 213 @file{emodules.h}. Due to the nature of dynamic modules, most of the |
214 internals of @value{emacs} are exposed. | 214 internals of @value{emacs} are exposed. |
215 @xref{Top,,,internals,@value{emacs} Internals Manual}, for a | 215 @xref{Top,,,internals,@value{emacs} Internals Manual}, for a |
216 more complete discussion on how to extend and understand @value{emacs}. All of | 216 more complete discussion on how to extend and understand @value{emacs}. All of |
217 the rules for C modules are discussed there. | 217 the rules for C modules are discussed there. |
218 | 218 |
219 @item | 219 @item |
220 @cindex samples | 220 @cindex samples |
221 Part of the @value{emacs} distribution is a set of sample modules. These are | 221 Part of the @value{emacs} distribution is a set of sample modules. These are |
243 document may have some overlap, but it is the internals manual which | 243 document may have some overlap, but it is the internals manual which |
244 should be considered the final authority. It will also help a great | 244 should be considered the final authority. It will also help a great |
245 deal to look at the actual @value{emacs} source code to see how things are | 245 deal to look at the actual @value{emacs} source code to see how things are |
246 done. | 246 done. |
247 | 247 |
248 @node Annatomy of a Module, Using ellcc, Introduction, Top | 248 @node Anatomy of a Module, Using ellcc, Introduction, Top |
249 @chapter Annatomy of a Module | 249 @chapter Anatomy of a Module |
250 @cindex annatomy | 250 @cindex anatomy |
251 @cindex module skeleton | 251 @cindex module skeleton |
252 @cindex skeleton, module | 252 @cindex skeleton, module |
253 @cindex module format | 253 @cindex module format |
254 @cindex format, module | 254 @cindex format, module |
255 | 255 |
256 Each dynamically loadable @value{emacs} extension (hereafter refered to as a | 256 Each dynamically loadable @value{emacs} extension (hereafter referred to as a |
257 module) has a certain compulsory format, and must contain several | 257 module) has a certain compulsory format, and must contain several |
258 pieces of information and several mandatory functions. This chapter | 258 pieces of information and several mandatory functions. This chapter |
259 describes the basic layout of a module, and provides a very simple | 259 describes the basic layout of a module, and provides a very simple |
260 sample. The source for this sample can be found in the file | 260 sample. The source for this sample can be found in the file |
261 @file{modules/simple/sample.c} in the main @value{emacs} source code tree. | 261 @file{modules/simple/sample.c} in the main @value{emacs} source code tree. |
262 | 262 |
263 @menu | 263 @menu |
264 * Required Header File:: Always include <emodules.h> | 264 * Required Header File:: Always include <emodules.h> |
265 * Required Functions:: Functions you must always provide | 265 * Required Functions:: Functions you must always provide |
266 * Required Variables:: Variables whose values you must provide | 266 * Required Variables:: Variables whose values you must provide |
267 * Loading other Modules:: How to load dependant modules | 267 * Loading other Modules:: How to load dependent modules |
268 @end menu | 268 @end menu |
269 | 269 |
270 @node Required Header File, Required Functions, Annatomy of a Module, Annatomy of a Module | 270 @node Required Header File, Required Functions, Anatomy of a Module, Anatomy of a Module |
271 @section Required Header File | 271 @section Required Header File |
272 @cindex required header | 272 @cindex required header |
273 @cindex include files | 273 @cindex include files |
274 | 274 |
275 @cindex emodules.h | 275 @cindex emodules.h |
276 @cindex config.h | 276 @cindex config.h |
277 Every module must include the file @file{<emodules.h>}. This | 277 Every module must include the file @file{<emodules.h>}. This |
278 will include several other @value{emacs} internal header files, and will set up | 278 will include several other @value{emacs} internal header files, and will set up |
279 certain vital macros. One of the most important files included by | 279 certain vital macros. One of the most important files included by |
280 @file{emodules.h} is the generated @file{config.h} file, which contains | 280 @file{emodules.h} is the generated @file{config.h} file, which contains |
281 all of the required system abstraction macros and definitions. Most | 281 all of the required system abstraction macros and definitions. Most |
282 modules will probably require some pre-processor conditionals based on | 282 modules will probably require some pre-processor conditionals based on |
283 constants defined in @file{config.h}. Please read that file to | 283 constants defined in @file{config.h}. Please read that file to |
284 familiarize yourself with the macros defined there. | 284 familiarize yourself with the macros defined there. |
285 | 285 |
286 Depending on exactly what your module will be doing, you will probably | 286 Depending on exactly what your module will be doing, you will probably |
287 need to include one or more of the @value{emacs} internal header files. When | 287 need to include one or more of the @value{emacs} internal header files. When |
288 you @code{#include <emodules.h>}, you will get a few of the most important | 288 you @code{#include <emodules.h>}, you will get a few of the most important |
289 @value{emacs} header files included automatically for you. The files included | 289 @value{emacs} header files included automatically for you. The files included |
290 are: | 290 are: |
291 | 291 |
292 @table @file | 292 @table @file |
293 @item lisp.h | 293 @item lisp.h |
294 This file contains most of the macros required for declaring Lisp object | 294 This file contains most of the macros required for declaring Lisp object |
295 types, macros for accessing Lisp objects, and global variable | 295 types, macros for accessing Lisp objects, and global variable |
296 declarations. | 296 declarations. |
297 | 297 |
298 @item sysdep.h | 298 @item sysdep.h |
299 All system dependant declarations and abstraction macros live here. You | 299 All system dependent declarations and abstraction macros live here. You |
300 should never call low level system functions directly. Rather, you | 300 should never call low level system functions directly. Rather, you |
301 should use the abstraction macros provided in this header file. | 301 should use the abstraction macros provided in this header file. |
302 | 302 |
303 @item window.h | 303 @item window.h |
304 This header file defines the window structures and Lisp types, and | 304 This header file defines the window structures and Lisp types, and |
315 @item frame.h | 315 @item frame.h |
316 Provides the required structure, macro and function definitions for | 316 Provides the required structure, macro and function definitions for |
317 manipulating @value{emacs} frames. | 317 manipulating @value{emacs} frames. |
318 @end table | 318 @end table |
319 | 319 |
320 @node Required Functions, Required Variables, Required Header File, Annatomy of a Module | 320 @node Required Functions, Required Variables, Required Header File, Anatomy of a Module |
321 @section Required Functions | 321 @section Required Functions |
322 @cindex initialization | 322 @cindex initialization |
323 @cindex functions, required | 323 @cindex functions, required |
324 @cindex required functions | 324 @cindex required functions |
325 | 325 |
326 Every module requires several initialization functions. It is the | 326 Every module requires several initialization functions. It is the |
327 responsibility of these functions to load in any dependant modules, and to | 327 responsibility of these functions to load in any dependent modules, and to |
328 declare all variables and functions which are to be made visibile to the | 328 declare all variables and functions which are to be made visible to the |
329 @value{emacs} Lisp reader. Each of these functions performs a very specific | 329 @value{emacs} Lisp reader. Each of these functions performs a very specific |
330 task, and they are executed in the correct order by @value{emacs}. All of | 330 task, and they are executed in the correct order by @value{emacs}. All of |
331 these functions are @code{void} functions which take no arguments. | 331 these functions are @code{void} functions which take no arguments. |
332 Here, briefly, are the required module functions. Note that the actual | 332 Here, briefly, are the required module functions. Note that the actual |
333 function names do not end with the string @code{_module}, but rather | 333 function names do not end with the string @code{_module}, but rather |
337 place-holder, not an actual function name. | 337 place-holder, not an actual function name. |
338 | 338 |
339 @table @code | 339 @table @code |
340 @item syms_of_module | 340 @item syms_of_module |
341 @findex syms_of_module | 341 @findex syms_of_module |
342 This required function is responsible for introducing to the Lisp reader | 342 This required function is responsible for introducing to the Lisp reader |
343 all functions that you have defined in your module using | 343 all functions that you have defined in your module using |
344 @code{DEFUN()}. Note that @emph{only} functions are declared here, using | 344 @code{DEFUN()}. Note that @emph{only} functions are declared here, using |
345 the @code{DEFSUBR()} macro. No variables are declared. | 345 the @code{DEFSUBR()} macro. No variables are declared. |
346 | 346 |
347 @item vars_of_module | 347 @item vars_of_module |
353 all internal @value{emacs} source code. | 353 all internal @value{emacs} source code. |
354 | 354 |
355 @item modules_of_module | 355 @item modules_of_module |
356 @findex modules_of_module | 356 @findex modules_of_module |
357 This optional function should be used to load in any modules which your | 357 This optional function should be used to load in any modules which your |
358 module depends on. The @value{emacs} module loading code makes sure that the | 358 module depends on. The @value{emacs} module loading code makes sure that the |
359 same module is not loaded twice, so several modules can safely call the | 359 same module is not loaded twice, so several modules can safely call the |
360 module load function for the same module. Only one copy of each module | 360 module load function for the same module. Only one copy of each module |
361 (at a given version) will ever be loaded. | 361 (at a given version) will ever be loaded. |
362 | 362 |
363 @item docs_of_module | 363 @item docs_of_module |
366 This function is created automatically by @code{ellcc} when the module | 366 This function is created automatically by @code{ellcc} when the module |
367 initialization code is produced. It is required to document all | 367 initialization code is produced. It is required to document all |
368 functions and variables declared in your module. | 368 functions and variables declared in your module. |
369 @end table | 369 @end table |
370 | 370 |
371 @node Required Variables, Loading other Modules, Required Functions, Annatomy of a Module | 371 @node Required Variables, Loading other Modules, Required Functions, Anatomy of a Module |
372 @section Required Variables | 372 @section Required Variables |
373 @cindex initialization | 373 @cindex initialization |
374 @cindex variables, required | 374 @cindex variables, required |
375 @cindex required variables | 375 @cindex required variables |
376 | 376 |
377 Not only does a module need to declare the initialization functions | 377 Not only does a module need to declare the initialization functions |
378 mentioned above, it is also required to provide certain variables which | 378 mentioned above, it is also required to provide certain variables which |
379 the module loading code searches for in order to determine the viability | 379 the module loading code searches for in order to determine the viability |
380 of a module. You are @emph{not} required to provide these variables in | 380 of a module. You are @emph{not} required to provide these variables in |
381 your source files. They are automatically set up in the module | 381 your source files. They are automatically set up in the module |
382 initialization file by the @code{ellcc} compiler. These variables are | 382 initialization file by the @code{ellcc} compiler. These variables are |
383 discussed here simply for the sake of completeness. | 383 discussed here simply for the sake of completeness. |
384 | 384 |
386 @item emodules_compiler | 386 @item emodules_compiler |
387 This is a variable of type @code{long}, and is used to indicate the | 387 This is a variable of type @code{long}, and is used to indicate the |
388 version of the @value{emacs} loading technology that was used to produce the | 388 version of the @value{emacs} loading technology that was used to produce the |
389 module being loaded. This version number is completely unrelated to | 389 module being loaded. This version number is completely unrelated to |
390 the @value{emacs} version number, as a given module may quite well work | 390 the @value{emacs} version number, as a given module may quite well work |
391 regardless of the version of @value{emacs} that was installed at the time the | 391 regardless of the version of @value{emacs} that was installed at the time the |
392 module was created. | 392 module was created. |
393 | 393 |
394 The @value{emacs} modules version is used to differentiate between major | 394 The @value{emacs} modules version is used to differentiate between major |
395 changes in the module loading technology, not versions of @value{emacs}. | 395 changes in the module loading technology, not versions of @value{emacs}. |
396 | 396 |
397 @item emodules_name | 397 @item emodules_name |
398 This is a short (typically 10 characters or less) name for the module, | 398 This is a short (typically 10 characters or less) name for the module, |
399 and it is used as a suffix for all of the required functions. This is | 399 and it is used as a suffix for all of the required functions. This is |
400 also the name by which the module is recognised when loading dependant | 400 also the name by which the module is recognized when loading dependent |
401 modules. The name does not necessarily have to be the same as the | 401 modules. The name does not necessarily have to be the same as the |
402 physical file name, although keeping the two names in sync is a pretty | 402 physical file name, although keeping the two names in sync is a pretty |
403 good idea. The name must not be empty, and it must be a valid part of a | 403 good idea. The name must not be empty, and it must be a valid part of a |
404 C function name. The value of this variable is appended to the function | 404 C function name. The value of this variable is appended to the function |
405 names @code{syms_of_}, @code{vars_of_}, @code{modules_of_} and | 405 names @code{syms_of_}, @code{vars_of_}, @code{modules_of_} and |
406 @code{docs_of_} to form the actual function names that the module | 406 @code{docs_of_} to form the actual function names that the module |
407 loading code looks for when loading a module. | 407 loading code looks for when loading a module. |
408 | 408 |
409 This variable is set by the @code{--mod-name} argument to @code{ellcc}. | 409 This variable is set by the @code{--mod-name} argument to @code{ellcc}. |
421 other special characters. It is used solely for descriptive purposes, | 421 other special characters. It is used solely for descriptive purposes, |
422 and does not affect the loading of the module. The value is set by the | 422 and does not affect the loading of the module. The value is set by the |
423 @code{--mod-title} argument to @code{ellcc}. | 423 @code{--mod-title} argument to @code{ellcc}. |
424 @end table | 424 @end table |
425 | 425 |
426 @node Loading other Modules, , Required Variables, Annatomy of a Module | 426 @node Loading other Modules, , Required Variables, Anatomy of a Module |
427 @section Loading other Modules | 427 @section Loading other Modules |
428 @cindex dependancies | 428 @cindex dependencies |
429 @findex modules_of_module | 429 @findex modules_of_module |
430 @findex emodules_load | 430 @findex emodules_load |
431 | 431 |
432 During the loading of a module, it is the responsibility of the function | 432 During the loading of a module, it is the responsibility of the function |
433 @code{modules_of_module} to load in any modules which the current module | 433 @code{modules_of_module} to load in any modules which the current module |
434 depends on. If the module is stand-alone, and does not depend on other | 434 depends on. If the module is stand-alone, and does not depend on other |
435 modules, then this function can be left empty or even undeclared. | 435 modules, then this function can be left empty or even undeclared. |
436 However, if it does have dependnacies, it must call | 436 However, if it does have dependencies, it must call |
437 @code{emodules_load}: | 437 @code{emodules_load}: |
438 | 438 |
439 @example | 439 @example |
440 @cartouche | 440 @cartouche |
441 int emodules_load (CONST char *module, | 441 int emodules_load (const char *module, |
442 CONST char *modname, | 442 const char *modname, |
443 CONST char *modver) | 443 const char *modver) |
444 @end cartouche | 444 @end cartouche |
445 @end example | 445 @end example |
446 | 446 |
447 The first argument @var{module} is the name of the actual shared object | 447 The first argument @var{module} is the name of the actual shared object |
448 or DLL. You can omit the @file{.so}, @file{.ell} or @file{.dll} | 448 or DLL. You can omit the @file{.so}, @file{.ell} or @file{.dll} |
449 extension of you wish. If you do not specify an absolute path name, | 449 extension of you wish. If you do not specify an absolute path name, |
450 then the same rules as apply to loading Lisp modules are applied when | 450 then the same rules as apply to loading Lisp modules are applied when |
451 searching for the module. If the module cannot be found in any of the | 451 searching for the module. If the module cannot be found in any of the |
452 standard places, and an absolute path name was not specified, | 452 standard places, and an absolute path name was not specified, |
453 @code{emodules_load} will signal an error and loading of the module | 453 @code{emodules_load} will signal an error and loading of the module |
454 will stop. | 454 will stop. |
455 | 455 |
456 The second argument (@var{modname}) is the module name to load, and | 456 The second argument (@var{modname}) is the module name to load, and |
457 must match the contents of the variable @var{emodule_name} in the | 457 must match the contents of the variable @var{emodule_name} in the |
458 module to be loaded. A mis-match will cause the module load to fail. If | 458 module to be loaded. A mis-match will cause the module load to fail. If |
459 this parameter is @code{NULL} or empty, then no checks are performed | 459 this parameter is @code{NULL} or empty, then no checks are performed |
460 against the target module's @var{emodule_name} variable. | 460 against the target module's @var{emodule_name} variable. |
461 | 461 |
462 The last argument, @var{modver}, is the desired version of the module | 462 The last argument, @var{modver}, is the desired version of the module |
463 to load, and is compared to the target module's | 463 to load, and is compared to the target module's |
464 @var{emodule_version} value. If this parameter is not @code{NULL} | 464 @var{emodule_version} value. If this parameter is not @code{NULL} |
465 or empty, and the match fails, then the load of the module will fail. | 465 or empty, and the match fails, then the load of the module will fail. |
466 | 466 |
467 @code{emodules_load} can be called recursively. If, at any point | 467 @code{emodules_load} can be called recursively. If, at any point |
468 during the loading of modules a failure is encountered, then all modules | 468 during the loading of modules a failure is encountered, then all modules |
469 that were loaded since the top level call to @code{emodules_load} | 469 that were loaded since the top level call to @code{emodules_load} |
470 will be unloaded. This means that if any child modules fail to load, | 470 will be unloaded. This means that if any child modules fail to load, |
471 then their parents will also fail to load. This does not include | 471 then their parents will also fail to load. This does not include |
472 previous successful calls to @code{emodules_load} at the top level. | 472 previous successful calls to @code{emodules_load} at the top level. |
473 | 473 |
474 @node Using ellcc, Defining Functions, Annatomy of a Module, Top | 474 @node Using ellcc, Defining Functions, Anatomy of a Module, Top |
475 @chapter Using @code{ellcc} | 475 @chapter Using @code{ellcc} |
476 @cindex @code{ellcc} | 476 @cindex @code{ellcc} |
477 @cindex module compiler | 477 @cindex module compiler |
478 | 478 |
479 Before discussing the anatomy of a module in greater detail, you should | 479 Before discussing the anatomy of a module in greater detail, you should |
492 compiler does, so in many cases you can simply set the @code{make} | 492 compiler does, so in many cases you can simply set the @code{make} |
493 variable @code{CC} to @code{ellcc} and your code will be compiled as | 493 variable @code{CC} to @code{ellcc} and your code will be compiled as |
494 an Emacs module rather than a static C object. | 494 an Emacs module rather than a static C object. |
495 | 495 |
496 @code{ellcc} has three distinct modes of operation. It can be run in | 496 @code{ellcc} has three distinct modes of operation. It can be run in |
497 compile, link or initialization mode. These modes are discussed in more | 497 compile, link or initialization mode. These modes are discussed in more |
498 detail below. If you want @code{ellcc} to show the commands it is | 498 detail below. If you want @code{ellcc} to show the commands it is |
499 executing, you can specify the option @code{--mode=verbose} to | 499 executing, you can specify the option @code{--mode=verbose} to |
500 @code{ellcc}. Specifying this option twice will enable certain extra | 500 @code{ellcc}. Specifying this option twice will enable certain extra |
501 debugging messages to be displayed on the standard output. | 501 debugging messages to be displayed on the standard output. |
502 | 502 |
511 @node Compile Mode, Initialization Mode, Using ellcc, Using ellcc | 511 @node Compile Mode, Initialization Mode, Using ellcc, Using ellcc |
512 @section Compile Mode | 512 @section Compile Mode |
513 @cindex compiling | 513 @cindex compiling |
514 | 514 |
515 By default, @code{ellcc} is in @dfn{compile} mode. This means that it | 515 By default, @code{ellcc} is in @dfn{compile} mode. This means that it |
516 assumes that all of the command line arguments are C compiler arguments, | 516 assumes that all of the command line arguments are C compiler arguments, |
517 and that you want to compile the specified source file or files. You | 517 and that you want to compile the specified source file or files. You |
518 can force compile mode by specifying the @code{--mode=compile} argument | 518 can force compile mode by specifying the @code{--mode=compile} argument |
519 to @code{ellcc}. | 519 to @code{ellcc}. |
520 | 520 |
521 In this mode, @code{ellcc} is simply a front-end to the same C compiler | 521 In this mode, @code{ellcc} is simply a front-end to the same C compiler |
524 the arguments you specify to @code{ellcc} itself. @code{ellcc} will | 524 the arguments you specify to @code{ellcc} itself. @code{ellcc} will |
525 then invoke the C compiler to compile your module, and will return the | 525 then invoke the C compiler to compile your module, and will return the |
526 same exit codes and messages that your C compiler does. | 526 same exit codes and messages that your C compiler does. |
527 | 527 |
528 By far the easiest way to compile modules is to construct a | 528 By far the easiest way to compile modules is to construct a |
529 @file{Makefile} as you would for a normal program, and simply insert, at | 529 @file{Makefile} as you would for a normal program, and simply insert, at |
530 some appropriate place something similar to: | 530 some appropriate place something similar to: |
531 | 531 |
532 @example | 532 @example |
533 @cartouche | 533 @cartouche |
534 CC=ellcc --mode=compile | 534 CC=ellcc --mode=compile |
552 @value{emacs} uses a rather bizarre way of documenting variables and | 552 @value{emacs} uses a rather bizarre way of documenting variables and |
553 functions. Rather than have the documentation for compiled functions | 553 functions. Rather than have the documentation for compiled functions |
554 and variables passed as static strings in the source code, the | 554 and variables passed as static strings in the source code, the |
555 documentation is included as a C comment. A special program, called | 555 documentation is included as a C comment. A special program, called |
556 @file{make-docfile}, is used to scan the source code files and extract | 556 @file{make-docfile}, is used to scan the source code files and extract |
557 the documentation from these comments, producing the @value{emacs} @file{DOC} | 557 the documentation from these comments, producing the @value{emacs} @file{DOC} |
558 file, which the internal help engine scans when the documentation for a | 558 file, which the internal help engine scans when the documentation for a |
559 function or variable is requested. | 559 function or variable is requested. |
560 | 560 |
561 Due to the internal construction of Lisp objects, subrs and other such | 561 Due to the internal construction of Lisp objects, subrs and other such |
562 things, adding documentation for a compiled function or variable in a | 562 things, adding documentation for a compiled function or variable in a |
563 compiled module, at any time after @value{emacs} has been @dfn{dumped} is | 563 compiled module, at any time after @value{emacs} has been @dfn{dumped} is |
564 somewhat problematic. Fortunately, as a module writer you are insulated | 564 somewhat problematic. Fortunately, as a module writer you are insulated |
565 from the difficulties thanks to your friend @code{ellcc} and some | 565 from the difficulties thanks to your friend @code{ellcc} and some |
566 internal trickery in the module loading code. This is all done using | 566 internal trickery in the module loading code. This is all done using |
567 the @dfn{initialization} mode of @code{ellcc}. | 567 the @dfn{initialization} mode of @code{ellcc}. |
568 | 568 |
569 The result of running @code{ellcc} in initialization mode is a C source | 569 The result of running @code{ellcc} in initialization mode is a C source |
570 file which you compile with (you guessed it) @code{ellcc} in compile | 570 file which you compile with (you guessed it) @code{ellcc} in compile |
571 mode. Initialization mode is where you set the module name, version, | 571 mode. Initialization mode is where you set the module name, version, |
572 title and gather together all of the documentaion strings for the | 572 title and gather together all of the documentation strings for the |
573 functions and vairables in your module. There are several options that | 573 functions and variables in your module. There are several options that |
574 you are required to pass @code{ellcc} in initialization mode, the first | 574 you are required to pass @code{ellcc} in initialization mode, the first |
575 of which is the mode switch itself, @code{--mode=init}. | 575 of which is the mode switch itself, @code{--mode=init}. |
576 | 576 |
577 Next, you need to specify the name of the C source code file that | 577 Next, you need to specify the name of the C source code file that |
578 @code{ellcc} will produce, and you specify this using the | 578 @code{ellcc} will produce, and you specify this using the |
600 purpose other than to inform the user of the function of the module. | 600 purpose other than to inform the user of the function of the module. |
601 This string should be brief, as it has to be formatted to fit the | 601 This string should be brief, as it has to be formatted to fit the |
602 screen. | 602 screen. |
603 | 603 |
604 Following all of these parameters, you need to provide the list of all | 604 Following all of these parameters, you need to provide the list of all |
605 source code modules that make up your module. These are the files which | 605 source code modules that make up your module. These are the files which |
606 are scanned by @file{make-docfile}, and provide the information required | 606 are scanned by @file{make-docfile}, and provide the information required |
607 to populate the @code{docs_of_module} function. Below is a sample | 607 to populate the @code{docs_of_module} function. Below is a sample |
608 @file{Makefile} fragment which indicates how all of this is used. | 608 @file{Makefile} fragment which indicates how all of this is used. |
609 | 609 |
610 @example | 610 @example |
611 @cartouche | 611 @cartouche |
654 @code{--mod-site-location} option. This directory is treated the same | 654 @code{--mod-site-location} option. This directory is treated the same |
655 way as the main module directory. Each sub-directory within it is | 655 way as the main module directory. Each sub-directory within it is |
656 searched for a given module when the user attempts to load it. The | 656 searched for a given module when the user attempts to load it. The |
657 valid extensions that the loader attempts to use are @file{.so}, | 657 valid extensions that the loader attempts to use are @file{.so}, |
658 @file{.ell} and @file{.dll}. You can use any of these extensions, | 658 @file{.ell} and @file{.dll}. You can use any of these extensions, |
659 although @file{.ell} is the prefered extension. | 659 although @file{.ell} is the preferred extension. |
660 | 660 |
661 @node Link Mode, Other ellcc options, Initialization Mode, Using ellcc | 661 @node Link Mode, Other ellcc options, Initialization Mode, Using ellcc |
662 @section Link Mode | 662 @section Link Mode |
663 @cindex linking | 663 @cindex linking |
664 | 664 |
665 Once all of your source code files have been compiled (including the | 665 Once all of your source code files have been compiled (including the |
666 generated init file) you need to link them all together to created the | 666 generated init file) you need to link them all together to create the |
667 loadable module. To do this, you invoke @code{ellcc} in link mode, by | 667 loadable module. To do this, you invoke @code{ellcc} in link mode, by |
668 pasing the @code{--mode-link} command. You need to specify the final | 668 passing the @code{--mode-link} option. You need to specify the final |
669 output file using the @code{--mod-output=NAME} command, but other than | 669 output file using the @code{--mod-output=NAME} option, but other than |
670 that all other arguments are passed on directly to the system compiler | 670 that all other arguments are passed on directly to the system compiler |
671 or linker, along with any other required arguments to create the | 671 or linker, along with any other required arguments to create the |
672 loadable module. | 672 loadable module. |
673 | 673 |
674 The module has complete access to all symbols that were present in the | 674 The module has complete access to all symbols that were present in the |
684 @section Other @code{ellcc} options | 684 @section Other @code{ellcc} options |
685 @cindex paths | 685 @cindex paths |
686 | 686 |
687 Aside from the three main @code{ellcc} modes described above, | 687 Aside from the three main @code{ellcc} modes described above, |
688 @code{ellcc} can accept several other options. These are typically used | 688 @code{ellcc} can accept several other options. These are typically used |
689 in a @file{Makefile} to determine installation paths. @code{ellcc} also | 689 in a @file{Makefile} to determine installation paths. @code{ellcc} also |
690 allows you to over-ride several of its built-in compiler and linker | 690 allows you to over-ride several of its built-in compiler and linker |
691 options using environment variables. Here is the complete list of | 691 options using environment variables. Here is the complete list of |
692 options that @code{ellcc} accepts. | 692 options that @code{ellcc} accepts. |
693 | 693 |
694 @table @code | 694 @table @code |
698 @item --mode=link | 698 @item --mode=link |
699 Enabled link edit mode. Use this to create the final module. | 699 Enabled link edit mode. Use this to create the final module. |
700 | 700 |
701 @item --mode=init | 701 @item --mode=init |
702 Used to create the documentation function and to initialize other | 702 Used to create the documentation function and to initialize other |
703 required variables. Produces a C source file that must be compiled with | 703 required variables. Produces a C source file that must be compiled with |
704 @code{ellcc} in compile mode before linking the final module. | 704 @code{ellcc} in compile mode before linking the final module. |
705 | 705 |
706 @item --mode=verbose | 706 @item --mode=verbose |
707 Enables verbose mode. This will show you the commands that are being | 707 Enables verbose mode. This will show you the commands that are being |
708 executed, as well as the version number of @code{ellcc}. If you specify | 708 executed, as well as the version number of @code{ellcc}. If you specify |
709 this option twice, then some extra debugging information is displayed. | 709 this option twice, then some extra debugging information is displayed. |
710 | 710 |
711 @item --mod-name=NAME | 711 @item --mod-name=NAME |
712 Sets the short internaml module @var{NAME} to the string specified, | 712 Sets the short internal module @var{NAME} to the string specified, |
713 which must consist only of valid C identifiers. Required during | 713 which must consist only of valid C identifiers. Required during |
714 initialization mode. | 714 initialization mode. |
715 | 715 |
716 @item --mod-version=VERSION | 716 @item --mod-version=VERSION |
717 Sets the internal module @var{VERSION} to the specified string. | 717 Sets the internal module @var{VERSION} to the specified string. |
727 initialization mode to set the name of the C source file that will be | 727 initialization mode to set the name of the C source file that will be |
728 created to @var{FILENAME}. During link mode, it sets the name of the | 728 created to @var{FILENAME}. During link mode, it sets the name of the |
729 final loadable module to @var{FILENAME}. | 729 final loadable module to @var{FILENAME}. |
730 | 730 |
731 @item --mod-location | 731 @item --mod-location |
732 This will print the name of the standard module installation path on the | 732 This will print the name of the standard module installation path on the |
733 standard output and immediately exit @code{ellcc}. Use this option to | 733 standard output and immediately exit @code{ellcc}. Use this option to |
734 determine the directory prefix of where you should install your modules. | 734 determine the directory prefix of where you should install your modules. |
735 | 735 |
736 @item --mod-site-location | 736 @item --mod-site-location |
737 This will print the name of the site specific module location and exit. | 737 This will print the name of the site specific module location and exit. |
738 | 738 |
739 @item --mod-archdir | 739 @item --mod-archdir |
740 Prints the name of the root of the architecture-dependant directory that | 740 Prints the name of the root of the architecture-dependent directory that |
741 @value{emacs} searches for architecture-dependant files. | 741 @value{emacs} searches for architecture-dependent files. |
742 | 742 |
743 @item --mod-config | 743 @item --mod-config |
744 Prints the name of the configuration for which @value{emacs} and @code{ellcc} | 744 Prints the name of the configuration for which @value{emacs} and @code{ellcc} |
745 were compiled. | 745 were compiled. |
746 @end table | 746 @end table |
747 | 747 |
748 @node Environment Variables, , Other ellcc options, Using ellcc | 748 @node Environment Variables, , Other ellcc options, Using ellcc |
749 @section Environment Variables | 749 @section Environment Variables |
750 @cindex environment variables | 750 @cindex environment variables |
751 | 751 |
752 During its normal operation, @code{ellcc} uses the compiler and linker | 752 During its normal operation, @code{ellcc} uses the compiler and linker |
753 flags that were determined at the time @value{emacs} was configured. In | 753 flags that were determined at the time @value{emacs} was configured. In |
754 certain rare circumstances you may wish to over-ride the flags passed to | 754 certain rare circumstances you may wish to over-ride the flags passed to |
755 the compiler or linker, and you can do so using environment variables. | 755 the compiler or linker, and you can do so using environment variables. |
756 The table below lists all of the environment variables that @code{ellcc} | 756 The table below lists all of the environment variables that @code{ellcc} |
757 recognises. | 757 recognizes. |
758 | 758 |
759 @table @code | 759 @table @code |
760 @item ELLCC | 760 @item ELLCC |
761 @cindex @code{ELLCC} | 761 @cindex @code{ELLCC} |
762 This is used to over-ride the name of the C compiler that is invoked by | 762 This is used to over-ride the name of the C compiler that is invoked by |
800 @chapter Defining Functions | 800 @chapter Defining Functions |
801 @cindex defining functions | 801 @cindex defining functions |
802 | 802 |
803 One of the main reasons you would ever write a module is to | 803 One of the main reasons you would ever write a module is to |
804 provide one or more @dfn{functions} for the user or the editor to use. | 804 provide one or more @dfn{functions} for the user or the editor to use. |
805 The term | 805 The term |
806 @dfn{function} is a bit overloaded here, as it refers to both a C | 806 @dfn{function} is a bit overloaded here, as it refers to both a C |
807 function and the way it appears to Lisp, which is a @dfn{subroutine}, or | 807 function and the way it appears to Lisp, which is a @dfn{subroutine}, or |
808 simply a @dfn{subr}. A Lisp subr is also known as a Lisp primitive, but | 808 simply a @dfn{subr}. A Lisp subr is also known as a Lisp primitive, but |
809 that term applies less to dynamic modules. @xref{Writing Lisp | 809 that term applies less to dynamic modules. @xref{Writing Lisp |
810 Primitives,,,internals,@value{emacs} Internals Manual}, for details on how to | 810 Primitives,,,internals,@value{emacs} Internals Manual}, for details on how to |
811 declare functions. You should familiarize yourself with the | 811 declare functions. You should familiarize yourself with the |
812 instructions there. The format of the function declaration is identical | 812 instructions there. The format of the function declaration is identical |
813 in modules. | 813 in modules. |
814 | 814 |
815 Normal Lisp primitives document the functions they defining by including | 815 Normal Lisp primitives document the functions they defining by including |
816 the documentation as a C comment. During the build process, a program | 816 the documentation as a C comment. During the build process, a program |
817 called @file{make-docfile} is run, which will extract all of these | 817 called @file{make-docfile} is run, which will extract all of these |
818 comments, build up a single large documentation file, and will store | 818 comments, build up a single large documentation file, and will store |
819 pointers to the start of each documentation entry in the dumped @value{emacs}. | 819 pointers to the start of each documentation entry in the dumped @value{emacs}. |
820 This, of course, will not work for dynamic modules, as they are loaded | 820 This, of course, will not work for dynamic modules, as they are loaded |
824 @code{ellcc} initialization mode. | 824 @code{ellcc} initialization mode. |
825 | 825 |
826 When using @code{DEFUN} in normal @value{emacs} C code, the sixth | 826 When using @code{DEFUN} in normal @value{emacs} C code, the sixth |
827 ``parameter'' is a C comment which documents the function. For a | 827 ``parameter'' is a C comment which documents the function. For a |
828 dynamic module, we of course need to convert the C comment to a usable | 828 dynamic module, we of course need to convert the C comment to a usable |
829 string, and we need to set the documentation pointer of the subr to this | 829 string, and we need to set the documentation pointer of the subr to this |
830 string. As a module programmer, you don't actually need to do any work | 830 string. As a module programmer, you don't actually need to do any work |
831 for this to happen. It is all taken care of in the | 831 for this to happen. It is all taken care of in the |
832 @code{docs_of_module} function created by @code{ellcc}. | 832 @code{docs_of_module} function created by @code{ellcc}. |
833 | 833 |
834 @menu | 834 @menu |
841 @cindex subrs | 841 @cindex subrs |
842 @findex DEFUN | 842 @findex DEFUN |
843 @cindex functions, Lisp | 843 @cindex functions, Lisp |
844 @cindex functions, defining | 844 @cindex functions, defining |
845 | 845 |
846 Although the full syntax of a function declaration is discussed in the | 846 Although the full syntax of a function declaration is discussed in the |
847 @value{emacs} internals manual in greater depth, what follows is a brief | 847 @value{emacs} internals manual in greater depth, what follows is a brief |
848 description of how to define and implement a new Lisp primitive in a | 848 description of how to define and implement a new Lisp primitive in a |
849 module. This is done using the @code{DEFUN} macro. Here is a small | 849 module. This is done using the @code{DEFUN} macro. Here is a small |
850 example: | 850 example: |
851 | 851 |
852 @example | 852 @example |
853 @cartouche | 853 @cartouche |
854 DEFUN ("my-function", Fmy_function, 1, 1, "FFile name: ", /* | 854 DEFUN ("my-function", Fmy_function, 1, 1, "FFile name: ", /* |
855 Sample Emacs primitive function. | 855 Sample Emacs primitive function. |
856 | 856 |
857 The specified FILE is frobricated before it is fnozzled. | 857 The specified FILE is frobnicated before it is fnozzled. |
858 */ | 858 */ |
859 (file)) | 859 (file)) |
860 @{ | 860 @{ |
861 char *filename; | 861 char *filename; |
862 | 862 |
869 @} | 869 @} |
870 @end cartouche | 870 @end cartouche |
871 @end example | 871 @end example |
872 | 872 |
873 The first argument is the name of the function as it will appear to the | 873 The first argument is the name of the function as it will appear to the |
874 Lisp reader. This must be provided as a string. The second argument is | 874 Lisp reader. This must be provided as a string. The second argument is |
875 the name of the actual C function that will be created. This is | 875 the name of the actual C function that will be created. This is |
876 typically the Lisp function name with a preceding capital @code{F}, with | 876 typically the Lisp function name with a preceding capital @code{F}, with |
877 hyphens converted to underscores. This must be a valid C function | 877 hyphens converted to underscores. This must be a valid C function |
878 name. Next come the minimum and maximum number of arguments, | 878 name. Next come the minimum and maximum number of arguments, |
879 respectively. This is used to ensure that the correct number of | 879 respectively. This is used to ensure that the correct number of |
880 arguments are passed to the function. Next is the @code{interactive} | 880 arguments are passed to the function. Next is the @code{interactive} |
881 definition. If this function is meant to be run by a user | 881 definition. If this function is meant to be run by a user |
889 @section Declaring Functions | 889 @section Declaring Functions |
890 @findex DEFSUBR | 890 @findex DEFSUBR |
891 @cindex functions, declaring | 891 @cindex functions, declaring |
892 | 892 |
893 Simply writing the code for a function is not enough to make it | 893 Simply writing the code for a function is not enough to make it |
894 availible to the Lisp reader. You have to, during module | 894 available to the Lisp reader. You have to, during module |
895 initialization, let the Lisp reader know about the new function. This | 895 initialization, let the Lisp reader know about the new function. This |
896 is done by calling @code{DEFSUBR} with the name of the function. This | 896 is done by calling @code{DEFSUBR} with the name of the function. This |
897 is the sole purpose of the initialization function | 897 is the sole purpose of the initialization function |
898 @code{syms_of_module}. @xref{Required Functions}, for more details. | 898 @code{syms_of_module}. @xref{Required Functions}, for more details. |
899 | 899 |
931 @cindex objects, defining | 931 @cindex objects, defining |
932 @cindex objects, Lisp | 932 @cindex objects, Lisp |
933 | 933 |
934 Rarely will you write a module that only contains functions. It is | 934 Rarely will you write a module that only contains functions. It is |
935 common to also provide variables which can be used to control the | 935 common to also provide variables which can be used to control the |
936 behaviour of the function, or store the results of the function being | 936 behavior of the function, or store the results of the function being |
937 executed. The actual C variable types are the same for modules | 937 executed. The actual C variable types are the same for modules |
938 and internal @value{emacs} primitives, and the declaration of the variables | 938 and internal @value{emacs} primitives, and the declaration of the variables |
939 is identical. | 939 is identical. |
940 | 940 |
941 @xref{Adding Global Lisp Variables,,,internals,XEmacs Internals Manual}, | 941 @xref{Adding Global Lisp Variables,,,internals,XEmacs Internals Manual}, |
942 for more information on variables and naming conventions. | 942 for more information on variables and naming conventions. |
943 | 943 |
944 Once your variables are defined, you need to initialize them and make | 944 Once your variables are defined, you need to initialize them and make |
945 the Lisp reader aware of them. This is done in the | 945 the Lisp reader aware of them. This is done in the |
946 @code{vars_of_module} initialization function using special @value{emacs} | 946 @code{vars_of_module} initialization function using special @value{emacs} |
947 macros such as @code{DEFVAR_LISP}, @code{DEFVAR_BOOL}, @code{DEFVAR_INT} | 947 macros such as @code{DEFVAR_LISP}, @code{DEFVAR_BOOL}, @code{DEFVAR_INT} |
948 etc. The best way to see how to use these macros is to look at existing | 948 etc. The best way to see how to use these macros is to look at existing |
949 source code, or read the internals manual. | 949 source code, or read the internals manual. |
950 | 950 |
951 One @emph{very} important difference between @value{emacs} variables and | 951 One @emph{very} important difference between @value{emacs} variables and |
952 module variables is how you use pure space. Simply put, you | 952 module variables is how you use pure space. Simply put, you |
953 @strong{never} use pure space in @value{emacs} modules. The pure space | 953 @strong{never} use pure space in @value{emacs} modules. The pure space |
954 storage is of a limited size, and is initialized propperly during the | 954 storage is of a limited size, and is initialized properly during the |
955 dumping of @value{emacs}. Because variables are being added dynamically to | 955 dumping of @value{emacs}. Because variables are being added dynamically to |
956 an already running @value{emacs} when you load a module, you cannot use pure | 956 an already running @value{emacs} when you load a module, you cannot use pure |
957 space. Be warned: @strong{do not use pure space in modules. Repeat, do | 957 space. Be warned: @strong{do not use pure space in modules. Repeat, do |
958 not use pure space in modules.} Once again, to remove all doubts: | 958 not use pure space in modules.} Once again, to remove all doubts: |
959 @strong{DO NOT USE PURE SPACE IN MODULES!!!} | 959 @strong{DO NOT USE PURE SPACE IN MODULES!!!} |