ftp.nice.ch/pub/next/graphics/3d/geomview.1.4.1.s.tar.gz#/Geomview/src/lib/oogl/lisp/lisp.h

This is lisp.h in view mode; [Download] [Up]

/* Copyright (c) 1992 The Geometry Center; University of Minnesota
   1300 South Second Street;  Minneapolis, MN  55454, USA;
   
This file is part of geomview/OOGL. geomview/OOGL is free software;
you can redistribute it and/or modify it only under the terms given in
the file COPYING, which you should have received along with this file.
This and other related software may be obtained via anonymous ftp from
geom.umn.edu; email: software@geom.umn.edu. */

/* Authors: Stuart Levy, Tamara Munzner, Mark Phillips */

#ifndef LISP_H
#define LISP_H

#include <stdarg.h>
#include "ooglutil.h"
#include "fsa.h"

#include "streampool.h"

typedef struct LType LType;
typedef struct LObject LObject;


typedef union {
  int i;
  float f;
  void *p;
} LCell;

struct LType {

  /* name of type */
  char *name;

  /* size of corresponding C type */
  int size;

  /* extract cell value from obj */
  int (*fromobj)(/* LObject *obj, void *x */);

  /* create a new LObject of this type */
  LObject *(*toobj)(/* void *x */);

  /* free a cell of this type */
  void (*free)(/* void *x */);

  /* write a cell value to a stream */
  void (*write)(/* FILE *fp, void *x */);

  /* test equality of two cells of this type */
  int (*match)(/* void *a, void *b */);

  /* pull a cell value from a va_list */
  void (*pull)(/* va_list *a_list, void *x */);

  /* parse an object of this type */
  LObject *(*parse)(/* Lake *lake */);

  /* magic number; always set to LTypeMagic */
  int magic;

};

#define LTypeMagic 314159

#define LNAME(type)	(type->name)
#define LSIZE(type)	(type->size)
#define LFROMOBJ(type)	(*(type->fromobj))
#define LTOOBJ(type)	(*(type->toobj))
#define LFREE(type)	(*(type->free))
#define LMATCH(type)	(*(type->match))
#define LWRITE(type)	(*(type->write))
#define LPULL(type)	(*(type->pull))
#define LPARSE(type)	(*(type->parse))

struct LObject {
  LType *type;
  int ref;
  LCell cell;
};

typedef struct {
  FILE *streamin;
  FILE *streamout;
  Pool *river;
  int   timing_interests;	/* Are we time-stamping interest reports? */
  float deltatime;		/* delta time between timestamps */
  float nexttime;		/* Pool time when next timestamp'll be needed */
  char *initial, *prefix, *suffix; /* printf format strings */
} Lake;


#define LakeMore(lake,c) ((c=fnextc(lake->streamin,0)) != ')' && c != EOF)
#define POOL(lake)  ((lake)->river)

typedef struct LList {
  LObject * 	car;
  struct LList *cdr;
} LList;

typedef LObject *(*LObjectFunc)();

typedef struct LInterest {
  Lake *lake;
  LList *filter;
  struct LInterest *next;
} LInterest;

typedef struct {
  enum { ANY,			/* match anything */
	 VAL,			/* match only our value */
	 NIL			/* match anything but report nil */
	 } flag;
  LObject *value;
} LFilter;

#define LFILTERVAL(lobject) ((LFilter *)(lobject->cell.p))
extern LType LFilterp;
#define LFILTER (&LFilterp)

/*
 * Built-in objects: Lnil and Lt:
 */
extern LObject *Lnil, *Lt;

/*
 * Built-in object types: string, list, and function.  Function type
 *  is only used internally.  See lisp.c for the code that initializes
 *  these type pointers.
 */
extern LType LStringp;
#define LSTRING (&LStringp)
#define LSTRINGVAL(obj) ((char*)((obj)->cell.p))

extern LType LIntp;
#define LINT (&LIntp)
#define LINTVAL(obj) ((obj)->cell.i)

extern LType LFloatp;
#define LFLOAT (&LFloatp)
#define LFLOATVAL(obj) ((obj)->cell.f)

extern LType LListp;
#define LLIST (&LListp)
#define LLISTVAL(obj) ((LList*)((obj)->cell.p))

