home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / oct93 / develop / umbscheme.lha / UMBScheme / src / object.h < prev    next >
C/C++ Source or Header  |  1992-08-04  |  27KB  |  972 lines

  1. /* object.h -- UMB Scheme, object interface.
  2.  
  3. UMB Scheme Interpreter                  $Revision: 2.5 $
  4. Copyright (C) 1988, 1991 William R Campbell
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. UMB Scheme was written by Bill Campbell with help from Karl Berry,
  21. Barbara Dixey, Ira Gerstein, Mary Glaser, Kathy Hargreaves, Bill McCabe,
  22. Long Nguyen, Susan Quina, Jeyashree Sivasubram, Bela Sohoni and Thang Quoc Tran.
  23.  
  24. For additional information about UMB Scheme, contact the author:
  25.  
  26.     Bill Campbell
  27.     Department of Mathematics and Computer Science
  28.     University of Massachusetts at Boston
  29.     Harbor Campus
  30.     Boston, MA 02125
  31.  
  32.     Telephone: 617-287-6449        Internet: bill@cs.umb.edu
  33.  
  34. */
  35.  
  36. /* Declarations for all the data objects and forms.
  37.  
  38. The Scheme interpreter operates on the C type `Object', meant to represent 
  39. a Scheme object; thus, Object is our central data abstraction.
  40.  
  41. The data type, Object, is the union of many sub-types which taken together
  42. can be used to denote the programs we are interpreting.  Most types 
  43. (e.g., Number_Object, String_Object, If_Object) correspond to objects and
  44. special forms that are discussed in the Scheme Reference Manual.  Others
  45. (e.g.,  Frame_Object) are necessary to our implementation.
  46.  
  47. There are six operations that are generally applicable to all objects:
  48.  
  49. 1.  Eval_Object        -- directs the explicit evaluator for this type.
  50. 2.  Compile_Object    -- compiles the result of a (read) to code.
  51. 3.  Display_Object    -- in human readable (eg "cat" => cat) form.
  52. 4.  Write_Object    -- in machine readable (eg "cat" => "cat") from.
  53. 5.  Show_Object        -- as part of the environment (in abbreviated form).
  54. 5.  GC_Object    -- for gc-ing objects of this type on the heap.
  55.  
  56. We can think of a sub-type as being defined by how these operations are
  57. particularly defined over that sub-type.  This is our basis for representing
  58. objects.  An object is represented by (a pointer to) a structure having one
  59. or more components, including (a pointer to) an operation vector of the five
  60. procedures that implement these operations.  An object's type is distinguished
  61. by its operation vector; e.g., Number_Objects are designated by (the pointer to)
  62. the vector of operations for evaluating, compiling, displaying, writing, and
  63. garbage collecting Number_Objects. */
  64.  
  65.  
  66. /* Here are the six common operations. */
  67.  
  68. typedef struct
  69. {
  70.     void (*Eval)();
  71.     void (*Compile)();
  72.     Integer (*Display)();
  73.     Integer (*Write)();
  74.     Integer (*Show)();
  75.     struct Object_Struct *(*GC)();
  76. } Op_Vector;
  77.  
  78. typedef Op_Vector *Scheme_Type;
  79.  
  80. /* The value register needs to be assigned a type t quite often. The call
  81. `Set_Result_Type(t)' will do it. */
  82.  
  83. #define Set_Result_Type(t) { Get_Type(Value_Register) = t;\
  84.                  Get_Type_Name(Value_Register) = ""  /* #t */; }
  85.  
  86. /* Every object has at least a `Common_Struct'. */
  87. typedef struct
  88. {
  89.     Scheme_Type Type;
  90.     String Type_Name;
  91. } Common_Struct;
  92.  
  93. /* And a way to access the common fields. */
  94.  
  95. #define Get_Type(o) ((o)->Common.Type)
  96. #define Get_Type_Name(o) ((o)->Common.Type_Name)
  97.  
  98. #define Eval_Object(o)        ((Get_Type(o)->Eval)(o))
  99. #define Compile_Object(o)    ((Get_Type(o)->Compile)())
  100. #define Display_Object(o,m)    ((Get_Type(o)->Display)(o,m))
  101. #define Write_Object(o,m)    ((Get_Type(o)->Write)(o,m))
  102. #define Show_Object(o,m)    ((Get_Type(o)->Show)(o,m))
  103. #define GC_Object(o)        ((Get_Type(o)->GC)(o))
  104.  
  105. /* Boolean; only the objects: The_True_Object and The_False_Object */
  106.  
  107. typedef struct
  108. {
  109.     int dummy;
  110. } Boolean_Struct;
  111.  
  112. Import    Op_Vector Boolean_Ops;
  113. Import    Integer    Boolean_Print();
  114. Import    struct    Object_Struct *Boolean_GC();
  115.  
  116. Import    Scheme_Type Boolean_Type;
  117.  
  118. Import    struct Object_Struct *The_True_Object, *The_False_Object;
  119.  
  120. #define Is_Boolean(o) (Get_Type(o) == Boolean_Type)
  121. #define Is_False(o) ((o) == The_False_Object || (o) == Nil)
  122.  
  123. #define Boolean_Size (sizeof(Boolean_Struct)+sizeof(Common_Struct))
  124.  
  125. /* Pair. */
  126.  
  127. typedef struct
  128. {
  129.     struct Object_Struct *Car;
  130.     struct Object_Struct *Cdr;
  131. } Pair_Struct;
  132.  
  133. Import    Op_Vector Pair_Ops;
  134. Import    Integer Pair_Display(), Pair_Write(), Pair_Show();
  135. struct    Object_Struct *Pair_GC();
  136.  
  137. Import    Scheme_Type Pair_Type;
  138.  
  139. #define Is_Pair(o) (Get_Type(o) == Pair_Type)
  140. #define Is_List(o) (Is_Pair(o) || Is_Empty_List(o))
  141.  
  142. #define Pair_Size (sizeof(Pair_Struct)+sizeof(Common_Struct))
  143.  
  144. #define Get_Pair_Car(o) ((o)->Specific.Pair.Car)
  145. #define Get_Pair_Cdr(o) ((o)->Specific.Pair.Cdr)
  146.  
  147. Import    void Make_Pair();
  148. Import    Integer Length();
  149. Import    struct Object_Struct *First();
  150. Import    struct Object_Struct *Second();
  151. Import    struct Object_Struct *Third();
  152. Import    struct Object_Struct *Fourth();
  153. Import    struct Object_Struct *Rest();
  154. Import    Boolean    Member();
  155.  
  156. /* Empty List */
  157.  
  158. typedef struct
  159. {
  160.     int dummy;
  161. } Empty_List_Struct;
  162.  
  163. Import    Op_Vector Empty_List_Ops;
  164. Import    Integer Empty_List_Print();
  165. Import    Integer Empty_List_Display();
  166. Import    Integer Empty_List_Write();
  167. struct    Object_Struct *Empty_List_GC();
  168.  
  169. Import    Scheme_Type Empty_List_Type;
  170.  
  171. Import    struct Object_Struct *Nil;
  172.  
  173. #define Is_Empty_List(o) (Get_Type(o) == Empty_List_Type)
  174. #define Empty_List_Size (sizeof(Empty_List_Struct)+sizeof(Common_Struct))
  175.  
  176. /* Symbol. */
  177. typedef struct
  178. {
  179.     struct    Object_Struct *Global_Binding;
  180.     struct    Object_Struct *How;
  181.     struct    Object_Struct *Property_List;
  182.     Boolean    User_Defined;
  183.     String    Name;
  184. } Symbol_Struct;
  185.  
  186. Import    Op_Vector Symbol_Ops;
  187. Import    Integer    Symbol_Print();
  188. struct    Object_Struct *Symbol_GC();
  189.  
  190. Import    Scheme_Type Symbol_Type;
  191.  
  192. Import    struct Object_Struct *QUOTE_Symbol, *DEFINE_Symbol,*SET_Symbol,
  193. *IF_Symbol, *MACRO_Symbol, *BEGIN_Symbol,
  194. *DELAY_Symbol, *LAMBDA_Symbol, *Special_Binding;
  195. Import    struct Object_Struct *The_Syntactic_Keyword, *The_Undefined_Symbol,
  196.                 *An_Argument;
  197.  
  198. #define Is_Symbol(o) (Get_Type(o) == Symbol_Type)
  199. #define Symbol_Size (sizeof(Symbol_Struct)+sizeof(Common_Struct))
  200.  
  201. #define Get_Global_Binding(o)    ((o)->Specific.Symbol.Global_Binding)
  202. #define    Get_Symbol_How(o)    ((o)->Specific.Symbol.How)
  203. #define    Get_Symbol_User_Defined(o) ((o)->Specific.Symbol.User_Defined)
  204. #define Get_Property_List(o)    ((o)->Specific.Symbol.Property_List)
  205. #define Get_Symbol_Name(o)    ((o)->Specific.Symbol.Name)
  206.  
  207. /* Is_Special_Symbol is not an lvalue. `Special_Binding' is simply
  208.    a dummy object. */
  209.  
  210. #define Is_Special_Symbol(o) (Get_Global_Binding(o)==Special_Binding)
  211.  
  212. Import    void Make_Symbol();
  213.  
  214. /* Number. */
  215.  
  216. typedef Integer Tower_Position;
  217.  
  218. #define FIXNUM_LEVEL     0
  219. #define BIGNUM_LEVEL     1
  220. #define RATIONAL_LEVEL    2
  221. #define    REAL_LEVEL    3
  222. #define    COMPLEX_LEVEL    4
  223.  
  224.  
  225. #define TOWER_LEVEL_COUNT 5
  226.  
  227. /* Fixnums */
  228.  
  229. #define Get_Number_Fixnum_Value(n) ((n)->Specific.Number.Specific.Fixnum_Value)
  230.  
  231.  
  232. /* Bignums */
  233.  
  234. typedef Short Number_Digit_Type;
  235.  
  236. typedef struct
  237. {
  238.     Integer Length;
  239.     Number_Digit_Type Digits[1];
  240. } Bignum_Struct;
  241.  
  242. #define Get_Number_Length(n) ((n)->Specific.Number.Specific.Bignum.Length)
  243. #define Get_Number_Sign(n) ((n)->Specific.Number.Specific.Bignum.Sign_Value)
  244. #define Get_Number_Digits(n) ((n)->Specific.Number.Specific.Bignum.Digits)
  245. #define Get_Number_Digit(n,i) (((n)->Specific.Number.Specific.Bignum.Digits)[i])
  246.  
  247. /* Rationals */
  248.  
  249. typedef struct
  250. {
  251.     struct Object_Struct *Numerator;
  252.     struct Object_Struct *Denominator;
  253. } Rational_Struct;
  254.  
  255. #define Get_Number_Rational_Numerator(n)\
  256.         ((n)->Specific.Number.Specific.Rational.Numerator)
  257. #define Get_Number_Rational_Denominator(n)\
  258.         ((n)->Specific.Number.Specific.Rational.Denominator)
  259.  
  260. /* Reals */
  261.  
  262. #define Get_Number_Real_Value(n) ((n)->Specific.Number.Specific.Real_Value)
  263.  
  264. /* Complex Numbers */
  265.  
  266. typedef struct
  267. {
  268.     Double    Real_Part;
  269.     Double    Imaginary_Part;
  270. } Complex_Struct;
  271.  
  272. #define    Get_Number_Complex_Real_Part(n)\
  273.         ((n)->Specific.Number.Specific.Complex.Real_Part)
  274. #define    Get_Number_Complex_Imaginary_Part(n)\
  275.         ((n)->Specific.Number.Specific.Complex.Imaginary_Part)
  276.  
  277. typedef struct
  278. {
  279.     Tower_Position Position;
  280.     Boolean    Is_Exact;
  281.  
  282.     union
  283.     {
  284.         Short Fixnum_Value;
  285.         Bignum_Struct Bignum;
  286.         Rational_Struct Rational;
  287.         Double Real_Value;
  288.         Complex_Struct Complex;
  289.     } Specific;
  290. } Number_Struct;
  291.  
  292. Import    Op_Vector Number_Ops;
  293. Import    Integer    Number_Print();
  294. struct    Object_Struct *Number_GC();
  295.  
  296. Import    Scheme_Type Number_Type;
  297.  
  298. #define Is_Number(o) (Get_Type(o) == Number_Type)
  299.  
  300. /* These number classes are unimplemented. Perhaps they should each have 
  301. their own `_Struct's. The `Number_Struct' here wastes a little space.
  302. (Except for the biggest number.) */
  303. #define Fixnum_Size (sizeof(Number_Struct)+sizeof(Common_Struct))
  304. #define Bignum_Size(n) (sizeof(Common_Struct)+sizeof(Tower_Position)+\
  305.             sizeof(Boolean)+\
  306.                   sizeof(Bignum_Struct)+(n-1)*sizeof(Number_Digit_Type))
  307.  
  308. #define Rational_Size (sizeof(Number_Struct)+sizeof(Common_Struct))
  309. #define Real_Size (sizeof(Number_Struct)+sizeof(Common_Struct))
  310. #define Complex_Size (sizeof(Number_Struct)+sizeof(Common_Struct))
  311.  
  312. #define Get_Number_Tower_Position(o) ((o)->Specific.Number.Position)
  313. #define Is_Exact_Number(o)    ((o)->Specific.Number.Is_Exact)
  314.  
  315. /* Make_Number doesn't exist, only Make_..._Number. */
  316.  
  317. Import    void Make_Fixnum_Number();
  318. Import    void Make_Bignum_Number();
  319. Import    void Make_Rational_Number();
  320. Import    void Make_Real_Number();
  321. Import    void Make_Complex_Number();
  322.  
  323. /* Character. */
  324.  
  325. typedef struct
  326. {
  327.     Character Value;
  328. } Character_Struct;
  329.  
  330. Import    Op_Vector Character_Ops;
  331. Import    Integer    Character_Write(), Character_Display();
  332. struct    Object_Struct *Character_GC();
  333.  
  334. Import    Scheme_Type Character_Type;
  335.  
  336. #define Is_Character(o) (Get_Type(o) == Character_Type)
  337.  
  338. #define Character_Size (sizeof(Character_Struct)+sizeof(Common_Struct))
  339.  
  340. #define Get_Character_Value(o) ((o)->Specific.Character.Value)
  341.  
  342. Import    void Make_Character();
  343.  
  344. /* String. 
  345.  
  346.     This is a variable-length object; the `1' here is merely a 
  347.     placeholder. Note that in this case, `*Value' and `Value[1]' are not
  348.     equivalent. 
  349. */
  350.  
  351. typedef struct
  352. {
  353.     Integer Length;
  354.     Character Value[1];
  355. } String_Struct;
  356.  
  357. Import    Op_Vector String_Ops;
  358. Import    Integer    String_Write(), String_Display();
  359. struct    Object_Struct *String_GC();
  360.  
  361. Import    Scheme_Type String_Type;
  362.  
  363. #define Is_String(o) (Get_Type(o) == String_Type)
  364.  
  365. /* `String_Size' computes the length of a string object for a string of 
  366. size `n'. (`Integer' is the other field in `String_Struct'.) */
  367. #define String_Size(n) ((n-1)+sizeof(String_Struct)+sizeof(Common_Struct))
  368.  
  369. #define Get_String_Length(o) ((o)->Specific.String.Length)
  370. #define Get_String_Value(o)  (&((o)->Specific.String.Value[0]))
  371.  
  372. Import    void Make_String(/*Integer*/);
  373. Import    void Make_Constant_String(/*string*/);
  374. Import    String Copy_String(/* string */);
  375.  
  376. /* Vector. */
  377.  
  378. typedef struct
  379. {
  380.     Integer Length;
  381.     struct Object_Struct *Value[1];
  382. } Vector_Struct;
  383.  
  384. Import    Op_Vector Vector_Ops;
  385. Import    Integer    Vector_Display(), Vector_Write(), Vector_Show();
  386. struct    Object_Struct *Vector_GC();
  387.  
  388. Import    Scheme_Type Vector_Type;
  389.  
  390. #define Is_Vector(o) (Get_Type(o) == Vector_Type)
  391.  
  392. /* The extra space for the elements (beyond the first) is allocated
  393.     via a parameter to Make_Vector. */
  394. #define Vector_Size(n) ((n-1)*sizeof(Object)+sizeof(Vector_Struct)\
  395.                             +sizeof(Common_Struct))
  396.  
  397. #define Get_Vector_Length(o) ((o)->Specific.Vector.Length)
  398. #define Get_Vector_Value(o)  ((o)->Specific.Vector.Value)
  399. #define Get_Vector_Elem(o,i) ((o)->Specific.Vector.Value[i])
  400.  
  401. Import    void Make_Vector();
  402.  
  403. /* Procedure.  (What lambda evaluates to). */
  404.  
  405. typedef struct
  406. {
  407.     String    Name;
  408.     Integer Numargs;
  409.     Boolean    Tracing;
  410.     Boolean    Has_Rest;
  411.     struct    Object_Struct *Body; /* A lambda form. */
  412.     struct    Object_Struct *Environment; /* An environment frame. */
  413.     struct    Object_Struct *Frame; /* For the arguments. */
  414. } Procedure_Struct;
  415.  
  416. Import    Op_Vector Procedure_Ops;
  417. Import    Integer    Procedure_Print(), Procedure_Show();
  418. struct    Object_Struct *Procedure_GC();
  419.  
  420. Import    Scheme_Type Procedure_Type;
  421.  
  422. #define Is_Procedure(o) (Get_Type(o) == Procedure_Type)
  423.  
  424. #define Procedure_Size (sizeof(Procedure_Struct)+sizeof(Common_Struct))
  425.  
  426. #define Get_Procedure_Name(o) ((o)->Specific.Procedure.Name)
  427. #define Get_Procedure_Numargs(o) ((o)->Specific.Procedure.Numargs)
  428. #define Get_Procedure_Tracing(o) ((o)->Specific.Procedure.Tracing)
  429. #define Get_Procedure_Has_Rest(o) ((o)->Specific.Procedure.Has_Rest)
  430. #define Get_Procedure_Body(o) ((o)->Specific.Procedure.Body)
  431. #define Get_Procedure_Environment(o) ((o)->Specific.Procedure.Environment)
  432. #define Get_Procedure_Frame(o) ((o)->Specific.Procedure.Frame)
  433.  
  434. Import    void Make_Procedure();
  435.  
  436. #define Is_Function(o) (Is_Procedure(o) || Is_Continuation(o) || Is_Primitive(o))
  437.  
  438. /* Primitive. (Scheme procedures implemented in C.) */
  439.  
  440. typedef struct
  441. {
  442.     String    Name;
  443.     Boolean    Tracing;
  444.     void    (*Procedure)();
  445.     Integer Arg_Count;
  446.     Scheme_Type Arg_Type[1];
  447. } Primitive_Struct;
  448.  
  449. Import    Op_Vector Primitive_Ops;
  450. Import    Integer    Primitive_Print();
  451. struct    Object_Struct *Primitive_GC();
  452.  
  453. Import    Scheme_Type Primitive_Type;
  454.  
  455. #define Is_Primitive(o) (Get_Type(o) == Primitive_Type)
  456.  
  457. #define    VARYING    (5)
  458.  
  459. #define Primitive_Size(n) (((n==VARYING)?0:n-1)*sizeof(Scheme_Type)\
  460.                 +sizeof(Primitive_Struct)+sizeof(Common_Struct))
  461.  
  462. #define Get_Primitive_Name(o) ((o)->Specific.Primitive.Name)
  463. #define Get_Primitive_Tracing(o) ((o)->Specific.Primitive.Tracing)
  464. #define Get_Primitive_Procedure(o) ((o)->Specific.Primitive.Procedure)
  465. #define Get_Primitive_Numargs(o) ((o)->Specific.Primitive.Arg_Count)
  466. #define Get_Primitive_Argtypes(o,i) ((o)->Specific.Primitive.Arg_Type[i])
  467.  
  468. Import    void Make_Primitive();
  469.  
  470. /* Continuation. */
  471.  
  472. typedef struct
  473. {
  474.     struct Object_Struct *State; /* A state frame. */
  475.     Integer Stacksize;
  476.     struct Object_Struct *Stack[1];
  477. } Continuation_Struct;
  478.  
  479. Import    Op_Vector Continuation_Ops;
  480. Import    Integer    Continuation_Print();
  481. struct    Object_Struct *Continuation_GC();
  482.  
  483. Import    Scheme_Type Continuation_Type;
  484.  
  485. #define Is_Continuation(o) (Get_Type(o) == Continuation_Type)
  486. #define Continuation_Size(n) ((n-1)*sizeof(Object)+sizeof(Continuation_Struct)+\
  487.                   sizeof(Common_Struct))
  488.  
  489. #define Get_Continuation_State(o) ((o)->Specific.Continuation.State)
  490. #define Get_Continuation_Stacksize(o) ((o)->Specific.Continuation.Stacksize)
  491. #define Get_Continuation_Stack_Elem(o,i) ((o)->Specific.Continuation.Stack[i])
  492.  
  493. Import    void Make_Continuation();
  494.  
  495.  
  496. /* Port. */
  497.  
  498. typedef struct
  499. {
  500.     Boolean Is_Input;
  501.     FILE *File;
  502.     String Name;
  503. } Port_Struct;
  504.  
  505. Import    Op_Vector Port_Ops;
  506. Import    Integer    Port_Print();
  507. struct    Object_Struct *Port_GC();
  508.  
  509. Import    Scheme_Type Port_Type;
  510.  
  511. Import    struct Object_Struct *Current_Input_Port,
  512. *Current_Output_Port, *The_Transcript_Port;
  513.  
  514. #define Is_Port(o) (Get_Type(o) == Port_Type)
  515. #define Port_Size (sizeof(Port_Struct)+sizeof(Common_Struct))
  516.  
  517. #define Is_Input_Port(o) ((o)->Specific.Port.Is_Input)
  518. #define Is_Output_Port(o) (! Is_Input_Port(o))
  519.  
  520. #define Get_Port_Value(o) ((o)->Specific.Port.Value)
  521. #define Get_Port_Name(o) ((o)->Specific.Port.Name)
  522. #define Get_Port_File(o) ((o)->Specific.Port.File)
  523.  
  524. Import    void    Make_Port();
  525.  
  526.  
  527. /* EOF (is its own type). */
  528.  
  529. typedef struct
  530. {
  531.     int dummy;
  532. } Eof_Struct;
  533.  
  534. Import    Op_Vector Eof_Ops;
  535. Import    Integer    Eof_Write(), Eof_Display();
  536. struct    Object_Struct *Eof_GC();
  537.  
  538. Import    Scheme_Type Eof_Type;
  539.  
  540. #define Is_Eof(o) (Get_Type(o) == Eof_Type)
  541. #define Eof_Size (sizeof(Eof_Struct)+sizeof(Common_Struct))
  542.  
  543. Import    struct Object_Struct *The_Eof_Object;
  544.  
  545. /* Variable (lexically addressed via frame number and displacement). */
  546.  
  547. typedef struct
  548. {
  549.     Boolean Local;
  550.     Integer Frame_Number;
  551.     Integer Displacement;
  552.     struct Object_Struct *Variable_Symbol;
  553. } Variable_Struct;
  554.  
  555. Import    Op_Vector Variable_Ops;
  556. Import    void    Variable_Eval(); 
  557. Import    Integer    Variable_Print();
  558. struct    Object_Struct *Variable_GC();
  559.  
  560. Import    Scheme_Type Variable_Type;
  561.  
  562. #define Is_Variable(o) (Get_Type(o) == Variable_Type)
  563. #define Variable_Size  (sizeof(Variable_Struct)+sizeof(Common_Struct))
  564.  
  565. #define Is_Local_Variable(o) ((o)->Specific.Variable.Local)
  566. #define Get_Variable_Frame_Number(o) ((o)->Specific.Variable.Frame_Number)
  567. #define Get_Variable_Displacement(o) ((o)->Specific.Variable.Displacement)
  568. #define Get_Variable_Symbol(o) ((o)->Specific.Variable.Variable_Symbol)
  569.  
  570. Import    void Make_Global_Variable();
  571. Import    void Make_Local_Variable();
  572.  
  573. /* Apply */
  574.  
  575. typedef struct
  576. {
  577.     struct Object_Struct *Operator;
  578.     Integer Numargs;
  579.     struct Object_Struct *Arg_List;
  580. } Apply_Struct;
  581.  
  582. Import    Op_Vector Apply_Ops;
  583. Import    void Apply_Eval(); 
  584. Import    Integer    Apply_Print();
  585. struct    Object_Struct *Apply_GC();
  586.  
  587. Import    Scheme_Type Apply_Type;
  588.  
  589. #define Is_Apply(o) (Get_Type(o) == Apply_Type)
  590. #define Apply_Size (sizeof(Apply_Struct)+sizeof(Common_Struct))
  591.  
  592. #define Get_Apply_Operator(o) ((o)->Specific.Apply.Operator)
  593. #define Get_Apply_Numargs(o)  ((o)->Specific.Apply.Numargs)
  594. #define Get_Apply_Arguments(o) ((o)->Specific.Apply.Arg_List)
  595.  
  596. Import    void Make_Apply();
  597.  
  598. /* Lambda  (An expression form that evaluates to a procedure). */
  599.  
  600. typedef struct 
  601. {
  602.     Integer Numargs;
  603.     Boolean Has_Rest;
  604.     struct Object_Struct *Frame; /* An environment frame. */
  605.     struct Object_Struct *Body; /* Anything. */
  606. } Lambda_Struct;
  607.  
  608. Import    Op_Vector Lambda_Ops;
  609. Import    void Lambda_Eval(); 
  610. Import    Integer    Lambda_Print(), Lambda_Show();
  611. struct    Object_Struct *Lambda_GC();
  612.  
  613. Import    Scheme_Type Lambda_Type;
  614.  
  615. #define Is_Lambda(o) (Get_Type(o) == Lambda_Type)
  616. #define Lambda_Size  (sizeof(Lambda_Struct)+sizeof(Common_Struct))
  617.  
  618. #define Get_Lambda_Numargs(o) ((o)->Specific.Lambda.Numargs)
  619. #define Get_Lambda_Has_Rest(o) ((o)->Specific.Lambda.Has_Rest)
  620. #define Get_Lambda_Frame(o) ((o)->Specific.Lambda.Frame)
  621. #define Get_Lambda_Body(o) ((o)->Specific.Lambda.Body)
  622.  
  623. Import    void Make_Lambda();
  624.  
  625. /* Conditional  (if condition consequent alternate) */
  626.  
  627. typedef struct 
  628. {
  629.     struct Object_Struct *Condition;
  630.     struct Object_Struct *Consequent;
  631.     struct Object_Struct *Alternate;
  632. } Conditional_Struct;
  633.  
  634. Import    Op_Vector Conditional_Ops;
  635. Import    void Conditional_Eval(); 
  636. Import    Integer    Conditional_Print(), Conditional_Show();
  637. struct    Object_Struct *Conditional_GC();
  638.  
  639. Import    Scheme_Type Conditional_Type;
  640.  
  641. #define Is_Conditional(o) (Get_Type(o) == Conditional_Type)
  642. #define Conditional_Size  (sizeof(Conditional_Struct)+sizeof(Common_Struct))
  643.  
  644. #define Get_Conditional_Test(o) ((o)->Specific.Conditional.Condition)
  645. #define Get_Conditional_Consequent(o) ((o)->Specific.Conditional.Consequent)
  646. #define Get_Conditional_Alternate(o) ((o)->Specific.Conditional.Alternate)
  647.  
  648. Import    void Make_Conditional();
  649.  
  650. /* Assignment  (set! lvalue rvalue) */
  651.  
  652. typedef struct
  653. {
  654.     struct Object_Struct *Lvalue;
  655.     struct Object_Struct *Rvalue;
  656. } Assignment_Struct;
  657.  
  658. Import    Op_Vector Assignment_Ops;
  659. Import    void Assignment_Eval(); 
  660. Import    Integer    Assignment_Print();
  661. struct    Object_Struct *Assignment_GC();
  662.  
  663. Import    Scheme_Type Assignment_Type;
  664.  
  665. #define Is_Assignment(o) (Get_Type(o) == Assignment_Type)
  666. #define Assignment_Size (sizeof(Assignment_Struct)+sizeof(Common_Struct))
  667.  
  668. #define Get_Assignment_Lvalue(o) ((o)->Specific.Assignment.Lvalue)
  669. #define Get_Assignment_Rvalue(o) ((o)->Specific.Assignment.Rvalue)
  670.  
  671. Import    void Make_Assignment();
  672.  
  673. /* Definition  (define lvalue rvalue)  */
  674.  
  675. typedef struct
  676. {
  677.     struct Object_Struct *Lvalue;
  678.     struct Object_Struct *Rvalue;
  679. } Definition_Struct;
  680.  
  681. Import    Op_Vector Definition_Ops;
  682. Import    void Definition_Eval(); 
  683. Import    Integer    Definition_Print();
  684. struct    Object_Struct *Definition_GC();
  685.  
  686. Import    Scheme_Type Definition_Type;
  687.  
  688. #define Is_Definition(o) (Get_Type(o) == Definition_Type)
  689. #define Definition_Size  (sizeof(Definition_Struct)+sizeof(Common_Struct))
  690.  
  691. #define Get_Definition_Lvalue(o) ((o)->Specific.Definition.Lvalue)
  692. #define Get_Definition_Rvalue(o)  ((o)->Specific.Definition.Rvalue)
  693.  
  694. Import    void Make_Definition();
  695.  
  696. /* Macro Definition */
  697.  
  698. typedef struct
  699. {
  700.     struct Object_Struct *Keyword;
  701.     struct Object_Struct *Transformer;
  702. } Macro_Struct;
  703.  
  704. Import    Op_Vector Macro_Ops;
  705. Import    Integer    Macro_Print(), Macro_Show();
  706. struct    Object_Struct *Macro_GC();
  707.  
  708. Import    Scheme_Type Macro_Type;
  709.  
  710. #define Is_Macro(o) (Get_Type(o) == Macro_Type)
  711. #define Macro_Size  (sizeof(Macro_Struct)+sizeof(Common_Struct))
  712.  
  713. #define Get_Macro_Keyword(o) ((o)->Specific.Macro.Keyword)
  714. #define Get_Macro_Transformer(o) ((o)->Specific.Macro.Transformer)
  715.  
  716. Import    void Make_Macro();
  717.  
  718. /* Macro Call */
  719.  
  720. typedef struct
  721. {
  722.     struct Object_Struct *Original;
  723.     struct Object_Struct *Expansion;
  724. } Macro_Call_Struct;
  725.  
  726. Import    Op_Vector Macro_Call_Ops;
  727. Import    void Macro_Call_Eval(); 
  728. Import    Integer Macro_Call_Print();
  729. struct    Object_Struct *Macro_Call_GC();
  730.  
  731. Import    Scheme_Type Macro_Call_Type;
  732.  
  733. #define Is_Macro_Call(o) (Get_Type(o) == Macro_Call_Type)
  734. #define Macro_Call_Size  (sizeof(Macro_Call_Struct)+sizeof(Common_Struct))
  735.  
  736. #define Get_Macro_Call_Original(o) ((o)->Specific.Macro_Call.Original)
  737. #define Get_Macro_Call_Expansion(o) ((o)->Specific.Macro_Call.Expansion)
  738.  
  739. Import    void Make_Macro_Call();
  740.  
  741. /* Sequence */
  742.  
  743. typedef struct
  744. {
  745.     struct Object_Struct *Clauses;
  746.     Boolean From_Begin;
  747. } Sequence_Struct;
  748.  
  749. Import    Op_Vector Sequence_Ops;
  750. Import    void Sequence_Eval(); 
  751. Import    Integer    Sequence_Print();
  752. struct    Object_Struct *Sequence_GC();
  753.  
  754. Import    Scheme_Type Sequence_Type;
  755.  
  756. #define Is_Sequence(o) (Get_Type(o) == Sequence_Type)
  757. #define Sequence_Size  (sizeof(Sequence_Struct)+sizeof(Common_Struct))
  758.  
  759. #define Get_Sequence_Clauses(o) ((o)->Specific.Sequence.Clauses)
  760. #define Get_Sequence_From_Begin(o) ((o)->Specific.Sequence.From_Begin)
  761.  
  762. Import    void Make_Sequence();
  763.  
  764.  
  765. /* Delay  (a form that evalautes to a promise). */
  766.  
  767. typedef struct
  768. {
  769.     struct Object_Struct *Expression;
  770. } Delay_Struct;
  771.  
  772. Import    Op_Vector Delay_Ops;
  773. Import    void Delay_Eval(); 
  774. Import    Integer Delay_Print();
  775. struct    Object_Struct *Delay_GC();
  776.  
  777. Import    Scheme_Type Delay_Type;
  778.  
  779. #define Is_Delay(o) (Get_Type(o) == Delay_Type)
  780. #define Delay_Size  (sizeof(Delay_Struct)+sizeof(Common_Struct))
  781.  
  782. #define Get_Delay_Expression(o) ((o)->Specific.Delay.Expression)
  783.  
  784. Import    void Make_Delay();
  785.  
  786. /* Promise */
  787.  
  788. typedef struct
  789. {
  790.     struct Object_Struct *Expression;
  791.     struct Object_Struct *Environment;
  792.     Boolean Forced;
  793. } Promise_Struct;
  794.  
  795. Import    Op_Vector Promise_Ops;
  796. Import    Integer Promise_Print(), Promise_Show();
  797. struct    Object_Struct *Promise_GC();
  798.  
  799. Import    Scheme_Type Promise_Type;
  800.  
  801. #define Is_Promise(o) (Get_Type(o) == Promise_Type)
  802. #define Promise_Size  (sizeof(Promise_Struct)+sizeof(Common_Struct))
  803.  
  804. #define Get_Promise_Expression(o) ((o)->Specific.Promise.Expression)
  805. #define Get_Promise_Environment(o) ((o)->Specific.Promise.Environment)
  806. #define Get_Promise_Forced(o)   ((o)->Specific.Promise.Forced)
  807.  
  808. Import    void Make_Promise();
  809.  
  810. /* Error -- evalauates to an error */
  811.  
  812. typedef struct
  813. {
  814.     String Message;
  815. } Error_Struct;
  816.  
  817. Import    Op_Vector Error_Ops;
  818. Import    Integer Error_Print();
  819. struct    Object_Struct *Error_GC();
  820.  
  821. Import    Scheme_Type Error_Type;
  822.  
  823. #define Is_Error(o) (Get_Type(o) == Error_Type)
  824. #define Error_Size  (sizeof(Error_Struct)+sizeof(Common_Struct))
  825.  
  826. #define Get_Error_Message(o) ((o)->Specific.Error.Message)
  827.  
  828. Import    void Make_Error();
  829.  
  830. /* Environment Frame */
  831.  
  832. typedef struct
  833. {
  834.     struct Object_Struct *Previous_Frame; /* Another environment frame. */
  835.     Integer Size;
  836.     Boolean Has_Rest;
  837.     struct Object_Struct *Slots[3];
  838. } Environment_Frame_Struct;
  839.  
  840. Import    Op_Vector Environment_Frame_Ops;
  841. Import    void    Environment_Frame_Eval(); 
  842. Import    Integer    Environment_Frame_Print(), Environment_Frame_Show();
  843. struct    Object_Struct *Environment_Frame_GC();
  844.  
  845. Import    Scheme_Type Environment_Frame_Type;
  846.  
  847. Import    struct Object_Struct *The_Global_Environment;
  848.  
  849. #define Is_Environment_Frame(o) (Get_Type(o) == Environment_Frame_Type)
  850. #define Environment_Frame_Size(n)  ((n-1)*3*sizeof(Object)+\
  851.                      sizeof(Environment_Frame_Struct)+\
  852.                                      sizeof(Common_Struct))
  853.  
  854. #define Get_Environment_Frame_Previous(o) \
  855.             ((o)->Specific.Environment_Frame.Previous_Frame)
  856. #define Get_Environment_Frame_Size(o) ((o)->Specific.Environment_Frame.Size)
  857. #define Get_Environment_Frame_Has_Rest(o) ((o)->Specific.Environment_Frame.\
  858.                         Has_Rest)
  859.  
  860. #define Get_Environment_Frame_Binding_Symbol(o,i) \
  861.       ((o)->Specific.Environment_Frame.Slots[i])
  862. #define Get_Environment_Frame_Binding_Value(o,i) \
  863.       ((o)->Specific.Environment_Frame.Slots[Get_Environment_Frame_Size(o)+i])
  864. #define Get_Environment_Frame_Binding_How(o,i) \
  865.       ((o)->Specific.Environment_Frame.Slots[2*Get_Environment_Frame_Size(o)+i])
  866.  
  867. Import    void Make_Symbol_Frame();
  868. Import    void Make_Environment_Frame();
  869.  
  870.  
  871. /* State Frame. */
  872.  
  873. typedef struct
  874. {
  875.     struct    Object_Struct *Expression;
  876.     struct    Object_Struct *Environment;
  877.     struct    Object_Struct *Function;
  878.     struct    Object_Struct *Arg_List;
  879.     struct    Object_Struct *State;
  880.     ELabel    PC;
  881.     Integer    Stack_Top_Ptr;
  882. } State_Frame_Struct;
  883.  
  884. Import    Op_Vector State_Frame_Ops;
  885. Import    void State_Frame_Eval();
  886. Import    Integer    State_Frame_Print();
  887. struct    Object_Struct *State_Frame_GC();
  888.  
  889. Import    Scheme_Type State_Frame_Type;
  890.  
  891. #define Is_State_Frame(o) (Get_Type(o) == State_Frame_Type)
  892. #define State_Frame_Size  (sizeof(State_Frame_Struct)+sizeof(Common_Struct))
  893.  
  894. #define Get_State_Frame_Expression(o) ((o)->Specific.State_Frame.Expression)
  895. #define Get_State_Frame_Environment(o) ((o)->Specific.State_Frame.Environment)
  896. #define Get_State_Frame_Function(o) ((o)->Specific.State_Frame.Function)
  897. #define Get_State_Frame_Arguments(o) ((o)->Specific.State_Frame.Arg_List)
  898. #define Get_State_Frame_State(o) ((o)->Specific.State_Frame.State)
  899. #define Get_State_Frame_PC(o) ((o)->Specific.State_Frame.PC)
  900. #define    Get_State_Frame_Top(o)    ((o)->Specific.State_Frame.Stack_Top_Ptr)
  901.  
  902. Import    void Make_State_Frame();
  903.  
  904. /* Eclectic (special objects of one sort or another). */
  905.  
  906. typedef struct
  907. {
  908.     int dummy;
  909. } Eclectic_Struct;
  910.  
  911. Import    Op_Vector Eclectic_Ops;
  912. Import    Integer Eclectic_Print();
  913. Import    struct Object_Struct *Eclectic_GC();
  914.  
  915. Import    Scheme_Type Eclectic_Type;
  916.  
  917. Import    struct Object_Struct *The_Rparen_Object, *The_Dot_Object;
  918.  
  919. #define Is_Eclectic(o) (Get_Type(o) == Eclectic_Type)
  920.  
  921. #define Eclectic_Size (sizeof(Eclectic_Struct)+sizeof(Common_Struct))
  922.  
  923. /* More Special objects and types. */
  924.  
  925. Import    Scheme_Type The_Undefined_Type;
  926.  
  927. /* `Any_Type' is a dummy type; it merely matches anything, for typechecking 
  928. purposes. */
  929.  
  930. Import    Scheme_Type Any_Type;
  931.  
  932. /* Type "Object" is essentially a union of all of these specific sub-types. */
  933.  
  934. typedef struct Object_Struct
  935. {
  936.     Common_Struct Common;
  937.     union
  938.         {
  939.         Boolean_Struct Boolean;
  940.         Pair_Struct Pair;
  941.         Empty_List_Struct Empty_List;
  942.         Symbol_Struct Symbol;
  943.         Number_Struct Number;
  944.         Character_Struct Character;
  945.         String_Struct String;
  946.         Vector_Struct Vector;
  947.         Procedure_Struct Procedure;
  948.         Primitive_Struct Primitive;
  949.         Continuation_Struct Continuation;
  950.         Port_Struct Port;
  951.         Eof_Struct Eof;
  952.         Variable_Struct Variable;
  953.         Apply_Struct Apply;
  954.         Lambda_Struct Lambda;
  955.         Conditional_Struct Conditional;
  956.         Assignment_Struct Assignment;
  957.         Definition_Struct Definition;
  958.         Macro_Struct Macro;
  959.         Macro_Call_Struct Macro_Call;
  960.         Sequence_Struct Sequence;
  961.         Delay_Struct Delay;
  962.         Promise_Struct Promise;
  963.         Error_Struct Error;
  964.         Environment_Frame_Struct Environment_Frame;
  965.         State_Frame_Struct State_Frame;
  966.         Eclectic_Struct Eclectic;
  967.     } Specific;
  968. } *Object;
  969.  
  970. Import    void Initialize_Object();
  971.  
  972.