Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!ncar!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.lisp Subject: Re: Calling C functions from Franz Lisp Message-ID: <12363@mimsy.UUCP> Date: 8 Jul 88 04:58:39 GMT References: <12196@sunybcs.UUCP> <484@aiva.ed.ac.uk> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 53 In article <484@aiva.ed.ac.uk> jeff@aiva.ed.ac.uk (Jeff Dalton) writes: >... For some purposes, you need the real definition in >`franz/h/global.h' in the Franz source directory. ... >(1) In many versions of Franz, you may not be able to use malloc >without confusing Lisp. The Lisp allocator does not care if something else steals pages, but the malloc allocator might. (I am not sure that this is true of all versions of Franz, but note that stdio uses malloc, and Franz uses stdio.) >... So, in order to allocate a cons cell (what Franz calls a >dtpr (dotted pair), you can't just allocate it anywhere: you have to >allocate it on a cons cell page. ... The function `newdot()' allocates a cons cell. `inewint(int value)' allocates an integer with value `value'. `matom(char *name)' makes an atom; `mstr(char *str)' makes a string; and `mfun(char *name, lispval fun, lispval type)' creates a function, where type is either lambda or nlambda (or, I suppose, flambda, although I am not sure that is done as a separate type). >(3) You don't say how you actually return the list. Remember that >your C function has to be made known to Lisp (with getaddress, say) >and have discipline "function". Things generally work better if you have an auxiliary setup function call mfun to make the functions. >What it comes down to is that it is a pain to write C code that >creates Lisp data. In addition to the things already mentioned, you >may have to worry about garbage collection (if you allocate a Lisp >object, the garbage collector may be called). You must use the `protect()' macro: >Consequently, you may >want to protect objects from collection, and that brings you into >contact with Franz internals that you may not want to know about. ... such as, for instance, that on a Vax you may not use more than four register variables, because what appear to be globals (np and lbot) must be translated into registers r6 and r7 by a `sed' script working on the assembly output of the compiler. protect() works by saving its lispval argument in *np++; np and lbot are used to implement the Lisp namestack. lbot[0] is the first argument to a function, and lbot[1] the second, and so forth; the number of actual arguments is np-lbot. The sed script also translates calls to newdot into `jsb' instructions, to avoid the Vax `calls' instruction overhead, so it must be used even if you are only allocating one dptr and never check any arguments. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris