void sv_free( void ) { proplist_free( the_prop_list ); formula_free( the_formula ); common_sv_free(); global_sv_free(); safe_free( common_l_members ); }
// Frees the context and all the formulas below the stack pointer. // All these formulas are copies. void context_free(Context c) { Formula f; f = pop(c); while (f) { formula_free(f); f = pop(c); } free(c->contextData); free(c); }
void formula_free(Formula f) { switch (f->type) { case PRED_F: free(f->form.pred_f.principal); break; case IMPL_F: formula_free(f->form.impl_f.formula1); formula_free(f->form.impl_f.formula2); break; case SAYS_F: free(f->form.says_f.principal); formula_free(f->form.says_f.formula); break; case SIGNED_F: free(f->form.signed_f.principal); formula_free(f->form.signed_f.formula); break; case CONFIRMS_F: free(f->form.confirms_f.principal); formula_free(f->form.confirms_f.formula); break; case ABS_F: formula_free(f->form.abs_f.formula); break; } free(f); }
struct rpf_t *formula_optimize( struct rpf_t *rpf ) { double _stack[512]; double *stack[512]; struct rpf_t _rpf_st[512]; struct rpf_t *rpf_st[512]; int fixed[512]; int sp; struct rpf_t *rpf_new; struct rpf_t rpf_new_st; int i; sp = 0; for( ; rpf; rpf = rpf->next ) { struct operation_t *op; double tmp; switch( rpf->type ) { case TYPE_VALUE: stack[sp] = ( (double*)rpf->value ); fixed[sp] = 1; rpf_st[sp] = rpf; sp ++; break; case TYPE_VARIABLE: stack[sp] = ( (double*)rpf->value ); fixed[sp] = 0; rpf_st[sp] = rpf; sp ++; break; default: op = (struct operation_t*)rpf->value; for( i = 0; i < op->narg; i ++ ) { if( !fixed[sp-1-i] ) break; } if( i == op->narg ) { tmp = (op->func)( &stack[ sp - op->narg ] ); sp -= op->narg; stack[sp] = &_stack[sp]; _stack[sp] = tmp; fixed[sp] = 1; rpf_st[sp] = &_rpf_st[sp]; rpf_st[sp]->type = TYPE_VALUE; rpf_st[sp]->value = &_stack[sp]; sp ++; } else { rpf_st[sp] = rpf; fixed[sp] = 0; sp ++; } break; } } rpf_new = &rpf_new_st; rpf_new->type = TYPE_START; for( i = 0; i < sp; i ++ ) { rpf_new = rpf_pushrpf( rpf_new, rpf_st[i] ); } formula_free( rpf ); return rpf_new_st.next; }