85 #include "ast_controller.h"
88 #include "auto_focus.h"
90 using namespace r_code;
94 template<
class U> ASTController<U>::ASTController(AutoFocusController *auto_focus, View *target) : OController(NULL) {
96 target_ = (_Fact *)target->object_;
97 tpx_ =
new CTPX(auto_focus, target);
98 thz_timestamp_ = Now() - Utils::GetTimeTolerance();
101 template<
class U> ASTController<U>::~ASTController() {
104 template<
class U>
void ASTController<U>::take_input(
r_exec::View *input) {
106 if (is_invalidated())
109 if (input->object_->code(0).asOpcode() == Opcodes::Fact ||
110 input->object_->code(0).asOpcode() == Opcodes::AntiFact) {
112 Goal *goal = ((_Fact *)input->object_)->get_goal();
113 if (goal && goal->get_actor() == _Mem::Get()->get_self())
115 if (input->get_ijt() >= thz_timestamp_)
116 Controller::__take_input<U>(input);
120 template<
class U>
void ASTController<U>::reduce(View *input) {
122 if (is_invalidated())
125 _Fact *input_object = input->object_;
126 if (input_object->is_invalidated()) {
128 reductionCS_.enter();
130 if (input_object == target_) {
132 tpx_->store_input(input);
133 reductionCS_.leave();
137 Pred *prediction = input_object->get_pred();
140 if (prediction->get_target()->is_fact()) {
141 switch (prediction->get_target()->is_timeless_evidence(target_)) {
142 case MATCH_SUCCESS_POSITIVE:
143 case MATCH_SUCCESS_NEGATIVE:
151 reductionCS_.leave();
154 ((U *)
this)->reduce(input, input_object);
156 reductionCS_.leave();
159 template<
class U>
void ASTController<U>::kill() {
162 get_view()->force_res(0);