#define LLAKEVAL(obj) ((Lake*)(obj->cell.p))
extern LType LLakep;
#define LLAKE (&LLakep)

extern LType LObjectp;
#define LLOBJECT (&LObjectp)

/*
 * Function definition stuff:
 */

#define LASSIGN_GOOD 1
#define LASSIGN_BAD  2
#define LPARSE_GOOD  3
#define LPARSE_BAD   4

#define LDECLARE(stuff) \
  switch (LParseArgs stuff) { \
  case LASSIGN_BAD: case LPARSE_BAD: return Lnil; \
  case LPARSE_GOOD: return Lt; \
  default: case LASSIGN_GOOD: break; \
  }

extern LType Larray;
#define LARRAY (&Larray)

extern LType Lend;
#define LEND (&Lend)

extern LType Lhold;
#define LHOLD (&Lhold)

extern LType Lliteral;
#define LLITERAL (&Lliteral)

extern LType Loptional;
#define LOPTIONAL (&Loptional)

extern LType Lrest;
#define	LREST (&Lrest)

/*
 * Function prototypes:
 */

void 	RemoveLakeInterests(Lake *lake);
void	  	LInit();
Lake *    	LakeDefine(FILE *streamin, FILE *streamout, void *river);
void	  	LakeFree(Lake *lake);
LObject * 	_LNew(LType *type, LCell *cell);
#define   	LNew(type,cell) _LNew(type,(LCell*)cell)
LObject * 	LRefIncr(LObject *obj);
void	  	LRefDecr(LObject *obj);
void	  	LWrite(FILE *fp, LObject *obj);
void	  	LFree(LObject *obj);
LObject	* 	LCopy(LObject *obj);
LObject * 	LSexpr(Lake *lake);
LObject *	LEvalSexpr(Lake *lake);
LObject * 	LEval(LObject *obj);
LList	* 	LListNew();
LList	* 	LListAppend(LList *list, LObject *obj);
void	  	LListFree(LList *list);
LList *	  	LListCopy(LList *list);
LObject * 	LListEntry(LList *list, int n);
int	  	LListLength(LList *list);
int	  	LParseArgs(char *name, Lake *lake, LList *args, ...);
int	  	LDefun(char *name, LObjectFunc func, char *help);
void		LListWrite(FILE *fp, LList *list);
LInterest *	LInterestList(char *funcname);
LObject *	LEvalFunc(char *name, ...);
int		LArgClassValid(LType *type);
void		LHelpDef(char *key, char *message);
char *		LakeName(Lake *lake);
char *		LSummarize(LObject *obj);
LObject *	LMakeArray(LType *basetype, char *data, int count);

void LShow(LObject *obj);	/* for debugging; writes obj to stderr */
void LListShow(LList *list);
void LWriteFile(char *fname, LObject *obj);

#include "clisp.h"

/*
  LDEFINE(name, ltype, doc) is the header used to declare a lisp
  function.  It should be followed by the body of a function
  (beginning with '{' and ending with '}').  LDEFINE delcares the
  function's name to be "Lname" (the "name" argument with "L"
  prepended to it).  It also defines a string named "Hname"
  initialized to "doc".  The "ltype" argument gives the lisp object
  type returned by the function (all functions defined via DEFILE
  *must* return a lisp object.)  LDEFINE actually ignores this but
  read the next paragraph.

  LDEFINE is intended for use in conjunction with the "lisp2c" shell
  script which searches for calls to LDEFINE and builds a C language
  interface to the functions so defined.  This script makes use of all
  3 arguments to LDEFINE, plus the use of the LDECLARE macro in the
  function body that follows, to build the files clang.c and clang.h.
  It makes certain assumptions about the way LDEFINE and LDECLARE
  are used.  See the comments at the top of lisp2c for details.
  (I don't want to write the assumptions down here because if they
  change I'll forget to update this comment!).
*/

#if defined(__STDC__) || defined(__ANSI_CPP__)
#define LDEFINE( name, ltype, doc ) \
  char H##name[] = doc ; LObject *L##name(Lake *lake, LList *args)
#else
#define LDEFINE( name, ltype, doc ) \
  char H/**/name[] = doc ; LObject *L/**/name(Lake *lake, LList *args)
#endif

#define LBEGIN lake, args

#endif /* ! LISP_H */

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.