home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
umbscheme-2.12.lha
/
UMBScheme
/
src
/
object.h
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-29
|
27KB
|
970 lines
/* object.h -- UMB Scheme, object interface.
UMB Scheme Interpreter $Revision: 2.12 $
Copyright (C) 1988, 1991 William R Campbell
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
UMB Scheme was written by Bill Campbell with help from Karl Berry,
Barbara Dixey, Ira Gerstein, Mary Glaser, Kathy Hargreaves, Bill McCabe,
Long Nguyen, Susan Quina, Jeyashree Sivasubram, Bela Sohoni and Thang Quoc Tran.
For additional information about UMB Scheme, contact the author:
Bill Campbell
Department of Mathematics and Computer Science
University of Massachusetts at Boston
Harbor Campus
Boston, MA 02125
Telephone: 617-287-6449 Internet: bill@cs.umb.edu
*/
/* Declarations for all the data objects and forms.
The Scheme interpreter operates on the C type `Object', meant to represent
a Scheme object; thus, Object is our central data abstraction.
The data type, Object, is the union of many sub-types which taken together
can be used to denote the programs we are interpreting. Most types
(e.g., Number_Object, String_Object, If_Object) correspond to objects and
special forms that are discussed in the Scheme Reference Manual. Others
(e.g., Frame_Object) are necessary to our implementation.
There are six operations that are generally applicable to all objects:
1. Eval_Object -- directs the explicit evaluator for this type.
2. Compile_Object -- compiles the result of a (read) to code.
3. Display_Object -- in human readable (eg "cat" => cat) form.
4. Write_Object -- in machine readable (eg "cat" => "cat") from.
5. Show_Object -- as part of the environment (in abbreviated form).
5. GC_Object -- for gc-ing objects of this type on the heap.
We can think of a sub-type as being defined by how these operations are
particularly defined over that sub-type. This is our basis for representing
objects. An object is represented by (a pointer to) a structure having one
or more components, including (a pointer to) an operation vector of the five
procedures that implement these operations. An object's type is distinguished
by its operation vector; e.g., Number_Objects are designated by (the pointer to)
the vector of operations for evaluating, compiling, displaying, writing, and
garbage collecting Number_Objects. */
/* Here are the six common operations. */
typedef struct
{
void (*Eval)();
void (*Compile)();
Integer (*Display)();
Integer (*Write)();
Integer (*Show)();
struct Object_Struct *(*GC)();
} Op_Vector;
typedef Op_Vector *Scheme_Type;
/* The value register needs to be assigned a type t quite often. The call
`Set_Result_Type(t)' will do it. */
#define Set_Result_Type(t) { Get_Type(Value_Register) = t;\
Get_Type_Name(Value_Register) = "" /* #t */; }
/* Every object has at least a `Common_Struct'. */
typedef struct
{
Scheme_Type Type;
String Type_Name;
} Common_Struct;
/* And a way to access the common fields. */
#define Get_Type(o) ((o)->Common.Type)
#define Get_Type_Name(o) ((o)->Common.Type_Name)
#define Eval_Object(o) ((Get_Type(o)->Eval)(o))
#define Compile_Object(o) ((Get_Type(o)->Compile)())
#define Display_Object(o,m) ((Get_Type(o)->Display)(o,m))
#define Write_Object(o,m) ((Get_Type(o)->Write)(o,m))
#define Show_Object(o,m) ((Get_Type(o)->Show)(o,m))
#define GC_Object(o) ((Get_Type(o)->GC)(o))
/* Boolean; only the objects: The_True_Object and The_False_Object */
typedef struct
{
int dummy;
} Boolean_Struct;
Import Op_Vector Boolean_Ops;
Import Integer Boolean_Print();
Import struct Object_Struct *Boolean_GC();
Import Scheme_Type Boolean_Type;
Import struct Object_Struct *The_True_Object, *The_False_Object;
#define Is_Boolean(o) (Get_Type(o) == Boolean_Type)
#define Is_False(o) ((o) == The_False_Object)
#define Boolean_Size (sizeof(Boolean_Struct)+sizeof(Common_Struct))
/* Pair. */
typedef struct
{
struct Object_Struct *Car;
struct Object_Struct *Cdr;
} Pair_Struct;
Import Op_Vector Pair_Ops;
Import Integer Pair_Display(), Pair_Write(), Pair_Show();
struct Object_Struct *Pair_GC();
Import Scheme_Type Pair_Type;
#define Is_Pair(o) (Get_Type(o) == Pair_Type)
#define Is_List(o) (Is_Pair(o) || Is_Empty_List(o))
#define Pair_Size (sizeof(Pair_Struct)+sizeof(Common_Struct))
#define Get_Pair_Car(o) ((o)->Specific.Pair.Car)
#define Get_Pair_Cdr(o) ((o)->Specific.Pair.Cdr)
Import void Make_Pair();
Import Integer Length();
Import struct Object_Struct *First();
Import struct Object_Struct *Second();
Import struct Object_Struct *Third();
Import struct Object_Struct *Fourth();
Import struct Object_Struct *Rest();
Import Boolean Member();
/* Empty List */
typedef struct
{
int dummy;
} Empty_List_Struct;
Import Op_Vector Empty_List_Ops;
Import Integer Empty_List_Print();
Import Integer Empty_List_Display();
Import Integer Empty_List_Write();
struct Object_Struct *Empty_List_GC();
Import Scheme_Type Empty_List_Type;
Import struct Object_Struct *Nil;
#define Is_Empty_List(o) (Get_Type(o) == Empty_List_Type)
#define Empty_List_Size (sizeof(Empty_List_Struct)+sizeof(Common_Struct))
/* Symbol. */
typedef struct
{
struct Object_Struct *Global_Binding;
struct Object_Struct *How;
struct Object_Struct *Property_List;
Boolean User_Defined;
String Name;
} Symbol_Struct;
Import Op_Vector Symbol_Ops;
Import Integer Symbol_Print();
struct Object_Struct *Symbol_GC();
Import Scheme_Type Symbol_Type;
Import struct Object_Struct *QUOTE_Symbol, *DEFINE_Symbol,*SET_Symbol,
*IF_Symbol, *MACRO_Symbol, *BEGIN_Symbol,
*DELAY_Symbol, *LAMBDA_Symbol, *Special_Binding;
Import struct Object_Struct *The_Syntactic_Keyword, *The_Undefined_Symbol,
*An_Argument;
#define Is_Symbol(o) (Get_Type(o) == Symbol_Type)
#define Symbol_Size (sizeof(Symbol_Struct)+sizeof(Common_Struct))
#define Get_Global_Binding(o) ((o)->Specific.Symbol.Global_Binding)
#define Get_Symbol_How(o) ((o)->Specific.Symbol.How)
#define Get_Symbol_User_Defined(o) ((o)->Specific.Symbol.User_Defined)
#define Get_Property_List(o) ((o)->Specific.Symbol.Property_List)
#define Get_Symbol_Name(o) ((o)->Specific.Symbol.Name)
/* Is_Special_Symbol is not an lvalue. `Special_Binding' is simply
a dummy object. */
#define Is_Special_Symbol(o) (Get_Global_Binding(o)==Special_Binding)
Import void Make_Symbol();
/* Number. */
typedef Integer Tower_Position;
#define FIXNUM_LEVEL 0
#define BIGNUM_LEVEL 1
#define RATIONAL_LEVEL 2
#define REAL_LEVEL 3
#define COMPLEX_LEVEL 4
#define TOWER_LEVEL_COUNT 5
/* Fixnums */
#define Get_Number_Fixnum_Value(n) ((n)->Specific.Number.Specific.Fixnum_Value)
/* Bignums */
typedef Short Number_Digit_Type;
typedef struct
{
Integer Length;
Number_Digit_Type Digits[1];
} Bignum_Struct;
#define Get_Number_Length(n) ((n)->Specific.Number.Specific.Bignum.Length)
#define Get_Number_Digits(n) ((n)->Specific.Number.Specific.Bignum.Digits)
#define Get_Number_Digit(n,i) (((n)->Specific.Number.Specific.Bignum.Digits)[i])
/* Rationals */
typedef struct
{
struct Object_Struct *Numerator;
struct Object_Struct *Denominator;
} Rational_Struct;
#define Get_Number_Rational_Numerator(n)\
((n)->Specific.Number.Specific.Rational.Numerator)
#define Get_Number_Rational_Denominator(n)\
((n)->Specific.Number.Specific.Rational.Denominator)
/* Reals */
#define Get_Number_Real_Value(n) ((n)->Specific.Number.Specific.Real_Value)
/* Complex Numbers */
typedef struct
{
Double Real_Part;
Double Imaginary_Part;
} Complex_Struct;
#define Get_Number_Complex_Real_Part(n)\
((n)->Specific.Number.Specific.Complex.Real_Part)
#define Get_Number_Complex_Imaginary_Part(n)\
((n)->Specific.Number.Specific.Complex.Imaginary_Part)
typedef