HerculesStorage.mesa (ex JunoStorage.mesa), coded June 81 by Greg Nelson.
Definitions of data types, plus basic allocation and deallocation procedures.
To do: remove link fields from points/actions/constraints; use LISTS (February 15, 1984 0:34 am)
To do: Change Frame to LIST of PointPtr again? (February 15, 1984 0:34 am)
To do: keep constraints in close-to-symbolic form (February 15, 1984 0:34 am)
To do: add pushstate-type actions (paint, font, etc) (February 15, 1984 0:34 am)
Last Edited by: GNelson, February 10, 1984 6:17 am
Last Edited by: Stolfi, February 22, 1984 5:47 am
DIRECTORY
HerculesAlgebra USING [Value, PointPtr, PointList, Frame, Se];
HerculesStorage: DEFINITIONS =
BEGIN OPEN
Alg: HerculesAlgebra;
- - - - POINTS
PointPtr: TYPE = Alg.PointPtr;
PointList: TYPE = Alg.PointList;
NewPoint: PROC [x, y: REAL, visible: BOOLTRUE] RETURNS [p: PointPtr];
DeletePoint: PROC [p, pAnt: PointPtr, list: PointList] RETURNS [newList: PointList];
-- Deletes the point p from the list. If pAnt is not NIL, it should be the previous point in list.
InsertPoint: PROC [p, pAnt: PointPtr, list: PointList] RETURNS [newList: PointList];
-- Inserts the point p into the list, just after pAnt
-- (if pAnt=NIL inserts at beginning)
GcPoint: PROC[p: PointPtr];
- - - - CONSTRAINTS
ConstrKind: TYPE = {hor, ver, para, perp, cong, at, ccw}; -- kind of constraint
ConstrPtr: TYPE = REF ConstrRec; -- to some kind of constraint record
ConstrList: TYPE = ConstrPtr; -- linked by link field.
ConstrRec: TYPE = RECORD [
link: ConstrPtr,
frame: Alg.Frame, -- for relativized constraints
constr: SELECT kind: ConstrKind FROM

hor =>  -- Constrains (i,j) to be horizontal
[i, j: PointPtr ← NIL],
ver =>  -- Constrains (i,j) to be vertical
[i, j: PointPtr ← NIL],
para => -- Constrains (i,j), (k,l) to be parallel
[i, j, k, l: PointPtr ← NIL],
perp => -- Constrains (i,j), (k,l) to be perpendicular (relative to the given frame)
[i, j, k, l: PointPtr ← NIL],
cong => -- Constrains segments (i,j), (k,l) to be congruent (relative to the given frame)
[i, j, k, l: PointPtr ← NIL],
at => -- Constrains p to have coordinates (x,y) (relative to the given frame)
[p: PointPtr ← NIL,
x, y: REAL ← 0],
ccw =>  -- Constrains (i,j,k) to be counterclockwise (rel to frame)
[i, j, k: PointPtr ← NIL],
ENDCASE];
HorPtr: TYPE = REF hor ConstrRec;
VerPtr: TYPE = REF ver ConstrRec;
ParaPtr: TYPE = REF para ConstrRec;
PerpPtr: TYPE = REF perp ConstrRec;
CongPtr: TYPE = REF cong ConstrRec;
AtPtr: TYPE = REF at ConstrRec;
CcwPtr: TYPE = REF ccw ConstrRec;
NewHor: PROC [i,j: PointPtr] RETURNS [cp: HorPtr];
NewVer: PROC [i,j: PointPtr] RETURNS [cp: VerPtr];
NewPara: PROC [i,j,k,l: PointPtr] RETURNS [cp: ParaPtr];
NewPerp: PROC [i,j,k,l: PointPtr, frame: Alg.Frame ← [NIL,NIL, NIL]] RETURNS [cp: PerpPtr];
NewCong: PROC [i,j,k,l: PointPtr, frame: Alg.Frame ← [NIL,NIL, NIL]] RETURNS [cp: CongPtr];
NewAt: PROC [p: PointPtr, x,y: REAL, frame: Alg.Frame ← [NIL,NIL, NIL]] RETURNS [cp: AtPtr];
NewCcw: PROC [i,j,k: PointPtr, frame: Alg.Frame ← [NIL,NIL, NIL]] RETURNS [cp: CcwPtr];
DeleteConstr: PROC [c, cAnt: ConstrPtr, list: ConstrList] RETURNS [newList: ConstrList];
-- Deletes the constraint c from the list. If cAnt is not NIL, it should be the previous constraint in list.
InsertConstr: PROC [c, cAnt: ConstrPtr, list: ConstrList] RETURNS [newList: ConstrList];
-- Inserts the constraint c into the list, just after cAnt
-- (if cAnt=NIL inserts at beginning)
GcConstr: PROC[cp: ConstrPtr];
- - - - ACTIONS
ActionPtr: TYPE = REF ActionRec; -- to some kind of action record
ActionList: TYPE = RECORD
[first, last: ActionPtr]; -- linked by link field in chronological (painting) order.;
ActionRec: TYPE = RECORD
[link: ActionPtr,
op: Alg.Se, -- operation (usually atom, the function name; may be lambda expr. or FunVal)
arg: Alg.Value -- argument (usually list of points)
];
NewAction: PROC [op: Alg.Se, arg: Alg.Value] RETURNS [ap: ActionPtr];
DeleteAction: PROC [a, aAnt: ActionPtr, list: ActionList] RETURNS [newList: ActionList];
-- Deletes the action a from the list. If aAnt is not NIL, it should be the previous action in list.
InsertAction: PROC [a, aAnt: ActionPtr, list: ActionList] RETURNS [newList: ActionList];
-- Inserts the action a into the list, just after aAnt
-- (if aAnt=NIL inserts at beginning)
GcAction: PROC[ap: ActionPtr];
- - - - IMAGES
Image: TYPE = RECORD
[points: PointList,
constrs: ConstrList,
actions: ActionList];
END.
Edited on January 25, 1984 0:54 am, by Stolfi
-- Added Tioga formatting
-- Made all actions and predicated into variants of Item
-- Replaced constructionList by the general itemLpad, itemRpad mechanism
-- Added frame field to constraints.
-- Name changes: AdLin--> AddPara, etc.
changes to: ItemKind (new), ItemPtr (new), ItemRec (new), itemLpad, itemRpad (new array: replaces all xxxLpads and xxxRpads), CongPtr, HorPtr, VerPtr, CCPtr, EdgePtr, ArcPtr, StringPtr, ApplyPtr (variants of ItemPtr), SaveStateRec, FramePtr (new), FrameRec (new), NewPara, AddPara (name changes), GcItem (new), constructionList (deleted)
Edited on January 27, 1984 0:04 am, by Stolfi
-- Added perp and $= constraints
-- Added relativized constraints
changes to: ItemKind, ItemRec (added perp and equals), PerpPtr, EqualsPtr, NewPerp, NewEquals, AddPerp, AddEquals (new), AddHor, AddVer, AdPara, AddCong, AddCC (added frame parameter), GcHor, GcVer, GcPara, GcCong, GcEdge, GcArc, GcString, GcX (deleted - use GcItem!) , MakeFrameRec (new)
Edited on January 28, 1984 4:04 am, by Stolfi
changes to: ItemRec (names of xheader, yheader changed to xCol, yCol; frame made local to the cong, perp, ccw, and equals variants only), NewTv, GcTV, TangentVector, TvRec, Basis, BasisRec, NewBasis, GcBasis (deleted), AddPara, AddHor, AddVer (removed frame parameter), FrameRec(added matrices), MakeFrameRec (option to check whether the frame points are fixed; creates matrices), Matrix, GetFrameMatrix, InvertMatrix, MultiplyMatrix, ComputeTransform, ComputeSomeTransform, TransformPoint (moved here from JunoBody)
Edited on February 1, 1984 3:52 pm, by Stolfi
changes to: FrameRec (removed matrices), MakeFrameRec (removed option to check whether the frame points are fixed)
Edited on February 4, 1984 3:25 am, by Stolfi

