123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #include "stdafx.h"
- #include "defs.h"
- static void _distill(void);
- void
- distill(void)
- {
- save();
- _distill();
- restore();
- }
- static void
- _distill(void)
- {
- p2 = pop();
- p1 = pop();
-
- if (find(p1, p2) == 0) {
- push(p1);
-
-
- return;
- }
-
- if (isadd(p1)) {
- distill_sum();
- return;
- }
-
- if (car(p1) == symbol(MULTIPLY)) {
- distill_product();
- return;
- }
-
- p3 = cdr(p1);
- while (iscons(p3)) {
- push(car(p3));
- push(p2);
- distill();
- p3 = cdr(p3);
- }
- }
- void
- distill_sum(void)
- {
- int h;
-
- p3 = cdr(p1);
- while (iscons(p3)) {
- if (find(car(p3), p2)) {
- push(car(p3));
- push(p2);
- distill();
- }
- p3 = cdr(p3);
- }
-
- h = tos;
- p3 = cdr(p1);
- while (iscons(p3)) {
- if (find(car(p3), p2) == 0)
- push(car(p3));
- p3 = cdr(p3);
- }
- if (tos - h) {
- add_all(tos - h);
- p3 = pop();
- push(p3);
- push(p3);
- negate();
- }
- }
- void
- distill_product(void)
- {
- int h;
-
- p3 = cdr(p1);
- while (iscons(p3)) {
- if (find(car(p3), p2)) {
- push(car(p3));
- push(p2);
- distill();
- }
- p3 = cdr(p3);
- }
-
- h = tos;
- p3 = cdr(p1);
- while (iscons(p3)) {
- if (find(car(p3), p2) == 0)
- push(car(p3));
- p3 = cdr(p3);
- }
- if (tos - h) {
- multiply_all(tos - h);
-
-
-
-
- }
- }
|