--- stack/stack.h 2002/03/07 01:21:07 1.3 +++ stack/stack.h 2002/03/10 20:08:47 1.10 @@ -1,27 +1,72 @@ +/* + stack - an interactive interpreter for a stack-based language + Copyright (C) 2002 Mats Alritzson and Teddy Hogeborn + + 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 2 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Authors: Mats Alritzson + Teddy Hogeborn +*/ #define HASHTBLSIZE 2048 /* First, define some types. */ +struct cons_struct; + /* A value of some type */ typedef struct { enum { integer, + tfloat, string, func, /* Function pointer */ symb, - list - } type:3; /* Type of stack element */ + tcons + } type:4; /* Type of stack element */ - int gc_garb:1; + union { + struct { + unsigned int mark:1; + unsigned int protect:1; + } flag; + unsigned int no_gc:2; + } gc; union { + struct cons_struct *c; void *ptr; /* Pointer to the content */ - int val; /* ...or an integer */ + int i; /* ...or an integer */ + float f; } content; /* Stores a pointer or an integer */ } value; +/* An item (value) on a stack */ +typedef struct stackitem_struct +{ + value *item; /* The value on the stack */ + /* (This is never NULL) */ + struct stackitem_struct *next; /* Next item */ +} stackitem; + +typedef struct cons_struct { + value *car; + value *cdr; +} cons; + /* A symbol with a name and possible value */ /* (These do not need reference counters, they are kept unique by hashing.) */ @@ -34,27 +79,18 @@ /* A type for a hash table for symbols */ typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */ -/* An item (value) on a stack */ -typedef struct stackitem_struct -{ - value *item; /* The value on the stack */ - /* (This is never NULL) */ - struct stackitem_struct *next; /* Next item */ -} stackitem; - /* An environment; gives access to the stack and a hash table of defined symbols */ typedef struct { stackitem *gc_ref; - stackitem *gc_protect; int gc_limit, gc_count; - stackitem *head; /* Head of the stack */ + cons *head; /* Head of the stack */ hashtbl symbols; /* Hash table of all variable bindings */ int err; /* Error flag */ char *in_string; /* Input pending to be read */ char *free_string; /* Free this string when all input is - read from in_string */ + read from in_string */ FILE *inputstream; /* stdin or a file, most likely */ int interactive; /* print prompts, stack, etc */ } environment; @@ -69,21 +105,23 @@ symbol **hash(hashtbl, const char*); value* new_val(environment*); void gc_mark(value*); +void gc_maybe(environment *env); extern void gc_init(environment*); void push_val(environment*, value*); void push_int(environment*, int); +void push_float(environment*, float); void push_cstring(environment*, const char*); char *mangle_str(const char*); extern void mangle(environment*); void push_sym(environment*, const char*); extern void nl(); extern void type(environment*); -void print_h(stackitem*, int); +void print_h(cons*, int); extern void print_(environment*); extern void print(environment*); extern void princ_(environment*); extern void princ(environment*); -void print_st(stackitem*, long); +void print_st(cons*, long); extern void printstack(environment*); extern void swap(environment*); extern void rot(environment*); @@ -115,5 +153,14 @@ extern void readline(environment*); extern void sx_72656164(environment*); extern void foreach(environment*); -void protect(environment*, value*); -void unprotect(environment*); +void protect(value*); +void unprotect(value*); +extern void copying(environment*); +extern void warranty(environment*); +extern void sx_2a(environment*); +extern void sx_2f(environment*); +extern void mod(environment*); +extern void sx_3c(environment*); +extern void sx_3c3d(environment*); +extern void sx_3e3d(environment*); +extern void sx_646976(environment*);