-- ItemRec split into ActionRec and ConstrRec
-- Moved lists of points, constraints and actions on current (unnamed) image to HerculesTop
changes to: ItemKind (made local to Impl), ConstrPtr, ConstrRec ActionPtr, and ActionRec (replace ItemPtr, ItemRec; changed field names of edge, string, and arc variants; removed right endpoint of string, width, height; replaced pointer to frame by frame record itself), itemLpad, itemRpad, pointLpad, pointRpad (moved to HerculesTop), AtPtr (new name of EqualsPtr), ApplPtr (new name of ApplyPtr), NewItem (made private) NewAppl (renamed from NewX), AddPara, AddCong, AddPerp, AddEquals, AddHor, AddVer, AddCcw, AddEdge, AddArc, AddString, AddX, lambdaAlist, HasDef, GetBody, GetLocals, AddDef, PushState, PopState, ResetJunoStorage, SaveStateRec (moved to HerculesTop), NewAt (replaces NewEquals), GcConstr, GcAction (replace GcItem), Frame (replaces FrameRec), FramePtr (deleted), MakeFrame (replaces MakeFrameRec) Point (deleted moveHasBeenPlotted field; deleted slink), NewPoint, NewHor, NewVer, NewPerp, NewPara, NewCong, NewAt, NewCcw, NewEdge, NewArc, NewString, NewAppl (field setup folded here from AddHor, etc), PointList, ActionList, ConstrList (new), NewPoint (added visible parameter) FindPoint (moved to JunoTop)
Edited on February 8, 1984 6:23 pm, by Stolfi
changes to: Point (added mark field), Se (moved here from HerculesAlgebra)DeletePoint, InsertPoint, DeleteConstr, InsertConstr, DeleteAction, InsertAction, Image (moved here from HerculesImage), GetFrameMatrix, ComputeTransform, ComputeSomeTransform (parameters changed to Frame), ActionRec, NewAppl (arg is Value)
Edited on February 10, 1984 6:26 am, by Stolfi
changes to: MakeFrame (deleted)
Edited on February 13, 1984 10:57 pm, by Stolfi
changes to: ActionKind, NewEdge, NewString, NewArc, NewAppl, ActionKind (deleted), ActionRec, NewAction (eliminated variants; now all actions are applications of a Se to a Value),
Edited on February 22, 1984 5:33 am, by Stolfi
changes to: Frame and frame transformation matrices (moved to HerculesAlgebra)