52 FT_LOCAL_DEF( CF2_Stack )
53 cf2_stack_init( FT_Memory memory,
58 CF2_Stack stack = NULL;
61 if ( FT_QNEW( stack ) )
64 stack->memory = memory;
68 if ( FT_QNEW_ARRAY( stack->buffer, stackSize ) )
74 stack->stackSize = stackSize;
75 stack->top = stack->buffer;
82 cf2_stack_free( CF2_Stack stack )
86 FT_Memory memory = stack->memory;
89 FT_FREE( stack->buffer );
97 FT_LOCAL_DEF( CF2_UInt )
98 cf2_stack_count( CF2_Stack stack )
100 return (CF2_UInt)( stack->top - stack->buffer );
105 cf2_stack_pushInt( CF2_Stack stack,
108 if ( stack->top == stack->buffer + stack->stackSize )
110 CF2_SET_ERROR( stack->error, Stack_Overflow );
114 stack->top->u.i = val;
115 stack->top->type = CF2_NumberInt;
121 cf2_stack_pushFixed( CF2_Stack stack,
124 if ( stack->top == stack->buffer + stack->stackSize )
126 CF2_SET_ERROR( stack->error, Stack_Overflow );
130 stack->top->u.r = val;
131 stack->top->type = CF2_NumberFixed;
137 FT_LOCAL_DEF( CF2_Int )
138 cf2_stack_popInt( CF2_Stack stack )
140 if ( stack->top == stack->buffer )
142 CF2_SET_ERROR( stack->error, Stack_Underflow );
145 if ( stack->top[-1].type != CF2_NumberInt )
147 CF2_SET_ERROR( stack->error, Syntax_Error );
153 return stack->top->u.i;
159 FT_LOCAL_DEF( CF2_Fixed )
160 cf2_stack_popFixed( CF2_Stack stack )
162 if ( stack->top == stack->buffer )
164 CF2_SET_ERROR( stack->error, Stack_Underflow );
165 return cf2_intToFixed( 0 );
170 switch ( stack->top->type )
173 return cf2_intToFixed( stack->top->u.i );
175 return cf2_fracToFixed( stack->top->u.f );
177 return stack->top->u.r;
184 FT_LOCAL_DEF( CF2_Fixed )
185 cf2_stack_getReal( CF2_Stack stack,
188 FT_ASSERT( cf2_stack_count( stack ) <= stack->stackSize );
190 if ( idx >= cf2_stack_count( stack ) )
192 CF2_SET_ERROR( stack->error, Stack_Overflow );
193 return cf2_intToFixed( 0 );
196 switch ( stack->buffer[idx].type )
199 return cf2_intToFixed( stack->buffer[idx].u.i );
201 return cf2_fracToFixed( stack->buffer[idx].u.f );
203 return stack->buffer[idx].u.r;
210 cf2_stack_setReal( CF2_Stack stack,
214 if ( idx > cf2_stack_count( stack ) )
216 CF2_SET_ERROR( stack->error, Stack_Overflow );
220 stack->buffer[idx].u.r = val;
221 stack->buffer[idx].type = CF2_NumberFixed;
227 cf2_stack_pop( CF2_Stack stack,
230 if ( num > cf2_stack_count( stack ) )
232 CF2_SET_ERROR( stack->error, Stack_Underflow );
240 cf2_stack_roll( CF2_Stack stack,
245 CF2_StackNumber last = { { 0 }, CF2_NumberInt };
247 CF2_Int start_idx, idx, i;
253 if ( (CF2_UInt)count > cf2_stack_count( stack ) )
255 CF2_SET_ERROR( stack->error, Stack_Overflow );
263 shift = -( ( -shift ) % count );
297 for ( i = 0; i < count; i++ )
302 if ( start_idx == idx )
306 last = stack->buffer[idx];
315 tmp = stack->buffer[idx];
316 stack->buffer[idx] = last;
323 cf2_stack_clear( CF2_Stack stack )
325 stack->top = stack->buffer;