DIRECTORY IPBasic USING [Any, Integer, maxInteger, nullAny, State, Vec, VecRep, Vector, VectorShape], IPConvert USING [AnyToInteger], IPErrors USING [MasterError], IPOps USING [EqN], IPStack USING [PopAny, PushAny], IPVector USING []; IPVectorImpl: CEDAR PROGRAM IMPORTS IPConvert, IPErrors, IPOps, IPStack EXPORTS IPVector = BEGIN OPEN IPBasic; VecToVector: PROC[v: Vec] RETURNS[Vector] = INLINE { RETURN[v] }; VectorToVec: PUBLIC PROC[v: Vector] RETURNS[Vec] = { WITH v SELECT FROM vec: Vec => RETURN[vec]; ENDCASE => { shape: VectorShape = Shape[v]; vec: Vec = NewVec[shape]; FOR i: NAT IN[0..vec.size) DO vec[i] _ Get[v, shape.l+i]; ENDLOOP; RETURN[vec]; }; }; NewVec: PUBLIC PROC[shape: VectorShape] RETURNS[Vec] = { IF shape.n>0 AND (shape.n-1)>(maxInteger-shape.l) THEN ERROR IPErrors.MasterError[InvalidArgs] ELSE IF shape.n>maxVecSize THEN ERROR IPErrors.MasterError[LimitExceeded] ELSE RETURN[NEW[VecRep[shape.n] _ [shape: shape, array: ]]]; }; CopyVec: PUBLIC PROC[v: Vec] RETURNS[Vec] = { new: Vec = NEW[VecRep[v.size] _ [shape: v.shape, array: ]]; FOR i: NAT IN[0..new.size) DO new[i] _ v[i] ENDLOOP; RETURN[new]; }; Get: PUBLIC PROC[v: Vector, n: Integer] RETURNS[Any] = { WITH v SELECT FROM v: Vec => { IF n IN[v.shape.l..v.shape.l+v.shape.n) THEN RETURN[v[n-v.shape.l]] ELSE ERROR IPErrors.MasterError[BoundsFault]; }; ENDCASE => ERROR IPErrors.MasterError[Unimplemented]; }; Shape: PUBLIC PROC[v: Vector] RETURNS[VectorShape] = { WITH v SELECT FROM v: Vec => RETURN[v.shape]; ENDCASE => ERROR IPErrors.MasterError[Unimplemented]; }; maxVecSize: NAT = (LAST[NAT]-SIZE[VecRep[0]])/SIZE[Any]; Make: PUBLIC PROC[self: State, shape: VectorShape] RETURNS[Vec] = { v: Vec = NewVec[shape]; FOR i: NAT DECREASING IN[0..v.size) DO v[i] _ IPStack.PopAny[self] ENDLOOP; RETURN[v]; }; MakeVec: PUBLIC PROC[self: State, n: Integer] RETURNS[Vector] = { shape: VectorShape = [l: 0, n: n]; RETURN[VecToVector[Make[self, shape]]]; }; MakeVecLU: PUBLIC PROC[self: State, l, u: Integer] RETURNS[Vector] = { IF l>0 AND (l-1)>u THEN ERROR IPErrors.MasterError[InvalidArgs] ELSE IF u>=l AND (u-l)>=maxInteger THEN ERROR IPErrors.MasterError[LimitExceeded] ELSE { shape: VectorShape = IF u