-- TexNode.mesa -- implementation of procedures in TexNodeDefs -- last written by Doug Wyatt, December 18, 1979 6:37 PM DIRECTORY TexDefs: FROM "TexDefs", TexErrorDefs: FROM "TexErrorDefs" USING[Confusion], TexGlueDefs: FROM "TexGlueDefs" USING[GluePtr,AddGlueLink,DelGlueLink,zeroGlueSet,FlexSumsPtr], TexMemDefs: FROM "TexMemDefs" USING[AllocMem,FreeMem], TexNodeDefs: FROM "TexNodeDefs", TexTokenDefs: FROM "TexTokenDefs" USING[TokenListPtr,DelRCLink], InlineDefs: FROM "InlineDefs" USING[COPY]; TexNode: PROGRAM IMPORTS TexErrorDefs,TexGlueDefs,TexMemDefs,TexNodeDefs,TexTokenDefs, InlineDefs EXPORTS TexNodeDefs = BEGIN OPEN TexGlueDefs,TexDefs,TexNodeDefs; -- eventually, most of these procedures should be made INLINE -- and moved to TexNodeDefs AllocHead: PROCEDURE RETURNS[NodeListPtr] = INLINE BEGIN RETURN[TexMemDefs.AllocMem[SIZE[listhead Node]]] END; FreeHead: PROCEDURE[p: NodeListPtr] = INLINE BEGIN TexMemDefs.FreeMem[p,SIZE[listhead Node]] END; InitNodeList: PUBLIC PROCEDURE RETURNS[NodeListPtr] = BEGIN list: NodeListPtr_AllocHead[]; list^_[link: NIL, body: listhead[last: list]]; RETURN[list]; END; MakeNodeList: PUBLIC PROCEDURE[p: NodePtr] RETURNS[NodeListPtr] = BEGIN list: NodeListPtr_AllocHead[]; list^_[link: p, body: listhead[last: NIL]]; RETURN[list]; END; FinishNodeList: PUBLIC PROCEDURE[list: NodeListPtr] RETURNS[NodePtr] = BEGIN p: NodePtr_list.link; FreeHead[list]; RETURN[p]; END; StoreNode: PUBLIC PROCEDURE[list: NodeListPtr, p: NodePtr] = BEGIN list.last.link_p; list.last_p END; InsertNode: PUBLIC PROCEDURE[list: NodeListPtr, p: NodePtr] = BEGIN -- inserts node p at the front of list IF (p.link_list.link)=NIL THEN list.last_p; list.link_p; END; RemoveNode: PUBLIC PROCEDURE[list: NodeListPtr] RETURNS[NodePtr] = BEGIN -- removes the node at the front of list p: NodePtr; IF (p_list.link)=NIL THEN RETURN[NIL]; IF (list.link_p.link)=NIL THEN list.last_list ELSE p.link_NIL; RETURN[p]; END; InsertNodeList: PUBLIC PROCEDURE[list, inslist: NodeListPtr] = BEGIN -- inserts inslist at the front of list; destroys inslist's list head IF inslist.link#NIL THEN BEGIN -- link the lists together and update list.last if list was empty IF (inslist.last.link_list.link)=NIL THEN list.last_inslist.last; list.link_inslist.link; END; FreeHead[inslist]; END; AppendNodeList: PUBLIC PROCEDURE[list, applist: NodeListPtr] = BEGIN -- appends applist at the back of list; destroys applist's list head IF applist.link#NIL THEN BEGIN list.last.link_applist.link; -- link the lists together list.last_applist.last; -- tail of the new list is tail of applist END; FreeHead[applist]; END; RemoveNodeList: PUBLIC PROCEDURE[list: NodeListPtr, p: NodePtr] RETURNS[NodeListPtr] = BEGIN -- removes nodes up to and including p from the front of list; -- makes and returns a new list remlist: NodeListPtr_AllocHead[]; remlist^_[link: list.link, body: listhead[last: p]]; IF (list.link_p.link)=NIL THEN list.last_list ELSE p.link_NIL; RETURN[remlist]; END; FreeNode: PROCEDURE[p: NodePtr, size: CARDINAL] = INLINE BEGIN TexMemDefs.FreeMem[p,size] END; DsNode: PUBLIC PROCEDURE[p: NodePtr] = BEGIN WITH pp:p SELECT FROM char,disc => FreeNode[p,SIZE[char Node]]; string => FreeNode[p,StringNodeSize[pp.length]]; box => BEGIN DsNodeList[pp.head]; FreeNode[p,SIZE[box Node]] END; rule => FreeNode[p,SIZE[rule Node]]; glue => BEGIN DelGlueLink[pp.g]; FreeNode[p,SIZE[glue Node]] END; space,kern => FreeNode[p,SIZE[space Node]]; leader => BEGIN DsNodeList[pp.p]; FreeNode[p,SIZE[leader Node]] END; hyph => FreeNode[p,SIZE[hyph Node]]; penalty => FreeNode[p,SIZE[penalty Node]]; eject => FreeNode[p,SIZE[eject Node]]; mark => BEGIN TexTokenDefs.DelRCLink[pp.t]; FreeNode[p,SIZE[mark Node]]; END; ins => BEGIN DsNodeList[pp.vlist]; DelGlueLink[pp.glue]; FreeNode[p,SIZE[ins Node]]; END; unset => BEGIN DsNode[pp.box]; FreeNode[p,SIZE[unset Node]]; END; listhead => ERROR TexErrorDefs.Confusion; ENDCASE => ERROR; -- bad node type END; DsNodeList: PUBLIC PROCEDURE[p: NodePtr] = BEGIN q: NodePtr_p; next: NodePtr; -- holds q.link WHILE q#NIL DO next_q.link; DsNode[q]; q_next ENDLOOP; END; MakeBoxNode: PUBLIC PROCEDURE[dir: Direction, head: NodePtr, h,d,w: Dimn] RETURNS[b: BoxNodePtr] = BEGIN b_TexMemDefs.AllocMem[SIZE[box Node]]; b^_[link: NIL, body: box[ dir: dir, altered: FALSE, encloses: TRUE, head: head, width: w, depth: d, height: h, shiftamt: 0, glueset: zeroGlueSet]]; END; NullBox: PUBLIC PROCEDURE RETURNS[b: BoxNodePtr] = BEGIN b_TexMemDefs.AllocMem[SIZE[box Node]]; b^_[link: NIL, body: box[ dir: hlist, altered: FALSE, encloses: TRUE, head: NIL, width: 0, depth: 0, height: 0, shiftamt: 0, glueset: zeroGlueSet]]; END; MakeCharNode: PUBLIC PROCEDURE[c: FChar] RETURNS[p: CharNodePtr] = BEGIN p_TexMemDefs.AllocMem[SIZE[char Node]]; p^_[link: NIL, body: char[c]]; END; MakeDiscNode: PUBLIC PROCEDURE[c: FChar] RETURNS[p: POINTER TO disc Node] = BEGIN p_TexMemDefs.AllocMem[SIZE[disc Node]]; p^_[link: NIL, body: disc[c]]; END; MakeEjectNode: PUBLIC PROCEDURE RETURNS[p: POINTER TO eject Node] = BEGIN p_TexMemDefs.AllocMem[SIZE[eject Node]]; p^_[link: NIL, body: eject[]]; END; MakeGlueNode: PUBLIC PROCEDURE[g: GluePtr] RETURNS[p: GlueNodePtr] = BEGIN p_TexMemDefs.AllocMem[SIZE[glue Node]]; p^_[link: NIL, body: glue[g]]; AddGlueLink[g]; -- increment reference count of GlueSpec END; MakeHyphNode: PUBLIC PROCEDURE[h: HyphControl] RETURNS[p: POINTER TO hyph Node] = BEGIN p_TexMemDefs.AllocMem[SIZE[hyph Node]]; p^_[link: NIL, body: hyph[h]]; END; MakeInsNode: PUBLIC PROCEDURE[tb: TopBotType, dir: Direction, hd: NodePtr, g: GluePtr] RETURNS[p: InsNodePtr] = BEGIN p_TexMemDefs.AllocMem[SIZE[ins Node]]; p^_[link: NIL, body: ins[where: tb, dir: dir, vlist: hd, glue: g]]; END; MakeKernNode: PUBLIC PROCEDURE[k: Dimn] RETURNS[p: POINTER TO kern Node] = BEGIN p_TexMemDefs.AllocMem[SIZE[kern Node]]; p^_[link: NIL, body: kern[k]]; END; MakeLeaderNode: PUBLIC PROCEDURE[q: NodePtr] RETURNS[p: POINTER TO leader Node] = BEGIN p_TexMemDefs.AllocMem[SIZE[leader Node]]; p^_[link: NIL, body: leader[q]]; END; MakeMarkNode: PUBLIC PROCEDURE[t: TexTokenDefs.TokenListPtr] RETURNS[p: POINTER TO mark Node] = BEGIN p_TexMemDefs.AllocMem[SIZE[mark Node]]; p^_[link: NIL, body: mark[t]]; END; MakePenaltyNode: PUBLIC PROCEDURE[pen: Penalty] RETURNS[p: POINTER TO penalty Node] = BEGIN p_TexMemDefs.AllocMem[SIZE[penalty Node]]; p^_[link: NIL, body: penalty[pen]]; END; MakeRuleNode: PUBLIC PROCEDURE[width,height,depth: Dimn] RETURNS[p: RuleNodePtr] = BEGIN p_TexMemDefs.AllocMem[SIZE[rule Node]]; p^_[link: NIL, body: rule[width: width, height: height, depth: depth]]; END; MakeSpace: PUBLIC PROCEDURE[s: Dimn] RETURNS[p: POINTER TO space Node] = BEGIN p_TexMemDefs.AllocMem[SIZE[space Node]]; p^_[link: NIL, body: space[s]]; END; MakeStringNode: PUBLIC PROCEDURE[f: Font, s: STRING] RETURNS[p: POINTER TO string Node] = BEGIN len: CARDINAL_s.length; p_TexMemDefs.AllocMem[StringNodeSize[len]]; p^_[link: NIL, body: string[font: f, length: len, text: ]]; InlineDefs.COPY[from: @s.text, to: @p.text, nwords: (len+1)/2]; END; MakeUnsetNode: PUBLIC PROCEDURE[box: BoxNodePtr,fPtr: FlexSumsPtr] RETURNS[p: UnsetNodePtr] = BEGIN p_TexMemDefs.AllocMem[SIZE[unset Node]]; p^_[link: NIL, body: unset[box,fPtr^]]; END; END.