40 static gerbv_instruction_t *
43 gerbv_instruction_t *instruction;
45 instruction = (gerbv_instruction_t *)malloc(
sizeof(gerbv_instruction_t));
46 if (instruction == NULL) {
51 memset(instruction, 0,
sizeof(gerbv_instruction_t));
60 static gerbv_amacro_t *
63 gerbv_amacro_t *amacro;
65 amacro = (gerbv_amacro_t *)malloc(
sizeof(gerbv_amacro_t));
71 memset(amacro, 0,
sizeof(gerbv_amacro_t));
104 #define MATH_OP_STACK_SIZE 2
105 #define MATH_OP_PUSH(val) math_op[math_op_idx++] = val
106 #define MATH_OP_POP math_op[--math_op_idx]
107 #define MATH_OP_TOP (math_op_idx > 0)?math_op[math_op_idx - 1]:GERBV_OPCODE_NOP
108 #define MATH_OP_EMPTY (math_op_idx == 0)
115 parse_aperture_macro(gerb_file_t *fd)
117 gerbv_amacro_t *amacro;
118 gerbv_instruction_t *ip = NULL;
119 int primitive = 0, c, found_primitive = 0;
124 unsigned char continueLoop = 1;
127 amacro = new_amacro();
134 amacro->name = gerb_fgetstring(fd,
'*');
144 amacro->program = new_instruction();
145 ip = amacro->program;
147 while(continueLoop) {
152 if (found_primitive) {
153 ip->next = new_instruction();
157 ip->data.ival = gerb_fgetint(fd, NULL);
160 equate = gerb_fgetint(fd, NULL);
164 while (!MATH_OP_EMPTY) {
165 ip->next = new_instruction();
167 ip->opcode = MATH_OP_POP;
173 if (found_primitive) {
174 ip->next = new_instruction();
178 ip->data.ival = equate;
181 ip->data.ival = primitive;
194 if (!found_primitive) {
198 while (!MATH_OP_EMPTY) {
199 ip->next = new_instruction();
201 ip->opcode = MATH_OP_POP;
206 while ((!MATH_OP_EMPTY) &&
208 ip->next = new_instruction();
210 ip->opcode = MATH_OP_POP;
221 while((!MATH_OP_EMPTY) &&
223 ip->next = new_instruction();
225 ip->opcode = MATH_OP_POP;
230 while ((!MATH_OP_EMPTY) &&
232 ip->next = new_instruction();
234 ip->opcode = MATH_OP_POP;
241 while ((!MATH_OP_EMPTY) &&
243 ip->next = new_instruction();
245 ip->opcode = MATH_OP_POP;
255 if (!found_primitive && (primitive == 0)) {
257 gerb_fgetstring(fd,
'*');
275 if (!found_primitive) {
276 primitive = (primitive * 10) + (c -
'0');
279 (void)gerb_ungetc(fd);
280 ip->next = new_instruction();
284 ip->data.fval = gerb_fgetdouble(fd);
286 ip->data.fval = -ip->data.fval;
308 free_amacro(gerbv_amacro_t *amacro)
310 gerbv_amacro_t *am1, *am2;
311 gerbv_instruction_t *instr1, *instr2;
314 while (am1 != NULL) {
318 instr1 = am1->program;
319 while (instr1 != NULL) {
321 instr1 = instr1->next;
337 print_program(gerbv_amacro_t *amacro)
339 gerbv_instruction_t *ip;
341 printf(
"Macroname [%s] :\n", amacro->name);
342 for (ip = amacro->program ; ip != NULL; ip = ip->next) {
348 printf(
" PUSH %f\n", ip->data.fval);
351 printf(
" PPOP %d\n", ip->data.ival);
354 printf(
" PPUSH %d\n", ip->data.ival);
369 printf(
" PRIM %d\n", ip->data.ival);