DEFINITION MODULE Machine;

CONST
	maxLength=24;
TYPE
   link=POINTER TO closure;
	handlerType=PROC;
   closure=POINTER TO clRec;
   envList=POINTER TO environment;
   wdPtr=POINTER TO wd;
   wd=RECORD
   		def:closure;
   		name:POINTER TO ARRAY [0..maxLength] OF CHAR
   	END;
   flag=(defined, primitive, packed, string, length);
   clRec=RECORD
            CASE kind:flag OF
               defined:
                  root:wdPtr;
               ELSE
                  handler:handlerType
            END;
            env,valEnv:envList
         END;
   environment=RECORD
                  name:wdPtr;
                  newDef:closure;
                  next:envList
               END;
VAR
	result,EmptyClosure,HandlePackage,HandleParent,parent,tempDef:closure;
	wPackage,wPacked,wType:link;
	debug:BOOLEAN;

PROCEDURE StartLayer;
PROCEDURE SaveDefinition(dp:link);
PROCEDURE NewLayer(d:closure);
PROCEDURE PopLayer;
PROCEDURE Keep(dp:link);

PROCEDURE Reduce(from:closure);

PROCEDURE Build;
PROCEDURE BuildReduced;

PROCEDURE Copy(from:closure; VAR to:closure);
PROCEDURE Root(def:closure):link;
PROCEDURE Join(VAR def:closure; description:closure);
PROCEDURE MakeDef(VAR new:closure; root:link);
PROCEDURE MakePrimitive(VAR new:closure; root:handlerType);
PROCEDURE MakePacked(VAR d:closure; root:link; contents:ARRAY OF BYTE);
PROCEDURE MakeString(VAR d:closure; root:link; start:ADDRESS);
PROCEDURE AddEnv(VAR d:closure; prop:link; value:closure);
PROCEDURE AddValuedEnv(VAR d:closure; prop:link; value:closure);
PROCEDURE RemoveEnv(VAR d:closure; prop:link);
PROCEDURE Equal(d1,d2:closure):BOOLEAN;
PROCEDURE ExtractPacked(package:closure; VAR contents:ARRAY OF BYTE);
PROCEDURE Envelope(VAR def:closure; struct:closure; cons,valCons,listEnd,prop,value,next:link);

PROCEDURE MarkString(VAR str:ADDRESS);
PROCEDURE MarkClosure(VAR d:closure);
PROCEDURE MarkLink(VAR dp:link);

END Machine.



