/* * Lisp global variables * Don Hopkins */ #include "lisp.h" /* * Counters for the number of allocated and used conses, atoms, and * numbers. */ int Cons_Count = 0, Cons_Free = 0; int Atom_Count = 0, Atom_Free = 0; int Number_Count = 0, Number_Free = 0; /* * Pointers to beginning of the the cons, atom, and number storage * spaces. */ struct cons *Cons = NULL; struct atom *Atom = NULL; struct number *Number = NULL; /* * Objects refering to atoms. These are set to refer to their * respective atoms in initialize(). */ object Nil, T, Quote, Lambda, Special, Macro; /* * Stacks used by lisp and known about by the garbage collector. These * are set to Nil in initialize(). */ object Ob_List, Ob_Stack, Back_Trace, Free_List, Input_Stack, Output_Stack; /* * Input and output streams. */ FILE *Input_File = stdin, *Output_File = stdout; /* * A longjmp() label for top level lisp read-eval-print loop. Used by * abort() to jump to lisp warm start in main(). */ jmp_buf Top_Level; /* * Names of the lisp object types. */ char *Type_Name[] = { "unknown 0000", "undefined", "atom", "number", "cons", "user function", "user special", "built in function", "built in special", "stream", "macro", "funarg" }; struct built_in Built_In[] = { /* * From math.c */ { "plus", built_in_function_object, plus, -1 }, { "times", built_in_function_object, times, -1 }, { "quotient", built_in_function_object, quotient, 2 }, { "remainder", built_in_function_object, lremainder, 2 }, { "minus", built_in_function_object, minus, 1 }, { "floor", built_in_function_object, lfloor, 1 }, { "numberp", built_in_function_object, numberp, 1 }, { "greaterp", built_in_function_object, greaterp, 2 }, { "zerop", built_in_function_object, zerop, 1 }, { "random", built_in_function_object, lrandom, 1 }, /* * From util.c */ { "push-output", built_in_function_object, push_output, 1 }, { "push-input", built_in_function_object, push_input, 1 }, { "pop-output", built_in_function_object, pop_output, 0 }, { "pop-input", built_in_function_object, pop_input, 0 }, { "eq", built_in_function_object, eq, 2 }, { "cons", built_in_function_object, lcons, 2 }, { "car", built_in_function_object, lcar, 1 }, { "cdr", built_in_function_object, lcdr, 1 }, { "atom", built_in_function_object, latom, 1 }, { "list", built_in_function_object, list, -1 }, { "type", built_in_function_object, type, 1 }, { "setq", built_in_special_object, setq, -1 }, { "quote", built_in_special_object, quote, 1 }, { "and", built_in_special_object, and, -1 }, { "or", built_in_special_object, or, -1 }, { "explode", built_in_function_object, explode, 1 }, { "implode", built_in_function_object, implode, 1 }, /* * From read.c */ { "read", built_in_function_object, sread, 0 }, /* * From print.c */ { "prin1", built_in_function_object, lprin1, 1 }, { "print", built_in_function_object, lprint, 1 }, { "printcr", built_in_function_object, lprintcr, 1 }, { "terpri", built_in_function_object, terpri, 0 }, /* * From gc.c */ { "gc", built_in_function_object, lgc, 0 }, /* * From eval.c */ { "body", built_in_function_object, body, 1 }, { "apply", built_in_function_object, lapply, 2 }, { "funcall", built_in_special_object, lfuncall, -1 }, { "eval", built_in_function_object, leval, 1 }, { "do", built_in_special_object, dolist, -1 }, { "cond", built_in_special_object, cond, -1 }, { "lambda", built_in_special_object, lambda, -1 }, { "special", built_in_special_object, special, -1 }, { "macro", built_in_special_object, macro, -1 }, { "function", built_in_special_object, function, 1 }, { "", 0, 0, 0 } }; /* * Create the initial atom table, initialize the stacks, add entries * for the built-in objects, and initialize global variables to point * to appropriate atoms. */ initialize() { object built_in; /* * Make T and Nil, and initialize them. */ Nil = make_atom("nil"); Atom_Value(Nil) = Nil; T = make_atom("t"); Atom_Value(T) = T; /* * Initialize stacks with Nil. */ Ob_List = Nil; Ob_Stack = Nil; Back_Trace = Nil; Free_List = Nil; Input_Stack = Nil; Output_Stack = Nil; /* * Define built-in objects. */ for (built_in = 0; *Built_In_Name(built_in) != '\0'; built_in++) Atom_Value(make_atom(Built_In_Name(built_in))) = Set_Type(Built_In_Type(built_in), built_in); /* * Initialize global variables that point to atoms. */ Quote = make_atom("quote"); Lambda = make_atom("lambda"); Special = make_atom("special"); Macro = make_atom("macro"); }