|
|
|
@ -51,7 +51,8 @@ |
|
|
|
|
/* `error'). */ |
|
|
|
|
FT_LOCAL_DEF( CF2_Stack ) |
|
|
|
|
cf2_stack_init( FT_Memory memory, |
|
|
|
|
FT_Error* e ) |
|
|
|
|
FT_Error* e, |
|
|
|
|
FT_UInt stackSize ) |
|
|
|
|
{ |
|
|
|
|
FT_Error error = FT_Err_Ok; /* for FT_QNEW */ |
|
|
|
|
|
|
|
|
@ -63,9 +64,18 @@ |
|
|
|
|
/* initialize the structure; FT_QNEW zeroes it */ |
|
|
|
|
stack->memory = memory; |
|
|
|
|
stack->error = e; |
|
|
|
|
stack->top = &stack->buffer[0]; /* empty stack */ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* allocate the stack buffer */ |
|
|
|
|
if ( FT_NEW_ARRAY( stack->buffer, stackSize ) ) |
|
|
|
|
{ |
|
|
|
|
FT_FREE( stack ); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
stack->stackSize = stackSize; |
|
|
|
|
stack->top = stack->buffer; /* empty stack */ |
|
|
|
|
|
|
|
|
|
return stack; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -77,6 +87,8 @@ |
|
|
|
|
{ |
|
|
|
|
FT_Memory memory = stack->memory; |
|
|
|
|
|
|
|
|
|
/* free the buffer */ |
|
|
|
|
FT_FREE( stack->buffer ); |
|
|
|
|
|
|
|
|
|
/* free the main structure */ |
|
|
|
|
FT_FREE( stack ); |
|
|
|
@ -87,7 +99,7 @@ |
|
|
|
|
FT_LOCAL_DEF( CF2_UInt ) |
|
|
|
|
cf2_stack_count( CF2_Stack stack ) |
|
|
|
|
{ |
|
|
|
|
return (CF2_UInt)( stack->top - &stack->buffer[0] ); |
|
|
|
|
return (CF2_UInt)( stack->top - stack->buffer ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -95,7 +107,7 @@ |
|
|
|
|
cf2_stack_pushInt( CF2_Stack stack, |
|
|
|
|
CF2_Int val ) |
|
|
|
|
{ |
|
|
|
|
if ( stack->top == &stack->buffer[CF2_OPERAND_STACK_SIZE] ) |
|
|
|
|
if ( stack->top == stack->buffer + stack->stackSize ) |
|
|
|
|
{ |
|
|
|
|
CF2_SET_ERROR( stack->error, Stack_Overflow ); |
|
|
|
|
return; /* stack overflow */ |
|
|
|
@ -111,7 +123,7 @@ |
|
|
|
|
cf2_stack_pushFixed( CF2_Stack stack, |
|
|
|
|
CF2_Fixed val ) |
|
|
|
|
{ |
|
|
|
|
if ( stack->top == &stack->buffer[CF2_OPERAND_STACK_SIZE] ) |
|
|
|
|
if ( stack->top == stack->buffer + stack->stackSize ) |
|
|
|
|
{ |
|
|
|
|
CF2_SET_ERROR( stack->error, Stack_Overflow ); |
|
|
|
|
return; /* stack overflow */ |
|
|
|
@ -127,7 +139,7 @@ |
|
|
|
|
FT_LOCAL_DEF( CF2_Int ) |
|
|
|
|
cf2_stack_popInt( CF2_Stack stack ) |
|
|
|
|
{ |
|
|
|
|
if ( stack->top == &stack->buffer[0] ) |
|
|
|
|
if ( stack->top == stack->buffer ) |
|
|
|
|
{ |
|
|
|
|
CF2_SET_ERROR( stack->error, Stack_Underflow ); |
|
|
|
|
return 0; /* underflow */ |
|
|
|
@ -149,7 +161,7 @@ |
|
|
|
|
FT_LOCAL_DEF( CF2_Fixed ) |
|
|
|
|
cf2_stack_popFixed( CF2_Stack stack ) |
|
|
|
|
{ |
|
|
|
|
if ( stack->top == &stack->buffer[0] ) |
|
|
|
|
if ( stack->top == stack->buffer ) |
|
|
|
|
{ |
|
|
|
|
CF2_SET_ERROR( stack->error, Stack_Underflow ); |
|
|
|
|
return cf2_intToFixed( 0 ); /* underflow */ |
|
|
|
@ -175,7 +187,7 @@ |
|
|
|
|
cf2_stack_getReal( CF2_Stack stack, |
|
|
|
|
CF2_UInt idx ) |
|
|
|
|
{ |
|
|
|
|
FT_ASSERT( cf2_stack_count( stack ) <= CF2_OPERAND_STACK_SIZE ); |
|
|
|
|
FT_ASSERT( cf2_stack_count( stack ) <= stack->stackSize ); |
|
|
|
|
|
|
|
|
|
if ( idx >= cf2_stack_count( stack ) ) |
|
|
|
|
{ |
|
|
|
@ -306,7 +318,7 @@ |
|
|
|
|
FT_LOCAL_DEF( void ) |
|
|
|
|
cf2_stack_clear( CF2_Stack stack ) |
|
|
|
|
{ |
|
|
|
|
stack->top = &stack->buffer[0]; |
|
|
|
|
stack->top = stack->buffer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|