/* CoreBasics.h */
	
# ifndef CoreBasics
# define CoreBasics

#define nil 0
#define false 0
#define true 1

#define New(pointerType, recordType) (pointerType)MemoryAllocate(sizeof(recordType))
#define NewSeq(pointerType, recordType, elementType, size) (pointerType)MemoryAllocate(sizeof(recordType)-sizeof(elementType)+(size*sizeof(elementType)))
#define Die {char *foo=nil; foo[0]='a';}
#define Val(enumerationConstant) (int)enumerationConstant
#define NatLast 2147483647L
	
/* Basic Types */
	
	typedef char *Ref;
	typedef Ref Atom;
	typedef unsigned Nat;
	typedef int Int;
	typedef int Bool;
		
/* Basic Operations */
	
	extern Nat Min();
		/* result, Nat a, Nat b */
		
	extern Nat Max();
		/* result, Nat a, Nat b */
		
/* Bit Operations */
	
	extern Nat NBits();
		/* result, Nat n */
		
	extern Bool EBFN();
		/* result, Nat container, Nat index, Nat containerSize */
		
/* Memory Management */
	
	extern Ref MemoryAllocate();
		/* result, Nat bytes */
		
/* String */
	
	typedef char *String;
		
	extern Bool StringEqual();
		/* result, String first, String second */
		
	extern Nat StringLength();
		/* length, String string */
		
	extern String StringCat();
		/* result, String first, String second */
		
	extern String StringFromNat();
		/* string, Nat number */
		
	extern void StringPrintIndent();
		/* Nat indent, Bool cr=true */
		
/* List */
	
	typedef struct ListRec {
		struct ListRec *rest;
		Ref first;
		} ListRec;
		
	typedef ListRec *List;
		
	typedef struct ListOfStringRec {
		struct ListOfStringRec *rest;
		String first;
		} ListOfStringRec;
		
	typedef ListOfStringRec *ListOfString;
		
	extern List ListCons();
		/* new, List list, Ref item */
		
	extern Nat ListLength();
		/* length, List list */
		
	extern Bool ListEnumerate();
		/* List list, ListItemProc each, Ref context */
		typedef Bool (*ListItemProc)();
		/* quit, Ref item, Ref context */
		
	extern Bool ListMemberString();
		/* found, ListOfString list, String candidate */
		
/* Property */
	
	typedef struct PropertyRec {  
		struct PropertyRec *rest;
		Atom key;
		Ref value;
		} PropertyRec;
		
	typedef PropertyRec *Property;
	typedef PropertyRec *Properties;
		
	typedef void (* PropertyPrintProc)();
		/* Atom property, Ref value, Nat indent, Nat level, Bool cr */
		
	extern Atom PropertyRegister();
		/* property, String name, PropertyPrintProc printProc */
		
	extern Ref PropertyGet();
		/* value, Properties from, Atom property */
		
	extern Property PropertyPut();
		/* new, Properties on, Atom property, Ref value */
		/* value==nil => remove property, the storage for the property becomes garbage  */
		
	extern void PropertyPrint();
		/* Properties properties, Nat indent=0, Bool cr=true, Nat level=2 */
		
	extern void PropertyPrintString();
		/* PropertyPrintProc */
		
/* Hash Table */
	
	typedef struct BucketsRec {
		Nat size;
		Properties elements[1];
		} BucketsRec;
		
	typedef BucketsRec *Buckets;
		
	typedef Nat (* HashProc)();
		/* index, Ref key */
		
	typedef Bool (* EqualProc)();
		/* equal, Ref key1, Ref key2 */
		
	typedef struct HashTableRec {
		HashProc hash;
		EqualProc equal;
		Nat size;
		Nat sizeLimit;
		Buckets buckets;
		} HashTableRec;
		
	typedef HashTableRec *HashTable;
		
	extern Nat HashTableHashString();
		/* HashProc */
		
	extern HashTable HashTableCreate();
		/* table, Nat size=17, HashProc hash=nil, EqualProc equal=nil */
		/* hash==nil => HashTableRefHash, equal==nil => HashTableRefEqual
		/* value1==value2 => hash(key1)==hash(key2) */
		
	extern Nat HashTableSize();
		/* size, HashTable table */
		
	extern Ref HashTableGet();
		/* value, HashTable table, Ref key */
		/* value==nil => not found */
		
	extern void HashTablePut();
		/* HashTable table, Ref key, Ref value */
		/* value==nil => delete pair */
		
	extern void HashTableFree();
		/* HashTablePointer table */
		/* releases HashTableRec, BucketsRec, and PropertyRec  */
		
	typedef Ref (* HashTableUpdateAction)();
		/* newValue, Ref key, Ref value, Ref context */
		/* newValue==nil => delete pair */
		
	extern void HashTableUpdate();
		/* HashTable table, HashTableUpdateAction action, Ref context */
		/* enumerates pairs currently in table in unspecified order; applies action to each pair */
		
# endif