| 1 |
/* stack.c -- primitives for managing instruction stack and stream |
| 2 |
* Copyright (C) 1996 Li-Da Lho, All right reserved. |
| 3 |
*/ |
| 4 |
#include "config.h" |
| 5 |
#include "ttf.h" |
| 6 |
#include "ttfutil.h" |
| 7 |
|
| 8 |
/* $Id: stack.c,v 1.1.1.1 1998/06/05 07:47:52 robert Exp $ */ |
| 9 |
|
| 10 |
#define stack (vm->Stack) |
| 11 |
#define sp (vm->sp) |
| 12 |
#define limit (vm->stklimit) |
| 13 |
#define ins (vm->iStream) |
| 14 |
#define ip (vm->ip) |
| 15 |
|
| 16 |
enum TTF_ERROR {StackOverflow ,InstructionOverflow}; |
| 17 |
|
| 18 |
/* Push LONG l onto the stack of vm */ |
| 19 |
inline void Push(VirtualMachine *vm, LONG l) |
| 20 |
{ |
| 21 |
if (sp < limit) |
| 22 |
{ |
| 23 |
stack[sp] = l; |
| 24 |
sp += 1; |
| 25 |
} |
| 26 |
else |
| 27 |
vm->Error_State = StackOverflow; |
| 28 |
} |
| 29 |
/* Pop LONG from the stack of vm and store in l */ |
| 30 |
inline LONG Pop(VirtualMachine *vm) |
| 31 |
{ |
| 32 |
LONG l; |
| 33 |
|
| 34 |
if (sp > 0) |
| 35 |
{ |
| 36 |
l = stack[sp]; |
| 37 |
sp -= 1; |
| 38 |
return l; |
| 39 |
} |
| 40 |
else |
| 41 |
{ |
| 42 |
vm->Error_State = StackOverflow; |
| 43 |
return 0; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/* read one byte from the instruction stream */ |
| 48 |
inline BYTE GetBYTE(VirtualMachine *vm) |
| 49 |
{ |
| 50 |
if (ip < vm->insLength+1) |
| 51 |
return ins[ip++]; |
| 52 |
else |
| 53 |
{ |
| 54 |
vm->Error_State = InstructionOverflow; |
| 55 |
return 0; |
| 56 |
} |
| 57 |
} |
| 58 |
/* read two bytes from the instruction stream */ |
| 59 |
inline SHORT GetSHORT(VirtualMachine *vm) |
| 60 |
{ |
| 61 |
SHORT n = 0; |
| 62 |
|
| 63 |
if (ip < vm->insLength + 2) |
| 64 |
{ |
| 65 |
n = ins[ip++] << 8; |
| 66 |
n |= ins[ip++]; |
| 67 |
return n; |
| 68 |
} |
| 69 |
else |
| 70 |
{ |
| 71 |
vm->Error_State = InstructionOverflow; |
| 72 |
return 0; |
| 73 |
} |
| 74 |
} |
| 75 |
#if 0 |
| 76 |
/* Not used */ |
| 77 |
/* read four bytes from the instruction steam */ |
| 78 |
inline LONG GetLONG(VirtualMachine *vm) |
| 79 |
{ |
| 80 |
LONG n = 0; |
| 81 |
|
| 82 |
if (ip < vm->insLength + 4) |
| 83 |
{ |
| 84 |
n = ins[ip++] << 24; |
| 85 |
n |= ins[ip++] << 16; |
| 86 |
n |= ins[ip++] << 8; |
| 87 |
n |= ins[ip++] ; |
| 88 |
return n; |
| 89 |
} |
| 90 |
else |
| 91 |
{ |
| 92 |
vm->Error_State = InstructionOverflow; |
| 93 |
return 0; |
| 94 |
} |
| 95 |
} |
| 96 |
#endif |